Skip to content

Commit c759cd5

Browse files
hgoldsteinaatxedcope-rbxVighnesh-Vvegorov-rbx
authored
Sync to upstream/release/656 (#1612)
# General All code has been re-formatted by `clang-format`; this is not mechanically enforced, so Luau may go out-of-sync over the course of the year. # New Solver * Track free types interior to a block of code on `Scope`, which should reduce the number of free types that remain un-generalized after type checking is complete (e.g.: less errors like `'a <: number is incompatible with number`). # Autocomplete * Fragment autocomplete now does *not* provide suggestions within comments (matching non-fragment autocomplete behavior). * Autocomplete now respects iteration and recursion limits (some hangs will now early exit with a "unification too complex error," some crashes will now become internal complier exceptions). # Runtime * Add a limit to how many Luau codegen slot nodes addresses can be in use at the same time (fixes #1605, fixes #1558). * Added constant folding for vector arithmetic (fixes #1553). * Added support for `buffer.readbits` and `buffer.writebits` (see: luau-lang/rfcs#18). --- Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: David Cope <dcope@roblox.com> Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
1 parent 945c510 commit c759cd5

File tree

85 files changed

+1299
-701
lines changed

Some content is hidden

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

85 files changed

+1299
-701
lines changed

Analysis/include/Luau/FragmentAutocomplete.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ namespace Luau
1515
{
1616
struct FrontendOptions;
1717

18+
enum class FragmentTypeCheckStatus
19+
{
20+
Success,
21+
SkipAutocomplete,
22+
};
23+
1824
struct FragmentAutocompleteAncestryResult
1925
{
2026
DenseHashMap<AstName, AstLocal*> localMap{AstName()};
@@ -29,6 +35,7 @@ struct FragmentParseResult
2935
AstStatBlock* root = nullptr;
3036
std::vector<AstNode*> ancestry;
3137
AstStat* nearestStatement = nullptr;
38+
std::vector<Comment> commentLocations;
3239
std::unique_ptr<Allocator> alloc = std::make_unique<Allocator>();
3340
};
3441

@@ -56,7 +63,7 @@ FragmentParseResult parseFragment(
5663
std::optional<Position> fragmentEndPosition
5764
);
5865

59-
FragmentTypeCheckResult typecheckFragment(
66+
std::pair<FragmentTypeCheckStatus, FragmentTypeCheckResult> typecheckFragment(
6067
Frontend& frontend,
6168
const ModuleName& moduleName,
6269
const Position& cursorPos,

Analysis/include/Luau/Module.h

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

19+
LUAU_FASTFLAG(LuauIncrementalAutocompleteCommentDetection)
20+
1921
namespace Luau
2022
{
2123

@@ -55,6 +57,7 @@ struct SourceModule
5557
}
5658
};
5759

60+
bool isWithinComment(const std::vector<Comment>& commentLocations, Position pos);
5861
bool isWithinComment(const SourceModule& sourceModule, Position pos);
5962
bool isWithinComment(const ParseResult& result, Position pos);
6063

Analysis/include/Luau/Scope.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct Scope
9595
// we need that the generic type `T` in both cases is the same, so we use a cache.
9696
std::unordered_map<Name, TypeId> typeAliasTypeParameters;
9797
std::unordered_map<Name, TypePackId> typeAliasTypePackParameters;
98+
99+
std::optional<std::vector<TypeId>> interiorFreeTypes;
98100
};
99101

100102
// Returns true iff the left scope encloses the right scope. A Scope* equal to

Analysis/include/Luau/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ struct TypeFunctionInstanceType
626626
std::vector<TypeId> typeArguments;
627627
std::vector<TypePackId> packArguments;
628628

629-
std::optional<AstName> userFuncName; // Name of the user-defined type function; only available for UDTFs
629+
std::optional<AstName> userFuncName; // Name of the user-defined type function; only available for UDTFs
630630
UserDefinedFunctionData userFuncData;
631631

632632
TypeFunctionInstanceType(

Analysis/include/Luau/TypeFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct TypeFunctionContext
7171
// The constraint being reduced in this run of the reduction
7272
const Constraint* constraint;
7373

74-
std::optional<AstName> userFuncName; // Name of the user-defined type function; only available for UDTFs
74+
std::optional<AstName> userFuncName; // Name of the user-defined type function; only available for UDTFs
7575

7676
TypeFunctionContext(NotNull<ConstraintSolver> cs, NotNull<Scope> scope, NotNull<const Constraint> constraint);
7777

Analysis/include/Luau/TypeUtils.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ bool isLiteral(const AstExpr* expr);
269269
std::vector<TypeId> findBlockedTypesIn(AstExprTable* expr, NotNull<DenseHashMap<const AstExpr*, TypeId>> astTypes);
270270

271271
/**
272-
* Given a function call and a mapping from expression to type, determine
273-
* whether the type of any argument in said call in depends on a blocked types.
272+
* Given a function call and a mapping from expression to type, determine
273+
* whether the type of any argument in said call in depends on a blocked types.
274274
* This is used as a precondition for bidirectional inference: be warned that
275275
* the behavior of this algorithm is tightly coupled to that of bidirectional
276276
* inference.
@@ -280,4 +280,13 @@ std::vector<TypeId> findBlockedTypesIn(AstExprTable* expr, NotNull<DenseHashMap<
280280
*/
281281
std::vector<TypeId> findBlockedArgTypesIn(AstExprCall* expr, NotNull<DenseHashMap<const AstExpr*, TypeId>> astTypes);
282282

283+
/**
284+
* Given a scope and a free type, find the closest parent that has a present
285+
* `interiorFreeTypes` and append the given type to said list. This list will
286+
* be generalized when the requiste `GeneralizationConstraint` is resolved.
287+
* @param scope Initial scope this free type was attached to
288+
* @param ty Free type to track.
289+
*/
290+
void trackInteriorFreeType(Scope* scope, TypeId ty);
291+
283292
} // namespace Luau

Analysis/src/AnyTypeSummary.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ void AnyTypeSummary::visit(const Scope* scope, AstStatReturn* ret, const Module*
177177
}
178178
}
179179
}
180-
181180
}
182181

