Skip to content

Commit a5b5504

Browse files
committed
v0.9.1+luau625
1 parent 6b8c97e commit a5b5504

14 files changed

+202
-65
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "luau0-src"
3-
version = "0.9.0+luau624"
3+
version = "0.9.1+luau625"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2021"
66
repository = "https://github.com/khvzak/luau-src-rs"

luau/Ast/src/Parser.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
1717
// flag so that we don't break production games by reverting syntax changes.
1818
// See docs/SyntaxChanges.md for an explanation.
1919
LUAU_FASTFLAG(LuauCheckedFunctionSyntax)
20-
LUAU_FASTFLAGVARIABLE(LuauReadWritePropertySyntax, false)
2120
LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false)
2221

2322
namespace Luau
@@ -1340,22 +1339,19 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
13401339
AstTableAccess access = AstTableAccess::ReadWrite;
13411340
std::optional<Location> accessLocation;
13421341

1343-
if (FFlag::LuauReadWritePropertySyntax || FFlag::DebugLuauDeferredConstraintResolution)
1342+
if (lexer.current().type == Lexeme::Name && lexer.lookahead().type != ':')
13441343
{
1345-
if (lexer.current().type == Lexeme::Name && lexer.lookahead().type != ':')
1344+
if (AstName(lexer.current().name) == "read")
13461345
{
1347-
if (AstName(lexer.current().name) == "read")
1348-
{
1349-
accessLocation = lexer.current().location;
1350-
access = AstTableAccess::Read;
1351-
lexer.next();
1352-
}
1353-
else if (AstName(lexer.current().name) == "write")
1354-
{
1355-
accessLocation = lexer.current().location;
1356-
access = AstTableAccess::Write;
1357-
lexer.next();
1358-
}
1346+
accessLocation = lexer.current().location;
1347+
access = AstTableAccess::Read;
1348+
lexer.next();
1349+
}
1350+
else if (AstName(lexer.current().name) == "write")
1351+
{
1352+
accessLocation = lexer.current().location;
1353+
access = AstTableAccess::Write;
1354+
lexer.next();
13591355
}
13601356
}
13611357

luau/CodeGen/include/Luau/BytecodeAnalysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ namespace CodeGen
1313
{
1414

1515
struct IrFunction;
16+
struct HostIrHooks;
1617

1718
void loadBytecodeTypeInfo(IrFunction& function);
1819
void buildBytecodeBlocks(IrFunction& function, const std::vector<uint8_t>& jumpTargets);
19-
void analyzeBytecodeTypes(IrFunction& function);
20+
void analyzeBytecodeTypes(IrFunction& function, const HostIrHooks& hostHooks);
2021

2122
} // namespace CodeGen
2223
} // namespace Luau

luau/CodeGen/include/Luau/CodeGen.h

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,39 @@ struct CompilationResult
6666
}
6767
};
6868

