-
Notifications
You must be signed in to change notification settings - Fork 391
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/616 (#1184)
# What's Changed * Add a compiler hint to improve Luau memory allocation inlining ### New Type Solver * Added a system for recommending explicit type annotations to users in cases where we've inferred complex generic types with type families. * Marked string library functions as `@checked` for use in new non-strict mode. * Fixed a bug with new non-strict mode where we would incorrectly report arity mismatches when missing optional arguments. * Implement an occurs check for unifications that would produce self-recursive types. * Fix bug where overload resolution would fail when applied to non-overloaded functions. * Fix bug that caused the subtyping to report an error whenever a generic was instantiated in an invariant context. * Fix crash caused by `SetPropConstraint` not blocking properly. ### Native Code Generation * Implement optimization to eliminate dead stores * Optimize vector ops for X64 when the source is computed (thanks, @zeux!) * Use more efficient lowering for UNM_* (thanks, @zeux!) --- ### 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: David Cope <[email protected]> Co-authored-by: Lily Brown <[email protected]> Co-authored-by: Vyacheslav Egorov <[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
9323be6
commit ae459a0
Showing
48 changed files
with
2,371 additions
and
283 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details | ||
|
||
#pragma once | ||
|
||
#include "Luau/Ast.h" | ||
#include "Luau/VecDeque.h" | ||
#include "Luau/DenseHash.h" | ||
#include "Luau/TypeFamily.h" | ||
#include "Luau/Type.h" | ||
#include "Luau/TypePack.h" | ||
#include "Luau/TypeUtils.h" | ||
#include "Luau/Normalize.h" | ||
#include "Luau/TypeFwd.h" | ||
#include "Luau/VisitType.h" | ||
#include "Luau/NotNull.h" | ||
|
||
namespace Luau | ||
{ | ||
|
||
struct TypeFamilyReductionGuessResult | ||
{ | ||
std::vector<std::pair<std::string, TypeId>> guessedFunctionAnnotations; | ||
TypeId guessedReturnType; | ||
bool shouldRecommendAnnotation = true; | ||
}; | ||
|
||
// An Inference result for a type family is a list of types corresponding to the guessed argument types, followed by a type for the result | ||
struct TypeFamilyInferenceResult | ||
{ | ||
std::vector<TypeId> operandInference; | ||
TypeId familyResultInference; | ||
}; | ||
|
||
struct TypeFamilyReductionGuesser | ||
{ | ||
// Tracks our hypothesis about what a type family reduces to | ||
DenseHashMap<TypeId, TypeId> familyReducesTo{nullptr}; | ||
// Tracks our constraints on type family operands | ||
DenseHashMap<TypeId, TypeId> substitutable{nullptr}; | ||
// List of instances to try progress | ||
VecDeque<TypeId> toInfer; | ||
DenseHashSet<TypeId> cyclicInstances{nullptr}; | ||
|
||
// Utilities | ||
NotNull<BuiltinTypes> builtins; | ||
NotNull<Normalizer> normalizer; | ||
|
||
TypeFamilyReductionGuesser(NotNull<BuiltinTypes> builtins, NotNull<Normalizer> normalizer); | ||
|
||
TypeFamilyReductionGuessResult guessTypeFamilyReductionForFunction(const AstExprFunction& expr, const FunctionType* ftv, TypeId retTy); | ||
|
||
private: | ||
std::optional<TypeId> guessType(TypeId arg); | ||
void dumpGuesses(); | ||
|
||
bool isNumericBinopFamily(const TypeFamilyInstanceType& instance); | ||
bool isComparisonFamily(const TypeFamilyInstanceType& instance); | ||
bool isOrAndFamily(const TypeFamilyInstanceType& instance); | ||
bool isNotFamily(const TypeFamilyInstanceType& instance); | ||
bool isLenFamily(const TypeFamilyInstanceType& instance); | ||
bool isUnaryMinus(const TypeFamilyInstanceType& instance); | ||
|
||
// Operand is assignable if it looks like a cyclic family instance, or a generic type | ||
bool operandIsAssignable(TypeId ty); | ||
std::optional<TypeId> tryAssignOperandType(TypeId ty); | ||
|
||
const NormalizedType* normalize(TypeId ty); | ||
void step(); | ||
void infer(); | ||
bool done(); | ||
|
||
bool isFunctionGenericsSaturated(const FunctionType& ftv, DenseHashSet<TypeId>& instanceArgs); | ||
void inferTypeFamilySubstitutions(TypeId ty, const TypeFamilyInstanceType* instance); | ||
TypeFamilyInferenceResult inferNumericBinopFamily(const TypeFamilyInstanceType* instance); | ||
TypeFamilyInferenceResult inferComparisonFamily(const TypeFamilyInstanceType* instance); | ||
TypeFamilyInferenceResult inferOrAndFamily(const TypeFamilyInstanceType* instance); | ||
TypeFamilyInferenceResult inferNotFamily(const TypeFamilyInstanceType* instance); | ||
TypeFamilyInferenceResult inferLenFamily(const TypeFamilyInstanceType* instance); | ||
TypeFamilyInferenceResult inferUnaryMinusFamily(const TypeFamilyInstanceType* instance); | ||
}; | ||
} // 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
Oops, something went wrong.