Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/src/Anyification.cpp
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
3
#include "Luau/Anyification.h"
4
5
#include "Luau/Common.h"
6
#include "Luau/Normalize.h"
7
#include "Luau/TxnLog.h"
8
9
namespace Luau
10
{
11
12
Anyification::Anyification(
13
TypeArena* arena,
14
NotNull<Scope> scope,
15
NotNull<BuiltinTypes> builtinTypes,
16
InternalErrorReporter* iceHandler,
17
TypeId anyType,
18
TypePackId anyTypePack
19
)
20
: Substitution(TxnLog::empty(), arena)
21
, scope(scope)
22
, builtinTypes(builtinTypes)
23
, iceHandler(iceHandler)
24
, anyType(anyType)
25
, anyTypePack(anyTypePack)
26
{
27
}
28
29
Anyification::Anyification(
30
TypeArena* arena,
31
const ScopePtr& scope,
32
NotNull<BuiltinTypes> builtinTypes,
33
InternalErrorReporter* iceHandler,
34
TypeId anyType,
35
TypePackId anyTypePack
36
)
37
: Anyification(arena, NotNull{scope.get()}, builtinTypes, iceHandler, anyType, anyTypePack)
38
{
39
}
40
41
bool Anyification::isDirty(TypeId ty)
42
{
43
if (ty->persistent)
44
return false;
45
46
if (const TableType* ttv = log->getMutable<TableType>(ty))
47
return (ttv->state == TableState::Free || ttv->state == TableState::Unsealed);
48
else if (log->getMutable<FreeType>(ty))
49
return true;
50
else
51
return false;
52
}
53
54
bool Anyification::isDirty(TypePackId tp)
55
{
56
if (tp->persistent)
57
return false;
58
59
if (log->getMutable<FreeTypePack>(tp))
60
return true;
61
else
62
return false;
63
}
64
65
TypeId Anyification::clean(TypeId ty)
66
{
67
LUAU_ASSERT(isDirty(ty));
68
if (const TableType* ttv = log->getMutable<TableType>(ty))
69
{
70
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, TableState::Sealed};
71
clone.definitionModuleName = ttv->definitionModuleName;
72
clone.definitionLocation = ttv->definitionLocation;
73
clone.name = ttv->name;
74
clone.syntheticName = ttv->syntheticName;
75
clone.tags = ttv->tags;
76
TypeId res = addType(std::move(clone));
77
return res;
78
}
79
else
80
return anyType;
81
}
82
83
TypePackId Anyification::clean(TypePackId tp)
84
{
85
LUAU_ASSERT(isDirty(tp));
86
return anyTypePack;
87
}
88
89
bool Anyification::ignoreChildren(TypeId ty)
90
{
91
if (get<ExternType>(ty))
92
return true;
93
94
return ty->persistent;
95
}
96
bool Anyification::ignoreChildren(TypePackId ty)
97
{
98
return ty->persistent;
99
}
100
101
} // namespace Luau
102
103