Skip to content

Commit

Permalink
Update Luau to 0.609
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Jan 19, 2024
1 parent e7d58bd commit bf731a7
Show file tree
Hide file tree
Showing 50 changed files with 804 additions and 253 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.7.11+luau606"
version = "0.8.0+luau609"
authors = ["Aleksandr Orlenko <[email protected]>"]
edition = "2021"
repository = "https://github.com/khvzak/luau-src-rs"
Expand Down
12 changes: 12 additions & 0 deletions luau/Ast/include/Luau/Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,21 @@ struct AstDeclaredClassProp
bool isMethod = false;
};

enum class AstTableAccess
{
Read = 0b01,
Write = 0b10,
ReadWrite = 0b11,
};

struct AstTableIndexer
{
AstType* indexType;
AstType* resultType;
Location location;

AstTableAccess access = AstTableAccess::ReadWrite;
std::optional<Location> accessLocation;
};

class AstStatDeclareClass : public AstStat
Expand Down Expand Up @@ -915,6 +925,8 @@ struct AstTableProp
AstName name;
Location location;
AstType* type;
AstTableAccess access = AstTableAccess::ReadWrite;
std::optional<Location> accessLocation;
};

class AstTypeTable : public AstType
Expand Down
2 changes: 1 addition & 1 deletion luau/Ast/include/Luau/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Parser
std::optional<AstTypeList> parseOptionalReturnType();
std::pair<Location, AstTypeList> parseReturnType();

AstTableIndexer* parseTableIndexer();
AstTableIndexer* parseTableIndexer(AstTableAccess access, std::optional<Location> accessLocation);

AstTypeOrPack parseFunctionType(bool allowPack, bool isCheckedFunction = false);
AstType* parseFunctionTypeTail(const Lexeme& begin, AstArray<AstGenericType> generics, AstArray<AstGenericTypePack> genericPacks,
Expand Down
41 changes: 32 additions & 9 deletions luau/Ast/src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
// See docs/SyntaxChanges.md for an explanation.
LUAU_FASTFLAGVARIABLE(LuauClipExtraHasEndProps, false)
LUAU_FASTFLAG(LuauCheckedFunctionSyntax)
LUAU_FASTFLAGVARIABLE(LuauReadWritePropertySyntax, false)

namespace Luau
{
Expand Down Expand Up @@ -945,14 +946,14 @@ AstStat* Parser::parseDeclaration(const Location& start)
{
// maybe we don't need to parse the entire badIndexer...
// however, we either have { or [ to lint, not the entire table type or the bad indexer.
AstTableIndexer* badIndexer = parseTableIndexer();
AstTableIndexer* badIndexer = parseTableIndexer(AstTableAccess::ReadWrite, std::nullopt);

// we lose all additional indexer expressions from the AST after error recovery here
report(badIndexer->location, "Cannot have more than one class indexer");
}
else
{
indexer = parseTableIndexer();
indexer = parseTableIndexer(AstTableAccess::ReadWrite, std::nullopt);
}
}
else
Expand Down Expand Up @@ -1317,7 +1318,7 @@ std::pair<Location, AstTypeList> Parser::parseReturnType()
}

// TableIndexer ::= `[' Type `]' `:' Type
AstTableIndexer* Parser::parseTableIndexer()
AstTableIndexer* Parser::parseTableIndexer(AstTableAccess access, std::optional<Location> accessLocation)
{
const Lexeme begin = lexer.current();
nextLexeme(); // [
Expand All @@ -1330,7 +1331,7 @@ AstTableIndexer* Parser::parseTableIndexer()

AstType* result = parseType();

return allocator.alloc<AstTableIndexer>(AstTableIndexer{index, result, Location(begin.location, result->location)});
return allocator.alloc<AstTableIndexer>(AstTableIndexer{index, result, Location(begin.location, result->location), access, accessLocation});
}

// TableProp ::= Name `:' Type
Expand All @@ -1351,6 +1352,28 @@ AstType* Parser::parseTableType(bool inDeclarationContext)

