2021-10-29 21:25:12 +01: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 02:34:35 +00:00
|
|
|
#include "Luau/Scope.h"
|
2023-01-04 20:53:17 +00:00
|
|
|
#include "Luau/Type.h"
|
2022-12-09 19:57:01 +00:00
|
|
|
|
|
|
|
#include <optional>
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2024-10-18 18:27:15 +01:00
|
|
|
static constexpr char kRequireTagName[] = "require";
|
|
|
|
|
2022-12-09 19:57:01 +00:00
|
|
|
struct Frontend;
|
2023-03-10 20:21:07 +00:00
|
|
|
struct GlobalTypes;
|
2022-12-09 19:57:01 +00:00
|
|
|
struct TypeChecker;
|
|
|
|
struct TypeArena;
|
2024-08-30 21:16:51 +01:00
|
|
|
struct Subtyping;
|
2022-12-09 19:57:01 +00:00
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
void registerBuiltinGlobals(Frontend& frontend, GlobalTypes& globals, bool typeCheckForAutocomplete = false);
|
2021-10-29 21:25:12 +01:00
|
|
|
TypeId makeUnion(TypeArena& arena, std::vector<TypeId>&& types);
|
|
|
|
TypeId makeIntersection(TypeArena& arena, std::vector<TypeId>&& types);
|
|
|
|
|
|
|
|
/** Build an optional 't'
|
|
|
|
*/
|
2023-03-10 20:21:07 +00:00
|
|
|
TypeId makeOption(NotNull<BuiltinTypes> builtinTypes, TypeArena& arena, TypeId t);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
/** Small utility function for building up type definitions from C++.
|
|
|
|
*/
|
|
|
|
TypeId makeFunction( // Monomorphic
|
2024-08-02 15:30:04 +01:00
|
|
|
TypeArena& arena,
|
|
|
|
std::optional<TypeId> selfType,
|
|
|
|
std::initializer_list<TypeId> paramTypes,
|
|
|
|
std::initializer_list<TypeId> retTypes,
|
|
|
|
bool checked = false
|
|
|
|
);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
TypeId makeFunction( // Polymorphic
|
2024-08-02 15:30:04 +01: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-29 21:25:12 +01:00
|
|
|
|
|
|
|
TypeId makeFunction( // Monomorphic
|
2024-08-02 15:30:04 +01: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-29 21:25:12 +01:00
|
|
|
|
|
|
|
TypeId makeFunction( // Polymorphic
|
2024-08-02 15:30:04 +01: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-29 21:25:12 +01:00
|
|
|
|
|
|
|
void attachMagicFunction(TypeId ty, MagicFunction fn);
|
2022-09-02 00:14:03 +01:00
|
|
|
void attachDcrMagicFunction(TypeId ty, DcrMagicFunction fn);
|
2022-12-02 18:09:59 +00:00
|
|
|
void attachDcrMagicRefinement(TypeId ty, DcrMagicRefinement fn);
|
2024-08-30 21:16:51 +01:00
|
|
|
void attachDcrMagicFunctionTypeCheck(TypeId ty, DcrMagicFunctionTypeCheck fn);
|
2021-10-29 21:25:12 +01:00
|
|
|
Property makeProperty(TypeId ty, std::optional<std::string> documentationSymbol = std::nullopt);
|
2023-01-04 20:53:17 +00:00
|
|
|
void assignPropDocumentationSymbols(TableType::Props& props, const std::string& baseName);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
std::string getBuiltinDefinitionSource();
|
|
|
|
|
2023-03-10 20:21:07 +00: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-29 21:25:12 +01:00
|
|
|
|
2024-10-25 21:15:01 +01: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-29 21:25:12 +01:00
|
|
|
} // namespace Luau
|