Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/include/Luau/BuiltinDefinitions.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/Scope.h"
5
#include "Luau/Type.h"
6
7
#include <optional>
8
9
namespace Luau
10
{
11
12
inline constexpr char kRequireTagName[] = "require";
13
14
struct Frontend;
15
struct GlobalTypes;
16
struct TypeChecker;
17
struct TypeArena;
18
struct Subtyping;
19
20
void registerBuiltinGlobals(Frontend& frontend, GlobalTypes& globals, bool typeCheckForAutocomplete = false);
21
TypeId makeUnion(TypeArena& arena, std::vector<TypeId>&& types);
22
TypeId makeIntersection(TypeArena& arena, std::vector<TypeId>&& types);
23
24
/** Build an optional 't'
25
*/
26
TypeId makeOption(NotNull<BuiltinTypes> builtinTypes, TypeArena& arena, TypeId t);
27
28
/** Small utility function for building up type definitions from C++.
29
*/
30
TypeId makeFunction( // Monomorphic
31
TypeArena& arena,
32
std::optional<TypeId> selfType,
33
std::initializer_list<TypeId> paramTypes,
34
std::initializer_list<TypeId> retTypes,
35
bool checked = false
36
);
37
38
TypeId makeFunction( // Polymorphic
39
TypeArena& arena,
40
std::optional<TypeId> selfType,
41
std::initializer_list<TypeId> generics,
42
std::initializer_list<TypePackId> genericPacks,
43
std::initializer_list<TypeId> paramTypes,
44
std::initializer_list<TypeId> retTypes,
45
bool checked = false
46
);
47
48
TypeId makeFunction( // Monomorphic
49
TypeArena& arena,
50
std::optional<TypeId> selfType,
51
std::initializer_list<TypeId> paramTypes,
52
std::initializer_list<std::string> paramNames,
53
std::initializer_list<TypeId> retTypes,
54
bool checked = false
55
);
56
57
TypeId makeFunction( // Polymorphic
58
TypeArena& arena,
59
std::optional<TypeId> selfType,
60
std::initializer_list<TypeId> generics,
61
std::initializer_list<TypePackId> genericPacks,
62
std::initializer_list<TypeId> paramTypes,
63
std::initializer_list<std::string> paramNames,
64
std::initializer_list<TypeId> retTypes,
65
bool checked = false
66
);
67
68
void attachMagicFunction(TypeId ty, std::shared_ptr<MagicFunction> fn);
69
Property makeProperty(TypeId ty, std::optional<std::string> documentationSymbol = std::nullopt);
70
void assignPropDocumentationSymbols(TableType::Props& props, const std::string& baseName);
71
72
std::string getBuiltinDefinitionSource();
73
std::string getTypeFunctionDefinitionSource();
74
75
void addGlobalBinding(GlobalTypes& globals, const std::string& name, TypeId ty, const std::string& packageName);
76
void addGlobalBinding(GlobalTypes& globals, const std::string& name, Binding binding);
77
void addGlobalBinding(GlobalTypes& globals, const ScopePtr& scope, const std::string& name, TypeId ty, const std::string& packageName);
78
void addGlobalBinding(GlobalTypes& globals, const ScopePtr& scope, const std::string& name, Binding binding);
79
std::optional<Binding> tryGetGlobalBinding(GlobalTypes& globals, const std::string& name);
80
Binding* tryGetGlobalBindingRef(GlobalTypes& globals, const std::string& name);
81
TypeId getGlobalBinding(GlobalTypes& globals, const std::string& name);
82
83
84
/** A number of built-in functions are magical enough that we need to match on them specifically by
85
* name when they are called. These are listed here to be used whenever necessary, instead of duplicating this logic repeatedly.
86
*/
87
88
bool matchSetMetatable(const AstExprCall& call);
89
bool matchTableFreeze(const AstExprCall& call);
90
bool matchAssert(const AstExprCall& call);
91
bool matchTypeOf(const AstExprCall& call);
92
93
// Returns `true` if the function should introduce typestate for its first argument.
94
bool shouldTypestateForFirstArgument(const AstExprCall& call);
95
96
} // namespace Luau
97
98