-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync to upstream/release/636 (#1346)
# What's Changed? - Telemetry support for usage of any type in old/new solver - Bug fixes and flag removals with the new solver ## New Solver - Fixed constraint ordering bug to infer types more accurately - Improved inferring a call to `setmetatable()` ## VM - Restored global metatable lookup for `typeof` on lightuserdata to fix unintentional API change (Fixes #1335) --- ### Internal Contributors Co-authored-by: Aaron Weiss <[email protected]> Co-authored-by: Alexander McCord <[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]>
- Loading branch information
1 parent
a80abdb
commit 5e0779f
Showing
40 changed files
with
2,281 additions
and
676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details | ||
#pragma once | ||
|
||
#include "Luau/Config.h" | ||
#include "Luau/ModuleResolver.h" | ||
#include "Luau/Scope.h" | ||
#include "Luau/Variant.h" | ||
#include "Luau/Normalize.h" | ||
#include "Luau/TypePack.h" | ||
#include "Luau/TypeArena.h" | ||
|
||
#include <mutex> | ||
#include <string> | ||
#include <vector> | ||
#include <optional> | ||
|
||
namespace Luau | ||
{ | ||
|
||
class AstStat; | ||
class ParseError; | ||
struct TypeError; | ||
struct LintWarning; | ||
struct GlobalTypes; | ||
struct ModuleResolver; | ||
struct ParseResult; | ||
struct DcrLogger; | ||
|
||
struct TelemetryTypePair | ||
{ | ||
std::string annotatedType; | ||
std::string inferredType; | ||
}; | ||
|
||
struct AnyTypeSummary | ||
{ | ||
TypeArena arena; | ||
|
||
DenseHashSet<TypeId> seenTypeFamilyInstances{nullptr}; | ||
|
||
int recursionCount = 0; | ||
|
||
std::string root; | ||
int strictCount = 0; | ||
|
||
DenseHashMap<const void*, bool> seen{nullptr}; | ||
|
||
AnyTypeSummary(); | ||
|
||
void traverse(Module* module, AstStat* src, NotNull<BuiltinTypes> builtinTypes); | ||
|
||
std::pair<bool, TypeId> checkForAnyCast(Scope* scope, AstExprTypeAssertion* expr); | ||
|
||
// Todo: errors resolved by anys | ||
void reportError(Location location, TypeErrorData err); | ||
|
||
bool containsAny(TypePackId typ); | ||
bool containsAny(TypeId typ); | ||
|
||
bool isAnyCast(Scope* scope, AstExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
bool isAnyCall(Scope* scope, AstExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
|
||
bool hasVariadicAnys(Scope* scope, AstExprFunction* expr, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
bool hasArgAnys(Scope* scope, AstExprFunction* expr, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
bool hasAnyReturns(Scope* scope, AstExprFunction* expr, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
|
||
TypeId checkForFamilyInhabitance(TypeId instance, Location location); | ||
TypeId lookupType(AstExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
TypePackId reconstructTypePack(AstArray<AstExpr*> exprs, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
|
||
DenseHashSet<TypeId> seenTypeFunctionInstances{nullptr}; | ||
TypeId lookupAnnotation(AstType* annotation, Module* module, NotNull<BuiltinTypes> builtintypes); | ||
std::optional<TypePackId> lookupPackAnnotation(AstTypePack* annotation, Module* module); | ||
TypeId checkForTypeFunctionInhabitance(TypeId instance, Location location); | ||
|
||
enum Pattern : uint64_t | ||
{ | ||
Casts, | ||
FuncArg, | ||
FuncRet, | ||
FuncApp, | ||
VarAnnot, | ||
VarAny, | ||
TableProp, | ||
Alias, | ||
Assign | ||
}; | ||
|
||
struct TypeInfo | ||
{ | ||
Pattern code; | ||
std::string node; | ||
TelemetryTypePair type; | ||
std::string debug; | ||
|
||
explicit TypeInfo(Pattern code, std::string node, TelemetryTypePair type); | ||
}; | ||
|
||
std::vector<TypeInfo> typeInfo; | ||
|
||
/** | ||
* Fabricates a scope that is a child of another scope. | ||
* @param node the lexical node that the scope belongs to. | ||
* @param parent the parent scope of the new scope. Must not be null. | ||
*/ | ||
Scope* childScope(AstNode* node, const Scope* parent); | ||
|
||
Scope* findInnerMostScope(Location location, Module* module); | ||
|
||
void visit(Scope* scope, AstStat* stat, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatBlock* block, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatIf* ifStatement, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatWhile* while_, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatRepeat* repeat, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatReturn* ret, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatLocal* local, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatFor* for_, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatForIn* forIn, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatAssign* assign, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatCompoundAssign* assign, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatFunction* function, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatLocalFunction* function, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatTypeAlias* alias, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatExpr* expr, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatDeclareGlobal* declareGlobal, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatDeclareClass* declareClass, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatDeclareFunction* declareFunction, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
void visit(Scope* scope, AstStatError* error, Module* module, NotNull<BuiltinTypes> builtinTypes); | ||
}; | ||
|
||
} // namespace Luau |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.