Add FFlag

This commit is contained in:
JohnnyMorganz 2023-06-07 11:58:04 +01:00
parent 22263d80cb
commit 0353860b28
6 changed files with 14 additions and 5 deletions

View file

@ -21,6 +21,7 @@
LUAU_FASTINT(LuauCheckRecursionLimit); LUAU_FASTINT(LuauCheckRecursionLimit);
LUAU_FASTFLAG(DebugLuauMagicTypes); LUAU_FASTFLAG(DebugLuauMagicTypes);
LUAU_FASTFLAG(LuauParseDeclareClassIndexer);
namespace Luau namespace Luau
{ {
@ -1151,7 +1152,7 @@ ControlFlow ConstraintGraphBuilder::visit(const ScopePtr& scope, AstStatDeclareC
scope->exportedTypeBindings[className] = TypeFun{{}, classTy}; scope->exportedTypeBindings[className] = TypeFun{{}, classTy};
if (declaredClass->indexer) if (FFlag::LuauParseDeclareClassIndexer && declaredClass->indexer)
{ {
// TODO: Recursion limit. // TODO: Recursion limit.
ctv->indexer = TableIndexer{ ctv->indexer = TableIndexer{

View file

@ -13,6 +13,8 @@
#include <string> #include <string>
LUAU_FASTFLAG(LuauParseDeclareClassIndexer);
static char* allocateString(Luau::Allocator& allocator, std::string_view contents) static char* allocateString(Luau::Allocator& allocator, std::string_view contents)
{ {
char* result = (char*)allocator.allocate(contents.size() + 1); char* result = (char*)allocator.allocate(contents.size() + 1);
@ -228,7 +230,7 @@ public:
} }
AstTableIndexer* indexer = nullptr; AstTableIndexer* indexer = nullptr;
if (ctv.indexer) if (FFlag::LuauParseDeclareClassIndexer && ctv.indexer)
{ {
RecursionCounter counter(&count); RecursionCounter counter(&count);

View file

@ -41,6 +41,7 @@ LUAU_FASTFLAGVARIABLE(LuauTypecheckTypeguards, false)
LUAU_FASTFLAGVARIABLE(LuauTinyControlFlowAnalysis, false) LUAU_FASTFLAGVARIABLE(LuauTinyControlFlowAnalysis, false)
LUAU_FASTFLAGVARIABLE(LuauTypecheckClassTypeIndexers, false) LUAU_FASTFLAGVARIABLE(LuauTypecheckClassTypeIndexers, false)
LUAU_FASTFLAGVARIABLE(LuauAlwaysCommitInferencesOfFunctionCalls, false) LUAU_FASTFLAGVARIABLE(LuauAlwaysCommitInferencesOfFunctionCalls, false)
LUAU_FASTFLAG(LuauParseDeclareClassIndexer)
namespace Luau namespace Luau
{ {
@ -1757,7 +1758,7 @@ ControlFlow TypeChecker::check(const ScopePtr& scope, const AstStatDeclareClass&
if (!ctv->metatable) if (!ctv->metatable)
ice("No metatable for declared class"); ice("No metatable for declared class");
if (const auto& indexer = declaredClass.indexer) if (const auto& indexer = declaredClass.indexer; FFlag::LuauParseDeclareClassIndexer && indexer)
ctv->indexer = TableIndexer(resolveType(scope, *indexer->indexType), resolveType(scope, *indexer->resultType)); ctv->indexer = TableIndexer(resolveType(scope, *indexer->indexType), resolveType(scope, *indexer->resultType));
TableType* metatable = getMutable<TableType>(*ctv->metatable); TableType* metatable = getMutable<TableType>(*ctv->metatable);

View file

@ -13,6 +13,7 @@
// See docs/SyntaxChanges.md for an explanation. // See docs/SyntaxChanges.md for an explanation.
LUAU_FASTINTVARIABLE(LuauRecursionLimit, 1000) LUAU_FASTINTVARIABLE(LuauRecursionLimit, 1000)
LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100) LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
LUAU_FASTFLAGVARIABLE(LuauParseDeclareClassIndexer, false)
#define ERROR_INVALID_INTERP_DOUBLE_BRACE "Double braces are not permitted within interpolated strings. Did you mean '\\{'?" #define ERROR_INVALID_INTERP_DOUBLE_BRACE "Double braces are not permitted within interpolated strings. Did you mean '\\{'?"
@ -886,7 +887,8 @@ AstStat* Parser::parseDeclaration(const Location& start)
{ {
props.push_back(parseDeclaredClassMethod()); props.push_back(parseDeclaredClassMethod());
} }
else if (lexer.current().type == '[' && (lexer.lookahead().type == Lexeme::RawString || lexer.lookahead().type == Lexeme::QuotedString)) else if (lexer.current().type == '[' && (!FFlag::LuauParseDeclareClassIndexer || lexer.lookahead().type == Lexeme::RawString ||
lexer.lookahead().type == Lexeme::QuotedString))
{ {
const Lexeme begin = lexer.current(); const Lexeme begin = lexer.current();
nextLexeme(); // [ nextLexeme(); // [
@ -905,7 +907,7 @@ AstStat* Parser::parseDeclaration(const Location& start)
else else
report(begin.location, "String literal contains malformed escape sequence"); report(begin.location, "String literal contains malformed escape sequence");
} }
else if (lexer.current().type == '[') else if (lexer.current().type == '[' && FFlag::LuauParseDeclareClassIndexer)
{ {
if (indexer) if (indexer)
{ {

View file

@ -1886,6 +1886,8 @@ TEST_CASE_FIXTURE(Fixture, "class_method_properties")
TEST_CASE_FIXTURE(Fixture, "class_indexer") TEST_CASE_FIXTURE(Fixture, "class_indexer")
{ {
ScopedFastFlag LuauParseDeclareClassIndexer("LuauParseDeclareClassIndexer", true);
AstStatBlock* stat = parseEx(R"( AstStatBlock* stat = parseEx(R"(
declare class Foo declare class Foo
prop: boolean prop: boolean

View file

@ -397,6 +397,7 @@ TEST_CASE_FIXTURE(Fixture, "class_definition_string_props")
TEST_CASE_FIXTURE(Fixture, "class_definition_indexer") TEST_CASE_FIXTURE(Fixture, "class_definition_indexer")
{ {
ScopedFastFlag LuauParseDeclareClassIndexer("LuauParseDeclareClassIndexer", true);
ScopedFastFlag LuauTypecheckClassTypeIndexers("LuauTypecheckClassTypeIndexers", true); ScopedFastFlag LuauTypecheckClassTypeIndexers("LuauTypecheckClassTypeIndexers", true);
loadDefinition(R"( loadDefinition(R"(