-
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.
* `ClassType` can now have an indexer defined on it. This allows custom types to be used in `t[x]` expressions. * Fixed search for closest executable breakpoint line. Previously, breakpoints might have been skipped in `else` blocks at the end of a function * Fixed how unification is performed for two optional types `a? <: b?`, previously it might have unified either 'a' or 'b' with 'nil'. Note that this fix is not enabled by default yet (see the list in `ExperimentalFlags.h`) In the new type solver, a concept of 'Type Families' has been introduced. Type families can be thought of as type aliases with custom type inference/reduction logic included with them. For example, we can have an `Add<T, U>` type family that will resolve the type that is the result of adding two values together. This will help type inference to figure out what 'T' and 'U' might be when explicit type annotations are not provided. In this update we don't define any type families, but they will be added in the near future. It is also possible for Luau embedders to define their own type families in the global/environment scope. Other changes include: * Fixed scope used to find out which generic types should be included in the function generic type list * Fixed a crash after cyclic bound types were created during unification And in native code generation (jit): * Use of arm64 target on M1 now requires macOS 13 * Entry into native code has been optimized. This is especially important for coroutine call/pcall performance as they involve going through a C call frame * LOP_LOADK(X) translation into IR has been improved to enable type tag/constant propagation * arm64 can use integer immediate values to synthesize floating-point values * x64 assembler removes duplicate 64bit numbers from the data section to save space * Linux `perf` can now be used to profile native Luau code (when running with --codegen-perf CLI argument)
- Loading branch information
1 parent
8d8c797
commit 97965c7
Showing
62 changed files
with
2,869 additions
and
276 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,115 @@ | ||
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details | ||
#pragma once | ||
|
||
#include "Luau/Error.h" | ||
#include "Luau/NotNull.h" | ||
#include "Luau/Variant.h" | ||
|
||
#include <functional> | ||
#include <string> | ||
#include <optional> | ||
|
||
namespace Luau | ||
{ | ||
|
||
struct Type; | ||
using TypeId = const Type*; | ||
|
||
struct TypePackVar; | ||
using TypePackId = const TypePackVar*; | ||
|
||
struct TypeArena; | ||
struct BuiltinTypes; | ||
struct TxnLog; | ||
|
||
/// Represents a reduction result, which may have successfully reduced the type, | ||
/// may have concretely failed to reduce the type, or may simply be stuck | ||
/// without more information. | ||
template<typename Ty> | ||
struct TypeFamilyReductionResult | ||
{ | ||
/// The result of the reduction, if any. If this is nullopt, the family | ||
/// could not be reduced. | ||
std::optional<Ty> result; | ||
/// Whether the result is uninhabited: whether we know, unambiguously and | ||
/// permanently, whether this type family reduction results in an | ||
/// uninhabitable type. This will trigger an error to be reported. | ||
bool uninhabited; | ||
/// Any types that need to be progressed or mutated before the reduction may | ||
/// proceed. | ||
std::vector<TypeId> blockedTypes; | ||
/// Any type packs that need to be progressed or mutated before the | ||
/// reduction may proceed. | ||
std::vector<TypePackId> blockedPacks; | ||
}; | ||
|
||
/// Represents a type function that may be applied to map a series of types and | ||
/// type packs to a single output type. | ||
struct TypeFamily | ||
{ | ||
/// The human-readable name of the type family. Used to stringify instance | ||
/// types. | ||
std::string name; | ||
|
||
/// The reducer function for the type family. | ||
std::function<TypeFamilyReductionResult<TypeId>( | ||
std::vector<TypeId>, std::vector<TypePackId>, NotNull<TypeArena>, NotNull<BuiltinTypes>, NotNull<const TxnLog> log)> | ||
reducer; | ||
}; | ||
|
||
/// Represents a type function that may be applied to map a series of types and | ||
/// type packs to a single output type pack. | ||
struct TypePackFamily | ||
{ | ||
/// The human-readable name of the type pack family. Used to stringify | ||
/// instance packs. | ||
std::string name; | ||
|
||
/// The reducer function for the type pack family. | ||
std::function<TypeFamilyReductionResult<TypePackId>( | ||
std::vector<TypeId>, std::vector<TypePackId>, NotNull<TypeArena>, NotNull<BuiltinTypes>, NotNull<const TxnLog> log)> | ||
reducer; | ||
}; | ||
|
||
struct FamilyGraphReductionResult | ||
{ | ||
ErrorVec errors; | ||
DenseHashSet<TypeId> blockedTypes{nullptr}; | ||
DenseHashSet<TypePackId> blockedPacks{nullptr}; | ||
DenseHashSet<TypeId> reducedTypes{nullptr}; | ||
DenseHashSet<TypePackId> reducedPacks{nullptr}; | ||
}; | ||
|
||
/** | ||
* Attempt to reduce all instances of any type or type pack family in the type | ||
* graph provided. | ||
* | ||
* @param entrypoint the entry point to the type graph. | ||
* @param location the location the reduction is occurring at; used to populate | ||
* type errors. | ||
* @param arena an arena to allocate types into. | ||
* @param builtins the built-in types. | ||
* @param log a TxnLog to use. If one is provided, substitution will take place | ||
* against the TxnLog, otherwise substitutions will directly mutate the type | ||
* graph. Do not provide the empty TxnLog, as a result. | ||
*/ | ||
FamilyGraphReductionResult reduceFamilies( | ||
TypeId entrypoint, Location location, NotNull<TypeArena> arena, NotNull<BuiltinTypes> builtins, TxnLog* log = nullptr, bool force = false); | ||
|
||
/** | ||
* Attempt to reduce all instances of any type or type pack family in the type | ||
* graph provided. | ||
* | ||
* @param entrypoint the entry point to the type graph. | ||
* @param location the location the reduction is occurring at; used to populate | ||
* type errors. | ||
* @param arena an arena to allocate types into. | ||
* @param builtins the built-in types. | ||
* @param log a TxnLog to use. If one is provided, substitution will take place | ||
* against the TxnLog, otherwise substitutions will directly mutate the type | ||
* graph. Do not provide the empty TxnLog, as a result. | ||
*/ | ||
FamilyGraphReductionResult reduceFamilies( | ||
TypePackId entrypoint, Location location, NotNull<TypeArena> arena, NotNull<BuiltinTypes> builtins, TxnLog* log = nullptr, bool force = false); | ||
|
||
} // 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.