while (lexer.current().type != '}')
{
AstTableAccess access = AstTableAccess::ReadWrite;
std::optional<Location> accessLocation;

if (FFlag::LuauReadWritePropertySyntax)
{
if (lexer.current().type == Lexeme::Name && lexer.lookahead().type != ':')
{
if (AstName(lexer.current().name) == "read")
{
accessLocation = lexer.current().location;
access = AstTableAccess::Read;
lexer.next();
}
else if (AstName(lexer.current().name) == "write")
{
accessLocation = lexer.current().location;
access = AstTableAccess::Write;
lexer.next();
}
}
}

if (lexer.current().type == '[' && (lexer.lookahead().type == Lexeme::RawString || lexer.lookahead().type == Lexeme::QuotedString))
{
const Lexeme begin = lexer.current();
Expand All @@ -1366,7 +1389,7 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
bool containsNull = chars && (strnlen(chars->data, chars->size) < chars->size);

if (chars && !containsNull)
props.push_back({AstName(chars->data), begin.location, type});
props.push_back(AstTableProp{AstName(chars->data), begin.location, type, access, accessLocation});
else
report(begin.location, "String literal contains malformed escape sequence or \\0");
}
Expand All @@ -1376,14 +1399,14 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
{
// maybe we don't need to parse the entire badIndexer...
// however, we either have { or [ to lint, not the entire table type or the bad indexer.
AstTableIndexer* badIndexer = parseTableIndexer();
AstTableIndexer* badIndexer = parseTableIndexer(access, accessLocation);

// we lose all additional indexer expressions from the AST after error recovery here
report(badIndexer->location, "Cannot have more than one table indexer");
}
else
{
indexer = parseTableIndexer();
indexer = parseTableIndexer(access, accessLocation);
}
}
else if (props.empty() && !indexer && !(lexer.current().type == Lexeme::Name && lexer.lookahead().type == ':'))
Expand All @@ -1392,7 +1415,7 @@ AstType* Parser::parseTableType(bool inDeclarationContext)

// array-like table type: {T} desugars into {[number]: T}
AstType* index = allocator.alloc<AstTypeReference>(type->location, std::nullopt, nameNumber, std::nullopt, type->location);
indexer = allocator.alloc<AstTableIndexer>(AstTableIndexer{index, type, type->location});
indexer = allocator.alloc<AstTableIndexer>(AstTableIndexer{index, type, type->location, access, accessLocation});

break;
}
Expand All @@ -1407,7 +1430,7 @@ AstType* Parser::parseTableType(bool inDeclarationContext)

AstType* type = parseType(inDeclarationContext);

props.push_back({name->name, name->location, type});
props.push_back(AstTableProp{name->name, name->location, type, access, accessLocation});
}

if (lexer.current().type == ',' || lexer.current().type == ';')
Expand Down
2 changes: 2 additions & 0 deletions luau/CodeGen/include/Luau/AssemblyBuilderA64.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class AssemblyBuilderA64

uint32_t getCodeSize() const;

unsigned getInstructionCount() const;

// Resulting data and code that need to be copied over one after the other
// The *end* of 'data' has to be aligned to 16 bytes, this will also align 'code'
std::vector<uint8_t> data;
Expand Down
4 changes: 4 additions & 0 deletions luau/CodeGen/include/Luau/AssemblyBuilderX64.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class AssemblyBuilderX64

uint32_t getCodeSize() const;

unsigned getInstructionCount() const;

// Resulting data and code that need to be copied over one after the other
// The *end* of 'data' has to be aligned to 16 bytes, this will also align 'code'
std::vector<uint8_t> data;
Expand Down Expand Up @@ -266,6 +268,8 @@ class AssemblyBuilderX64

uint8_t* codePos = nullptr;
uint8_t* codeEnd = nullptr;

unsigned instructionCount = 0;
};

} // namespace X64
Expand Down
19 changes: 17 additions & 2 deletions luau/CodeGen/include/Luau/CodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ struct AssemblyOptions
bool includeIr = false;
bool includeOutlinedCode = false;

bool includeIrPrefix = true; // "#" before IR blocks and instructions
bool includeUseInfo = true;
bool includeCfgInfo = true;
bool includeRegFlowInfo = true;

// Optional annotator function can be provided to describe each instruction, it takes function id and sequential instruction id
AnnotatorFn annotator = nullptr;
void* annotatorContext = nullptr;
Expand All @@ -102,13 +107,23 @@ struct BlockLinearizationStats
}
};

enum FunctionStatsFlags
{
// Enable stats collection per function
FunctionStats_Enable = 1 << 0,
// Compute function bytecode summary
FunctionStats_BytecodeSummary = 1 << 1,
};

struct FunctionStats
{
std::string name;
int line = -1;
unsigned bcodeCount = 0;
unsigned irCount = 0;
unsigned asmCount = 0;
unsigned asmSize = 0;
std::vector<std::vector<unsigned>> bytecodeSummary;
};

struct LoweringStats
Expand All @@ -127,7 +142,7 @@ struct LoweringStats

BlockLinearizationStats blockLinearizationStats;

bool collectFunctionStats = false;
unsigned functionStatsFlags = 0;
std::vector<FunctionStats> functions;

