Skip to content

Commit 82b9c85

Browse files
committed
v0.9.2+luau628
1 parent a5b5504 commit 82b9c85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1111
-959
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.9.1+luau625"
3+
version = "0.9.2+luau628"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2021"
66
repository = "https://github.com/khvzak/luau-src-rs"

luau/Ast/src/Lexer.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <limits.h>
99

1010
LUAU_FASTFLAGVARIABLE(LuauLexerLookaheadRemembersBraceType, false)
11-
LUAU_FASTFLAGVARIABLE(LuauCheckedFunctionSyntax, false)
1211

1312
namespace Luau
1413
{
@@ -995,17 +994,14 @@ Lexeme Lexer::readNext()
995994
}
996995
case '@':
997996
{
998-
if (FFlag::LuauCheckedFunctionSyntax)
999-
{
1000-
// We're trying to lex the token @checked
1001-
LUAU_ASSERT(peekch() == '@');
997+
// We're trying to lex the token @checked
998+
LUAU_ASSERT(peekch() == '@');
1002999

1003-
std::pair<AstName, Lexeme::Type> maybeChecked = readName();
1004-
if (maybeChecked.second != Lexeme::ReservedChecked)
1005-
return Lexeme(Location(start, position()), Lexeme::Error);
1000+
std::pair<AstName, Lexeme::Type> maybeChecked = readName();
1001+
if (maybeChecked.second != Lexeme::ReservedChecked)
1002+
return Lexeme(Location(start, position()), Lexeme::Error);
10061003

1007-
return Lexeme(Location(start, position()), maybeChecked.second, maybeChecked.first.value);
1008-
}
1004+
return Lexeme(Location(start, position()), maybeChecked.second, maybeChecked.first.value);
10091005
}
10101006
default:
10111007
if (isDigit(peekch()))

luau/Ast/src/Parser.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
1616
// Warning: If you are introducing new syntax, ensure that it is behind a separate
1717
// flag so that we don't break production games by reverting syntax changes.
1818
// See docs/SyntaxChanges.md for an explanation.
19-
LUAU_FASTFLAG(LuauCheckedFunctionSyntax)
2019
LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false)
2120

