Skip to content

Commit

Permalink
v0.10.2+luau635
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Jul 24, 2024
1 parent ba10589 commit 73ad680
Show file tree
Hide file tree
Showing 50 changed files with 1,177 additions and 1,845 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "luau0-src"
version = "0.10.1+luau630"
version = "0.10.2+luau635"
authors = ["Aleksandr Orlenko <[email protected]>"]
edition = "2021"
repository = "https://github.com/khvzak/luau-src-rs"
Expand Down
18 changes: 12 additions & 6 deletions luau/Ast/include/Luau/Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,12 @@ class AstStatDeclareGlobal : public AstStat
public:
LUAU_RTTI(AstStatDeclareGlobal)

AstStatDeclareGlobal(const Location& location, const AstName& name, AstType* type);
AstStatDeclareGlobal(const Location& location, const AstName& name, const Location& nameLocation, AstType* type);

void visit(AstVisitor* visitor) override;

AstName name;
Location nameLocation;
AstType* type;
};

Expand All @@ -839,13 +840,13 @@ class AstStatDeclareFunction : public AstStat
public:
LUAU_RTTI(AstStatDeclareFunction)

AstStatDeclareFunction(const Location& location, const AstName& name, const AstArray<AstGenericType>& generics,
const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params, const AstArray<AstArgumentName>& paramNames,
const AstTypeList& retTypes);
AstStatDeclareFunction(const Location& location, const AstName& name, const Location& nameLocation, const AstArray<AstGenericType>& generics,
const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params, const AstArray<AstArgumentName>& paramNames, bool vararg,
const Location& varargLocation, const AstTypeList& retTypes);

AstStatDeclareFunction(const Location& location, const AstArray<AstAttr*>& attributes, const AstName& name,
AstStatDeclareFunction(const Location& location, const AstArray<AstAttr*>& attributes, const AstName& name, const Location& nameLocation,
const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params,
const AstArray<AstArgumentName>& paramNames, const AstTypeList& retTypes);
const AstArray<AstArgumentName>& paramNames, bool vararg, const Location& varargLocation, const AstTypeList& retTypes);


void visit(AstVisitor* visitor) override;
Expand All @@ -854,18 +855,23 @@ class AstStatDeclareFunction : public AstStat

AstArray<AstAttr*> attributes;
AstName name;
Location nameLocation;
AstArray<AstGenericType> generics;
AstArray<AstGenericTypePack> genericPacks;
AstTypeList params;
AstArray<AstArgumentName> paramNames;
bool vararg = false;
Location varargLocation;
AstTypeList retTypes;
};

struct AstDeclaredClassProp
{
AstName name;
Location nameLocation;
AstType* ty = nullptr;
bool isMethod = false;
Location location;
};

enum class AstTableAccess
Expand Down
8 changes: 8 additions & 0 deletions luau/Ast/include/Luau/TimeTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ struct ThreadContext
static constexpr size_t kEventFlushLimit = 8192;
};

using ThreadContextProvider = ThreadContext& (*)();

inline ThreadContextProvider& threadContextProvider()
{
static ThreadContextProvider handler = nullptr;
return handler;
}

ThreadContext& getThreadContext();

struct Scope
Expand Down
19 changes: 13 additions & 6 deletions luau/Ast/src/Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,10 @@ void AstStatTypeAlias::visit(AstVisitor* visitor)
}
}

AstStatDeclareGlobal::AstStatDeclareGlobal(const Location& location, const AstName& name, AstType* type)
AstStatDeclareGlobal::AstStatDeclareGlobal(const Location& location, const AstName& name, const Location& nameLocation, AstType* type)
: AstStat(ClassIndex(), location)
, name(name)
, nameLocation(nameLocation)
, type(type)
{
}
Expand All @@ -718,30 +719,36 @@ void AstStatDeclareGlobal::visit(AstVisitor* visitor)
type->visit(visitor);
}

