Skip to content

Commit ce8495a

Browse files
joonyoo181aatxealexmccordandyfriesenVighnesh-V
authored
Sync to upstream/release/637 (#1354)
# What's Changed? - Code refactoring with a new clang-format - More bug fixes / test case fixes in the new solver ## New Solver - More precise telemetry collection of `any` types - Simplification of two completely disjoint tables combines them into a single table that inherits all properties / indexers - Refining a `never & <anything>` does not produce type family types nor constraints - Silence "inference failed to complete" error when it is the only error reported --- ### Internal Contributors Co-authored-by: Aaron Weiss <[email protected]> Co-authored-by: Andy Friesen <[email protected]> Co-authored-by: Dibri Nsofor <[email protected]> Co-authored-by: Jeremy Yoo <[email protected]> Co-authored-by: Vighnesh Vijay <[email protected]> Co-authored-by: Vyacheslav Egorov <[email protected]> --------- Co-authored-by: Aaron Weiss <[email protected]> Co-authored-by: Alexander McCord <[email protected]> Co-authored-by: Andy Friesen <[email protected]> Co-authored-by: Vighnesh <[email protected]> Co-authored-by: Aviral Goel <[email protected]> Co-authored-by: David Cope <[email protected]> Co-authored-by: Lily Brown <[email protected]> Co-authored-by: Vyacheslav Egorov <[email protected]>
1 parent 58f8c24 commit ce8495a

File tree

218 files changed

+11090
-5124
lines changed

Some content is hidden

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

218 files changed

+11090
-5124
lines changed

.clang-format

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ SortIncludes: false
1616
IndentWidth: 4
1717
TabWidth: 4
1818
ObjCBlockIndentWidth: 4
19-
AlignAfterOpenBracket: DontAlign
2019
UseTab: Never
2120
PointerAlignment: Left
2221
SpaceAfterTemplateKeyword: false
2322
AlignEscapedNewlines: DontAlign
2423
AlwaysBreakTemplateDeclarations: Yes
2524
MaxEmptyLinesToKeep: 10
25+
AllowAllParametersOfDeclarationOnNextLine: false
26+
AlignAfterOpenBracket: BlockIndent
27+
BinPackArguments: false
28+
BinPackParameters: false
29+
PenaltyReturnTypeOnItsOwnLine: 10000

Analysis/include/Luau/AnyTypeSummary.h

+57-41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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/AstQuery.h"
45
#include "Luau/Config.h"
56
#include "Luau/ModuleResolver.h"
67
#include "Luau/Scope.h"
@@ -36,6 +37,7 @@ struct AnyTypeSummary
3637
{
3738
TypeArena arena;
3839

40+
AstStatBlock* rootSrc = nullptr;
3941
DenseHashSet<TypeId> seenTypeFamilyInstances{nullptr};
4042

4143
int recursionCount = 0;
@@ -47,33 +49,30 @@ struct AnyTypeSummary
4749

4850
AnyTypeSummary();
4951

50-
void traverse(Module* module, AstStat* src, NotNull<BuiltinTypes> builtinTypes);
52+
void traverse(const Module* module, AstStat* src, NotNull<BuiltinTypes> builtinTypes);
5153

52-
std::pair<bool, TypeId> checkForAnyCast(Scope* scope, AstExprTypeAssertion* expr);
53-
54-
// Todo: errors resolved by anys
55-
void reportError(Location location, TypeErrorData err);
54+
std::pair<bool, TypeId> checkForAnyCast(const Scope* scope, AstExprTypeAssertion* expr);
5655

5756
bool containsAny(TypePackId typ);
5857
bool containsAny(TypeId typ);
5958

60-
bool isAnyCast(Scope* scope, AstExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes);
61-
bool isAnyCall(Scope* scope, AstExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes);
59+
bool isAnyCast(const Scope* scope, AstExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
60+
bool isAnyCall(const Scope* scope, AstExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
6261

63-
bool hasVariadicAnys(Scope* scope, AstExprFunction* expr, Module* module, NotNull<BuiltinTypes> builtinTypes);
64-
bool hasArgAnys(Scope* scope, AstExprFunction* expr, Module* module, NotNull<BuiltinTypes> builtinTypes);
65-
bool hasAnyReturns(Scope* scope, AstExprFunction* expr, Module* module, NotNull<BuiltinTypes> builtinTypes);
62+
bool hasVariadicAnys(const Scope* scope, AstExprFunction* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
63+
bool hasArgAnys(const Scope* scope, AstExprFunction* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
64+
bool hasAnyReturns(const Scope* scope, AstExprFunction* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
6665

67-
TypeId checkForFamilyInhabitance(TypeId instance, Location location);
68-
TypeId lookupType(AstExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes);
69-
TypePackId reconstructTypePack(AstArray<AstExpr*> exprs, Module* module, NotNull<BuiltinTypes> builtinTypes);
66+
TypeId checkForFamilyInhabitance(const TypeId instance, Location location);
67+
TypeId lookupType(const AstExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
68+
TypePackId reconstructTypePack(const AstArray<AstExpr*> exprs, const Module* module, NotNull<BuiltinTypes> builtinTypes);
7069

7170
DenseHashSet<TypeId> seenTypeFunctionInstances{nullptr};
72-
TypeId lookupAnnotation(AstType* annotation, Module* module, NotNull<BuiltinTypes> builtintypes);
73-
std::optional<TypePackId> lookupPackAnnotation(AstTypePack* annotation, Module* module);
74-
TypeId checkForTypeFunctionInhabitance(TypeId instance, Location location);
71+
TypeId lookupAnnotation(AstType* annotation, const Module* module, NotNull<BuiltinTypes> builtintypes);
72+
std::optional<TypePackId> lookupPackAnnotation(AstTypePack* annotation, const Module* module);
73+
TypeId checkForTypeFunctionInhabitance(const TypeId instance, const Location location);
7574

76-
enum Pattern : uint64_t
75+
enum Pattern: uint64_t
7776
{
7877
Casts,
7978
FuncArg,
@@ -91,41 +90,58 @@ struct AnyTypeSummary
9190
Pattern code;
9291
std::string node;
9392
TelemetryTypePair type;
94-
std::string debug;
9593

9694
explicit TypeInfo(Pattern code, std::string node, TelemetryTypePair type);
9795
};
9896

97+
struct FindReturnAncestry final : public AstVisitor
98+
{
99+
AstNode* currNode{nullptr};
100+
AstNode* stat{nullptr};
101+
Position rootEnd;
102+
bool found = false;
103+
104+
explicit FindReturnAncestry(AstNode* stat, Position rootEnd);
105+
106+
bool visit(AstType* node) override;
107+
bool visit(AstNode* node) override;
108+
bool visit(AstStatFunction* node) override;
109+
bool visit(AstStatLocalFunction* node) override;
110+
};
111+
99112
std::vector<TypeInfo> typeInfo;
100113

101114
/**
102115
* Fabricates a scope that is a child of another scope.
103116
* @param node the lexical node that the scope belongs to.
104117
* @param parent the parent scope of the new scope. Must not be null.
105118
*/
106-
Scope* childScope(AstNode* node, const Scope* parent);
107-
108-
Scope* findInnerMostScope(Location location, Module* module);
109-
110-
void visit(Scope* scope, AstStat* stat, Module* module, NotNull<BuiltinTypes> builtinTypes);
111-
void visit(Scope* scope, AstStatBlock* block, Module* module, NotNull<BuiltinTypes> builtinTypes);
112-
void visit(Scope* scope, AstStatIf* ifStatement, Module* module, NotNull<BuiltinTypes> builtinTypes);
113-
void visit(Scope* scope, AstStatWhile* while_, Module* module, NotNull<BuiltinTypes> builtinTypes);
114-
void visit(Scope* scope, AstStatRepeat* repeat, Module* module, NotNull<BuiltinTypes> builtinTypes);
115-
void visit(Scope* scope, AstStatReturn* ret, Module* module, NotNull<BuiltinTypes> builtinTypes);
116-
void visit(Scope* scope, AstStatLocal* local, Module* module, NotNull<BuiltinTypes> builtinTypes);
117-
void visit(Scope* scope, AstStatFor* for_, Module* module, NotNull<BuiltinTypes> builtinTypes);
118-
void visit(Scope* scope, AstStatForIn* forIn, Module* module, NotNull<BuiltinTypes> builtinTypes);
119-
void visit(Scope* scope, AstStatAssign* assign, Module* module, NotNull<BuiltinTypes> builtinTypes);
120-
void visit(Scope* scope, AstStatCompoundAssign* assign, Module* module, NotNull<BuiltinTypes> builtinTypes);
121-
void visit(Scope* scope, AstStatFunction* function, Module* module, NotNull<BuiltinTypes> builtinTypes);
122-
void visit(Scope* scope, AstStatLocalFunction* function, Module* module, NotNull<BuiltinTypes> builtinTypes);
123-
void visit(Scope* scope, AstStatTypeAlias* alias, Module* module, NotNull<BuiltinTypes> builtinTypes);
124-
void visit(Scope* scope, AstStatExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes);
125-
void visit(Scope* scope, AstStatDeclareGlobal* declareGlobal, Module* module, NotNull<BuiltinTypes> builtinTypes);
126-
void visit(Scope* scope, AstStatDeclareClass* declareClass, Module* module, NotNull<BuiltinTypes> builtinTypes);
127-
void visit(Scope* scope, AstStatDeclareFunction* declareFunction, Module* module, NotNull<BuiltinTypes> builtinTypes);
128-
void visit(Scope* scope, AstStatError* error, Module* module, NotNull<BuiltinTypes> builtinTypes);
119+
const Scope* childScope(const AstNode* node, const Scope* parent);
120+
121+
std::optional<AstExpr*> matchRequire(const AstExprCall& call);
122+
AstNode* getNode(AstStatBlock* root, AstNode* node);
123+
const Scope* findInnerMostScope(const Location location, const Module* module);
124+
const AstNode* findAstAncestryAtLocation(const AstStatBlock* root, AstNode* node);
125+
126+
void visit(const Scope* scope, AstStat* stat, const Module* module, NotNull<BuiltinTypes> builtinTypes);
127+
void visit(const Scope* scope, AstStatBlock* block, const Module* module, NotNull<BuiltinTypes> builtinTypes);
128+
void visit(const Scope* scope, AstStatIf* ifStatement, const Module* module, NotNull<BuiltinTypes> builtinTypes);
129+
void visit(const Scope* scope, AstStatWhile* while_, const Module* module, NotNull<BuiltinTypes> builtinTypes);
130+
void visit(const Scope* scope, AstStatRepeat* repeat, const Module* module, NotNull<BuiltinTypes> builtinTypes);
131+
void visit(const Scope* scope, AstStatReturn* ret, const Module* module, NotNull<BuiltinTypes> builtinTypes);
132+
void visit(const Scope* scope, AstStatLocal* local, const Module* module, NotNull<BuiltinTypes> builtinTypes);
133+
void visit(const Scope* scope, AstStatFor* for_, const Module* module, NotNull<BuiltinTypes> builtinTypes);
134+
void visit(const Scope* scope, AstStatForIn* forIn, const Module* module, NotNull<BuiltinTypes> builtinTypes);
135+
void visit(const Scope* scope, AstStatAssign* assign, const Module* module, NotNull<BuiltinTypes> builtinTypes);
136+
void visit(const Scope* scope, AstStatCompoundAssign* assign, const Module* module, NotNull<BuiltinTypes> builtinTypes);
137+
void visit(const Scope* scope, AstStatFunction* function, const Module* module, NotNull<BuiltinTypes> builtinTypes);
138+
void visit(const Scope* scope, AstStatLocalFunction* function, const Module* module, NotNull<BuiltinTypes> builtinTypes);
139+
void visit(const Scope* scope, AstStatTypeAlias* alias, const Module* module, NotNull<BuiltinTypes> builtinTypes);
140+
void visit(const Scope* scope, AstStatExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
141+
void visit(const Scope* scope, AstStatDeclareGlobal* declareGlobal, const Module* module, NotNull<BuiltinTypes> builtinTypes);
142+
void visit(const Scope* scope, AstStatDeclareClass* declareClass, const Module* module, NotNull<BuiltinTypes> builtinTypes);
143+
void visit(const Scope* scope, AstStatDeclareFunction* declareFunction, const Module* module, NotNull<BuiltinTypes> builtinTypes);
144+
void visit(const Scope* scope, AstStatError* error, const Module* module, NotNull<BuiltinTypes> builtinTypes);
129145
};
130146

131147
} // namespace Luau

Analysis/include/Luau/Anyification.h

+16-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,22 @@ using ScopePtr = std::shared_ptr<Scope>;
1919
// A substitution which replaces free types by any
2020
struct Anyification : Substitution
2121
{
22-
Anyification(TypeArena* arena, NotNull<Scope> scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter* iceHandler, TypeId anyType,
23-
TypePackId anyTypePack);
24-
Anyification(TypeArena* arena, const ScopePtr& scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter* iceHandler, TypeId anyType,
25-
TypePackId anyTypePack);
22+
Anyification(
23+
TypeArena* arena,
24+
NotNull<Scope> scope,
25+
NotNull<BuiltinTypes> builtinTypes,
26+
InternalErrorReporter* iceHandler,
27+
TypeId anyType,
28+
TypePackId anyTypePack
29+
);
30+
Anyification(
31+
TypeArena* arena,
32+
const ScopePtr& scope,
33+
NotNull<BuiltinTypes> builtinTypes,
34+
InternalErrorReporter* iceHandler,
35+
TypeId anyType,
36+
TypePackId anyTypePack
37+
);
2638
NotNull<Scope> scope;
2739
NotNull<BuiltinTypes> builtinTypes;
2840
InternalErrorReporter* iceHandler;

Analysis/include/Luau/BuiltinDefinitions.h

+30-9
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,42 @@ TypeId makeOption(NotNull<BuiltinTypes> builtinTypes, TypeArena& arena, TypeId t
2525
/** Small utility function for building up type definitions from C++.
2626
*/
2727
TypeId makeFunction( // Monomorphic
28-
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> paramTypes, std::initializer_list<TypeId> retTypes,
29-
bool checked = false);
28+
TypeArena& arena,
29+
std::optional<TypeId> selfType,
30+
std::initializer_list<TypeId> paramTypes,
31+
std::initializer_list<TypeId> retTypes,
32+
bool checked = false
33+
);
3034

3135
TypeId makeFunction( // Polymorphic
32-
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> generics, std::initializer_list<TypePackId> genericPacks,
33-
std::initializer_list<TypeId> paramTypes, std::initializer_list<TypeId> retTypes, bool checked = false);
36+
TypeArena& arena,
37+
std::optional<TypeId> selfType,
38+
std::initializer_list<TypeId> generics,
39+
std::initializer_list<TypePackId> genericPacks,
40+
std::initializer_list<TypeId> paramTypes,
41+
std::initializer_list<TypeId> retTypes,
42+
bool checked = false
43+
);
3444

3545
TypeId makeFunction( // Monomorphic
36-
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> paramTypes, std::initializer_list<std::string> paramNames,
37-
std::initializer_list<TypeId> retTypes, bool checked = false);
46+
TypeArena& arena,
47+
std::optional<TypeId> selfType,
48+
std::initializer_list<TypeId> paramTypes,
49+
std::initializer_list<std::string> paramNames,
50+
std::initializer_list<TypeId> retTypes,
51+
bool checked = false
52+
);
3853

3954
TypeId makeFunction( // Polymorphic
40-
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> generics, std::initializer_list<TypePackId> genericPacks,
41-
std::initializer_list<TypeId> paramTypes, std::initializer_list<std::string> paramNames, std::initializer_list<TypeId> retTypes,
42-
bool checked = false);
55+
TypeArena& arena,
56+
std::optional<TypeId> selfType,
57+
std::initializer_list<TypeId> generics,
58+
std::initializer_list<TypePackId> genericPacks,
59+
std::initializer_list<TypeId> paramTypes,
60+
std::initializer_list<std::string> paramNames,
61+
std::initializer_list<TypeId> retTypes,
62+
bool checked = false
63+
);
4364

4465
void attachMagicFunction(TypeId ty, MagicFunction fn);
4566
void attachDcrMagicFunction(TypeId ty, DcrMagicFunction fn);

Analysis/include/Luau/Constraint.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,24 @@ struct ReducePackConstraint
256256
TypePackId tp;
257257
};
258258

259-
using ConstraintV = Variant<SubtypeConstraint, PackSubtypeConstraint, GeneralizationConstraint, IterableConstraint, NameConstraint,
260-
TypeAliasExpansionConstraint, FunctionCallConstraint, FunctionCheckConstraint, PrimitiveTypeConstraint, HasPropConstraint, HasIndexerConstraint,
261-
AssignPropConstraint, AssignIndexConstraint, UnpackConstraint, ReduceConstraint, ReducePackConstraint, EqualityConstraint>;
259+
using ConstraintV = Variant<
260+
SubtypeConstraint,
261+
PackSubtypeConstraint,
262+
GeneralizationConstraint,
263+
IterableConstraint,
264+
NameConstraint,
265+
TypeAliasExpansionConstraint,
266+
FunctionCallConstraint,
267+
FunctionCheckConstraint,
268+
PrimitiveTypeConstraint,
269+
HasPropConstraint,
270+
HasIndexerConstraint,
271+
AssignPropConstraint,
272+
AssignIndexConstraint,
273+
UnpackConstraint,
274+
ReduceConstraint,
275+
ReducePackConstraint,
276+
EqualityConstraint>;
262277

263278
struct Constraint
264279
{

0 commit comments

Comments
 (0)