Skip to content

Commit 9a6536a

Browse files
authored
Merge pull request #9 from secondlife/wip_690
Merge upstream Luau 0.691
2 parents e703819 + ffb9790 commit 9a6536a

File tree

230 files changed

+13027
-6463
lines changed

Some content is hidden

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

230 files changed

+13027
-6463
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ on:
99
- 'papers/**'
1010
- 'rfcs/**'
1111
- '*.md'
12-
pull_request:
13-
paths-ignore:
14-
- 'docs/**'
15-
- 'papers/**'
16-
- 'rfcs/**'
17-
- '*.md'
12+
# pull_request:
13+
# paths-ignore:
14+
# - 'docs/**'
15+
# - 'papers/**'
16+
# - 'rfcs/**'
17+
# - '*.md'
1818

1919
jobs:
2020
unix:

Analysis/include/Luau/AstUtils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#pragma once
3+
4+
#include "Luau/Ast.h"
5+
#include "Luau/DenseHash.h"
6+
#include "Luau/NotNull.h"
7+
#include "Luau/TypeFwd.h"
8+
9+
namespace Luau
10+
{
11+
12+
// Search through the expression 'expr' for types that are known to represent
13+
// uniquely held references. Append these types to 'uniqueTypes'.
14+
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, AstExpr* expr, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);
15+
16+
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, AstArray<AstExpr*> exprs, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);
17+
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, const std::vector<AstExpr*>& exprs, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);
18+
19+
}

Analysis/include/Luau/AutocompleteTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum class AutocompleteContext
1818
Type,
1919
Keyword,
2020
String,
21+
HotComment,
2122
};
2223

2324
enum class AutocompleteEntryKind
@@ -30,6 +31,7 @@ enum class AutocompleteEntryKind
3031
Module,
3132
GeneratedFunction,
3233
RequirePath,
34+
HotComment,
3335
};
3436

3537
enum class ParenthesesRecommendation

Analysis/include/Luau/Constraint.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct GeneralizationConstraint
5252

5353
std::vector<TypeId> interiorTypes;
5454
bool hasDeprecatedAttribute = false;
55+
AstAttr::DeprecatedInfo deprecatedInfo;
5556

5657
/// If true, never introduce generics. Always replace free types by their
5758
/// bounds or unknown. Presently used only to generalize the whole module.
@@ -91,6 +92,10 @@ struct FunctionCallConstraint
9192
TypeId fn;
9293
TypePackId argsPack;
9394
TypePackId result;
95+
96+
// callSite can be nullptr in the case that this constraint was
97+
// synthetically generated from some other constraint. eg
98+
// IterableConstraint.
9499
class AstExprCall* callSite = nullptr;
95100
std::vector<std::optional<TypeId>> discriminantTypes;
96101

@@ -115,21 +120,6 @@ struct FunctionCheckConstraint
115120
NotNull<DenseHashMap<const AstExpr*, TypeId>> astExpectedTypes;
116121
};
117122

118-
// table_check expectedType exprType
119-
//
120-
// If `expectedType` is a table type and `exprType` is _also_ a table type,
121-
// propogate the member types of `expectedType` into the types of `exprType`.
122-
// This is used to implement bidirectional inference on table assignment.
123-
// Also see: FunctionCheckConstraint.
124-
struct TableCheckConstraint
125-
{
126-
TypeId expectedType;
127-
TypeId exprType;
128-
AstExprTable* table = nullptr;
129-
NotNull<DenseHashMap<const AstExpr*, TypeId>> astTypes;
130-
NotNull<DenseHashMap<const AstExpr*, TypeId>> astExpectedTypes;
131-
};
132-
133123
// prim FreeType ExpectedType PrimitiveType
134124
//
135125
// FreeType is bounded below by the singleton type and above by PrimitiveType
@@ -302,6 +292,15 @@ struct PushFunctionTypeConstraint
302292
bool isSelf;
303293
};
304294