AstStatDeclareFunction::AstStatDeclareFunction(const Location& location, const AstName& name, const AstArray<AstGenericType>& generics,
const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params, const AstArray<AstArgumentName>& paramNames,
const AstTypeList& retTypes)
AstStatDeclareFunction::AstStatDeclareFunction(const Location& location, const AstName& name, const Location& nameLocation,
const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params,
const AstArray<AstArgumentName>& paramNames, bool vararg, const Location& varargLocation, const AstTypeList& retTypes)
: AstStat(ClassIndex(), location)
, attributes()
, name(name)
, nameLocation(nameLocation)
, generics(generics)
, genericPacks(genericPacks)
, params(params)
, paramNames(paramNames)
, vararg(vararg)
, varargLocation(varargLocation)
, retTypes(retTypes)
{
}

AstStatDeclareFunction::AstStatDeclareFunction(const Location& location, const AstArray<AstAttr*>& attributes, const AstName& name,
const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params,
const AstArray<AstArgumentName>& paramNames, const AstTypeList& retTypes)
const Location& nameLocation, const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks,
const AstTypeList& params, const AstArray<AstArgumentName>& paramNames, bool vararg, const Location& varargLocation, const AstTypeList& retTypes)
: AstStat(ClassIndex(), location)
, attributes(attributes)
, name(name)
, nameLocation(nameLocation)
, generics(generics)
, genericPacks(genericPacks)
, params(params)
, paramNames(paramNames)
, vararg(vararg)
, varargLocation(varargLocation)
, retTypes(retTypes)
{
}
Expand Down
91 changes: 69 additions & 22 deletions luau/Ast/src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ LUAU_FASTFLAG(LuauAttributeSyntax)
LUAU_FASTFLAGVARIABLE(LuauLeadingBarAndAmpersand2, false)
LUAU_FASTFLAGVARIABLE(LuauNativeAttribute, false)
LUAU_FASTFLAGVARIABLE(LuauAttributeSyntaxFunExpr, false)
LUAU_FASTFLAGVARIABLE(LuauDeclarationExtraPropData, false)

