Skip to content

Commit 0e5b4bb

Browse files
committed
Bump Luau to 0.678
1 parent fea30f3 commit 0e5b4bb

24 files changed

+341
-46
lines changed

luau/Ast/include/Luau/Parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ class Parser
130130
// function funcname funcbody
131131
LUAU_FORCEINLINE AstStat* parseFunctionStat(const AstArray<AstAttr*>& attributes = {nullptr, 0});
132132

133-
std::pair<bool, AstAttr::Type> validateAttribute(const char* attributeName, const TempVector<AstAttr*>& attributes);
133+
std::pair<bool, AstAttr::Type> validateAttribute_DEPRECATED(const char* attributeName, const TempVector<AstAttr*>& attributes);
134+
std::optional<AstAttr::Type> validateAttribute(const char* attributeName, const TempVector<AstAttr*>& attributes);
134135

135136
// attribute ::= '@' NAME
136137
void parseAttribute(TempVector<AstAttr*>& attribute);

luau/Ast/src/Parser.cpp

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ LUAU_FASTFLAGVARIABLE(LuauParseStringIndexer)
2424
LUAU_FASTFLAGVARIABLE(LuauStoreReturnTypesAsPackOnAst)
2525
LUAU_FASTFLAGVARIABLE(LuauStoreLocalAnnotationColonPositions)
2626
LUAU_FASTFLAGVARIABLE(LuauCSTForReturnTypeFunctionTail)
27+
LUAU_FASTFLAGVARIABLE(LuauParseAttributeFixUninit)
2728
LUAU_DYNAMIC_FASTFLAGVARIABLE(DebugLuauReportReturnTypeVariadicWithTypeSuffix, false)
2829

2930
// Clip with DebugLuauReportReturnTypeVariadicWithTypeSuffix
@@ -808,8 +809,10 @@ AstStat* Parser::parseFunctionStat(const AstArray<AstAttr*>& attributes)
808809
}
809810

810811

