Skip to content

Commit 70d93d0

Browse files
committed
v0.22.0+luau740
1 parent e627013 commit 70d93d0

43 files changed

Lines changed: 802 additions & 526 deletions

Some content is hidden

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

‎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.22.0+luau739"
3+
version = "0.22.0+luau740"
44
authors = ["Aleksandr Orlenko <zxteam@protonmail.com>"]
55
edition = "2024"
66
repository = "https://github.com/mlua-rs/luau-src-rs"

‎luau/Ast/include/Luau/Ast.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,12 +1262,13 @@ class AstTypeTable : public AstType
12621262
public:
12631263
LUAU_RTTI(AstTypeTable)
12641264

1265-
AstTypeTable(const Location& location, const AstArray<AstTableProp>& props, AstTableIndexer* indexer = nullptr);
1265+
AstTypeTable(const Location& location, const AstArray<AstTableProp>& props, AstTableIndexer* indexer = nullptr, bool isExact = false);
12661266

12671267
void visit(AstVisitor* visitor) override;
12681268

12691269
AstArray<AstTableProp> props;
12701270
AstTableIndexer* indexer;
1271+
bool isExact = false;
12711272
};
12721273

12731274
class AstTypeFunction : public AstType

‎luau/Ast/src/Ast.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "Luau/Common.h"
55

6+
LUAU_FASTFLAG(LuauExperimentalIfLocalSyntax)
67