namespace Luau
{
Expand Down Expand Up @@ -796,7 +797,7 @@ AstStat* Parser::parseAttributeStat()
}
default:
return reportStatError(lexer.current().location, {}, {},
"Expected 'function', 'local function', 'declare function' or a function type declaration after attribute, but got %s intead",
"Expected 'function', 'local function', 'declare function' or a function type declaration after attribute, but got %s instead",
lexer.current().toString().c_str());
}
}
Expand Down Expand Up @@ -835,7 +836,7 @@ AstStat* Parser::parseLocal(const AstArray<AstAttr*>& attributes)
{
if (FFlag::LuauAttributeSyntax && attributes.size != 0)
{
return reportStatError(lexer.current().location, {}, {}, "Expected 'function' after local declaration with attribute, but got %s intead",
return reportStatError(lexer.current().location, {}, {}, "Expected 'function' after local declaration with attribute, but got %s instead",
lexer.current().toString().c_str());
}

Expand Down Expand Up @@ -909,8 +910,16 @@ AstStat* Parser::parseTypeAlias(const Location& start, bool exported)

AstDeclaredClassProp Parser::parseDeclaredClassMethod()
{
Location start;

if (FFlag::LuauDeclarationExtraPropData)
start = lexer.current().location;

nextLexeme();
Location start = lexer.current().location;

if (!FFlag::LuauDeclarationExtraPropData)
start = lexer.current().location;

Name fnName = parseName("function name");

// TODO: generic method declarations CLI-39909
Expand All @@ -935,15 +944,15 @@ AstDeclaredClassProp Parser::parseDeclaredClassMethod()
expectMatchAndConsume(')', matchParen);

AstTypeList retTypes = parseOptionalReturnType().value_or(AstTypeList{copy<AstType*>(nullptr, 0), nullptr});
Location end = lexer.current().location;
Location end = FFlag::LuauDeclarationExtraPropData ? lexer.previousLocation() : lexer.current().location;

TempVector<AstType*> vars(scratchType);
TempVector<std::optional<AstArgumentName>> varNames(scratchOptArgName);

if (args.size() == 0 || args[0].name.name != "self" || args[0].annotation != nullptr)
{
return AstDeclaredClassProp{
fnName.name, reportTypeError(Location(start, end), {}, "'self' must be present as the unannotated first parameter"), true};
return AstDeclaredClassProp{fnName.name, FFlag::LuauDeclarationExtraPropData ? fnName.location : Location{},
reportTypeError(Location(start, end), {}, "'self' must be present as the unannotated first parameter"), true};
}

// Skip the first index.
Expand All @@ -963,15 +972,16 @@ AstDeclaredClassProp Parser::parseDeclaredClassMethod()
AstType* fnType = allocator.alloc<AstTypeFunction>(
Location(start, end), generics, genericPacks, AstTypeList{copy(vars), varargAnnotation}, copy(varNames), retTypes);

return AstDeclaredClassProp{fnName.name, fnType, true};
return AstDeclaredClassProp{fnName.name, FFlag::LuauDeclarationExtraPropData ? fnName.location : Location{}, fnType, true,
FFlag::LuauDeclarationExtraPropData ? Location(start, end) : Location{}};
}

AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*>& attributes)
{
// `declare` token is already parsed at this point

if (FFlag::LuauAttributeSyntax && (attributes.size != 0) && (lexer.current().type != Lexeme::ReservedFunction))
return reportStatError(lexer.current().location, {}, {}, "Expected a function type declaration after attribute, but got %s intead",
return reportStatError(lexer.current().location, {}, {}, "Expected a function type declaration after attribute, but got %s instead",
lexer.current().toString().c_str());

if (lexer.current().type == Lexeme::ReservedFunction)
Expand Down Expand Up @@ -1014,8 +1024,12 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
if (vararg && !varargAnnotation)
return reportStatError(Location(start, end), {}, {}, "All declaration parameters must be annotated");

return allocator.alloc<AstStatDeclareFunction>(Location(start, end), attributes, globalName.name, generics, genericPacks,
AstTypeList{copy(vars), varargAnnotation}, copy(varNames), retTypes);
if (FFlag::LuauDeclarationExtraPropData)
return allocator.alloc<AstStatDeclareFunction>(Location(start, end), attributes, globalName.name, globalName.location, generics,
genericPacks, AstTypeList{copy(vars), varargAnnotation}, copy(varNames), vararg, varargLocation, retTypes);
else
return allocator.alloc<AstStatDeclareFunction>(Location(start, end), attributes, globalName.name, Location{}, generics, genericPacks,
AstTypeList{copy(vars), varargAnnotation}, copy(varNames), false, Location{}, retTypes);
}
else if (AstName(lexer.current().name) == "class")
{
Expand Down Expand Up @@ -1045,19 +1059,42 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
const Lexeme begin = lexer.current();
nextLexeme(); // [

std::optional<AstArray<char>> chars = parseCharArray();
if (FFlag::LuauDeclarationExtraPropData)
{
const Location nameBegin = lexer.current().location;
std::optional<AstArray<char>> chars = parseCharArray();

expectMatchAndConsume(']', begin);
expectAndConsume(':', "property type annotation");
AstType* type = parseType();
const Location nameEnd = lexer.previousLocation();

// since AstName contains a char*, it can't contain null
bool containsNull = chars && (strnlen(chars->data, chars->size) < chars->size);
expectMatchAndConsume(']', begin);
expectAndConsume(':', "property type annotation");
AstType* type = parseType();

if (chars && !containsNull)
props.push_back(AstDeclaredClassProp{AstName(chars->data), type, false});
// since AstName contains a char*, it can't contain null
bool containsNull = chars && (strnlen(chars->data, chars->size) < chars->size);

if (chars && !containsNull)
props.push_back(AstDeclaredClassProp{
AstName(chars->data), Location(nameBegin, nameEnd), type, false, Location(begin.location, lexer.previousLocation())});
else
report(begin.location, "String literal contains malformed escape sequence or \\0");
}
else
report(begin.location, "String literal contains malformed escape sequence or \\0");
{
std::optional<AstArray<char>> chars = parseCharArray();

expectMatchAndConsume(']', begin);
expectAndConsume(':', "property type annotation");
AstType* type = parseType();

// since AstName contains a char*, it can't contain null
bool containsNull = chars && (strnlen(chars->data, chars->size) < chars->size);

if (chars && !containsNull)
props.push_back(AstDeclaredClassProp{AstName(chars->data), Location{}, type, false});
else
report(begin.location, "String literal contains malformed escape sequence or \\0");
}
}
else if (lexer.current().type == '[')
{
Expand All @@ -1075,12 +1112,21 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
indexer = parseTableIndexer(AstTableAccess::ReadWrite, std::nullopt);
}
}
else if (FFlag::LuauDeclarationExtraPropData)
{
Location propStart = lexer.current().location;
Name propName = parseName("property name");
expectAndConsume(':', "property type annotation");
AstType* propType = parseType();
props.push_back(
AstDeclaredClassProp{propName.name, propName.location, propType, false, Location(propStart, lexer.previousLocation())});
}
else
{
Name propName = parseName("property name");
expectAndConsume(':', "property type annotation");
AstType* propType = parseType();
props.push_back(AstDeclaredClassProp{propName.name, propType, false});
props.push_back(AstDeclaredClassProp{propName.name, Location{}, propType, false});
}
}

