Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Compiler/src/ValueTracking.h
2725 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/Ast.h"
5
#include "Luau/DenseHash.h"
6
7
namespace Luau
8
{
9
class AstNameTable;
10
}
11
12
namespace Luau
13
{
14
namespace Compile
15
{
16
17
enum class Global
18
{
19
Default = 0,
20
Mutable, // builtin that has contents unknown at compile time, blocks GETIMPORT for chains
21
Written, // written in the code which means we can't reason about the value
22
};
23
24
struct Variable
25
{
26
AstExpr* init = nullptr; // initial value of the variable; filled by trackValues
27
bool written = false; // is the variable ever assigned to? filled by trackValues
28
bool constant = false; // is the variable's value a compile-time constant? filled by constantFold
29
};
30
31
void assignMutable(DenseHashMap<AstName, Global>& globals, const AstNameTable& names, const char* const* mutableGlobals);
32
void trackValues(DenseHashMap<AstName, Global>& globals, DenseHashMap<AstLocal*, Variable>& variables, AstNode* root);
33
34
inline Global getGlobalState(const DenseHashMap<AstName, Global>& globals, AstName name)
35
{
36
const Global* it = globals.find(name);
37
38
return it ? *it : Global::Default;
39
}
40
41
} // namespace Compile
42
} // namespace Luau
43
44