69+
struct IrBuilder;
70+
71+
using HostVectorOperationBytecodeType = uint8_t (*)(const char* member, size_t memberLength);
72+
using HostVectorAccessHandler = bool (*)(IrBuilder& builder, const char* member, size_t memberLength, int resultReg, int sourceReg, int pcpos);
73+
using HostVectorNamecallHandler = bool (*)(
74+
IrBuilder& builder, const char* member, size_t memberLength, int argResReg, int sourceReg, int params, int results, int pcpos);
75+
76+
struct HostIrHooks
77+
{
78+
// Suggest result type of a vector field access
79+
HostVectorOperationBytecodeType vectorAccessBytecodeType = nullptr;
80+
81+
// Suggest result type of a vector function namecall
82+
HostVectorOperationBytecodeType vectorNamecallBytecodeType = nullptr;
83+
84+
// Handle vector value field access
85+
// 'sourceReg' is guaranteed to be a vector
86+
// Guards should take a VM exit to 'pcpos'
87+
HostVectorAccessHandler vectorAccess = nullptr;
88+
89+
// Handle namecalled performed on a vector value
90+
// 'sourceReg' (self argument) is guaranteed to be a vector
91+
// All other arguments can be of any type
92+
// Guards should take a VM exit to 'pcpos'
93+
HostVectorNamecallHandler vectorNamecall = nullptr;
94+
};
95+
96+
struct CompilationOptions
97+
{
98+
unsigned int flags = 0;
99+
HostIrHooks hooks;
100+
};
101+
69102
struct CompilationStats
70103
{
71104
size_t bytecodeSizeBytes = 0;
@@ -118,8 +151,11 @@ void setNativeExecutionEnabled(lua_State* L, bool enabled);
118151
using ModuleId = std::array<uint8_t, 16>;
119152

120153
// Builds target function and all inner functions
121-
CompilationResult compile(lua_State* L, int idx, unsigned int flags = 0, CompilationStats* stats = nullptr);
122-
CompilationResult compile(const ModuleId& moduleId, lua_State* L, int idx, unsigned int flags = 0, CompilationStats* stats = nullptr);
154+
CompilationResult compile(lua_State* L, int idx, unsigned int flags, CompilationStats* stats = nullptr);
155+
CompilationResult compile(const ModuleId& moduleId, lua_State* L, int idx, unsigned int flags, CompilationStats* stats = nullptr);
156+
157+
CompilationResult compile(lua_State* L, int idx, const CompilationOptions& options, CompilationStats* stats = nullptr);
158+
CompilationResult compile(const ModuleId& moduleId, lua_State* L, int idx, const CompilationOptions& options, CompilationStats* stats = nullptr);
123159

124160
using AnnotatorFn = void (*)(void* context, std::string& result, int fid, int instpos);
125161

@@ -164,7 +200,7 @@ struct AssemblyOptions
164200

165201
Target target = Host;
166202

167-
unsigned int flags = 0;
203+
CompilationOptions compilationOptions;
168204

169205
bool outputBinary = false;
170206

luau/CodeGen/include/Luau/IrBuilder.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ namespace Luau
1616
namespace CodeGen
1717
{
1818

19-
struct AssemblyOptions;
19+
struct HostIrHooks;
2020

2121
struct IrBuilder
2222
{
23-
IrBuilder();
23+
IrBuilder(const HostIrHooks& hostHooks);
2424

2525
void buildFunctionIr(Proto* proto);
2626

@@ -64,13 +64,17 @@ struct IrBuilder
6464

6565
IrOp vmExit(uint32_t pcpos);
6666

67+
const HostIrHooks& hostHooks;
68+
6769
bool inTerminatedBlock = false;
6870

6971
bool interruptRequested = false;
7072

7173
bool activeFastcallFallback = false;
7274
IrOp fastcallFallbackReturn;
73-
int fastcallSkipTarget = -1;
75+
76+
// Force builder to skip source commands
77+
int cmdSkipTarget = -1;
7478

7579
IrFunction function;
7680

luau/CodeGen/src/BytecodeAnalysis.cpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "Luau/BytecodeAnalysis.h"
33

44
#include "Luau/BytecodeUtils.h"
5+
#include "Luau/CodeGen.h"
56
#include "Luau/IrData.h"
67
#include "Luau/IrUtils.h"
78

@@ -17,6 +18,8 @@ LUAU_FASTFLAG(LuauLoadTypeInfo) // Because new VM typeinfo loa
1718
LUAU_FASTFLAGVARIABLE(LuauCodegenTypeInfo, false) // New analysis is flagged separately
1819
LUAU_FASTFLAG(LuauTypeInfoLookupImprovement)
1920
LUAU_FASTFLAGVARIABLE(LuauCodegenVectorMispredictFix, false)
21+
LUAU_FASTFLAGVARIABLE(LuauCodegenAnalyzeHostVectorOps, false)
22+
LUAU_FASTFLAGVARIABLE(LuauCodegenLoadTypeUpvalCheck, false)
2023

2124
namespace Luau
2225
{
@@ -95,7 +98,10 @@ void loadBytecodeTypeInfo(IrFunction& function)
9598
uint32_t upvalCount = readVarInt(data, offset);
9699
uint32_t localCount = readVarInt(data, offset);
97100

98-
CODEGEN_ASSERT(upvalCount == unsigned(proto->nups));
101+
if (!FFlag::LuauCodegenLoadTypeUpvalCheck)
102+
{
103+
CODEGEN_ASSERT(upvalCount == unsigned(proto->nups));
104+
}
99105

100106
if (typeSize != 0)
101107
{
@@ -114,6 +120,11 @@ void loadBytecodeTypeInfo(IrFunction& function)
114120

115121
if (upvalCount != 0)
116122
{
123+
if (FFlag::LuauCodegenLoadTypeUpvalCheck)
124+
{
125+
CODEGEN_ASSERT(upvalCount == unsigned(proto->nups));
126+
}
127+
117128
typeInfo.upvalueTypes.resize(upvalCount);
118129

119130
uint8_t* types = (uint8_t*)data + offset;
@@ -611,7 +622,7 @@ void buildBytecodeBlocks(IrFunction& function, const std::vector<uint8_t>& jumpT
611622
}
612623
}
613624

614-
void analyzeBytecodeTypes(IrFunction& function)
625+
void analyzeBytecodeTypes(IrFunction& function, const HostIrHooks& hostHooks)
615626
{
616627
Proto* proto = function.proto;
617628
CODEGEN_ASSERT(proto);
@@ -662,6 +673,8 @@ void analyzeBytecodeTypes(IrFunction& function)
662673
for (int i = proto->numparams; i < proto->maxstacksize; ++i)
663674
regTags[i] = LBC_TYPE_ANY;
664675

676+
LuauBytecodeType knownNextCallResult = LBC_TYPE_ANY;
677+
665678
for (int i = block.startpc; i <= block.finishpc;)
666679
{
667680
const Instruction* pc = &proto->code[i];
@@ -790,6 +803,9 @@ void analyzeBytecodeTypes(IrFunction& function)
790803
if (ch == 'x' || ch == 'y' || ch == 'z')
791804
regTags[ra] = LBC_TYPE_NUMBER;
792805
}
806+
807+
if (FFlag::LuauCodegenAnalyzeHostVectorOps && regTags[ra] == LBC_TYPE_ANY && hostHooks.vectorAccessBytecodeType)
808+
regTags[ra] = hostHooks.vectorAccessBytecodeType(field, str->len);
793809
}
794810
}
795811
else
@@ -1161,6 +1177,34 @@ void analyzeBytecodeTypes(IrFunction& function)
11611177
regTags[ra + 1] = bcType.a;
11621178

11631179
bcType.result = LBC_TYPE_FUNCTION;
1180+
1181+
if (FFlag::LuauCodegenAnalyzeHostVectorOps && bcType.a == LBC_TYPE_VECTOR && hostHooks.vectorNamecallBytecodeType)
1182+
{
1183+
TString* str = gco2ts(function.proto->k[kc].value.gc);
1184+
const char* field = getstr(str);
1185+
1186+
knownNextCallResult = LuauBytecodeType(hostHooks.vectorNamecallBytecodeType(field, str->len));
1187+
}
1188+
}
1189+
break;
1190+
}
1191+
case LOP_CALL:
1192+
{
1193+
if (FFlag::LuauCodegenAnalyzeHostVectorOps)
1194+
{
1195+
int ra = LUAU_INSN_A(*pc);
1196+
1197+
if (knownNextCallResult != LBC_TYPE_ANY)
1198+
{
1199+
bcType.result = knownNextCallResult;
1200+
1201+
knownNextCallResult = LBC_TYPE_ANY;
1202+
1203+
regTags[ra] = bcType.result;
1204+
}
1205+
1206+
if (FFlag::LuauCodegenTypeInfo)
1207+
refineRegType(bcTypeInfo, ra, i, bcType.result);
11641208
}
11651209
break;
11661210
}
@@ -1199,7 +1243,6 @@ void analyzeBytecodeTypes(IrFunction& function)
11991243
}
12001244
case LOP_GETGLOBAL:
12011245
case LOP_SETGLOBAL:
1202-
case LOP_CALL:
12031246
case LOP_RETURN:
12041247
case LOP_JUMP:
12051248
case LOP_JUMPBACK:

luau/CodeGen/src/CodeGen.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ static void logPerfFunction(Proto* p, uintptr_t addr, unsigned size)
201201
}
202202