Expand All @@ -1094,7 +1140,8 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
expectAndConsume(':', "global variable declaration");

AstType* type = parseType(/* in declaration context */ true);
return allocator.alloc<AstStatDeclareGlobal>(Location(start, type->location), globalName->name, type);
return allocator.alloc<AstStatDeclareGlobal>(
Location(start, type->location), globalName->name, FFlag::LuauDeclarationExtraPropData ? globalName->location : Location{}, type);
}
else
{
Expand Down Expand Up @@ -2391,7 +2438,7 @@ AstExpr* Parser::parseSimpleExpr()
if (lexer.current().type != Lexeme::ReservedFunction)
{
return reportExprError(
start, {}, "Expected 'function' declaration after attribute, but got %s intead", lexer.current().toString().c_str());
start, {}, "Expected 'function' declaration after attribute, but got %s instead", lexer.current().toString().c_str());
}
}

Expand Down
4 changes: 4 additions & 0 deletions luau/Ast/src/TimeTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ void flushEvents(GlobalContext& context, uint32_t threadId, const std::vector<Ev

ThreadContext& getThreadContext()
{
// Check custom provider that which might implement a custom TLS
if (auto provider = threadContextProvider())
return provider();

thread_local ThreadContext context;
return context;
}
Expand Down
18 changes: 11 additions & 7 deletions luau/CodeGen/include/Luau/IrData.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ enum class IrCmd : uint8_t
// A: double
ABS_NUM,

// Get the sign of the argument (math.sign)
// A: double
SIGN_NUM,

// Add/Sub/Mul/Div/Idiv two vectors
// A, B: TValue
ADD_VEC,
Expand Down Expand Up @@ -326,22 +330,22 @@ enum class IrCmd : uint8_t
// This is used to recover after calling a variadic function
ADJUST_STACK_TO_TOP,

// Execute fastcall builtin function in-place
// Execute fastcall builtin function with 1 argument in-place
// This is used for a few builtins that can have more than 1 result and cannot be represented as a regular instruction
// A: unsigned int (builtin id)
// B: Rn (result start)
// C: Rn (argument start)
// D: Rn or Kn or undef (optional second argument)
// E: int (argument count)
// F: int (result count)
// C: Rn (first argument)
// D: int (result count)
FASTCALL,

// Call the fastcall builtin function
// A: unsigned int (builtin id)
// B: Rn (result start)
// C: Rn (argument start)
// D: Rn or Kn or undef (optional second argument)
// E: int (argument count or -1 to use all arguments up to stack top)
// F: int (result count or -1 to preserve all results and adjust stack top)
// E: Rn or Kn or undef (optional third argument)
// F: int (argument count or -1 to use all arguments up to stack top)
// G: int (result count or -1 to preserve all results and adjust stack top)
INVOKE_FASTCALL,

// Check that fastcall builtin function invocation was successful (negative result count jumps to fallback)
Expand Down
2 changes: 0 additions & 2 deletions luau/CodeGen/include/Luau/IrDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ void toString(IrToStringContext& ctx, IrOp op);

void toString(std::string& result, IrConst constant);

const char* getBytecodeTypeName_DEPRECATED(uint8_t type);
const char* getBytecodeTypeName(uint8_t type, const char* const* userdataTypes);

void toString_DEPRECATED(std::string& result, const BytecodeTypes& bcTypes);
void toString(std::string& result, const BytecodeTypes& bcTypes, const char* const* userdataTypes);

void toStringDetailed(
Expand Down
Loading

0 comments on commit 73ad680

Please sign in to comment.