LoweringStats operator+(const LoweringStats& other) const
Expand All @@ -150,7 +165,7 @@ struct LoweringStats
this->regAllocErrors += that.regAllocErrors;
this->loweringErrors += that.loweringErrors;
this->blockLinearizationStats += that.blockLinearizationStats;
if (this->collectFunctionStats)
if (this->functionStatsFlags & FunctionStats_Enable)
this->functions.insert(this->functions.end(), that.functions.begin(), that.functions.end());
return *this;
}
Expand Down
42 changes: 14 additions & 28 deletions luau/CodeGen/include/Luau/IrData.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <stdint.h>
#include <string.h>

LUAU_FASTFLAG(LuauKeepVmapLinear2)

struct Proto;

namespace Luau
Expand Down Expand Up @@ -89,6 +87,11 @@ enum class IrCmd : uint8_t
// B: tag
STORE_TAG,

// Store an integer into the extra field of the TValue
// A: Rn
// B: int
STORE_EXTRA,

// Store a pointer (*) into TValue
// A: Rn
// B: pointer
Expand Down Expand Up @@ -129,7 +132,7 @@ enum class IrCmd : uint8_t
ADD_INT,
SUB_INT,

// Add/Sub/Mul/Div/Mod two double numbers
// Add/Sub/Mul/Div/Idiv/Mod two double numbers
// A, B: double
// In final x64 lowering, B can also be Rn or Kn
ADD_NUM,
Expand Down Expand Up @@ -964,7 +967,6 @@ struct IrFunction
// For each instruction, an operand that can be used to recompute the value
std::vector<IrOp> valueRestoreOps;
std::vector<uint32_t> validRestoreOpBlocks;
uint32_t validRestoreOpBlockIdx = 0;

Proto* proto = nullptr;
bool variadic = false;
Expand Down Expand Up @@ -1108,37 +1110,21 @@ struct IrFunction
if (instIdx >= valueRestoreOps.size())
return {};

if (FFlag::LuauKeepVmapLinear2)
// When spilled, values can only reference restore operands in the current block chain
if (limitToCurrentBlock)
{
// When spilled, values can only reference restore operands in the current block chain
if (limitToCurrentBlock)
for (uint32_t blockIdx : validRestoreOpBlocks)
{
for (uint32_t blockIdx : validRestoreOpBlocks)
{
const IrBlock& block = blocks[blockIdx];

if (instIdx >= block.start && instIdx <= block.finish)
return valueRestoreOps[instIdx];
}
const IrBlock& block = blocks[blockIdx];

return {};
if (instIdx >= block.start && instIdx <= block.finish)
return valueRestoreOps[instIdx];
}

return valueRestoreOps[instIdx];
return {};
}
else
{
const IrBlock& block = blocks[validRestoreOpBlockIdx];

// When spilled, values can only reference restore operands in the current block
if (limitToCurrentBlock)
{
if (instIdx < block.start || instIdx > block.finish)
return {};
}

return valueRestoreOps[instIdx];
}
return valueRestoreOps[instIdx];
}

IrOp findRestoreOp(const IrInst& inst, bool limitToCurrentBlock) const
Expand Down
3 changes: 2 additions & 1 deletion luau/CodeGen/include/Luau/IrDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void toString(std::string& result, IrConst constant);
void toString(std::string& result, const BytecodeTypes& bcTypes);

void toStringDetailed(IrToStringContext& ctx, const IrBlock& block, uint32_t blockIdx, const IrInst& inst, uint32_t instIdx, bool includeUseInfo);
void toStringDetailed(IrToStringContext& ctx, const IrBlock& block, uint32_t index, bool includeUseInfo); // Block title
void toStringDetailed(
IrToStringContext& ctx, const IrBlock& block, uint32_t blockIdx, bool includeUseInfo, bool includeCfgInfo, bool includeRegFlowInfo);

std::string toString(const IrFunction& function, bool includeUseInfo);

Expand Down
1 change: 1 addition & 0 deletions luau/CodeGen/include/Luau/IrVisitUseDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void visitVmRegDefsUses(T& visitor, IrFunction& function, const IrInst& i
visitor.maybeUse(inst.a); // Argument can also be a VmConst
break;
case IrCmd::STORE_TAG:
case IrCmd::STORE_EXTRA:
case IrCmd::STORE_POINTER:
case IrCmd::STORE_DOUBLE:
case IrCmd::STORE_INT:
Expand Down
5 changes: 5 additions & 0 deletions luau/CodeGen/src/AssemblyBuilderA64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,11 @@ uint32_t AssemblyBuilderA64::getCodeSize() const
return uint32_t(codePos - code.data());
}

unsigned AssemblyBuilderA64::getInstructionCount() const
{
return unsigned(getCodeSize()) / 4;
}

bool AssemblyBuilderA64::isMaskSupported(uint32_t mask)
{
int lz = countlz(mask);
Expand Down
Loading

0 comments on commit bf731a7

Please sign in to comment.