Skip to content

Commit db80939

Browse files
authored
Sync to upstream/release/649 (#1489)
1 parent e491128 commit db80939

Some content is hidden

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

42 files changed

+1363
-437
lines changed

Analysis/include/Luau/BuiltinDefinitions.h

+12
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,16 @@ std::optional<Binding> tryGetGlobalBinding(GlobalTypes& globals, const std::stri
8282
Binding* tryGetGlobalBindingRef(GlobalTypes& globals, const std::string& name);
8383
TypeId getGlobalBinding(GlobalTypes& globals, const std::string& name);
8484

85+
86+
/** A number of built-in functions are magical enough that we need to match on them specifically by
87+
* name when they are called. These are listed here to be used whenever necessary, instead of duplicating this logic repeatedly.
88+
*/
89+
90+
bool matchSetMetatable(const AstExprCall& call);
91+
bool matchTableFreeze(const AstExprCall& call);
92+
bool matchAssert(const AstExprCall& call);
93+
94+
// Returns `true` if the function should introduce typestate for its first argument.
95+
bool shouldTypestateForFirstArgument(const AstExprCall& call);
96+
8597
} // namespace Luau

Analysis/include/Luau/Clone.h

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ struct CloneState
2222
SeenTypePacks seenTypePacks;
2323
};
2424

25+
/** `shallowClone` will make a copy of only the _top level_ constructor of the type,
26+
* while `clone` will make a deep copy of the entire type and its every component.
27+
*
28+
* Be mindful about which behavior you actually _want_.
29+
*/
30+
31+
TypePackId shallowClone(TypePackId tp, TypeArena& dest, CloneState& cloneState);
32+
TypeId shallowClone(TypeId typeId, TypeArena& dest, CloneState& cloneState);
33+
2534
TypePackId clone(TypePackId tp, TypeArena& dest, CloneState& cloneState);
2635
TypeId clone(TypeId tp, TypeArena& dest, CloneState& cloneState);
2736
TypeFun clone(const TypeFun& typeFun, TypeArena& dest, CloneState& cloneState);

Analysis/include/Luau/ConstraintGenerator.h

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ struct ConstraintGenerator
146146
*/
147147
void visitModuleRoot(AstStatBlock* block);
148148

149+
void visitFragmentRoot(const ScopePtr& resumeScope, AstStatBlock* block);
150+
149151
private:
150152
std::vector<std::vector<TypeId>> interiorTypes;
151153

Analysis/include/Luau/ConstraintSolver.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include "Luau/Constraint.h"
6+
#include "Luau/DataFlowGraph.h"
67
#include "Luau/DenseHash.h"
78
#include "Luau/Error.h"
89
#include "Luau/Location.h"
@@ -69,6 +70,9 @@ struct ConstraintSolver
6970
NotNull<Scope> rootScope;
7071
ModuleName currentModuleName;
7172

73+
// The dataflow graph of the program, used in constraint generation and for magic functions.
74+
NotNull<const DataFlowGraph> dfg;
75+
7276
// Constraints that the solver has generated, rather than sourcing from the
7377
// scope tree.
7478
std::vector<std::unique_ptr<Constraint>> solverConstraints;
@@ -120,6 +124,7 @@ struct ConstraintSolver
120124
NotNull<ModuleResolver> moduleResolver,
121125
std::vector<RequireCycle> requireCycles,
122126
DcrLogger* logger,
127+
NotNull<const DataFlowGraph> dfg,
123128
TypeCheckLimits limits
124129
);
125130

@@ -167,9 +172,9 @@ struct ConstraintSolver
167172
*/
168173
bool tryDispatch(NotNull<const Constraint> c, bool force);
169174

