Skip to content

Commit ba10589

Browse files
committed
v0.10.1+luau630
1 parent b70db0f commit ba10589

21 files changed

+242
-36
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "luau0-src"
3-
version = "0.10.0+luau629"
3+
version = "0.10.1+luau630"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2021"
66
repository = "https://github.com/khvzak/luau-src-rs"

luau/Ast/include/Luau/Ast.h

+3
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class AstAttr : public AstNode
207207
enum Type
208208
{
209209
Checked,
210+
Native,
210211
};
211212

212213
AstAttr(const Location& location, Type type);
@@ -420,6 +421,8 @@ class AstExprFunction : public AstExpr
420421

421422
void visit(AstVisitor* visitor) override;
422423

424+
bool hasNativeAttribute() const;
425+
423426
AstArray<AstAttr*> attributes;
424427
AstArray<AstGenericType> generics;
425428
AstArray<AstGenericTypePack> genericPacks;

luau/Ast/include/Luau/Parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class Parser
234234
// asexp -> simpleexp [`::' Type]
235235
AstExpr* parseAssertionExpr();
236236

237-
// simpleexp -> NUMBER | STRING | NIL | true | false | ... | constructor | FUNCTION body | primaryexp
237+
// simpleexp -> NUMBER | STRING | NIL | true | false | ... | constructor | [attributes] FUNCTION body | primaryexp
238238
AstExpr* parseSimpleExpr();
239239

240240
// args ::= `(' [explist] `)' | tableconstructor | String

luau/Ast/src/Ast.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Luau/Common.h"
55

66
LUAU_FASTFLAG(LuauAttributeSyntax);
7+
LUAU_FASTFLAG(LuauNativeAttribute);
78

89
namespace Luau
910
{
@@ -214,6 +215,18 @@ void AstExprFunction::visit(AstVisitor* visitor)
214215
}
215216
}
216217

218+
bool AstExprFunction::hasNativeAttribute() const
219+
{
220+
LUAU_ASSERT(FFlag::LuauNativeAttribute);
221+
222+
for (const auto attribute : attributes)
223+
{
224+
if (attribute->type == AstAttr::Type::Native)
225+
return true;
226+
}
227+
return false;
228+
}
229+
217230
AstExprTable::AstExprTable(const Location& location, const AstArray<Item>& items)
218231
: AstExpr(ClassIndex(), location)
219232
, items(items)

luau/Ast/src/Parser.cpp

+29-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
1818
// See docs/SyntaxChanges.md for an explanation.
1919
LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false)
2020
LUAU_FASTFLAG(LuauAttributeSyntax)
21-
LUAU_FASTFLAGVARIABLE(LuauLeadingBarAndAmpersand, false)
21+
LUAU_FASTFLAGVARIABLE(LuauLeadingBarAndAmpersand2, false)
22+
LUAU_FASTFLAGVARIABLE(LuauNativeAttribute, false)
23+
LUAU_FASTFLAGVARIABLE(LuauAttributeSyntaxFunExpr, false)
2224

2325
namespace Luau
2426
{
@@ -29,7 +31,7 @@ struct AttributeEntry
2931
AstAttr::Type type;
3032
};
3133

32-
AttributeEntry kAttributeEntries[] = {{"@checked", AstAttr::Type::Checked}, {nullptr, AstAttr::Type::Checked}};
34+
AttributeEntry kAttributeEntries[] = {{"@checked", AstAttr::Type::Checked}, {"@native", AstAttr::Type::Native}, {nullptr, AstAttr::Type::Checked}};
3335

