Skip to content

Commit ee1c6bf

Browse files
aviralghgoldsteinvrn-snayoungbloodrbxmenarulalam
authored
Sync to upstream/release/668 (#1760)
## New Type Solver 1. Update resolved types for singleton unions and intersections to avoid crashing when type checking type assertions. 2. Generalize free return type pack of a function type inferred at call site to ensure that the free type does not leak to another module. 3. Fix crash from cyclic indexers by reducing if possible or producing an error otherwise. 4. Fix handling of irreducible type functions to prevent type inference from failing. 5. Fix handling of recursive metatables to avoid infinite recursion. ## New and Old Type Solver Fix accidental capture of all exceptions in multi-threaded typechecking by converting all typechecking exceptions to `InternalCompilerError` and only capturing those. ## Fragment Autocomplete 1. Add a block based diff algorithm based on class index and span for re-typechecking. This reduces the granularity of fragment autocomplete to avoid flakiness when the fragment does not have enough type information. 2. Fix bugs arising from incorrect scope selection for autocompletion. ## Roundtrippable AST Store type alias location in `TypeFun` class to ensure it is accessible for exported types as part of the public interface. ## Build System 1. Bump minimum supported CMake version to 3.10 since GitHub is phasing out the currently supported minimum version 3.0, released 11 years ago. 2. Fix compilation when `HARDSTACKTESTS` is enabled. ## Miscellaneous Flag removals and cleanup of unused code. ## Internal Contributors Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com> Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Talha Pathan <tpathan@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> ## External Contributors Thanks to [@grh-official](https://github.com/grh-official) for PR #1759 **Full Changelog**: 0.667...0.668 --------- Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Co-authored-by: Alexander Youngblood <ayoungblood@roblox.com> Co-authored-by: Menarul Alam <malam@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
1 parent 6b33251 commit ee1c6bf

39 files changed

+1135
-714
lines changed

Analysis/include/Luau/ConstraintGenerator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ struct ConstraintGenerator
132132

133133
DenseHashMap<TypeId, TypeIds> localTypes{nullptr};
134134

135+
DenseHashMap<AstExpr*, Inference> inferredExprCache{nullptr};
136+
135137
DcrLogger* logger;
136138

137139
ConstraintGenerator(

Analysis/include/Luau/FragmentAutocomplete.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct FragmentRegion
8686
AstStatBlock* parentBlock = nullptr; // used for scope detection
8787
};
8888

89+
std::optional<Position> blockDiffStart(AstStatBlock* blockOld, AstStatBlock* blockNew, AstStat* nearestStatementNewAst);
8990
FragmentRegion getFragmentRegion(AstStatBlock* root, const Position& cursorPosition);
9091
FragmentAutocompleteAncestryResult findAncestryForFragmentParse(AstStatBlock* stale, const Position& cursorPos, AstStatBlock* lastGoodParse);
9192
FragmentAutocompleteAncestryResult findAncestryForFragmentParse_DEPRECATED(AstStatBlock* root, const Position& cursorPos);

Analysis/include/Luau/Frontend.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,6 @@ struct Frontend
215215
std::function<void(std::function<void()> task)> executeTask = {},
216216
std::function<bool(size_t done, size_t total)> progress = {}
217217
);
218-
std::vector<ModuleName> checkQueuedModules_DEPRECATED(
219-
std::optional<FrontendOptions> optionOverride = {},
220-
std::function<void(std::function<void()> task)> executeTask = {},
221-
std::function<bool(size_t done, size_t total)> progress = {}
222-
);
223218

224219
std::optional<CheckResult> getCheckResult(const ModuleName& name, bool accumulateNested, bool forAutocomplete = false);
225220
std::vector<ModuleName> getRequiredScripts(const ModuleName& name);

Analysis/include/Luau/Module.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <unordered_map>
1616
#include <optional>
1717

18-
LUAU_FASTFLAG(LuauIncrementalAutocompleteCommentDetection)
19-
2018
namespace Luau
2119
{
2220

Analysis/include/Luau/TxnLog.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,6 @@ struct TxnLog
192192
// The pointer returned lives until `commit` or `clear` is called.
193193
PendingTypePack* changeLevel(TypePackId tp, TypeLevel newLevel);
194194

195-
// Queues the replacement of a type's scope with the provided scope.
196-
//
197-
// The pointer returned lives until `commit` or `clear` is called.
198-
PendingType* changeScope(TypeId ty, NotNull<Scope> scope);
199-
200-
// Queues the replacement of a type pack's scope with the provided scope.
201-
//
202-
// The pointer returned lives until `commit` or `clear` is called.
203-
PendingTypePack* changeScope(TypePackId tp, NotNull<Scope> scope);
204-
205195
// Queues a replacement of a table type with another table type with a new
206196
// indexer.
207197
//

Analysis/include/Luau/Type.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,8 @@ struct FunctionType
356356
);
357357

358358
// Local monomorphic function
359-
FunctionType(TypeLevel level, TypePackId argTypes, TypePackId retTypes, std::optional<FunctionDefinition> defn = {}, bool hasSelf = false);
360359
FunctionType(
361360
TypeLevel level,
362-
Scope* scope,
363361
TypePackId argTypes,
364362
TypePackId retTypes,
365363
std::optional<FunctionDefinition> defn = {},
@@ -376,16 +374,6 @@ struct FunctionType
376374
std::optional<FunctionDefinition> defn = {},
377375
bool hasSelf = false
378376
);
379-
FunctionType(
380-
TypeLevel level,
381-
Scope* scope,
382-
std::vector<TypeId> generics,
383-
std::vector<TypePackId> genericPacks,
384-
TypePackId argTypes,
385-
TypePackId retTypes,
386-
std::optional<FunctionDefinition> defn = {},
387-
bool hasSelf = false
388-
);
389377