2221
namespace Luau
@@ -838,7 +837,7 @@ AstStat* Parser::parseDeclaration(const Location& start)
838837
{
839838
nextLexeme();
840839
bool checkedFunction = false;
841-
if (FFlag::LuauCheckedFunctionSyntax && lexer.current().type == Lexeme::ReservedChecked)
840+
if (lexer.current().type == Lexeme::ReservedChecked)
842841
{
843842
checkedFunction = true;
844843
nextLexeme();
@@ -1731,9 +1730,8 @@ AstTypeOrPack Parser::parseSimpleType(bool allowPack, bool inDeclarationContext)
17311730
{
17321731
return {parseTableType(/* inDeclarationContext */ inDeclarationContext), {}};
17331732
}
1734-
else if (FFlag::LuauCheckedFunctionSyntax && inDeclarationContext && lexer.current().type == Lexeme::ReservedChecked)
1733+
else if (inDeclarationContext && lexer.current().type == Lexeme::ReservedChecked)
17351734
{
1736-
LUAU_ASSERT(FFlag::LuauCheckedFunctionSyntax);
17371735
nextLexeme();
17381736
return parseFunctionType(allowPack, /* isCheckedFunction */ true);
17391737
}

luau/CodeGen/include/Luau/CodeGen.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
struct lua_State;
1414

15+
#if defined(__x86_64__) || defined(_M_X64)
16+
#define CODEGEN_TARGET_X64
17+
#elif defined(__aarch64__) || defined(_M_ARM64)
18+
#define CODEGEN_TARGET_A64
19+
#endif
20+
1521
namespace Luau
1622
{
1723
namespace CodeGen
@@ -86,7 +92,7 @@ struct HostIrHooks
8692
// Guards should take a VM exit to 'pcpos'
8793
HostVectorAccessHandler vectorAccess = nullptr;
8894

89-
// Handle namecalled performed on a vector value
95+
// Handle namecall performed on a vector value
9096
// 'sourceReg' (self argument) is guaranteed to be a vector
9197
// All other arguments can be of any type
9298
// Guards should take a VM exit to 'pcpos'
@@ -97,6 +103,9 @@ struct CompilationOptions
97103
{
98104
unsigned int flags = 0;
99105
HostIrHooks hooks;
106+
107+
// null-terminated array of userdata types names that might have custom lowering
108+
const char* const* userdataTypes = nullptr;
100109
};
101110

102111
struct CompilationStats
@@ -138,8 +147,17 @@ using UniqueSharedCodeGenContext = std::unique_ptr<SharedCodeGenContext, SharedC
138147
// SharedCodeGenContext must be destroyed before this function is called.
139148
void destroySharedCodeGenContext(const SharedCodeGenContext* codeGenContext) noexcept;
140149

141-
void create(lua_State* L, AllocationCallback* allocationCallback, void* allocationCallbackContext);
150+
// Initializes native code-gen on the provided Luau VM, using a VM-specific
151+
// code-gen context and either the default allocator parameters or custom
152+
// allocator parameters.
142153
void create(lua_State* L);
154+
void create(lua_State* L, AllocationCallback* allocationCallback, void* allocationCallbackContext);
155+
void create(lua_State* L, size_t blockSize, size_t maxTotalSize, AllocationCallback* allocationCallback, void* allocationCallbackContext);
156+
157+
// Initializes native code-gen on the provided Luau VM, using the provided
158+
// SharedCodeGenContext. Note that after this function is called, the
159+
// SharedCodeGenContext must not be destroyed until after the Luau VM L is
160+
// destroyed via lua_close.
143161
void create(lua_State* L, SharedCodeGenContext* codeGenContext);
144162

145163
// Check if native execution is enabled
@@ -148,6 +166,12 @@ void create(lua_State* L, SharedCodeGenContext* codeGenContext);
148166
// Enable or disable native execution according to `enabled` argument
149167
void setNativeExecutionEnabled(lua_State* L, bool enabled);
150168

169+
// Given a name, this function must return the index of the type which matches the type array used all CompilationOptions and AssemblyOptions
170+
// If the type is unknown, 0xff has to be returned
171+
using UserdataRemapperCallback = uint8_t(void* context, const char* name, size_t nameLength);
172+
173+
void setUserdataRemapper(lua_State* L, void* context, UserdataRemapperCallback cb);
174+
151175
using ModuleId = std::array<uint8_t, 16>;
152176

153177
// Builds target function and all inner functions

luau/CodeGen/include/Luau/IrDump.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ void toString(IrToStringContext& ctx, IrOp op);
3131

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

34-
const char* getBytecodeTypeName(uint8_t type);
34+
const char* getBytecodeTypeName_DEPRECATED(uint8_t type);
35+
const char* getBytecodeTypeName(uint8_t type, const char* const* userdataTypes);
3536

36-
void toString(std::string& result, const BytecodeTypes& bcTypes);
37+
void toString_DEPRECATED(std::string& result, const BytecodeTypes& bcTypes);
38+
void toString(std::string& result, const BytecodeTypes& bcTypes, const char* const* userdataTypes);
3739

3840
void toStringDetailed(
3941
IrToStringContext& ctx, const IrBlock& block, uint32_t blockIdx, const IrInst& inst, uint32_t instIdx, IncludeUseInfo includeUseInfo);

luau/CodeGen/include/Luau/IrUtils.h

+4
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ IrValueKind getCmdValueKind(IrCmd cmd);
241241

242242
bool isGCO(uint8_t tag);
243243

244+
// Optional bit has to be cleared at call site, otherwise, this will return 'false' for 'userdata?'
245+
bool isUserdataBytecodeType(uint8_t ty);
246+
bool isCustomUserdataBytecodeType(uint8_t ty);
247+
244248
// Manually add or remove use of an operand
245249
void addUse(IrFunction& function, IrOp op);
246250
void removeUse(IrFunction& function, IrOp op);

luau/CodeGen/include/Luau/UnwindBuilder.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace CodeGen
1616
{
1717

1818
// This value is used in 'finishFunction' to mark the function that spans to the end of the whole code block
19-
static uint32_t kFullBlockFuncton = ~0u;
19+
static uint32_t kFullBlockFunction = ~0u;
2020

2121
class UnwindBuilder
2222
{
@@ -52,11 +52,10 @@ class UnwindBuilder
5252
virtual void prologueX64(uint32_t prologueSize, uint32_t stackSize, bool setupFrame, std::initializer_list<X64::RegisterX64> gpr,
5353
const std::vector<X64::RegisterX64>& simd) = 0;
5454

55-
virtual size_t getSize() const = 0;
56-
virtual size_t getFunctionCount() const = 0;
55+
virtual size_t getUnwindInfoSize(size_t blockSize) const = 0;
5756

5857
// This will place the unwinding data at the target address and might update values of some fields
59-
virtual void finalize(char* target, size_t offset, void* funcAddress, size_t funcSize) const = 0;
58+
virtual size_t finalize(char* target, size_t offset, void* funcAddress, size_t blockSize) const = 0;
6059
};
6160

6261
} // namespace CodeGen

luau/CodeGen/include/Luau/UnwindBuilderDwarf2.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ class UnwindBuilderDwarf2 : public UnwindBuilder
3333
void prologueX64(uint32_t prologueSize, uint32_t stackSize, bool setupFrame, std::initializer_list<X64::RegisterX64> gpr,
3434
const std::vector<X64::RegisterX64>& simd) override;
3535

36-
size_t getSize() const override;
37-
size_t getFunctionCount() const override;
36+
size_t getUnwindInfoSize(size_t blockSize = 0) const override;
3837

39-
void finalize(char* target, size_t offset, void* funcAddress, size_t funcSize) const override;
38+
size_t finalize(char* target, size_t offset, void* funcAddress, size_t blockSize) const override;
4039

4140
private:
4241
size_t beginOffset = 0;

luau/CodeGen/include/Luau/UnwindBuilderWin.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ class UnwindBuilderWin : public UnwindBuilder
5353
void prologueX64(uint32_t prologueSize, uint32_t stackSize, bool setupFrame, std::initializer_list<X64::RegisterX64> gpr,
5454
const std::vector<X64::RegisterX64>& simd) override;
5555

56-
size_t getSize() const override;
57-
size_t getFunctionCount() const override;
56+
size_t getUnwindInfoSize(size_t blockSize = 0) const override;
5857

59-
void finalize(char* target, size_t offset, void* funcAddress, size_t funcSize) const override;
58+
size_t finalize(char* target, size_t offset, void* funcAddress, size_t blockSize) const override;
6059

6160
private:
6261
size_t beginOffset = 0;

luau/CodeGen/src/BytecodeAnalysis.cpp

+31-69
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212
#include <algorithm>
1313

14-
#include <algorithm>
15-
1614
LUAU_FASTFLAG(LuauCodegenDirectUserdataFlow)
1715
LUAU_FASTFLAG(LuauLoadTypeInfo) // Because new VM typeinfo load changes the format used by Codegen, same flag is used
1816
LUAU_FASTFLAGVARIABLE(LuauCodegenTypeInfo, false) // New analysis is flagged separately
19-
LUAU_FASTFLAG(LuauTypeInfoLookupImprovement)
20-
LUAU_FASTFLAGVARIABLE(LuauCodegenVectorMispredictFix, false)
2117
LUAU_FASTFLAGVARIABLE(LuauCodegenAnalyzeHostVectorOps, false)
2218
LUAU_FASTFLAGVARIABLE(LuauCodegenLoadTypeUpvalCheck, false)
2319

@@ -70,21 +66,13 @@ void loadBytecodeTypeInfo(IrFunction& function)
7066

7167
Proto* proto = function.proto;
7268

73-
if (FFlag::LuauTypeInfoLookupImprovement)
74-
{
75-
if (!proto)
76-
return;
77-
}
78-
else
79-
{
80-
if (!proto || !proto->typeinfo)
81-
return;
82-
}
69+
if (!proto)
70+
return;
8371

8472
BytecodeTypeInfo& typeInfo = function.bcTypeInfo;
8573

8674
// If there is no typeinfo, we generate default values for arguments and upvalues
87-
if (FFlag::LuauTypeInfoLookupImprovement && !proto->typeinfo)
75+
if (!proto->typeinfo)
8876
{
8977
typeInfo.argumentTypes.resize(proto->numparams, LBC_TYPE_ANY);
9078
typeInfo.upvalueTypes.resize(proto->nups, LBC_TYPE_ANY);
@@ -152,8 +140,6 @@ void loadBytecodeTypeInfo(IrFunction& function)
152140

153141
static void prepareRegTypeInfoLookups(BytecodeTypeInfo& typeInfo)
154142
{
155-
CODEGEN_ASSERT(FFlag::LuauTypeInfoLookupImprovement);
156-
157143
// Sort by register first, then by end PC
158144
std::sort(typeInfo.regTypes.begin(), typeInfo.regTypes.end(), [](const BytecodeRegTypeInfo& a, const BytecodeRegTypeInfo& b) {
159145
if (a.reg != b.reg)
@@ -188,39 +174,26 @@ static BytecodeRegTypeInfo* findRegType(BytecodeTypeInfo& info, uint8_t reg, int
188174
{
189175
CODEGEN_ASSERT(FFlag::LuauCodegenTypeInfo);
190176

191-
if (FFlag::LuauTypeInfoLookupImprovement)
192-
{
193-
auto b = info.regTypes.begin() + info.regTypeOffsets[reg];
194-
auto e = info.regTypes.begin() + info.regTypeOffsets[reg + 1];
195-
196-
// Doen't have info
197-
if (b == e)
198-
return nullptr;
177+
auto b = info.regTypes.begin() + info.regTypeOffsets[reg];
178+
auto e = info.regTypes.begin() + info.regTypeOffsets[reg + 1];
199179

200-
// No info after the last live range
201-
if (pc >= (e - 1)->endpc)
202-
return nullptr;
203-
204-
for (auto it = b; it != e; ++it)
205-
{
206-
CODEGEN_ASSERT(it->reg == reg);
207-
208-
if (pc >= it->startpc && pc < it->endpc)
209-
return &*it;
210-
}
180+
// Doen't have info
181+
if (b == e)
182+
return nullptr;
211183

184+
// No info after the last live range
185+
if (pc >= (e - 1)->endpc)
212186
return nullptr;
213-
}
214-
else
187+
188+
for (auto it = b; it != e; ++it)
215189
{
216-
for (BytecodeRegTypeInfo& el : info.regTypes)
217-
{
218-
if (reg == el.reg && pc >= el.startpc && pc < el.endpc)
219-
return &el;
220-
}
190+
CODEGEN_ASSERT(it->reg == reg);
221191

222-
return nullptr;
192+
if (pc >= it->startpc && pc < it->endpc)
193+
return &*it;
223194
}
195+
196+
return nullptr;
224197
}
225198

226199
static void refineRegType(BytecodeTypeInfo& info, uint8_t reg, int pc, uint8_t ty)
@@ -235,7 +208,7 @@ static void refineRegType(BytecodeTypeInfo& info, uint8_t reg, int pc, uint8_t t
235208
if (regType->type == LBC_TYPE_ANY)
236209
regType->type = ty;
237210
}
238-
else if (FFlag::LuauTypeInfoLookupImprovement && reg < info.argumentTypes.size())
211+
else if (reg < info.argumentTypes.size())
239212
{
240213
if (info.argumentTypes[reg] == LBC_TYPE_ANY)
241214
info.argumentTypes[reg] = ty;
@@ -629,8 +602,7 @@ void analyzeBytecodeTypes(IrFunction& function, const HostIrHooks& hostHooks)
629602

630603
BytecodeTypeInfo& bcTypeInfo = function.bcTypeInfo;
631604

632-
if (FFlag::LuauTypeInfoLookupImprovement)
633-
prepareRegTypeInfoLookups(bcTypeInfo);
605+
prepareRegTypeInfoLookups(bcTypeInfo);
634606

635607
// Setup our current knowledge of type tags based on arguments
636608
uint8_t regTags[256];
@@ -788,32 +760,22 @@ void analyzeBytecodeTypes(IrFunction& function, const HostIrHooks& hostHooks)
788760

789761
regTags[ra] = LBC_TYPE_ANY;
790762

791-
if (FFlag::LuauCodegenVectorMispredictFix)
763+
if (bcType.a == LBC_TYPE_VECTOR)
792764
{
793-
if (bcType.a == LBC_TYPE_VECTOR)
794-
{
795-
TString* str = gco2ts(function.proto->k[kc].value.gc);
796-
const char* field = getstr(str);
797-
798-
if (str->len == 1)
799-
{
800-
// Same handling as LOP_GETTABLEKS block in lvmexecute.cpp - case-insensitive comparison with "X" / "Y" / "Z"
801-
char ch = field[0] | ' ';
765+
TString* str = gco2ts(function.proto->k[kc].value.gc);
766+
const char* field = getstr(str);
802767

803-
if (ch == 'x' || ch == 'y' || ch == 'z')
804-
regTags[ra] = LBC_TYPE_NUMBER;
805-
}
768+
if (str->len == 1)
769+
{
770+
// Same handling as LOP_GETTABLEKS block in lvmexecute.cpp - case-insensitive comparison with "X" / "Y" / "Z"
771+
char ch = field[0] | ' ';
806772

807-
if (FFlag::LuauCodegenAnalyzeHostVectorOps && regTags[ra] == LBC_TYPE_ANY && hostHooks.vectorAccessBytecodeType)
808-
regTags[ra] = hostHooks.vectorAccessBytecodeType(field, str->len);
773+
if (ch == 'x' || ch == 'y' || ch == 'z')
774+
regTags[ra] = LBC_TYPE_NUMBER;
809775
}
810-
}
811-
else
812-
{
813-
// Assuming that vector component is being indexed
814-
// TODO: check what key is used
815-
if (bcType.a == LBC_TYPE_VECTOR)
816-
regTags[ra] = LBC_TYPE_NUMBER;
776+
777+
if (FFlag::LuauCodegenAnalyzeHostVectorOps && regTags[ra] == LBC_TYPE_ANY && hostHooks.vectorAccessBytecodeType)
778+
regTags[ra] = hostHooks.vectorAccessBytecodeType(field, str->len);
817779
}
818780

819781
bcType.result = regTags[ra];

0 commit comments

Comments
 (0)