mirror of
https://github.com/luau-lang/luau.git
synced 2025-08-26 11:27:08 +01:00
## General - Introduce `Frontend::parseModules` for parsing a group of modules at once. - Support chained function types in the CST. ## New Type Solver - Enable write-only table properties (described in [this RFC](https://rfcs.luau.org/property-writeonly.html)). - Disable singleton inference for large tables to improve performance. - Fix a bug that occurs when we try to expand a type alias to itself. - Catch cancelation during the type-checking phase in addition to during constraint solving. - Fix stringification of the empty type pack: `()`. - Improve errors for calls being rejected on the primitive `function` type. - Rework generalization: We now generalize types as soon as the last constraint relating to them is finished. We think this will reduce the number of cases where type inference fails to complete and reduce the number of instances where `*blocked*` types appear in the inference result. ## VM/Runtime - Dynamically disable native execution for functions that incur a slowdown (relative to bytecode execution). - Improve names for `thread`/`closure`/`proto` in the Luau heap dump. --- Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Talha Pathan <tpathan@roblox.com> Co-authored-by: Varun Saini <vsaini@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> --------- Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Alexander Youngblood <ayoungblood@roblox.com> Co-authored-by: Menarul Alam <malam@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com>
127 lines
3.8 KiB
C++
127 lines
3.8 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/Ast.h"
|
|
#include "Luau/EqSatSimplification.h"
|
|
#include "Luau/Error.h"
|
|
#include "Luau/InsertionOrderedMap.h"
|
|
#include "Luau/Location.h"
|
|
#include "Luau/NotNull.h"
|
|
#include "Luau/Subtyping.h"
|
|
#include "Luau/TypeFwd.h"
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct BuiltinTypes;
|
|
struct TypeArena;
|
|
struct Scope;
|
|
struct InternalErrorReporter;
|
|
struct TypeCheckLimits;
|
|
struct Subtyping;
|
|
|
|
class Normalizer;
|
|
|
|
struct OverloadResolver
|
|
{
|
|
enum Analysis
|
|
{
|
|
Ok,
|
|
TypeIsNotAFunction,
|
|
ArityMismatch,
|
|
OverloadIsNonviable, // Arguments were incompatible with the overloads parameters but were otherwise compatible by arity
|
|
};
|
|
|
|
OverloadResolver(
|
|
NotNull<BuiltinTypes> builtinTypes,
|
|
NotNull<TypeArena> arena,
|
|
NotNull<Simplifier> simplifier,
|
|
NotNull<Normalizer> normalizer,
|
|
NotNull<TypeFunctionRuntime> typeFunctionRuntime,
|
|
NotNull<Scope> scope,
|
|
NotNull<InternalErrorReporter> reporter,
|
|
NotNull<TypeCheckLimits> limits,
|
|
Location callLocation
|
|
);
|
|
|
|
NotNull<BuiltinTypes> builtinTypes;
|
|
NotNull<TypeArena> arena;
|
|
NotNull<Simplifier> simplifier;
|
|
NotNull<Normalizer> normalizer;
|
|
NotNull<TypeFunctionRuntime> typeFunctionRuntime;
|
|
NotNull<Scope> scope;
|
|
NotNull<InternalErrorReporter> ice;
|
|
NotNull<TypeCheckLimits> limits;
|
|
Subtyping subtyping;
|
|
Location callLoc;
|
|
|
|
// Resolver results
|
|
std::vector<TypeId> ok;
|
|
std::vector<TypeId> nonFunctions;
|
|
std::vector<std::pair<TypeId, ErrorVec>> arityMismatches;
|
|
std::vector<std::pair<TypeId, ErrorVec>> nonviableOverloads;
|
|
InsertionOrderedMap<TypeId, std::pair<OverloadResolver::Analysis, size_t>> resolution;
|
|
|
|
|
|
std::pair<OverloadResolver::Analysis, TypeId> selectOverload(TypeId ty, TypePackId args, bool useFreeTypeBounds);
|
|
void resolve(TypeId fnTy, const TypePack* args, AstExpr* selfExpr, const std::vector<AstExpr*>* argExprs);
|
|
|
|
private:
|
|
std::optional<ErrorVec> testIsSubtype(const Location& location, TypeId subTy, TypeId superTy);
|
|
std::optional<ErrorVec> testIsSubtype(const Location& location, TypePackId subTy, TypePackId superTy);
|
|
std::pair<Analysis, ErrorVec> checkOverload(
|
|
TypeId fnTy,
|
|
const TypePack* args,
|
|
AstExpr* fnLoc,
|
|
const std::vector<AstExpr*>* argExprs,
|
|
bool callMetamethodOk = true
|
|
);
|
|
static bool isLiteral(AstExpr* expr);
|
|
LUAU_NOINLINE
|
|
std::pair<Analysis, ErrorVec> checkOverload_(
|
|
TypeId fnTy,
|
|
const FunctionType* fn,
|
|
const TypePack* args,
|
|
AstExpr* fnExpr,
|
|
const std::vector<AstExpr*>* argExprs
|
|
);
|
|
size_t indexof(Analysis analysis);
|
|
void add(Analysis analysis, TypeId ty, ErrorVec&& errors);
|
|
};
|
|
|
|
struct SolveResult
|
|
{
|
|
enum OverloadCallResult
|
|
{
|
|
Ok,
|
|
CodeTooComplex,
|
|
OccursCheckFailed,
|
|
NoMatchingOverload,
|
|
};
|
|
|
|
OverloadCallResult result;
|
|
std::optional<TypePackId> typePackId; // nullopt if result != Ok
|
|
|
|
TypeId overloadToUse = nullptr;
|
|
TypeId inferredTy = nullptr;
|
|
DenseHashMap<TypeId, std::vector<TypeId>> expandedFreeTypes{nullptr};
|
|
};
|
|
|
|
// Helper utility, presently used for binary operator type functions.
|
|
//
|
|
// Given a function and a set of arguments, select a suitable overload.
|
|
SolveResult solveFunctionCall(
|
|
NotNull<TypeArena> arena,
|
|
NotNull<BuiltinTypes> builtinTypes,
|
|
NotNull<Simplifier> simplifier,
|
|
NotNull<Normalizer> normalizer,
|
|
NotNull<TypeFunctionRuntime> typeFunctionRuntime,
|
|
NotNull<InternalErrorReporter> iceReporter,
|
|
NotNull<TypeCheckLimits> limits,
|
|
NotNull<Scope> scope,
|
|
const Location& location,
|
|
TypeId fn,
|
|
TypePackId argsPack
|
|
);
|
|
|
|
} // namespace Luau
|