Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/include/Luau/Refinement.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/NotNull.h"
5
#include "Luau/TypedAllocator.h"
6
#include "Luau/Variant.h"
7
#include "Luau/TypeFwd.h"
8
9
namespace Luau
10
{
11
12
struct RefinementKey;
13
using DefId = NotNull<const struct Def>;
14
15
struct Variadic;
16
struct Negation;
17
struct Conjunction;
18
struct Disjunction;
19
struct Equivalence;
20
struct Proposition;
21
using Refinement = Variant<Variadic, Negation, Conjunction, Disjunction, Equivalence, Proposition>;
22
using RefinementId = Refinement*; // Can and most likely is nullptr.
23
24
struct Variadic
25
{
26
std::vector<RefinementId> refinements;
27
};
28
29
struct Negation
30
{
31
RefinementId refinement;
32
};
33
34
struct Conjunction
35
{
36
RefinementId lhs;
37
RefinementId rhs;
38
};
39
40
struct Disjunction
41
{
42
RefinementId lhs;
43
RefinementId rhs;
44
};
45
46
struct Equivalence
47
{
48
RefinementId lhs;
49
RefinementId rhs;
50
};
51
52
struct Proposition
53
{
54
const RefinementKey* key;
55
TypeId discriminantTy;
56
bool implicitFromCall;
57
};
58
59
template<typename T>
60
const T* get(RefinementId refinement)
61
{
62
return get_if<T>(refinement);
63
}
64
65
struct RefinementArena
66
{
67
RefinementId variadic(const std::vector<RefinementId>& refis);
68
RefinementId negation(RefinementId refinement);
69
RefinementId conjunction(RefinementId lhs, RefinementId rhs);
70
RefinementId disjunction(RefinementId lhs, RefinementId rhs);
71
RefinementId equivalence(RefinementId lhs, RefinementId rhs);
72
RefinementId proposition(const RefinementKey* key, TypeId discriminantTy);
73
RefinementId implicitProposition(const RefinementKey* key, TypeId discriminantTy);
74
75
private:
76
TypedAllocator<Refinement> allocator;
77
};
78
79
} // namespace Luau
80
81