811-
std::pair<bool, AstAttr::Type> Parser::validateAttribute(const char* attributeName, const TempVector<AstAttr*>& attributes)
812+
std::pair<bool, AstAttr::Type> Parser::validateAttribute_DEPRECATED(const char* attributeName, const TempVector<AstAttr*>& attributes)
812813
{
814+
LUAU_ASSERT(!FFlag::LuauParseAttributeFixUninit);
815+
813816
AstAttr::Type type;
814817

815818
// check if the attribute name is valid
@@ -848,20 +851,69 @@ std::pair<bool, AstAttr::Type> Parser::validateAttribute(const char* attributeNa
848851
return {found, type};
849852
}
850853

854+
std::optional<AstAttr::Type> Parser::validateAttribute(const char* attributeName, const TempVector<AstAttr*>& attributes)
855+
{
856+
LUAU_ASSERT(FFlag::LuauParseAttributeFixUninit);
857+
858+
// check if the attribute name is valid
859+
std::optional<AstAttr::Type> type;
860+
861+
for (int i = 0; kAttributeEntries[i].name; ++i)
862+
{
863+
if (strcmp(attributeName, kAttributeEntries[i].name) == 0)
864+
{
865+
type = kAttributeEntries[i].type;
866+
break;
867+
}
868+
}
869+
870+
if (!type)
871+
{
872+
if (strlen(attributeName) == 1)
873+
report(lexer.current().location, "Attribute name is missing");
874+
else
875+
report(lexer.current().location, "Invalid attribute '%s'", attributeName);
876+
}
877+
else
878+
{
879+
// check that attribute is not duplicated
880+
for (const AstAttr* attr : attributes)
881+
{
882+
if (attr->type == *type)
883+
report(lexer.current().location, "Cannot duplicate attribute '%s'", attributeName);
884+
}
885+
}
886+
887+
return type;
888+
}
889+
851890
// attribute ::= '@' NAME
852891
void Parser::parseAttribute(TempVector<AstAttr*>& attributes)
853892
{
854893
LUAU_ASSERT(lexer.current().type == Lexeme::Type::Attribute);
855894

856895
Location loc = lexer.current().location;
857896

858-
const char* name = lexer.current().name;
859-
const auto [found, type] = validateAttribute(name, attributes);
897+
if (FFlag::LuauParseAttributeFixUninit)
898+
{
899+
const char* name = lexer.current().name;
900+
std::optional<AstAttr::Type> type = validateAttribute(name, attributes);
901+
902+
nextLexeme();
860903

861-
nextLexeme();
904+
if (type)
905+
attributes.push_back(allocator.alloc<AstAttr>(loc, *type));
906+
}
907+
else
908+
{
909+
const char* name = lexer.current().name;
910+
const auto [found, type] = validateAttribute_DEPRECATED(name, attributes);
911+
912+
nextLexeme();
862913

863-
if (found)
864-
attributes.push_back(allocator.alloc<AstAttr>(loc, type));
914+
if (found)
915+
attributes.push_back(allocator.alloc<AstAttr>(loc, type));
916+
}
865917
}
866918

867919
// attributes ::= {attribute}

luau/CodeGen/include/Luau/IrBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct IrBuilder
4141

4242
IrOp constInt(int value);
4343
IrOp constUint(unsigned value);
44+
IrOp constImport(unsigned value);
4445
IrOp constDouble(double value);
4546
IrOp constTag(uint8_t value);
4647
IrOp constAny(IrConst constant, uint64_t asCommonKey);

luau/CodeGen/include/Luau/IrData.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,19 @@ enum class IrCmd : uint8_t
392392
// C: Rn or unsigned int (key)
393393
SET_TABLE,
394394

395+
// TODO: remove with FFlagLuauCodeGenSimplifyImport
395396
// Lookup a value in the environment
396397
// A: Rn (where to store the result)
397398
// B: unsigned int (import path)
398399
GET_IMPORT,
399400

401+
// Store an import from constant or the import path
402+
// A: Rn (where to store the result)
403+
// B: Kn
404+
// C: unsigned int (import path)
405+
// D: unsigned int (pcpos)
406+
GET_CACHED_IMPORT,
407+
400408
// Concatenate multiple TValues into a string
401409
// A: Rn (value start)
402410
// B: unsigned int (number of registers to go over)
@@ -763,6 +771,7 @@ enum class IrConstKind : uint8_t
763771
Uint,
764772
Double,
765773
Tag,
774+
Import,
766775
};
767776

768777
struct IrConst
@@ -1129,6 +1138,14 @@ struct IrFunction
11291138
return value.valueUint;
11301139
}
11311140