295+
struct PushTypeConstraint
296+
{
297+
TypeId expectedType;
298+
TypeId targetType;
299+
NotNull<DenseHashMap<const AstExpr*, TypeId>> astTypes;
300+
NotNull<DenseHashMap<const AstExpr*, TypeId>> astExpectedTypes;
301+
NotNull<const AstExpr> expr;
302+
};
303+
305304
using ConstraintV = Variant<
306305
SubtypeConstraint,
307306
PackSubtypeConstraint,
@@ -320,9 +319,9 @@ using ConstraintV = Variant<
320319
ReduceConstraint,
321320
ReducePackConstraint,
322321
EqualityConstraint,
323-
TableCheckConstraint,
324322
SimplifyConstraint,
325-
PushFunctionTypeConstraint>;
323+
PushFunctionTypeConstraint,
324+
PushTypeConstraint>;
326325

327326
struct Constraint
328327
{

Analysis/include/Luau/ConstraintGenerator.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "Luau/ControlFlow.h"
88
#include "Luau/DataFlowGraph.h"
99
#include "Luau/EqSatSimplification.h"
10+
#include "Luau/HashUtil.h"
1011
#include "Luau/InsertionOrderedMap.h"
1112
#include "Luau/Module.h"
1213
#include "Luau/ModuleResolver.h"
@@ -135,6 +136,8 @@ struct ConstraintGenerator
135136

136137
DcrLogger* logger;
137138

139+
bool recursionLimitMet = false;
140+
138141
ConstraintGenerator(
139142
ModulePtr module,
140143
NotNull<Normalizer> normalizer,
@@ -170,11 +173,12 @@ struct ConstraintGenerator
170173
std::vector<TypePackId> typePacks;
171174
};
172175

173-
std::vector<std::vector<TypeId>> DEPRECATED_interiorTypes;
174176
std::vector<InteriorFreeTypes> interiorFreeTypes;
175177

176178
std::vector<TypeId> unionsToSimplify;
177179

180+
DenseHashMap<std::pair<TypeId, std::string>, TypeId, PairHash<TypeId, std::string>> propIndexPairsSeen{{nullptr, ""}};
181+
178182
// Used to keep track of when we are inside a large table and should
179183
// opt *not* to do type inference for singletons.
180184
size_t largeTableDepth = 0;
@@ -260,7 +264,6 @@ struct ConstraintGenerator
260264
LUAU_NOINLINE void checkAliases(const ScopePtr& scope, AstStatBlock* block);
261265

262266
ControlFlow visitBlockWithoutChildScope(const ScopePtr& scope, AstStatBlock* block);
263-
ControlFlow visitBlockWithoutChildScope_DEPRECATED(const ScopePtr& scope, AstStatBlock* block);
264267

265268
ControlFlow visit(const ScopePtr& scope, AstStat* stat);
266269
ControlFlow visit(const ScopePtr& scope, AstStatBlock* block);
@@ -497,6 +500,7 @@ struct ConstraintGenerator
497500

498501
void updateRValueRefinements(const ScopePtr& scope, DefId def, TypeId ty) const;
499502
void updateRValueRefinements(Scope* scope, DefId def, TypeId ty) const;
503+
void resolveGenericDefaultParameters(const ScopePtr& defnScope, AstStatTypeAlias* alias, const TypeFun& fun);
500504
};
501505

502506
} // namespace Luau

Analysis/include/Luau/ConstraintSolver.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct ConstraintSolver
108108
std::vector<NotNull<Constraint>> constraints;
109109
NotNull<DenseHashMap<Scope*, TypeId>> scopeToFunction;
110110
NotNull<Scope> rootScope;
111-
ModuleName currentModuleName;
111+
ModulePtr module;
112112