390378
std::optional<FunctionDefinition> definition;
391379
/// These should all be generic
@@ -394,7 +382,6 @@ struct FunctionType
394382
std::vector<std::optional<FunctionArgument>> argNames;
395383
Tags tags;
396384
TypeLevel level;
397-
Scope* scope = nullptr;
398385
TypePackId argTypes;
399386
TypePackId retTypes;
400387
std::shared_ptr<MagicFunction> magic = nullptr;
@@ -481,7 +468,9 @@ struct Property
481468
TypeId type() const;
482469
void setType(TypeId ty);
483470

484-
// Sets the write type of this property to the read type.
471+
// If this property has a present `writeTy`, set it equal to the `readTy`.
472+
// This is to ensure that if we normalize a property that has divergent
473+
// read and write types, we make them converge (for now).
485474
void makeShared();
486475

487476
bool isShared() const;
@@ -526,9 +515,6 @@ struct TableType
526515
std::optional<TypeId> boundTo;
527516
Tags tags;
528517

529-
// Methods of this table that have an untyped self will use the same shared self type.
530-
std::optional<TypeId> selfTy;
531-
532518
// We track the number of as-yet-unadded properties to unsealed tables.
533519
// Some constraints will use this information to decide whether or not they
534520
// are able to dispatch.
@@ -890,23 +876,33 @@ struct TypeFun
890876
*/
891877
TypeId type;
892878

879+
// The location of where this TypeFun was defined, if available
880+
std::optional<Location> definitionLocation;
881+
893882
TypeFun() = default;
894883

895884
explicit TypeFun(TypeId ty)
896885
: type(ty)
897886
{
898887
}
899888

900-
TypeFun(std::vector<GenericTypeDefinition> typeParams, TypeId type)
889+
TypeFun(std::vector<GenericTypeDefinition> typeParams, TypeId type, std::optional<Location> definitionLocation = std::nullopt)
901890
: typeParams(std::move(typeParams))
902891
, type(type)
892+
, definitionLocation(definitionLocation)
903893
{
904894
}
905895

906-
TypeFun(std::vector<GenericTypeDefinition> typeParams, std::vector<GenericTypePackDefinition> typePackParams, TypeId type)
896+
TypeFun(
897+
std::vector<GenericTypeDefinition> typeParams,
898+
std::vector<GenericTypePackDefinition> typePackParams,
899+
TypeId type,
900+
std::optional<Location> definitionLocation = std::nullopt
901+
)
907902
: typeParams(std::move(typeParams))
908903
, typePackParams(std::move(typePackParams))
909904
, type(type)
905+
, definitionLocation(definitionLocation)
910906
{
911907
}
912908

Analysis/src/BuiltinDefinitions.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
*/
3030

3131
LUAU_FASTFLAG(LuauSolverV2)
32-
LUAU_FASTFLAGVARIABLE(LuauStringFormatErrorSuppression)
3332
LUAU_FASTFLAGVARIABLE(LuauTableCloneClonesType3)
3433
LUAU_FASTFLAG(LuauTrackInteriorFreeTypesOnScope)
3534
LUAU_FASTFLAGVARIABLE(LuauFollowTableFreeze)
@@ -712,10 +711,8 @@ bool MagicFormat::typeCheck(const MagicFunctionTypeCheckContext& context)
712711

713712
if (!result.isSubtype)
714713
{
715-
if (FFlag::LuauStringFormatErrorSuppression)
714+
switch (shouldSuppressErrors(NotNull{&context.typechecker->normalizer}, actualTy))
716715
{
717-
switch (shouldSuppressErrors(NotNull{&context.typechecker->normalizer}, actualTy))
718-
{
719716
case ErrorSuppression::Suppress:
720717
break;
721718
case ErrorSuppression::NormalizationFailed:
@@ -725,12 +722,6 @@ bool MagicFormat::typeCheck(const MagicFunctionTypeCheckContext& context)
725722

726723
if (!reasonings.suppressed)
727724
context.typechecker->reportError(TypeMismatch{expectedTy, actualTy, reasonings.toString()}, location);
728-
}
729-
}
730-
else
731-
{
732-
Reasonings reasonings = context.typechecker->explainReasonings(actualTy, expectedTy, location, result);
733-
context.typechecker->reportError(TypeMismatch{expectedTy, actualTy, reasonings.toString()}, location);
734725
}
735726
}
736727
}

Analysis/src/Clone.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ class TypeCloner
179179
generic->scope = nullptr;
180180
else if (auto free = getMutable<FreeType>(target))
181181
free->scope = nullptr;
182-
else if (auto fn = getMutable<FunctionType>(target))
183-
fn->scope = nullptr;
184182
else if (auto table = getMutable<TableType>(target))
185183
table->scope = nullptr;
186184

@@ -521,11 +519,6 @@ class FragmentAutocompleteTypeCloner final : public TypeCloner
521519
if (FFlag::LuauClonedTableAndFunctionTypesMustHaveScopes)
522520
tt->scope = replacementForNullScope;
523521
}
524-
else if (auto fn = getMutable<FunctionType>(target))
525-
{
526-
if (FFlag::LuauClonedTableAndFunctionTypesMustHaveScopes)
527-
fn->scope = replacementForNullScope;
528-
}
529522

530523
(*types)[ty] = target;
531524
queue.emplace_back(target);

0 commit comments

Comments
 (0)