1141+
unsigned importOp(IrOp op)
1142+
{
1143+
IrConst& value = constOp(op);
1144+
1145+
CODEGEN_ASSERT(value.kind == IrConstKind::Import);
1146+
return value.valueUint;
1147+
}
1148+
11321149
std::optional<unsigned> asUintOp(IrOp op)
11331150
{
11341151
if (op.kind != IrOpKind::Constant)

luau/CodeGen/include/Luau/IrDump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void toString(IrToStringContext& ctx, const IrInst& inst, uint32_t index);
3232
void toString(IrToStringContext& ctx, const IrBlock& block, uint32_t index); // Block title
3333
void toString(IrToStringContext& ctx, IrOp op);
3434

35-
void toString(std::string& result, IrConst constant);
35+
void toString(std::string& result, Proto* proto, IrConst constant);
3636

3737
const char* getBytecodeTypeName(uint8_t type, const char* const* userdataTypes);
3838

luau/CodeGen/include/Luau/IrVisitUseDef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ static void visitVmRegDefsUses(T& visitor, IrFunction& function, const IrInst& i
6868
case IrCmd::GET_IMPORT:
6969
visitor.def(inst.a);
7070
break;
71+
case IrCmd::GET_CACHED_IMPORT:
72+
visitor.def(inst.a);
73+
break;
7174
case IrCmd::CONCAT:
7275
visitor.useRange(vmRegOp(inst.a), function.uintOp(inst.b));
7376

luau/CodeGen/src/CodeGenUtils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ Udata* newUserdata(lua_State* L, size_t s, int tag)
235235
return u;
236236
}
237237

238+
void getImport(lua_State* L, StkId res, unsigned id, unsigned pc)
239+
{
240+
Closure* cl = clvalue(L->ci->func);
241+
L->ci->savedpc = cl->l.p->code + pc;
242+
243+
luaV_getimport(L, cl->env, cl->l.p->k, res, id, /*propagatenil*/ false);
244+
}
245+
238246
// Extracted as-is from lvmexecute.cpp with the exception of control flow (reentry) and removed interrupts/savedpc
239247
Closure* callFallback(lua_State* L, StkId ra, StkId argtop, int nresults)
240248
{

luau/CodeGen/src/CodeGenUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Closure* callProlog(lua_State* L, TValue* ra, StkId argtop, int nresults);
1818
void callEpilogC(lua_State* L, int nresults, int n);
1919

2020
Udata* newUserdata(lua_State* L, size_t s, int tag);
21+
void getImport(lua_State* L, StkId res, unsigned id, unsigned pc);
2122

2223
#define CALL_FALLBACK_YIELD 1
2324

luau/CodeGen/src/IrBuilder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,14 @@ IrOp IrBuilder::constUint(unsigned value)
676676
return constAny(constant, uint64_t(value));
677677
}
678678

679+
IrOp IrBuilder::constImport(unsigned value)
680+
{
681+
IrConst constant;
682+
constant.kind = IrConstKind::Import;
683+
constant.valueUint = value;
684+
return constAny(constant, uint64_t(value));
685+
}
686+
679687
IrOp IrBuilder::constDouble(double value)
680688
{
681689
IrConst constant;

luau/CodeGen/src/IrDump.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ const char* getCmdName(IrCmd cmd)
251251
return "SET_TABLE";
252252
case IrCmd::GET_IMPORT:
253253
return "GET_IMPORT";
254+
case IrCmd::GET_CACHED_IMPORT:
255+
return "GET_CACHED_IMPORT";
254256
case IrCmd::CONCAT:
255257
return "CONCAT";
256258
case IrCmd::GET_UPVALUE:
@@ -501,7 +503,7 @@ void toString(IrToStringContext& ctx, IrOp op)
501503
append(ctx.result, "undef");
502504
break;
503505
case IrOpKind::Constant:
504-
toString(ctx.result, ctx.constants[op.index]);
506+
toString(ctx.result, ctx.proto, ctx.constants[op.index]);
505507
break;
506508
case IrOpKind::Condition:
507509
CODEGEN_ASSERT(op.index < uint32_t(IrCondition::Count));
@@ -539,7 +541,7 @@ void toString(IrToStringContext& ctx, IrOp op)
539541
}
540542
}
541543

542-
void toString(std::string& result, IrConst constant)
544+
void toString(std::string& result, Proto* proto, IrConst constant)
543545
{
544546
switch (constant.kind)
545547
{
@@ -558,6 +560,36 @@ void toString(std::string& result, IrConst constant)
558560
case IrConstKind::Tag:
559561
result.append(getTagName(constant.valueTag));
560562
break;
563+
case IrConstKind::Import:
564+
append(result, "%uu", constant.valueUint);
565+
566+
if (proto)
567+
{
568+
append(result, " (");
569+
570+
int count = constant.valueUint >> 30;
571+
int id0 = count > 0 ? int(constant.valueUint >> 20) & 1023 : -1;
572+
int id1 = count > 1 ? int(constant.valueUint >> 10) & 1023 : -1;
573+
int id2 = count > 2 ? int(constant.valueUint) & 1023 : -1;
574+
575+
if (id0 != -1)
576+
appendVmConstant(result, proto, id0);
577+
578+
if (id1 != -1)
579+
{
580+
append(result, ".");
581+
appendVmConstant(result, proto, id1);
582+
}
583+
584+
if (id2 != -1)
585+
{
586+
append(result, ".");
587+
appendVmConstant(result, proto, id2);
588+
}
589+
590+
append(result, ")");
591+
}
592+
break;
561593
}
562594
}
563595

0 commit comments

Comments
 (0)