113113
// The dataflow graph of the program, used in constraint generation and for magic functions.
114114
NotNull<const DataFlowGraph> dfg;
@@ -169,7 +169,7 @@ struct ConstraintSolver
169169
NotNull<Normalizer> normalizer,
170170
NotNull<Simplifier> simplifier,
171171
NotNull<TypeFunctionRuntime> typeFunctionRuntime,
172-
ModuleName moduleName,
172+
ModulePtr module,
173173
NotNull<ModuleResolver> moduleResolver,
174174
std::vector<RequireCycle> requireCycles,
175175
DcrLogger* logger,
@@ -178,14 +178,15 @@ struct ConstraintSolver
178178
ConstraintSet constraintSet
179179
);
180180

181+
// TODO CLI-169086: Replace all uses of this constructor with the ConstraintSet constructor, above.
181182
explicit ConstraintSolver(
182183
NotNull<Normalizer> normalizer,
183184
NotNull<Simplifier> simplifier,
184185
NotNull<TypeFunctionRuntime> typeFunctionRuntime,
185186
NotNull<Scope> rootScope,
186187
std::vector<NotNull<Constraint>> constraints,
187188
NotNull<DenseHashMap<Scope*, TypeId>> scopeToFunction,
188-
ModuleName moduleName,
189+
ModulePtr module,
189190
NotNull<ModuleResolver> moduleResolver,
190191
std::vector<RequireCycle> requireCycles,
191192
DcrLogger* logger,
@@ -249,8 +250,7 @@ struct ConstraintSolver
249250
bool tryDispatch(const NameConstraint& c, NotNull<const Constraint> constraint);
250251
bool tryDispatch(const TypeAliasExpansionConstraint& c, NotNull<const Constraint> constraint);
251252
bool tryDispatch(const FunctionCallConstraint& c, NotNull<const Constraint> constraint, bool force);
252-
bool tryDispatch(const TableCheckConstraint& c, NotNull<const Constraint> constraint);
253-
bool tryDispatch(const FunctionCheckConstraint& c, NotNull<const Constraint> constraint);
253+
bool tryDispatch(const FunctionCheckConstraint& c, NotNull<const Constraint> constraint, bool force);
254254
bool tryDispatch(const PrimitiveTypeConstraint& c, NotNull<const Constraint> constraint);
255255
bool tryDispatch(const HasPropConstraint& c, NotNull<const Constraint> constraint);
256256

@@ -275,6 +275,7 @@ struct ConstraintSolver
275275
bool tryDispatch(const SimplifyConstraint& c, NotNull<const Constraint> constraint, bool force);
276276

277277
bool tryDispatch(const PushFunctionTypeConstraint& c, NotNull<const Constraint> constraint);
278+
bool tryDispatch(const PushTypeConstraint& c, NotNull<const Constraint> constraint, bool force);
278279

279280
// for a, ... in some_table do
280281
// also handles __iter metamethod

Analysis/include/Luau/Error.h

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
22
#pragma once
33

4+
#include "Luau/Ast.h"
45
#include "Luau/Location.h"
56
#include "Luau/NotNull.h"
67
#include "Luau/Type.h"
8+
#include "Luau/TypeIds.h"
79
#include "Luau/Variant.h"
8-
#include "Luau/Ast.h"
910

1011
#include <set>
1112

@@ -86,6 +87,15 @@ struct CannotExtendTable
8687
bool operator==(const CannotExtendTable& rhs) const;
8788
};
8889

90+
struct CannotCompareUnrelatedTypes
91+
{
92+
TypeId left;
93+
TypeId right;
94+
AstExprBinary::Op op;
95+
96+
bool operator==(const CannotCompareUnrelatedTypes& rhs) const;
97+
};
98+
8999
struct OnlyTablesCanHaveMethods
90100
{
91101
TypeId tableType;
@@ -504,12 +514,49 @@ struct MultipleNonviableOverloads
504514
bool operator==(const MultipleNonviableOverloads& rhs) const;
505515
};
506516

