@@ -32,7 +32,6 @@ LUAU_FASTINT(LuauCheckRecursionLimit)
32
32
LUAU_FASTFLAG(DebugLuauLogSolverToJson)
33
33
LUAU_FASTFLAG(DebugLuauMagicTypes)
34
34
LUAU_FASTFLAG(DebugLuauEqSatSimplification)
35
- LUAU_DYNAMIC_FASTINT(LuauTypeSolverRelease)
36
35
LUAU_FASTFLAG(LuauTypestateBuiltins2)
37
36
38
37
LUAU_FASTFLAGVARIABLE(LuauNewSolverVisitErrorExprLvalues)
@@ -225,8 +224,7 @@ void ConstraintGenerator::visitModuleRoot(AstStatBlock* block)
225
224
226
225
Checkpoint start = checkpoint (this );
227
226
228
- ControlFlow cf =
229
- DFInt::LuauTypeSolverRelease >= 646 ? visitBlockWithoutChildScope (scope, block) : visitBlockWithoutChildScope_DEPRECATED (scope, block);
227
+ ControlFlow cf = visitBlockWithoutChildScope (scope, block);
230
228
if (cf == ControlFlow::None)
231
229
addConstraint (scope, block->location , PackSubtypeConstraint{builtinTypes->emptyTypePack , rootScope->returnType });
232
230
@@ -876,123 +874,6 @@ ControlFlow ConstraintGenerator::visitBlockWithoutChildScope(const ScopePtr& sco
876
874
return firstControlFlow.value_or (ControlFlow::None);
877
875
}
878
876
879
- ControlFlow ConstraintGenerator::visitBlockWithoutChildScope_DEPRECATED (const ScopePtr& scope, AstStatBlock* block)
880
- {
881
- RecursionCounter counter{&recursionCount};
882
-
883
- if (recursionCount >= FInt::LuauCheckRecursionLimit)
884
- {
885
- reportCodeTooComplex (block->location );
886
- return ControlFlow::None;
887
- }
888
-
889
- std::unordered_map<Name, Location> aliasDefinitionLocations;
890
-
891
- // In order to enable mutually-recursive type aliases, we need to
892
- // populate the type bindings before we actually check any of the
893
- // alias statements.
894
- for (AstStat* stat : block->body )
895
- {
896
- if (auto alias = stat->as <AstStatTypeAlias>())
897
- {
898
- if (scope->exportedTypeBindings .count (alias->name .value ) || scope->privateTypeBindings .count (alias->name .value ))
899
- {
900
- auto it = aliasDefinitionLocations.find (alias->name .value );
901
- LUAU_ASSERT (it != aliasDefinitionLocations.end ());
902
- reportError (alias->location , DuplicateTypeDefinition{alias->name .value , it->second });
903
- continue ;
904
- }
905
-
906
- // A type alias might have no name if the code is syntactically
907
- // illegal. We mustn't prepopulate anything in this case.
908
- if (alias->name == kParseNameError || alias->name == " typeof" )
909
- continue ;
910
-
911
- ScopePtr defnScope = childScope (alias, scope);
912
-
913
- TypeId initialType = arena->addType (BlockedType{});
914
- TypeFun initialFun{initialType};
915
-
916
- for (const auto & [name, gen] : createGenerics (defnScope, alias->generics , /* useCache */ true ))
917
- {
918
- initialFun.typeParams .push_back (gen);
919
- }
920
-
921
- for (const auto & [name, genPack] : createGenericPacks (defnScope, alias->genericPacks , /* useCache */ true ))
922
- {
923
- initialFun.typePackParams .push_back (genPack);
924
- }
925
-
926
- if (alias->exported )
927
- scope->exportedTypeBindings [alias->name .value ] = std::move (initialFun);
928
- else
929
- scope->privateTypeBindings [alias->name .value ] = std::move (initialFun);
930
-
931
- astTypeAliasDefiningScopes[alias] = defnScope;
932
- aliasDefinitionLocations[alias->name .value ] = alias->location ;
933
- }
934
- else if (auto function = stat->as <AstStatTypeFunction>())
935
- {
936
- // If a type function w/ same name has already been defined, error for having duplicates
937
- if (scope->exportedTypeBindings .count (function->name .value ) || scope->privateTypeBindings .count (function->name .value ))
938
- {
939
- auto it = aliasDefinitionLocations.find (function->name .value );
940
- LUAU_ASSERT (it != aliasDefinitionLocations.end ());
941
- reportError (function->location , DuplicateTypeDefinition{function->name .value , it->second });
942
- continue ;
943
- }
944
-
945
- if (scope->parent != globalScope)
946
- {
947
- reportError (function->location , GenericError{" Local user-defined functions are not supported yet" });
948
- continue ;
949
- }
950
-
951
- ScopePtr defnScope = childScope (function, scope);
952
-
953
- // Create TypeFunctionInstanceType
954
-
955
- std::vector<TypeId> typeParams;
956
- typeParams.reserve (function->body ->args .size );
957
-
958
- std::vector<GenericTypeDefinition> quantifiedTypeParams;
959
- quantifiedTypeParams.reserve (function->body ->args .size );
960
-
961
- for (size_t i = 0 ; i < function->body ->args .size ; i++)
962
- {
963
- std::string name = format (" T%zu" , i);
964
- TypeId ty = arena->addType (GenericType{name});
965
- typeParams.push_back (ty);
966
-
967
- GenericTypeDefinition genericTy{ty};
968
- quantifiedTypeParams.push_back (genericTy);
969
- }
970
-
971
- if (std::optional<std::string> error = typeFunctionRuntime->registerFunction (function))
972
- reportError (function->location , GenericError{*error});
973
-
974
- TypeId typeFunctionTy =
975
- arena->addType (TypeFunctionInstanceType{NotNull{&builtinTypeFunctions ().userFunc }, std::move (typeParams), {}, function->name , {}});
976
-
977
- TypeFun typeFunction{std::move (quantifiedTypeParams), typeFunctionTy};
978
-
979
- // Set type bindings and definition locations for this user-defined type function
980
- scope->privateTypeBindings [function->name .value ] = std::move (typeFunction);
981
- aliasDefinitionLocations[function->name .value ] = function->location ;
982
- }
983
- }
984
-
985
- std::optional<ControlFlow> firstControlFlow;
986
- for (AstStat* stat : block->body )
987
- {
988
- ControlFlow cf = visit (scope, stat);
989
- if (cf != ControlFlow::None && !firstControlFlow)
990
- firstControlFlow = cf;
991
- }
992
-
993
- return firstControlFlow.value_or (ControlFlow::None);
994
- }
995
-
996
877
ControlFlow ConstraintGenerator::visit (const ScopePtr& scope, AstStat* stat)
997
878
{
998
879
RecursionLimiter limiter{&recursionCount, FInt::LuauCheckRecursionLimit};
@@ -1336,10 +1217,7 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatRepeat* rep
1336
1217
{
1337
1218
ScopePtr repeatScope = childScope (repeat, scope);
1338
1219
1339
- if (DFInt::LuauTypeSolverRelease >= 646 )
1340
- visitBlockWithoutChildScope (repeatScope, repeat->body );
1341
- else
1342
- visitBlockWithoutChildScope_DEPRECATED (repeatScope, repeat->body );
1220
+ visitBlockWithoutChildScope (repeatScope, repeat->body );
1343
1221
1344
1222
check (repeatScope, repeat->condition );
1345
1223
@@ -1513,8 +1391,7 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatBlock* bloc
1513
1391
{
1514
1392
ScopePtr innerScope = childScope (block, scope);
1515
1393
1516
- ControlFlow flow = DFInt::LuauTypeSolverRelease >= 646 ? visitBlockWithoutChildScope (innerScope, block)
1517
- : visitBlockWithoutChildScope_DEPRECATED (innerScope, block);
1394
+ ControlFlow flow = visitBlockWithoutChildScope (innerScope, block);
1518
1395
1519
1396
// An AstStatBlock has linear control flow, i.e. one entry and one exit, so we can inherit
1520
1397
// all the changes to the environment occurred by the statements in that block.
@@ -1705,7 +1582,7 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatTypeFunctio
1705
1582
TypeFun typeFunction = bindingIt->second ;
1706
1583
1707
1584
// Adding typeAliasExpansionConstraint on user-defined type function for the constraint solver
1708
- if (auto typeFunctionTy = get<TypeFunctionInstanceType>(DFInt::LuauTypeSolverRelease >= 646 ? follow (typeFunction.type ) : typeFunction. type ))
1585
+ if (auto typeFunctionTy = get<TypeFunctionInstanceType>(follow (typeFunction.type )))
1709
1586
{
1710
1587
TypeId expansionTy = arena->addType (PendingExpansionType{{}, function->name , typeFunctionTy->typeArguments , typeFunctionTy->packArguments });
1711
1588
addConstraint (scope, function->location , TypeAliasExpansionConstraint{/* target */ expansionTy});
@@ -3026,32 +2903,12 @@ Inference ConstraintGenerator::check(const ScopePtr& scope, AstExprTable* expr,
3026
2903
{
3027
2904
Unifier2 unifier{arena, builtinTypes, NotNull{scope.get ()}, ice};
3028
2905
std::vector<TypeId> toBlock;
3029
- if (DFInt::LuauTypeSolverRelease >= 648 )
3030
- {
3031
- // This logic is incomplete as we want to re-run this
3032
- // _after_ blocked types have resolved, but this
3033
- // allows us to do some bidirectional inference.
3034
- toBlock = findBlockedTypesIn (expr, NotNull{&module->astTypes });
3035
- if (toBlock.empty ())
3036
- {
3037
- matchLiteralType (
3038
- NotNull{&module->astTypes },
3039
- NotNull{&module->astExpectedTypes },
3040
- builtinTypes,
3041
- arena,
3042
- NotNull{&unifier},
3043
- *expectedType,
3044
- ty,
3045
- expr,
3046
- toBlock
3047
- );
3048
- // The visitor we ran prior should ensure that there are no
3049
- // blocked types that we would encounter while matching on
3050
- // this expression.
3051
- LUAU_ASSERT (toBlock.empty ());
3052
- }
3053
- }
3054
- else
2906
+ // This logic is incomplete as we want to re-run this
2907
+ // _after_ blocked types have resolved, but this
2908
+ // allows us to do some bidirectional inference.
2909
+ toBlock = findBlockedTypesIn (expr, NotNull{&module->astTypes });
2910
+
2911
+ if (toBlock.empty ())
3055
2912
{
3056
2913
matchLiteralType (
3057
2914
NotNull{&module->astTypes },
@@ -3063,7 +2920,11 @@ Inference ConstraintGenerator::check(const ScopePtr& scope, AstExprTable* expr,
3063
2920
ty,
3064
2921
expr,
3065
2922
toBlock
3066
- );
2923
+ );
2924
+ // The visitor we ran prior should ensure that there are no
2925
+ // blocked types that we would encounter while matching on
2926
+ // this expression.
2927
+ LUAU_ASSERT (toBlock.empty ());
3067
2928
}
3068
2929
}
3069
2930
@@ -3265,8 +3126,7 @@ ConstraintGenerator::FunctionSignature ConstraintGenerator::checkFunctionSignatu
3265
3126
void ConstraintGenerator::checkFunctionBody (const ScopePtr& scope, AstExprFunction* fn)
3266
3127
{
3267
3128
// If it is possible for execution to reach the end of the function, the return type must be compatible with ()
3268
- ControlFlow cf =
3269
- DFInt::LuauTypeSolverRelease >= 646 ? visitBlockWithoutChildScope (scope, fn->body ) : visitBlockWithoutChildScope_DEPRECATED (scope, fn->body );
3129
+ ControlFlow cf = visitBlockWithoutChildScope (scope, fn->body );
3270
3130
if (cf == ControlFlow::None)
3271
3131
addConstraint (scope, fn->location , PackSubtypeConstraint{builtinTypes->emptyTypePack , scope->returnType });
3272
3132
}
@@ -3745,11 +3605,18 @@ struct FragmentTypeCheckGlobalPrepopulator : AstVisitor
3745
3605
const NotNull<Scope> globalScope;
3746
3606
const NotNull<Scope> currentScope;
3747
3607
const NotNull<const DataFlowGraph> dfg;
3608
+ const NotNull<TypeArena> arena;
3748
3609
3749
- FragmentTypeCheckGlobalPrepopulator (NotNull<Scope> globalScope, NotNull<Scope> currentScope, NotNull<const DataFlowGraph> dfg)
3610
+ FragmentTypeCheckGlobalPrepopulator (
3611
+ NotNull<Scope> globalScope,
3612
+ NotNull<Scope> currentScope,
3613
+ NotNull<const DataFlowGraph> dfg,
3614
+ NotNull<TypeArena> arena
3615
+ )
3750
3616
: globalScope(globalScope)
3751
3617
, currentScope(currentScope)
3752
3618
, dfg(dfg)
3619
+ , arena(arena)
3753
3620
{
3754
3621
}
3755
3622
@@ -3761,6 +3628,32 @@ struct FragmentTypeCheckGlobalPrepopulator : AstVisitor
3761
3628
// We only want to write into the current scope the type of the global
3762
3629
currentScope->lvalueTypes [def] = *ty;
3763
3630
}
3631
+ else if (auto ty = currentScope->lookup (global->name ))
3632
+ {
3633
+ // We are trying to create a binding for a brand new function, so we actually do have to write it into the scope.
3634
+ DefId def = dfg->getDef (global);
3635
+ // We only want to write into the current scope the type of the global
3636
+ currentScope->lvalueTypes [def] = *ty;
3637
+ }
3638
+
3639
+ return true ;
3640
+ }
3641
+
3642
+ bool visit (AstStatFunction* function) override
3643
+ {
3644
+ if (AstExprGlobal* g = function->name ->as <AstExprGlobal>())
3645
+ {
3646
+ if (auto ty = globalScope->lookup (g->name ))
3647
+ {
3648
+ currentScope->bindings [g->name ] = Binding{*ty};
3649
+ }
3650
+ else
3651
+ {
3652
+ // Hasn't existed since a previous typecheck
3653
+ TypeId bt = arena->addType (BlockedType{});
3654
+ currentScope->bindings [g->name ] = Binding{bt};
3655
+ }
3656
+ }
3764
3657
3765
3658
return true ;
3766
3659
}
@@ -3814,7 +3707,7 @@ struct GlobalPrepopulator : AstVisitor
3814
3707
3815
3708
void ConstraintGenerator::prepopulateGlobalScopeForFragmentTypecheck (const ScopePtr& globalScope, const ScopePtr& resumeScope, AstStatBlock* program)
3816
3709
{
3817
- FragmentTypeCheckGlobalPrepopulator gp{NotNull{globalScope.get ()}, NotNull{resumeScope.get ()}, dfg};
3710
+ FragmentTypeCheckGlobalPrepopulator gp{NotNull{globalScope.get ()}, NotNull{resumeScope.get ()}, dfg, arena };
3818
3711
if (prepareModuleScope)
3819
3712
prepareModuleScope (module->name , resumeScope);
3820
3713
program->visit (&gp);
0 commit comments