3436
ParseError::ParseError(const Location& location, const std::string& message)
3537
: location(location)
@@ -703,6 +705,10 @@ std::pair<bool, AstAttr::Type> Parser::validateAttribute(const char* attributeNa
703705
if (found)
704706
{
705707
type = kAttributeEntries[i].type;
708+
709+
if (!FFlag::LuauNativeAttribute && type == AstAttr::Type::Native)
710+
found = false;
711+
706712
break;
707713
}
708714
}
@@ -772,7 +778,7 @@ AstStat* Parser::parseAttributeStat()
772778
{
773779
LUAU_ASSERT(FFlag::LuauAttributeSyntax);
774780

775-
AstArray<AstAttr*> attributes = Parser::parseAttributes();
781+
AstArray<AstAttr*> attributes = parseAttributes();
776782

777783
Lexeme::Type type = lexer.current().type;
778784

@@ -1654,7 +1660,7 @@ AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin)
16541660
{
16551661
TempVector<AstType*> parts(scratchType);
16561662

1657-
if (!FFlag::LuauLeadingBarAndAmpersand || type != nullptr)
1663+
if (!FFlag::LuauLeadingBarAndAmpersand2 || type != nullptr)
16581664
{
16591665
parts.push_back(type);
16601666
}
@@ -1682,6 +1688,8 @@ AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin)
16821688
}
16831689
else if (c == '?')
16841690
{
1691+
LUAU_ASSERT(parts.size() >= 1);
1692+
16851693
Location loc = lexer.current().location;
16861694
nextLexeme();
16871695

@@ -1714,7 +1722,7 @@ AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin)
17141722
}
17151723

17161724
if (parts.size() == 1)
1717-
return type;
1725+
return FFlag::LuauLeadingBarAndAmpersand2 ? parts[0] : type;
17181726