517+
// Error where a type alias violates the recursive restraint, ie when a type alias T<A> has T with different arguments on the RHS.
518+
struct RecursiveRestraintViolation
519+
{
520+
bool operator==(const RecursiveRestraintViolation& rhs) const
521+
{
522+
return true;
523+
}
524+
};
525+
526+
// Error during subtyping when the inferred bounds of a generic type are incompatible
527+
struct GenericBoundsMismatch
528+
{
529+
std::string_view genericName;
530+
std::vector<TypeId> lowerBounds;
531+
std::vector<TypeId> upperBounds;
532+
533+
GenericBoundsMismatch(std::string_view genericName, TypeIds lowerBoundSet, TypeIds upperBoundSet);
534+
535+
bool operator==(const GenericBoundsMismatch& rhs) const;
536+
};
537+
538+
// Error when referencing a type function without providing explicit generics.
539+
//
540+
// type function create_table_with_key()
541+
// local tbl = types.newtable()
542+
// tbl:setproperty(types.singleton "key", types.unionof(types.string, types.singleton(nil)))
543+
// return tbl
544+
// end
545+
// local a: create_table_with_key = {}
546+
// ^^^^^^^^^^^^^^^^^^^^^ This should have `<>` at the end.
547+
//
548+
struct UnappliedTypeFunction
549+
{
550+
bool operator==(const UnappliedTypeFunction& rhs) const;
551+
};
552+
507553
using TypeErrorData = Variant<
508554
TypeMismatch,
509555
UnknownSymbol,
510556
UnknownProperty,
511557
NotATable,
512558
CannotExtendTable,
559+
CannotCompareUnrelatedTypes,
513560
OnlyTablesCanHaveMethods,
514561
DuplicateTypeDefinition,
515562
CountMismatch,
@@ -559,7 +606,11 @@ using TypeErrorData = Variant<
559606
CannotCheckDynamicStringFormatCalls,
560607
GenericTypeCountMismatch,
561608
GenericTypePackCountMismatch,
562-
MultipleNonviableOverloads>;
609+
MultipleNonviableOverloads,
610+
RecursiveRestraintViolation,
611+
GenericBoundsMismatch,
612+
UnappliedTypeFunction>;
613+
563614

564615
struct TypeErrorSummary
565616
{

Analysis/include/Luau/FragmentAutocomplete.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ FragmentAutocompleteResult fragmentAutocomplete(
127127
StringCompletionCallback callback,
128128
std::optional<Position> fragmentEndPosition = std::nullopt,
129129
AstStatBlock* recentParse = nullptr,
130-
IFragmentAutocompleteReporter* reporter = nullptr
130+
IFragmentAutocompleteReporter* reporter = nullptr,
131+
bool isInHotComment = false
131132
);
132133

133134
enum class FragmentAutocompleteStatus

Analysis/include/Luau/Frontend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct Frontend
176176

177177
Frontend(FileResolver* fileResolver, ConfigResolver* configResolver, const FrontendOptions& options = {});
178178

179-
void setLuauSolverSelectionFromWorkspace(SolverMode mode);
179+
void setLuauSolverMode(SolverMode mode);
180180
SolverMode getLuauSolverMode() const;
181181
// The default value assuming there is no workspace setup yet
182182
std::atomic<SolverMode> useNewLuauSolver{FFlag::LuauSolverV2 ? SolverMode::New : SolverMode::Old};
@@ -330,7 +330,7 @@ ModulePtr check(
330330
NotNull<InternalErrorReporter> iceHandler,
331331
NotNull<ModuleResolver> moduleResolver,
332332
NotNull<FileResolver> fileResolver,
333-
const ScopePtr& globalScope,
333+
const ScopePtr& parentScope,
334334
const ScopePtr& typeFunctionScope,
335335
std::function<void(const ModuleName&, const ScopePtr&)> prepareModuleScope,
336336
FrontendOptions options,

Analysis/include/Luau/GlobalTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct GlobalTypes
2020
TypeArena globalTypes;
2121
SourceModule globalNames; // names for symbols entered into globalScope
2222

23-
ScopePtr globalScope; // shared by all modules
23+
ScopePtr globalScope; // shared by all modules
2424
ScopePtr globalTypeFunctionScope; // shared by all modules
2525

2626
SolverMode mode = SolverMode::Old;

0 commit comments

Comments
 (0)