203203
template<typename AssemblyBuilder>
204-
static std::optional<OldNativeProto> createNativeFunction(
205-
AssemblyBuilder& build, ModuleHelpers& helpers, Proto* proto, uint32_t& totalIrInstCount, CodeGenCompilationResult& result)
204+
static std::optional<OldNativeProto> createNativeFunction(AssemblyBuilder& build, ModuleHelpers& helpers, Proto* proto, uint32_t& totalIrInstCount,
205+
const HostIrHooks& hooks, CodeGenCompilationResult& result)
206206
{
207207
CODEGEN_ASSERT(!FFlag::LuauCodegenContext);
208208

209-
IrBuilder ir;
209+
IrBuilder ir(hooks);
210210
ir.buildFunctionIr(proto);
211211

212212
unsigned instCount = unsigned(ir.function.instructions.size());
@@ -476,7 +476,7 @@ void setNativeExecutionEnabled(lua_State* L, bool enabled)
476476
}
477477
}
478478

479-
static CompilationResult compile_OLD(lua_State* L, int idx, unsigned int flags, CompilationStats* stats)
479+
static CompilationResult compile_OLD(lua_State* L, int idx, const CompilationOptions& options, CompilationStats* stats)
480480
{
481481
CompilationResult compilationResult;
482482

@@ -485,7 +485,7 @@ static CompilationResult compile_OLD(lua_State* L, int idx, unsigned int flags,
485485

486486
Proto* root = clvalue(func)->l.p;
487487

488-
if ((flags & CodeGen_OnlyNativeModules) != 0 && (root->flags & LPF_NATIVE_MODULE) == 0)
488+
if ((options.flags & CodeGen_OnlyNativeModules) != 0 && (root->flags & LPF_NATIVE_MODULE) == 0)
489489
{
490490
compilationResult.result = CodeGenCompilationResult::NotNativeModule;
491491
return compilationResult;
@@ -500,7 +500,7 @@ static CompilationResult compile_OLD(lua_State* L, int idx, unsigned int flags,
500500
}
501501

502502
std::vector<Proto*> protos;
503-
gatherFunctions(protos, root, flags);
503+
gatherFunctions(protos, root, options.flags);
504504

505505
// Skip protos that have been compiled during previous invocations of CodeGen::compile
506506
protos.erase(std::remove_if(protos.begin(), protos.end(),
@@ -541,7 +541,7 @@ static CompilationResult compile_OLD(lua_State* L, int idx, unsigned int flags,
541541
{
542542
CodeGenCompilationResult protoResult = CodeGenCompilationResult::Success;
543543

544-
if (std::optional<OldNativeProto> np = createNativeFunction(build, helpers, p, totalIrInstCount, protoResult))
544+
if (std::optional<OldNativeProto> np = createNativeFunction(build, helpers, p, totalIrInstCount, options.hooks, protoResult))
545545
results.push_back(*np);
546546
else
547547
compilationResult.protoFailures.push_back({protoResult, p->debugname ? getstr(p->debugname) : "", p->linedefined});
@@ -618,21 +618,43 @@ static CompilationResult compile_OLD(lua_State* L, int idx, unsigned int flags,
618618

619619
CompilationResult compile(lua_State* L, int idx, unsigned int flags, CompilationStats* stats)
620620
{
621+
Luau::CodeGen::CompilationOptions options{flags};
622+
621623
if (FFlag::LuauCodegenContext)
622624
{
623-
return compile_NEW(L, idx, flags, stats);
625+
return compile_NEW(L, idx, options, stats);
624626
}
625627
else
626628
{
627-
return compile_OLD(L, idx, flags, stats);
629+
return compile_OLD(L, idx, options, stats);
628630
}
629631
}
630632

631633
CompilationResult compile(const ModuleId& moduleId, lua_State* L, int idx, unsigned int flags, CompilationStats* stats)
632634
{
633635
CODEGEN_ASSERT(FFlag::LuauCodegenContext);
634636

635-
return compile_NEW(moduleId, L, idx, flags, stats);
637+
Luau::CodeGen::CompilationOptions options{flags};
638+
return compile_NEW(moduleId, L, idx, options, stats);
639+
}
640+
641+
CompilationResult compile(lua_State* L, int idx, const CompilationOptions& options, CompilationStats* stats)
642+
{
643+
if (FFlag::LuauCodegenContext)
644+
{
645+
return compile_NEW(L, idx, options, stats);
646+
}
647+
else
648+
{
649+
return compile_OLD(L, idx, options, stats);
650+
}
651+
}
652+
653+
CompilationResult compile(const ModuleId& moduleId, lua_State* L, int idx, const CompilationOptions& options, CompilationStats* stats)
654+
{
655+
CODEGEN_ASSERT(FFlag::LuauCodegenContext);
656+
657+
return compile_NEW(moduleId, L, idx, options, stats);
636658
}
637659

638660
void setPerfLog(void* context, PerfLogFn logFn)

luau/CodeGen/src/CodeGenAssembly.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ static std::string getAssemblyImpl(AssemblyBuilder& build, const TValue* func, A
183183
{
184184
Proto* root = clvalue(func)->l.p;
185185

186-
if ((options.flags & CodeGen_OnlyNativeModules) != 0 && (root->flags & LPF_NATIVE_MODULE) == 0)
186+
if ((options.compilationOptions.flags & CodeGen_OnlyNativeModules) != 0 && (root->flags & LPF_NATIVE_MODULE) == 0)
187187
return std::string();
188188

189189
std::vector<Proto*> protos;
190-
gatherFunctions(protos, root, options.flags);
190+
gatherFunctions(protos, root, options.compilationOptions.flags);
191191

192192
protos.erase(std::remove_if(protos.begin(), protos.end(),
193193
[](Proto* p) {
@@ -215,7 +215,7 @@ static std::string getAssemblyImpl(AssemblyBuilder& build, const TValue* func, A
215215

216216
for (Proto* p : protos)
217217
{
218-
IrBuilder ir;
218+
IrBuilder ir(options.compilationOptions.hooks);
219219
ir.buildFunctionIr(p);
220220
unsigned asmSize = build.getCodeSize();
221221
unsigned asmCount = build.getInstructionCount();

0 commit comments

Comments
 (0)