78
namespace Luau
89
{
@@ -549,6 +550,9 @@ void AstExprIfElse::visit(AstVisitor* visitor)
549550
{
550551
if (visitor->visit(this))
551552
{
553+
if (FFlag::LuauExperimentalIfLocalSyntax && conditionLocal && conditionLocal->annotation)
554+
conditionLocal->annotation->visit(visitor);
555+
552556
condition->visit(visitor);
553557
trueExpr->visit(visitor);
554558
falseExpr->visit(visitor);
@@ -666,6 +670,9 @@ void AstStatIf::visit(AstVisitor* visitor)
666670
{
667671
if (visitor->visit(this))
668672
{
673+
if (FFlag::LuauExperimentalIfLocalSyntax && conditionLocal && conditionLocal->annotation)
674+
conditionLocal->annotation->visit(visitor);
675+
669676
condition->visit(visitor);
670677
thenbody->visit(visitor);
671678

@@ -1203,10 +1210,11 @@ void AstTypeReference::visit(AstVisitor* visitor)
12031210
}
12041211
}
12051212

1206-
AstTypeTable::AstTypeTable(const Location& location, const AstArray<AstTableProp>& props, AstTableIndexer* indexer)
1213+
AstTypeTable::AstTypeTable(const Location& location, const AstArray<AstTableProp>& props, AstTableIndexer* indexer, bool isExact)
12071214
: AstType(ClassIndex(), location)
12081215
, props(props)
12091216
, indexer(indexer)
1217+
, isExact(isExact)
12101218
{
12111219
}
12121220

‎luau/Ast/src/Parser.cpp‎

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
#include "Luau/TimeTrace.h"
77

88
#include <algorithm>
9+
#include <unordered_set>
910

1011
#include <errno.h>
1112
#include <limits.h>
13+
#include <stdlib.h>
1214
#include <string.h>
13-
#include <unordered_set>
1415

1516
LUAU_FASTINTVARIABLE(LuauRecursionLimit, 1000)
1617
LUAU_FASTINTVARIABLE(LuauTypeLengthLimit, 1000)
@@ -23,14 +24,16 @@ LUAU_FASTFLAGVARIABLE(LuauSolverV2)
2324
LUAU_DYNAMIC_FASTFLAGVARIABLE(DebugLuauReportReturnTypeVariadicWithTypeSuffix, false)
2425
LUAU_FASTFLAGVARIABLE(LuauIntegerType2)
2526
LUAU_FASTFLAGVARIABLE(LuauExportValueSyntax)
26-
LUAU_FLAGVERSION(LuauExportValueSyntax, 4)
27+
LUAU_FLAGVERSION(LuauExportValueSyntax, 5)
2728

2829
LUAU_FASTFLAGVARIABLE(DebugLuauNoInline)
2930
LUAU_FASTFLAGVARIABLE(DebugLuauUserDefinedClasses)
3031
LUAU_FASTFLAGVARIABLE(LuauAllowGlobalDeclarationToBeCalledClass)
3132
LUAU_FASTFLAGVARIABLE(LuauNoDuplicateBinaryPrefix)
3233
LUAU_FASTFLAGVARIABLE(LuauSingleTypeOptionalPackReturnsAttributeParens)
33-
LUAU_FASTFLAGVARIABLE(DebugLuauIfLocalSyntax)
34+
LUAU_FASTFLAGVARIABLE(DebugLuauParseExactTables)
35+
LUAU_FASTFLAGVARIABLE(LuauExperimentalIfLocalSyntax)
36+
LUAU_FLAGVERSION(LuauExperimentalIfLocalSyntax, 2)
3437

3538
// Clip with DebugLuauReportReturnTypeVariadicWithTypeSuffix
3639
bool luau_telemetry_parsed_return_type_variadic_with_type_suffix = false;
@@ -579,9 +582,14 @@ AstStat* Parser::parseIf()
579582

580583
nextLexeme(); // if / elseif
581584

582-
if (FFlag::DebugLuauIfLocalSyntax &&
583-
(lexer.current().type == Lexeme::ReservedLocal || (lexer.current().type == Lexeme::Name && AstName(lexer.current().name) == "const")))
584-
return parseIfLocalCondition(start);
585+
if (FFlag::LuauExperimentalIfLocalSyntax)
586+
{
587+
if (lexer.current().type == Lexeme::ReservedLocal)
588+
return parseIfLocalCondition(start);
589+
590+
if (lexer.current().type == Lexeme::Name && AstName(lexer.current().name) == "const" && lexer.lookahead().type == Lexeme::Name)
591+
return parseIfLocalCondition(start);
592+
}
585593

586594
AstExpr* cond = parseExpr();
587595

@@ -606,7 +614,7 @@ AstStat* Parser::parseIf()
606614
// consumed `if`/`elseif` keyword; the current lexeme is the `local`/`const` keyword.
607615
LUAU_NOINLINE AstStat* Parser::parseIfLocalCondition(const Location& start)
608616
{
609-
LUAU_ASSERT(FFlag::DebugLuauIfLocalSyntax);
617+
LUAU_ASSERT(FFlag::LuauExperimentalIfLocalSyntax);
610618

611619
bool condIsConst = (lexer.current().type == Lexeme::Name && AstName(lexer.current().name) == "const");
612620
std::optional<Location> condKeywordLocation = lexer.current().location;
@@ -649,7 +657,13 @@ LUAU_NOINLINE AstStat* Parser::parseIfLocalCondition(const Location& start)
649657
return node;
650658
}
651659

652-
AstStat* Parser::parseElseBody(const Location& start, const Lexeme& matchThen, AstStatBlock* thenbody, Location& end, std::optional<Location>& elseLocation)
660+
AstStat* Parser::parseElseBody(
661+
const Location& start,
662+
const Lexeme& matchThen,
663+
AstStatBlock* thenbody,
664+
Location& end,
665+
std::optional<Location>& elseLocation
666+
)
653667
{
654668
AstStat* elsebody = nullptr;
655669
end = start;
@@ -1347,7 +1361,8 @@ AstStat* Parser::parseLocal(
13471361

13481362
Location location{start.begin, body->location.end};
13491363

1350-
AstStatLocalFunction* node = allocator.alloc<AstStatLocalFunction>(location, var, body, isConst, isConst ? keywordPosition : Position::missing());
1364+
AstStatLocalFunction* node =
1365+
allocator.alloc<AstStatLocalFunction>(location, var, body, isConst, isConst ? keywordPosition : Position::missing());
13511366
if (options.storeCstData)
13521367
{
13531368
cstNodeMap[node] = cstAttrLists != nullptr
@@ -1591,14 +1606,10 @@ LUAU_NOINLINE AstStat* Parser::parseClassStat(const Location& start, bool export
15911606
propType = parseType();
15921607
}
15931608

1594-
if (propName->name == "new")
1595-
report(propName->location, "Class properties cannot be named 'new'. Define a method named '__init' to define a constructor.");
1596-
else if (strncmp(propName->name.value, "__", 2) == 0)
1609+
if (strncmp(propName->name.value, "__", 2) == 0)
15971610
report(propName->location, "Class properties cannot start with '__'");
15981611
else if (classMemberNamespace.contains(propName->name))
1599-
{
16001612
report(propName->location, "Duplicate class member '%s'", propName->name.value);
1601-
}
16021613
else
16031614
{
16041615
classMemberNamespace.insert(propName->name);
@@ -1643,9 +1654,7 @@ LUAU_NOINLINE AstStat* Parser::parseClassStat(const Location& start, bool export
16431654
if (body->args.size > 0 && body->args.data[0]->name == "self" && body->args.data[0]->annotation != nullptr)
16441655
report(body->args.data[0]->annotation->location, "The 'self' parameter cannot have a type annotation");
16451656

1646-
if (name.name == "new")
1647-
report(name.location, "Class methods cannot be named 'new'. Name it '__init' to define a constructor.");
1648-
else if (strncmp(name.name.value, "__", 2) == 0)
1657+
if (strncmp(name.name.value, "__", 2) == 0)
16491658
{
16501659
if (kExplicitlyDisallowedMetamethods.count(name.name.value) > 0)
16511660
report(name.location, "Classes cannot define '%s' as a metamethod", name.name.value);
@@ -2801,12 +2810,22 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
28012810
expectAndConsume('{', "table type");
28022811

28032812
bool isArray = false;
2813+
// When the flag is set, tables are exact by default unless ... is present at the end.
2814+
bool isExact = FFlag::DebugLuauParseExactTables;
28042815

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

2821+
if (FFlag::DebugLuauParseExactTables && lexer.current().type == Lexeme::Dot3)
2822+
{
2823+
nextLexeme();
2824+
isExact = false;
2825+
// ... is always last.
2826+
break;
2827+
}
2828+
28102829
if (lexer.current().type == Lexeme::Name && lexer.lookahead().type != ':')
28112830
{
28122831
if (AstName(lexer.current().name) == "read")
@@ -2913,6 +2932,17 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
29132932
Location nullTypeLocation = Location(start.begin, 0);
29142933
AstType* index = allocator.alloc<AstTypeReference>(nullTypeLocation, std::nullopt, nameNumber, std::nullopt, nullTypeLocation);
29152934
indexer = allocator.alloc<AstTableIndexer>(AstTableIndexer{index, type, type->location, access, accessLocation});
2935+
2936+
if (FFlag::DebugLuauParseExactTables)
2937+
{
2938+
if (lexer.current().type == ',' && lexer.lookahead().type == Lexeme::Dot3)
2939+
{
2940+
nextLexeme();
2941+
nextLexeme();
2942+
isExact = false;
2943+
}
2944+
}
2945+
29162946
break;
29172947
}
29182948
else
@@ -2960,7 +2990,7 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
29602990
if (!expectMatchAndConsume('}', matchBrace, /* searchForMissing = */ true))
29612991
end = lexer.previousLocation();
29622992

2963-
AstTypeTable* node = allocator.alloc<AstTypeTable>(Location(start, end), copy(props), indexer);
2993+
AstTypeTable* node = allocator.alloc<AstTypeTable>(Location(start, end), copy(props), indexer, isExact);
29642994
if (options.storeCstData)
29652995
cstNodeMap[node] = allocator.alloc<CstTypeTable>(copy(cstItems), isArray);
29662996
return node;
@@ -4414,9 +4444,14 @@ AstExpr* Parser::parseIfElseExpr()
44144444

44154445
nextLexeme(); // skip if / elseif
44164446

4417-
if (FFlag::DebugLuauIfLocalSyntax &&
4418-
(lexer.current().type == Lexeme::ReservedLocal || (lexer.current().type == Lexeme::Name && AstName(lexer.current().name) == "const")))
4419-
return parseIfElseExprLocalCondition(start);
4447+
if (FFlag::LuauExperimentalIfLocalSyntax)
4448+
{
4449+
if (lexer.current().type == Lexeme::ReservedLocal)
4450+
return parseIfElseExprLocalCondition(start);
4451+
4452+
if (lexer.current().type == Lexeme::Name && AstName(lexer.current().name) == "const" && lexer.lookahead().type == Lexeme::Name)
4453+
return parseIfElseExprLocalCondition(start);
4454+
}
44204455

44214456
AstExpr* condition = parseExpr();
44224457

@@ -4445,7 +4480,7 @@ AstExpr* Parser::parseIfElseExpr()
44454480
// consumed `if`/`elseif` keyword; the current lexeme is the `local`/`const` keyword.
44464481
LUAU_NOINLINE AstExpr* Parser::parseIfElseExprLocalCondition(const Location& start)
44474482
{
4448-
LUAU_ASSERT(FFlag::DebugLuauIfLocalSyntax);
4483+
LUAU_ASSERT(FFlag::LuauExperimentalIfLocalSyntax);
44494484

44504485
bool condIsConst = (lexer.current().type == Lexeme::Name && AstName(lexer.current().name) == "const");
44514486
std::optional<Location> condKeywordLocation = lexer.current().location;

‎luau/Ast/src/PrettyPrinter.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
LUAU_FASTFLAG(DebugLuauUserDefinedClasses)
1414
LUAU_FASTFLAG(LuauExportValueSyntax)
1515
LUAU_FASTFLAGVARIABLE(LuauPrettyPrintVisualizeIndexerAccess)
16-
LUAU_FASTFLAG(DebugLuauIfLocalSyntax)
16+
LUAU_FASTFLAG(LuauExperimentalIfLocalSyntax)
1717

1818
namespace
1919
{
@@ -1547,7 +1547,7 @@ struct Printer
15471547

15481548
void visualizeElseIf(AstStatIf& elseif)
15491549
{
1550-
if (FFlag::DebugLuauIfLocalSyntax && elseif.conditionLocal)
1550+
if (FFlag::LuauExperimentalIfLocalSyntax && elseif.conditionLocal)
15511551
{
15521552
const auto cstNode = lookupCstNode<CstStatIf>(&elseif);
15531553

@@ -1597,7 +1597,7 @@ struct Printer
15971597
{
15981598
const auto cstNode = lookupCstNode<CstExprIfElse>(&elseif);
15991599

1600-
if (FFlag::DebugLuauIfLocalSyntax && elseif.conditionLocal)
1600+
if (FFlag::LuauExperimentalIfLocalSyntax && elseif.conditionLocal)
16011601
{
16021602
if (elseif.conditionKeywordLocation)
16031603
advance(elseif.conditionKeywordLocation->begin);

‎luau/Bytecode/src/BytecodeBuilder.cpp‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
#include <algorithm>
99
#include <array>
10+
11+
#include <stdlib.h>
1012
#include <string.h>
11-
#include <climits>
1213

1314
LUAU_FASTFLAG(LuauIntegerType2)
1415
LUAU_FASTFLAG(DebugLuauUserDefinedClasses)
15-
LUAU_FASTFLAGVARIABLE(LuauCompileExpandLimit)
16-
LUAU_FASTFLAGVARIABLE(LuauCompileExpandShortLimit)
1716
LUAU_FASTFLAGVARIABLE(LuauCompileUndoEmitAdjust)
1817
LUAU_FASTFLAGVARIABLE(LuauEmitCallFeedback)
1918
LUAU_FASTFLAGVARIABLE(LuauVirtualBcBuilder)
@@ -1404,7 +1403,7 @@ std::vector<uint32_t> BytecodeBuilder::expandJumps(bool& hasLongJumpError)
14041403
{
14051404
int offset = int(jumps[currentJump].target) - int(jumps[currentJump].source) - 1;
14061405

1407-
if (FFlag::LuauCompileExpandShortLimit ? abs(offset) >= kMaxJumpDistanceConservative : abs(offset) > kMaxJumpDistanceConservative)
1406+
if (abs(offset) >= kMaxJumpDistanceConservative)
14081407
{
14091408
// insert jump trampoline as described above; we keep JUMPX offset uninitialized in this pass
14101409
newinsns.push_back(LOP_JUMP | (1 << 16));
@@ -1443,12 +1442,12 @@ std::vector<uint32_t> BytecodeBuilder::expandJumps(bool& hasLongJumpError)
14431442
int offset = int(jump.target) - int(jump.source) - 1;
14441443
int newoffset = int(remap[jump.target]) - int(remap[jump.source]) - 1;
14451444

1446-
if (FFlag::LuauCompileExpandLimit && abs(newoffset) + 1 >= kMaxJumpDistance)
1445+
if (abs(newoffset) + 1 >= kMaxJumpDistance)
14471446
{
14481447
hasLongJumpError = true;
14491448
return {};
14501449
}
1451-
else if (FFlag::LuauCompileExpandShortLimit ? abs(offset) >= kMaxJumpDistanceConservative : abs(offset) > kMaxJumpDistanceConservative)
1450+
else if (abs(offset) >= kMaxJumpDistanceConservative)
14521451
{
14531452
// fix up jump trampoline
14541453
uint32_t& insnt = newinsns[remap[jump.source] - 1];
@@ -2642,11 +2641,11 @@ void BytecodeBuilder::dumpInstruction(const uint32_t* code, std::string& result,
26422641
break;
26432642

26442643
case LOP_GETUPVAL:
2645-
formatAppend(result, "GETUPVAL R%d %d\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn));
2644+
formatAppend(result, "GETUPVAL R%d U%d\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn));
26462645
break;
26472646

26482647
case LOP_SETUPVAL:
2649-
formatAppend(result, "SETUPVAL R%d %d\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn));
2648+
formatAppend(result, "SETUPVAL R%d U%d\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn));
26502649
break;
26512650

26522651
case LOP_CLOSEUPVALS:

‎luau/CodeGen/include/Luau/ConditionA64.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
22
#pragma once
33

4+
#include "Luau/CodeGenCommon.h"
5+
46
namespace Luau
57
{
68
namespace CodeGen

‎luau/CodeGen/include/Luau/ConditionX64.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "Luau/CodeGenCommon.h"
55

6+
#include <stdint.h>
7+
68
namespace Luau
79
{
810
namespace CodeGen

0 commit comments

Comments
 (0)