2021-10-30 04:25:12 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
2021-11-05 10:34:35 +08:00
|
|
|
#include "Luau/Scope.h"
|
2023-01-05 04:53:17 +08:00
|
|
|
#include "Luau/Type.h"
|
2022-12-10 03:57:01 +08:00
|
|
|
|
|
|
|
#include <optional>
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2024-10-19 01:27:15 +08:00
|
|
|
static constexpr char kRequireTagName[] = "require";
|
|
|
|
|
2022-12-10 03:57:01 +08:00
|
|
|
struct Frontend;
|
2023-03-11 04:21:07 +08:00
|
|
|
struct GlobalTypes;
|
2022-12-10 03:57:01 +08:00
|
|
|
struct TypeChecker;
|
|
|
|
struct TypeArena;
|
2024-08-31 04:16:51 +08:00
|
|
|
struct Subtyping;
|
2022-12-10 03:57:01 +08:00
|
|
|
|
2023-04-08 05:01:29 +08:00
|
|
|
void registerBuiltinGlobals(Frontend& frontend, GlobalTypes& globals, bool typeCheckForAutocomplete = false);
|
2021-10-30 04:25:12 +08:00
|
|
|
TypeId makeUnion(TypeArena& arena, std::vector<TypeId>&& types);
|
|
|
|
TypeId makeIntersection(TypeArena& arena, std::vector<TypeId>&& types);
|
|
|
|
|
|
|
|
/** Build an optional 't'
|
|
|
|
*/
|
2023-03-11 04:21:07 +08:00
|
|
|
TypeId makeOption(NotNull<BuiltinTypes> builtinTypes, TypeArena& arena, TypeId t);
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
/** Small utility function for building up type definitions from C++.
|
|
|
|
*/
|
|
|
|
TypeId makeFunction( // Monomorphic
|
2024-08-02 22:30:04 +08:00
|
|
|
TypeArena& arena,
|
|
|
|
std::optional<TypeId> selfType,
|
|
|
|
std::initializer_list<TypeId> paramTypes,
|
|
|
|
std::initializer_list<TypeId> retTypes,
|
|
|
|
bool checked = false
|
|
|
|
);
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
TypeId makeFunction( // Polymorphic
|
2024-08-02 22:30:04 +08:00
|
|
|
TypeArena& arena,
|
|
|
|
std::optional<TypeId> selfType,
|
|
|
|
std::initializer_list<TypeId> generics,
|
|
|
|
std::initializer_list<TypePackId> genericPacks,
|
|
|
|
std::initializer_list<TypeId> paramTypes,
|
|
|
|
std::initializer_list<TypeId> retTypes,
|
|
|
|
bool checked = false
|
|
|
|
);
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
TypeId makeFunction( // Monomorphic
|
2024-08-02 22:30:04 +08:00
|
|
|
TypeArena& arena,
|
|
|
|
std::optional<TypeId> selfType,
|
|
|
|
std::initializer_list<TypeId> paramTypes,
|
|
|
|
std::initializer_list<std::string> paramNames,
|
|
|
|
std::initializer_list<TypeId> retTypes,
|
|
|
|
bool checked = false
|
|
|
|
);
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
TypeId makeFunction( // Polymorphic
|
2024-08-02 22:30:04 +08:00
|
|
|
TypeArena& arena,
|
|
|
|
std::optional<TypeId> selfType,
|
|
|
|
std::initializer_list<TypeId> generics,
|
|
|
|
std::initializer_list<TypePackId> genericPacks,
|
|
|
|
std::initializer_list<TypeId> paramTypes,
|
|
|
|
std::initializer_list<std::string> paramNames,
|
|
|
|
std::initializer_list<TypeId> retTypes,
|
|
|
|
bool checked = false
|
|
|
|
);
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
void attachMagicFunction(TypeId ty, MagicFunction fn);
|
2022-09-02 07:14:03 +08:00
|
|
|
void attachDcrMagicFunction(TypeId ty, DcrMagicFunction fn);
|
2022-12-03 02:09:59 +08:00
|
|
|
void attachDcrMagicRefinement(TypeId ty, DcrMagicRefinement fn);
|
2024-08-31 04:16:51 +08:00
|
|
|
void attachDcrMagicFunctionTypeCheck(TypeId ty, DcrMagicFunctionTypeCheck fn);
|
2021-10-30 04:25:12 +08:00
|
|
|
Property makeProperty(TypeId ty, std::optional<std::string> documentationSymbol = std::nullopt);
|
2023-01-05 04:53:17 +08:00
|
|
|
void assignPropDocumentationSymbols(TableType::Props& props, const std::string& baseName);
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
std::string getBuiltinDefinitionSource();
|
|
|
|
|
2023-03-11 04:21:07 +08:00
|
|
|
void addGlobalBinding(GlobalTypes& globals, const std::string& name, TypeId ty, const std::string& packageName);
|
|
|
|
void addGlobalBinding(GlobalTypes& globals, const std::string& name, Binding binding);
|
|
|
|
void addGlobalBinding(GlobalTypes& globals, const ScopePtr& scope, const std::string& name, TypeId ty, const std::string& packageName);
|
|
|
|
void addGlobalBinding(GlobalTypes& globals, const ScopePtr& scope, const std::string& name, Binding binding);
|
|
|
|
std::optional<Binding> tryGetGlobalBinding(GlobalTypes& globals, const std::string& name);
|
|
|
|
Binding* tryGetGlobalBindingRef(GlobalTypes& globals, const std::string& name);
|
|
|
|
TypeId getGlobalBinding(GlobalTypes& globals, const std::string& name);
|
2021-10-30 04:25:12 +08:00
|
|
|
|
2024-10-26 04:15:01 +08:00
|
|
|
|
|
|
|
/** A number of built-in functions are magical enough that we need to match on them specifically by
|
|
|
|
* name when they are called. These are listed here to be used whenever necessary, instead of duplicating this logic repeatedly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool matchSetMetatable(const AstExprCall& call);
|
|
|
|
bool matchTableFreeze(const AstExprCall& call);
|
|
|
|
bool matchAssert(const AstExprCall& call);
|
|
|
|
|
|
|
|
// Returns `true` if the function should introduce typestate for its first argument.
|
|
|
|
bool shouldTypestateForFirstArgument(const AstExprCall& call);
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
} // namespace Luau
|