183182
void AnyTypeSummary::visit(const Scope* scope, AstStatLocal* local, const Module* module, NotNull<BuiltinTypes> builtinTypes)

Analysis/src/AutocompleteCore.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ LUAU_FASTINT(LuauTypeInferIterationLimit)
2525
LUAU_FASTINT(LuauTypeInferRecursionLimit)
2626

2727
LUAU_FASTFLAGVARIABLE(LuauAutocompleteRefactorsForIncrementalAutocomplete)
28+
LUAU_FASTFLAGVARIABLE(LuauAutocompleteUseLimits)
2829

2930
static const std::unordered_set<std::string> kStatementStartingKeywords =
3031
{"while", "if", "local", "repeat", "function", "do", "for", "return", "break", "continue", "type", "export"};
@@ -177,6 +178,12 @@ static bool checkTypeMatch(TypeId subTy, TypeId superTy, NotNull<Scope> scope, T
177178
unifier.normalize = false;
178179
unifier.checkInhabited = false;
179180

181+
if (FFlag::LuauAutocompleteUseLimits)
182+
{
183+
unifierState.counters.recursionLimit = FInt::LuauTypeInferRecursionLimit;
184+
unifierState.counters.iterationLimit = FInt::LuauTypeInferIterationLimit;
185+
}
186+
180187
return unifier.canUnify(subTy, superTy).empty();
181188
}
182189
}

Analysis/src/BuiltinDefinitions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,9 @@ static void dcrMagicFunctionTypeCheckFormat(MagicFunctionTypeCheckContext contex
611611
if (!fmt)
612612
{
613613
if (FFlag::LuauStringFormatArityFix)
614-
context.typechecker->reportError(CountMismatch{1, std::nullopt, 0, CountMismatch::Arg, true, "string.format"}, context.callSite->location);
614+
context.typechecker->reportError(
615+
CountMismatch{1, std::nullopt, 0, CountMismatch::Arg, true, "string.format"}, context.callSite->location
616+
);
615617
return;
616618
}
617619

Analysis/src/Constraint.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct ReferenceCountInitializer : TypeOnceVisitor
6262
// of this type, hence:
6363
return !FFlag::LuauDontRefCountTypesInTypeFunctions;
6464
}
65-
6665
};
6766

6867
bool isReferenceCountedType(const TypeId typ)

0 commit comments

Comments
 (0)