170-
bool tryDispatch(const SubtypeConstraint& c, NotNull<const Constraint> constraint, bool force);
171-
bool tryDispatch(const PackSubtypeConstraint& c, NotNull<const Constraint> constraint, bool force);
172-
bool tryDispatch(const GeneralizationConstraint& c, NotNull<const Constraint> constraint, bool force);
175+
bool tryDispatch(const SubtypeConstraint& c, NotNull<const Constraint> constraint);
176+
bool tryDispatch(const PackSubtypeConstraint& c, NotNull<const Constraint> constraint);
177+
bool tryDispatch(const GeneralizationConstraint& c, NotNull<const Constraint> constraint);
173178
bool tryDispatch(const IterableConstraint& c, NotNull<const Constraint> constraint, bool force);
174179
bool tryDispatch(const NameConstraint& c, NotNull<const Constraint> constraint);
175180
bool tryDispatch(const TypeAliasExpansionConstraint& c, NotNull<const Constraint> constraint);
@@ -194,14 +199,14 @@ struct ConstraintSolver
194199
bool tryDispatch(const UnpackConstraint& c, NotNull<const Constraint> constraint);
195200
bool tryDispatch(const ReduceConstraint& c, NotNull<const Constraint> constraint, bool force);
196201
bool tryDispatch(const ReducePackConstraint& c, NotNull<const Constraint> constraint, bool force);
197-
bool tryDispatch(const EqualityConstraint& c, NotNull<const Constraint> constraint, bool force);
202+
bool tryDispatch(const EqualityConstraint& c, NotNull<const Constraint> constraint);
198203

199204
// for a, ... in some_table do
200205
// also handles __iter metamethod
201206
bool tryDispatchIterableTable(TypeId iteratorTy, const IterableConstraint& c, NotNull<const Constraint> constraint, bool force);
202207

203208
// for a, ... in next_function, t, ... do
204-
bool tryDispatchIterableFunction(TypeId nextTy, TypeId tableTy, const IterableConstraint& c, NotNull<const Constraint> constraint, bool force);
209+
bool tryDispatchIterableFunction(TypeId nextTy, TypeId tableTy, const IterableConstraint& c, NotNull<const Constraint> constraint);
205210

