Skip to content

Commit 12e1493

Browse files
committed
Update Luau to 0.647
1 parent 388225e commit 12e1493

20 files changed

+173
-218
lines changed

luau/Ast/include/Luau/ParseOptions.h

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
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/Ast.h"
5+
#include "Luau/DenseHash.h"
6+
7+
#include <vector>
8+
49
namespace Luau
510
{
611

@@ -12,10 +17,17 @@ enum class Mode
1217
Definition, // Type definition module, has special parsing rules
1318
};
1419

20+
struct FragmentParseResumeSettings
21+
{
22+
DenseHashMap<AstName, AstLocal*> localMap{AstName()};
23+
std::vector<AstLocal*> localStack;
24+
};
25+
1526
struct ParseOptions
1627
{
1728
bool allowDeclarationSyntax = false;
1829
bool captureComments = false;
30+
std::optional<FragmentParseResumeSettings> parseFragment = std::nullopt;
1931
};
2032

2133
} // namespace Luau

luau/Ast/include/Luau/Parser.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Parser
146146
AstStat* parseTypeAlias(const Location& start, bool exported);
147147

148148
// type function Name ... end
149-
AstStat* parseTypeFunction(const Location& start);
149+
AstStat* parseTypeFunction(const Location& start, bool exported);
150150

151151
AstDeclaredClassProp parseDeclaredClassMethod();
152152

@@ -423,6 +423,7 @@ class Parser
423423
MatchLexeme endMismatchSuspect;
424424

425425
std::vector<Function> functionStack;
426+
size_t typeFunctionDepth = 0;
426427

427428
DenseHashMap<AstName, AstLocal*> localMap;
428429
std::vector<AstLocal*> localStack;
@@ -452,4 +453,4 @@ class Parser
452453
std::string scratchData;
453454
};
454455

455-
} // namespace Luau
456+
} // namespace Luau

luau/Ast/include/Luau/TimeTrace.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <memory>
88

99
#include <stdint.h>
10+
#include <string.h>
1011

1112
LUAU_FASTFLAG(DebugLuauTimeTracing)
1213

luau/Ast/src/Ast.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
LUAU_FASTFLAG(LuauNativeAttribute);
77

8+
// The default value here is 643 because the first release in which this was implemented is 644,
9+
// and actively we want new changes to be off by default until they're enabled consciously.
10+
// The flag is placed in AST project here to be common in all Luau libraries
11+
LUAU_DYNAMIC_FASTINTVARIABLE(LuauTypeSolverRelease, 643)
12+
813
namespace Luau
914
{
1015

luau/Ast/src/Lexer.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
#include <limits.h>
99

10-
LUAU_FASTFLAGVARIABLE(LuauLexerLookaheadRemembersBraceType, false)
11-
1210
namespace Luau
1311
{
1412

@@ -434,13 +432,11 @@ Lexeme Lexer::lookahead()
434432
lineOffset = currentLineOffset;
435433
lexeme = currentLexeme;
436434
prevLocation = currentPrevLocation;
437-
if (FFlag::LuauLexerLookaheadRemembersBraceType)
438-
{
439-
if (braceStack.size() < currentBraceStackSize)
440-
braceStack.push_back(currentBraceType);
441-
else if (braceStack.size() > currentBraceStackSize)
442-
braceStack.pop_back();
443-
}
435+
436+
if (braceStack.size() < currentBraceStackSize)
437+
braceStack.push_back(currentBraceType);
438+
else if (braceStack.size() > currentBraceStackSize)
439+
braceStack.pop_back();
444440

445441
return result;
446442
}

luau/Ast/src/Parser.cpp

+30-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ 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_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false)
19+
LUAU_FASTFLAGVARIABLE(LuauSolverV2, false)
2020
LUAU_FASTFLAGVARIABLE(LuauNativeAttribute, false)
2121
LUAU_FASTFLAGVARIABLE(LuauAttributeSyntaxFunExpr, false)
22-
LUAU_FASTFLAGVARIABLE(LuauUserDefinedTypeFunctions, false)
22+
LUAU_FASTFLAGVARIABLE(LuauUserDefinedTypeFunctionsSyntax2, false)
23+
LUAU_FASTFLAGVARIABLE(LuauAllowFragmentParsing, false)
2324