17191727
if (isUnion && isIntersection)
17201728
{
@@ -1761,7 +1769,7 @@ AstType* Parser::parseType(bool inDeclarationContext)
17611769

17621770
Location begin = lexer.current().location;
17631771

1764-
if (FFlag::LuauLeadingBarAndAmpersand)
1772+
if (FFlag::LuauLeadingBarAndAmpersand2)
17651773
{
17661774
AstType* type = nullptr;
17671775

@@ -2369,11 +2377,24 @@ static ConstantNumberParseResult parseDouble(double& result, const char* data)
23692377
return ConstantNumberParseResult::Ok;
23702378
}
23712379

2372-
// simpleexp -> NUMBER | STRING | NIL | true | false | ... | constructor | FUNCTION body | primaryexp
2380+
// simpleexp -> NUMBER | STRING | NIL | true | false | ... | constructor | [attributes] FUNCTION body | primaryexp
23732381
AstExpr* Parser::parseSimpleExpr()
23742382
{
23752383
Location start = lexer.current().location;
23762384

2385+
AstArray<AstAttr*> attributes{nullptr, 0};
2386+
2387+
if (FFlag::LuauAttributeSyntax && FFlag::LuauAttributeSyntaxFunExpr && lexer.current().type == Lexeme::Attribute)
2388+
{
2389+
attributes = parseAttributes();
2390+
2391+
if (lexer.current().type != Lexeme::ReservedFunction)
2392+
{
2393+
return reportExprError(
2394+
start, {}, "Expected 'function' declaration after attribute, but got %s intead", lexer.current().toString().c_str());
2395+
}
2396+
}
2397+
23772398
if (lexer.current().type == Lexeme::ReservedNil)
23782399
{
23792400
nextLexeme();
@@ -2397,7 +2418,7 @@ AstExpr* Parser::parseSimpleExpr()
23972418
Lexeme matchFunction = lexer.current();
23982419
nextLexeme();
23992420

2400-
return parseFunctionBody(false, matchFunction, AstName(), nullptr, AstArray<AstAttr*>({nullptr, 0})).first;
2421+
return parseFunctionBody(false, matchFunction, AstName(), nullptr, attributes).first;
24012422
}
24022423
else if (lexer.current().type == Lexeme::Number)
24032424
{

luau/CodeGen/include/Luau/IrBuilder.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct IrBuilder
5454
IrOp inst(IrCmd cmd, IrOp a, IrOp b, IrOp c, IrOp d);
5555
IrOp inst(IrCmd cmd, IrOp a, IrOp b, IrOp c, IrOp d, IrOp e);
5656
IrOp inst(IrCmd cmd, IrOp a, IrOp b, IrOp c, IrOp d, IrOp e, IrOp f);
57+
IrOp inst(IrCmd cmd, IrOp a, IrOp b, IrOp c, IrOp d, IrOp e, IrOp f, IrOp g);
5758

5859
IrOp block(IrBlockKind kind); // Requested kind can be ignored if we are in an outlined sequence
5960
IrOp blockAtInst(uint32_t index);

luau/CodeGen/include/Luau/IrData.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum
3131
// * Rn - VM stack register slot, n in 0..254
3232
// * Kn - VM proto constant slot, n in 0..2^23-1
3333
// * UPn - VM function upvalue slot, n in 0..199
34-
// * A, B, C, D, E are instruction arguments
34+
// * A, B, C, D, E, F, G are instruction arguments
3535
enum class IrCmd : uint8_t
3636
{
3737
NOP,
@@ -869,6 +869,7 @@ struct IrInst
869869
IrOp d;
870870
IrOp e;
871871
IrOp f;
872+
IrOp g;
872873

873874
uint32_t lastUse = 0;
874875
uint16_t useCount = 0;
@@ -923,6 +924,7 @@ struct IrInstHash
923924
h = mix(h, key.d);
924925
h = mix(h, key.e);
925926
h = mix(h, key.f);
927+
h = mix(h, key.g);
926928

927929
// MurmurHash2 tail
928930
h ^= h >> 13;
@@ -937,7 +939,7 @@ struct IrInstEq
937939
{
938940
bool operator()(const IrInst& a, const IrInst& b) const
939941
{
940-
return a.cmd == b.cmd && a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d && a.e == b.e && a.f == b.f;
942+
return a.cmd == b.cmd && a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d && a.e == b.e && a.f == b.f && a.g == b.g;
941943
}
942944
};
943945

luau/CodeGen/include/Luau/IrVisitUseDef.h

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static void visitVmRegDefsUses(T& visitor, IrFunction& function, const IrInst& i
228228
CODEGEN_ASSERT(inst.d.kind != IrOpKind::VmReg);
229229
CODEGEN_ASSERT(inst.e.kind != IrOpKind::VmReg);
230230
CODEGEN_ASSERT(inst.f.kind != IrOpKind::VmReg);
231+
CODEGEN_ASSERT(inst.g.kind != IrOpKind::VmReg);
231232
break;
232233
}
233234
}

luau/CodeGen/src/BytecodeSummary.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "lobject.h"
99
#include "lstate.h"
1010

11+
LUAU_FASTFLAG(LuauNativeAttribute)
12+
1113
namespace Luau
1214
{
1315
namespace CodeGen
@@ -56,7 +58,10 @@ std::vector<FunctionBytecodeSummary> summarizeBytecode(lua_State* L, int idx, un
5658
Proto* root = clvalue(func)->l.p;
5759

5860
std::vector<Proto*> protos;
59-
gatherFunctions(protos, root, CodeGen_ColdFunctions);
61+
if (FFlag::LuauNativeAttribute)
62+
gatherFunctions(protos, root, CodeGen_ColdFunctions, root->flags & LPF_NATIVE_FUNCTION);
63+
else
64+
gatherFunctions_DEPRECATED(protos, root, CodeGen_ColdFunctions);
6065

6166
std::vector<FunctionBytecodeSummary> summaries;
6267
summaries.reserve(protos.size());

luau/CodeGen/src/CodeGenAssembly.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
LUAU_FASTFLAG(LuauCodegenTypeInfo)
1616
LUAU_FASTFLAG(LuauLoadUserdataInfo)
17+
LUAU_FASTFLAG(LuauNativeAttribute)
1718

1819
namespace Luau
1920
{
@@ -200,7 +201,10 @@ static std::string getAssemblyImpl(AssemblyBuilder& build, const TValue* func, A
200201
return std::string();
201202

202203
std::vector<Proto*> protos;
203-
gatherFunctions(protos, root, options.compilationOptions.flags);
204+
if (FFlag::LuauNativeAttribute)
205+
gatherFunctions(protos, root, options.compilationOptions.flags, root->flags & LPF_NATIVE_FUNCTION);
206+
else
207+
gatherFunctions_DEPRECATED(protos, root, options.compilationOptions.flags);
204208

205209
protos.erase(std::remove_if(protos.begin(), protos.end(),
206210
[](Proto* p) {

luau/CodeGen/src/CodeGenContext.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ LUAU_FASTFLAGVARIABLE(LuauCodegenCheckNullContext, false)
1616

1717
LUAU_FASTINTVARIABLE(LuauCodeGenBlockSize, 4 * 1024 * 1024)
1818
LUAU_FASTINTVARIABLE(LuauCodeGenMaxTotalSize, 256 * 1024 * 1024)
19+
LUAU_FASTFLAG(LuauNativeAttribute)
1920

2021
namespace Luau
2122
{
@@ -455,15 +456,18 @@ template<typename AssemblyBuilder>
455456

456457
Proto* root = clvalue(func)->l.p;
457458

458-
if ((options.flags & CodeGen_OnlyNativeModules) != 0 && (root->flags & LPF_NATIVE_MODULE) == 0)
459+
if ((options.flags & CodeGen_OnlyNativeModules) != 0 && (root->flags & LPF_NATIVE_MODULE) == 0 && (root->flags & LPF_NATIVE_FUNCTION) == 0)
459460
return CompilationResult{CodeGenCompilationResult::NotNativeModule};
460461

461462
BaseCodeGenContext* codeGenContext = getCodeGenContext(L);
462463
if (codeGenContext == nullptr)
463464
return CompilationResult{CodeGenCompilationResult::CodeGenNotInitialized};
464465

465466
std::vector<Proto*> protos;
466-
gatherFunctions(protos, root, options.flags);
467+
if (FFlag::LuauNativeAttribute)
468+
gatherFunctions(protos, root, options.flags, root->flags & LPF_NATIVE_FUNCTION);
469+
else
470+
gatherFunctions_DEPRECATED(protos, root, options.flags);
467471

468472
// Skip protos that have been compiled during previous invocations of CodeGen::compile
469473
protos.erase(std::remove_if(protos.begin(), protos.end(),

luau/CodeGen/src/CodeGenLower.h

+32-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ LUAU_FASTINT(CodegenHeuristicsBlockLimit)
2929
LUAU_FASTINT(CodegenHeuristicsBlockInstructionLimit)
3030
LUAU_FASTFLAG(LuauCodegenRemoveDeadStores5)
3131
LUAU_FASTFLAG(LuauLoadUserdataInfo)
32+
LUAU_FASTFLAG(LuauNativeAttribute)
3233

3334
namespace Luau
3435
{
3536
namespace CodeGen
3637
{
3738

38-
inline void gatherFunctions(std::vector<Proto*>& results, Proto* proto, unsigned int flags)
39+
inline void gatherFunctions_DEPRECATED(std::vector<Proto*>& results, Proto* proto, unsigned int flags)
3940
{
4041
if (results.size() <= size_t(proto->bytecodeid))
4142
results.resize(proto->bytecodeid + 1);
@@ -50,7 +51,36 @@ inline void gatherFunctions(std::vector<Proto*>& results, Proto* proto, unsigned
5051

5152
// Recursively traverse child protos even if we aren't compiling this one
5253
for (int i = 0; i < proto->sizep; i++)
53-
gatherFunctions(results, proto->p[i], flags);
54+
gatherFunctions_DEPRECATED(results, proto->p[i], flags);
55+
}
56+
57+
inline void gatherFunctionsHelper(
58+
std::vector<Proto*>& results, Proto* proto, const unsigned int flags, const bool hasNativeFunctions, const bool root)
59+
{
60+
if (results.size() <= size_t(proto->bytecodeid))
61+
results.resize(proto->bytecodeid + 1);
62+
63+
// Skip protos that we've already compiled in this run: this happens because at -O2, inlined functions get their protos reused
64+
if (results[proto->bytecodeid])
65+
return;
66+
67+
// if native module, compile cold functions if requested
68+
// if not native module, compile function if it has native attribute and is not root
69+
bool shouldGather = hasNativeFunctions ? (!root && (proto->flags & LPF_NATIVE_FUNCTION) != 0)
70+
: ((proto->flags & LPF_NATIVE_COLD) == 0 || (flags & CodeGen_ColdFunctions) != 0);
71+
72+
if (shouldGather)
73+
results[proto->bytecodeid] = proto;
74+
75+
// Recursively traverse child protos even if we aren't compiling this one
76+
for (int i = 0; i < proto->sizep; i++)
77+
gatherFunctionsHelper(results, proto->p[i], flags, hasNativeFunctions, false);
78+
}
79+
80+
inline void gatherFunctions(std::vector<Proto*>& results, Proto* root, const unsigned int flags, const bool hasNativeFunctions = false)
81+
{
82+
LUAU_ASSERT(FFlag::LuauNativeAttribute);
83+
gatherFunctionsHelper(results, root, flags, hasNativeFunctions, true);
5484
}
5585

5686
inline unsigned getInstructionCount(const std::vector<IrInst>& instructions, IrCmd cmd)

0 commit comments

Comments
 (0)