mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
24fdac4c05
## What's Changed - Improve POSIX compliance in `CLI/FileUtils.cpp` by @SamuraiCrow #1064 - `AstStat*::hasEnd` is deprecated; use `AstStatBlock::hasEnd` instead - Added a lint for common misuses of the `#` operator - Luau now issues deprecated diagnostics for some uses of `getfenv` and `setfenv` - Fixed a case where we included a trailing space in some error stringifications ### Compiler - Do not do further analysis in O2 on self functions - Improve detection of invalid repeat..until expressions vs continue ### New Type Solver - We now cache subtype test results to improve performance - Improved operator inference mechanics (aka type families) - Further work towards type states - Work towards [new non-strict mode](https://github.com/Roblox/luau/blob/master/rfcs/new-nonstrict.md) continues ### Native Codegen - Instruction last use locations should follow the order in which blocks are lowered - Add a bonus assertion to IrLoweringA64::tempAddr --- Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
91 lines
2.9 KiB
C++
91 lines
2.9 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
#include "Luau/DenseHash.h"
|
|
#include "Luau/NotNull.h"
|
|
#include "Type.h"
|
|
#include "TypePairHash.h"
|
|
#include "TypeCheckLimits.h"
|
|
#include "TypeChecker2.h"
|
|
|
|
#include <optional>
|
|
#include <vector>
|
|
#include <utility>
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
using TypeId = const struct Type*;
|
|
using TypePackId = const struct TypePackVar*;
|
|
|
|
struct BuiltinTypes;
|
|
struct InternalErrorReporter;
|
|
struct Scope;
|
|
struct TypeArena;
|
|
|
|
enum class OccursCheckResult
|
|
{
|
|
Pass,
|
|
Fail
|
|
};
|
|
|
|
struct Unifier2
|
|
{
|
|
NotNull<TypeArena> arena;
|
|
NotNull<BuiltinTypes> builtinTypes;
|
|
NotNull<Scope> scope;
|
|
NotNull<InternalErrorReporter> ice;
|
|
TypeCheckLimits limits;
|
|
|
|
DenseHashSet<std::pair<TypeId, TypeId>, TypePairHash> seenTypePairings{{nullptr, nullptr}};
|
|
DenseHashSet<std::pair<TypePackId, TypePackId>, TypePairHash> seenTypePackPairings{{nullptr, nullptr}};
|
|
|
|
int recursionCount = 0;
|
|
int recursionLimit = 0;
|
|
|
|
Unifier2(NotNull<TypeArena> arena, NotNull<BuiltinTypes> builtinTypes, NotNull<Scope> scope, NotNull<InternalErrorReporter> ice);
|
|
|
|
/** Attempt to commit the subtype relation subTy <: superTy to the type
|
|
* graph.
|
|
*
|
|
* @returns true if successful.
|
|
*
|
|
* Note that incoherent types can and will successfully be unified. We stop
|
|
* when we *cannot know* how to relate the provided types, not when doing so
|
|
* would narrow something down to never or broaden it to unknown.
|
|
*
|
|
* Presently, the only way unification can fail is if we attempt to bind one
|
|
* free TypePack to another and encounter an occurs check violation.
|
|
*/
|
|
bool unify(TypeId subTy, TypeId superTy);
|
|
bool unify(TypeId subTy, const FunctionType* superFn);
|
|
bool unify(const UnionType* subUnion, TypeId superTy);
|
|
bool unify(TypeId subTy, const UnionType* superUnion);
|
|
bool unify(const IntersectionType* subIntersection, TypeId superTy);
|
|
bool unify(TypeId subTy, const IntersectionType* superIntersection);
|
|
bool unify(const TableType* subTable, const TableType* superTable);
|
|
bool unify(const MetatableType* subMetatable, const MetatableType* superMetatable);
|
|
|
|
// TODO think about this one carefully. We don't do unions or intersections of type packs
|
|
bool unify(TypePackId subTp, TypePackId superTp);
|
|
|
|
std::optional<TypeId> generalize(TypeId ty);
|
|
|
|
private:
|
|
/**
|
|
* @returns simplify(left | right)
|
|
*/
|
|
TypeId mkUnion(TypeId left, TypeId right);
|
|
|
|
/**
|
|
* @returns simplify(left & right)
|
|
*/
|
|
TypeId mkIntersection(TypeId left, TypeId right);
|
|
|
|
// Returns true if needle occurs within haystack already. ie if we bound
|
|
// needle to haystack, would a cyclic TypePack result?
|
|
OccursCheckResult occursCheck(DenseHashSet<TypePackId>& seen, TypePackId needle, TypePackId haystack);
|
|
};
|
|
|
|
} // namespace Luau
|