2425
namespace Luau
2526
{
@@ -211,6 +212,15 @@ Parser::Parser(const char* buffer, size_t bufferSize, AstNameTable& names, Alloc
211212
scratchExpr.reserve(16);
212213
scratchLocal.reserve(16);
213214
scratchBinding.reserve(16);
215+
216+
if (FFlag::LuauAllowFragmentParsing)
217+
{
218+
if (options.parseFragment)
219+
{
220+
localMap = options.parseFragment->localMap;
221+
localStack = options.parseFragment->localStack;
222+
}
223+
}
214224
}
215225

216226
bool Parser::blockFollow(const Lexeme& l)
@@ -784,6 +794,7 @@ AstStat* Parser::parseAttributeStat()
784794
AstExpr* expr = parsePrimaryExpr(/* asStatement= */ true);
785795
return parseDeclaration(expr->location, attributes);
786796
}
797+
[[fallthrough]];
787798
default:
788799
return reportStatError(
789800
lexer.current().location,
@@ -890,10 +901,10 @@ AstStat* Parser::parseReturn()
890901
AstStat* Parser::parseTypeAlias(const Location& start, bool exported)
891902
{
892903
// parsing a type function
893-
if (FFlag::LuauUserDefinedTypeFunctions)
904+
if (FFlag::LuauUserDefinedTypeFunctionsSyntax2)
894905
{
895906
if (lexer.current().type == Lexeme::ReservedFunction)
896-
return parseTypeFunction(start);
907+
return parseTypeFunction(start, exported);
897908
}
898909

899910
// parsing a type alias
@@ -916,20 +927,28 @@ AstStat* Parser::parseTypeAlias(const Location& start, bool exported)
916927
}
917928

918929
// type function Name `(' arglist `)' `=' funcbody `end'
919-
AstStat* Parser::parseTypeFunction(const Location& start)
930+
AstStat* Parser::parseTypeFunction(const Location& start, bool exported)
920931
{
921932
Lexeme matchFn = lexer.current();
922933
nextLexeme();
923934

935+
if (exported)
936+
report(start, "Type function cannot be exported");
937+
924938
// parse the name of the type function
925939
std::optional<Name> fnName = parseNameOpt("type function name");
926940
if (!fnName)
927941
fnName = Name(nameError, lexer.current().location);
928942

929943
matchRecoveryStopOnToken[Lexeme::ReservedEnd]++;
930944

945+
size_t oldTypeFunctionDepth = typeFunctionDepth;
946+
typeFunctionDepth = functionStack.size();
947+
931948
AstExprFunction* body = parseFunctionBody(/* hasself */ false, matchFn, fnName->name, nullptr, AstArray<AstAttr*>({nullptr, 0})).first;
932949

950+
typeFunctionDepth = oldTypeFunctionDepth;
951+
933952
matchRecoveryStopOnToken[Lexeme::ReservedEnd]--;
934953

935954
return allocator.alloc<AstStatTypeFunction>(Location(start, body->location), fnName->name, fnName->location, body);
@@ -2280,6 +2299,12 @@ AstExpr* Parser::parseNameExpr(const char* context)
22802299
{
22812300
AstLocal* local = *value;
22822301

2302+
if (FFlag::LuauUserDefinedTypeFunctionsSyntax2)
2303+
{
2304+
if (local->functionDepth < typeFunctionDepth)
2305+
return reportExprError(lexer.current().location, {}, "Type function cannot reference outer local '%s'", local->name.value);
2306+
}
2307+
22832308
return allocator.alloc<AstExprLocal>(name->location, local, local->functionDepth != functionStack.size() - 1);
22842309
}
22852310

luau/Ast/src/TimeTrace.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "Luau/StringUtils.h"
55

6+
#include <algorithm>
67
#include <mutex>
78
#include <string>
89

luau/CodeGen/src/CodeGenContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ void SharedCodeGenContextDeleter::operator()(const SharedCodeGenContext* codeGen
346346
return static_cast<BaseCodeGenContext*>(L->global->ecb.context);
347347
}
348348

349-
static void onCloseState(lua_State* L) noexcept
349+
static void onCloseState(lua_State* L)
350350
{
351351
getCodeGenContext(L)->onCloseState();
352352
L->global->ecb = lua_ExecutionCallbacks{};
353353
}
354354

355-
static void onDestroyFunction(lua_State* L, Proto* proto) noexcept
355+
static void onDestroyFunction(lua_State* L, Proto* proto)
356356
{
357357
getCodeGenContext(L)->onDestroyFunction(proto->execdata);
358358
proto->execdata = nullptr;

luau/CodeGen/src/IrLoweringA64.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "lstate.h"
1212
#include "lgc.h"
1313

14-
LUAU_FASTFLAGVARIABLE(LuauCodegenArmNumToVecFix, false)
15-
1614
namespace Luau
1715
{
1816
namespace CodeGen
@@ -1121,7 +1119,7 @@ void IrLoweringA64::lowerInst(IrInst& inst, uint32_t index, const IrBlock& next)
11211119
else
11221120
{
11231121
RegisterA64 tempd = tempDouble(inst.a);
1124-
RegisterA64 temps = FFlag::LuauCodegenArmNumToVecFix ? regs.allocTemp(KindA64::s) : castReg(KindA64::s, tempd);
1122+
RegisterA64 temps = regs.allocTemp(KindA64::s);
11251123

11261124
build.fcvt(temps, tempd);
11271125
build.dup_4s(inst.regA64, castReg(KindA64::q, temps), 0);

luau/Common/include/Luau/Bytecode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ enum LuauBytecodeTag
441441
// Bytecode version; runtime supports [MIN, MAX], compiler emits TARGET by default but may emit a higher version when flags are enabled
442442
LBC_VERSION_MIN = 3,
443443
LBC_VERSION_MAX = 6,
444-
LBC_VERSION_TARGET = 5,
444+
LBC_VERSION_TARGET = 6,
445445
// Type encoding version
446446
LBC_TYPE_VERSION_MIN = 1,
447447
LBC_TYPE_VERSION_MAX = 3,

luau/Common/include/Luau/Common.h

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@
2020
#define LUAU_DEBUGBREAK() __builtin_trap()
2121
#endif
2222

23+
// LUAU_FALLTHROUGH is a C++11-compatible alternative to [[fallthrough]] for use in the VM library
24+
#if defined(__clang__) && defined(__has_warning)
25+
#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
26+
#define LUAU_FALLTHROUGH [[clang::fallthrough]]
27+
#else
28+
#define LUAU_FALLTHROUGH
29+
#endif
30+
#elif defined(__GNUC__) && __GNUC__ >= 7
31+
#define LUAU_FALLTHROUGH [[gnu::fallthrough]]
32+
#else
33+
#define LUAU_FALLTHROUGH
34+
#endif
35+
2336
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
2437
#define LUAU_BIG_ENDIAN
2538
#endif

luau/Common/include/Luau/ExperimentalFlags.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ inline bool isFlagExperimental(const char* flag)
1414
"LuauInstantiateInSubtyping", // requires some fixes to lua-apps code
1515
"LuauFixIndexerSubtypingOrdering", // requires some small fixes to lua-apps code since this fixes a false negative
1616
"StudioReportLuauAny2", // takes telemetry data for usage of any types
17+
"LuauSolverV2",
1718
// makes sure we always have at least one entry
1819
nullptr,
1920
};

0 commit comments

Comments
 (0)