206211
std::pair<std::vector<TypeId>, std::optional<TypeId>> lookupTableProp(
207212
NotNull<const Constraint> constraint,

Analysis/include/Luau/DataFlowGraph.h

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct DataFlowGraph
3535
DataFlowGraph& operator=(DataFlowGraph&&) = default;
3636

3737
DefId getDef(const AstExpr* expr) const;
38+
// Look up the definition optionally, knowing it may not be present.
39+
std::optional<DefId> getDefOptional(const AstExpr* expr) const;
3840
// Look up for the rvalue def for a compound assignment.
3941
std::optional<DefId> getRValueDefForCompoundAssign(const AstExpr* expr) const;
4042

Analysis/include/Luau/FragmentAutocomplete.h

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Luau
1414
{
15+
struct FrontendOptions;
1516

1617
struct FragmentAutocompleteAncestryResult
1718
{
@@ -29,15 +30,30 @@ struct FragmentParseResult
2930
std::unique_ptr<Allocator> alloc = std::make_unique<Allocator>();
3031
};
3132

33+
struct FragmentTypeCheckResult
34+
{
35+
ModulePtr incrementalModule = nullptr;
36+
Scope* freshScope = nullptr;
37+
};
38+
3239
FragmentAutocompleteAncestryResult findAncestryForFragmentParse(AstStatBlock* root, const Position& cursorPos);
3340

3441
FragmentParseResult parseFragment(const SourceModule& srcModule, std::string_view src, const Position& cursorPos);
3542

43+
FragmentTypeCheckResult typecheckFragment(
44+
Frontend& frontend,
45+
const ModuleName& moduleName,
46+
const Position& cursorPos,
47+
std::optional<FrontendOptions> opts,
48+
std::string_view src
49+
);
50+
3651
AutocompleteResult fragmentAutocomplete(
3752
Frontend& frontend,
3853
std::string_view src,
3954
const ModuleName& moduleName,
4055
Position& cursorPosition,
56+
std::optional<FrontendOptions> opts,
4157
StringCompletionCallback callback
4258
);
4359

Analysis/include/Luau/Instantiation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct ReplaceGenerics : Substitution
6060
};
6161

6262
// A substitution which replaces generic functions by monomorphic functions
63-
struct Instantiation : Substitution
63+
struct Instantiation final : Substitution
6464
{
6565
Instantiation(const TxnLog* log, TypeArena* arena, NotNull<BuiltinTypes> builtinTypes, TypeLevel level, Scope* scope)
6666
: Substitution(log, arena)

Analysis/include/Luau/Normalize.h

+24-9
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ using ModulePtr = std::shared_ptr<Module>;
2323

2424
bool isSubtype(TypeId subTy, TypeId superTy, NotNull<Scope> scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice);
2525
bool isSubtype(TypePackId subTy, TypePackId superTy, NotNull<Scope> scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice);
26-
bool isConsistentSubtype(TypeId subTy, TypeId superTy, NotNull<Scope> scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice);
27-
bool isConsistentSubtype(TypePackId subTy, TypePackId superTy, NotNull<Scope> scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice);
2826

2927
class TypeIds
3028
{
@@ -336,6 +334,7 @@ struct NormalizedType
336334
};
337335

338336

337+
using SeenTablePropPairs = Set<std::pair<TypeId, TypeId>, TypeIdPairHash>;
339338

340339
class Normalizer
341340
{
@@ -390,7 +389,13 @@ class Normalizer
390389
void unionTablesWithTable(TypeIds& heres, TypeId there);
391390
void unionTables(TypeIds& heres, const TypeIds& theres);
392391
NormalizationResult unionNormals(NormalizedType& here, const NormalizedType& there, int ignoreSmallerTyvars = -1);
393-
NormalizationResult unionNormalWithTy(NormalizedType& here, TypeId there, Set<TypeId>& seenSetTypes, int ignoreSmallerTyvars = -1);
392+
NormalizationResult unionNormalWithTy(
393+
NormalizedType& here,
394+
TypeId there,
395+
SeenTablePropPairs& seenTablePropPairs,
396+
Set<TypeId>& seenSetTypes,
397+
int ignoreSmallerTyvars = -1
398+
);
394399

395400
// ------- Negations
396401
std::optional<NormalizedType> negateNormal(const NormalizedType& here);
@@ -407,16 +412,26 @@ class Normalizer
407412
void intersectClassesWithClass(NormalizedClassType& heres, TypeId there);
408413
void intersectStrings(NormalizedStringType& here, const NormalizedStringType& there);
409414
std::optional<TypePackId> intersectionOfTypePacks(TypePackId here, TypePackId there);
410-
std::optional<TypeId> intersectionOfTables(TypeId here, TypeId there, Set<TypeId>& seenSet);
411-
void intersectTablesWithTable(TypeIds& heres, TypeId there, Set<TypeId>& seenSetTypes);
415+
std::optional<TypeId> intersectionOfTables(TypeId here, TypeId there, SeenTablePropPairs& seenTablePropPairs, Set<TypeId>& seenSet);
416+
void intersectTablesWithTable(TypeIds& heres, TypeId there, SeenTablePropPairs& seenTablePropPairs, Set<TypeId>& seenSetTypes);
412417
void intersectTables(TypeIds& heres, const TypeIds& theres);
413418
std::optional<TypeId> intersectionOfFunctions(TypeId here, TypeId there);
414419
void intersectFunctionsWithFunction(NormalizedFunctionType& heress, TypeId there);
415420
void intersectFunctions(NormalizedFunctionType& heress, const NormalizedFunctionType& theress);
416-
NormalizationResult intersectTyvarsWithTy(NormalizedTyvars& here, TypeId there, Set<TypeId>& seenSetTypes);
421+
NormalizationResult intersectTyvarsWithTy(
422+
NormalizedTyvars& here,
423+
TypeId there,
424+
SeenTablePropPairs& seenTablePropPairs,
425+
Set<TypeId>& seenSetTypes
426+
);
417427
NormalizationResult intersectNormals(NormalizedType& here, const NormalizedType& there, int ignoreSmallerTyvars = -1);
418-
NormalizationResult intersectNormalWithTy(NormalizedType& here, TypeId there, Set<TypeId>& seenSetTypes);
419-
NormalizationResult normalizeIntersections(const std::vector<TypeId>& intersections, NormalizedType& outType, Set<TypeId>& seenSet);
428+
NormalizationResult intersectNormalWithTy(NormalizedType& here, TypeId there, SeenTablePropPairs& seenTablePropPairs, Set<TypeId>& seenSetTypes);
429+
NormalizationResult normalizeIntersections(
430+
const std::vector<TypeId>& intersections,
431+
NormalizedType& outType,
432+
SeenTablePropPairs& seenTablePropPairs,
433+
Set<TypeId>& seenSet
434+
);
420435

421436
// Check for inhabitance
422437
NormalizationResult isInhabited(TypeId ty);
@@ -426,7 +441,7 @@ class Normalizer
426441

427442
// Check for intersections being inhabited
428443
NormalizationResult isIntersectionInhabited(TypeId left, TypeId right);
429-
NormalizationResult isIntersectionInhabited(TypeId left, TypeId right, Set<TypeId>& seenSet);
444+
NormalizationResult isIntersectionInhabited(TypeId left, TypeId right, SeenTablePropPairs& seenTablePropPairs, Set<TypeId>& seenSet);
430445

431446
// -------- Convert back from a normalized type to a type
432447
TypeId typeFromNormal(const NormalizedType& norm);

Analysis/include/Luau/Type.h

+7
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,13 @@ struct Type final
806806
Type& operator=(const TypeVariant& rhs);
807807
Type& operator=(TypeVariant&& rhs);
808808

809+
Type(Type&&) = default;
810+
Type& operator=(Type&&) = default;
811+
812+
Type clone() const;
813+
814+
private:
815+
Type(const Type&) = default;
809816
Type& operator=(const Type& rhs);
810817
};
811818

Analysis/include/Luau/Unifier.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ struct Unifier
179179
bool occursCheck(TypePackId needle, TypePackId haystack, bool reversed);
180180
bool occursCheck(DenseHashSet<TypePackId>& seen, TypePackId needle, TypePackId haystack);
181181

182-
Unifier makeChildUnifier();
182+
std::unique_ptr<Unifier> makeChildUnifier();
183183

184184
void reportError(TypeError err);
185185
LUAU_NOINLINE void reportError(Location location, TypeErrorData data);

Analysis/src/Autocomplete.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <utility>
1717

1818
LUAU_FASTFLAG(LuauSolverV2)
19-
LUAU_FASTFLAG(LuauAutocompleteNewSolverLimit)
2019
LUAU_FASTFLAGVARIABLE(AutocompleteRequirePathSuggestions, false)
2120

2221
LUAU_DYNAMIC_FASTINT(LuauTypeSolverRelease)
@@ -157,11 +156,8 @@ static bool checkTypeMatch(TypeId subTy, TypeId superTy, NotNull<Scope> scope, T
157156
NotNull{&iceReporter}, NotNull{&limits}
158157
}; // TODO: maybe subtyping checks should not invoke user-defined type function runtime
159158

160-
if (FFlag::LuauAutocompleteNewSolverLimit)
161-
{
162-
unifierState.counters.recursionLimit = FInt::LuauTypeInferRecursionLimit;
163-
unifierState.counters.iterationLimit = FInt::LuauTypeInferIterationLimit;
164-
}
159+
unifierState.counters.recursionLimit = FInt::LuauTypeInferRecursionLimit;
160+
unifierState.counters.iterationLimit = FInt::LuauTypeInferIterationLimit;
165161

166162
Subtyping subtyping{builtinTypes, NotNull{typeArena}, NotNull{&normalizer}, NotNull{&typeFunctionRuntime}, NotNull{&iceReporter}};
167163

0 commit comments

Comments
 (0)