Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/tests/ConstraintGeneratorFixture.cpp
2723 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#include "ConstraintGeneratorFixture.h"
3
#include "ScopedFlags.h"
4
5
LUAU_FASTFLAG(DebugLuauForceOldSolver);
6
7
namespace Luau
8
{
9
10
ConstraintGeneratorFixture::ConstraintGeneratorFixture()
11
: Fixture()
12
, mainModule(new Module)
13
, forceTheFlag{FFlag::DebugLuauForceOldSolver, false}
14
{
15
getFrontend(); // Force the frontend to exist in the constructor.
16
mainModule->name = "MainModule";
17
mainModule->humanReadableName = "MainModule";
18
19
BlockedTypePack::nextIndex = 0;
20
}
21
22
void ConstraintGeneratorFixture::generateConstraints(const std::string& code)
23
{
24
AstStatBlock* root = parse(code);
25
dfg = std::make_unique<DataFlowGraph>(
26
DataFlowGraphBuilder::build(root, NotNull{&mainModule->defArena}, NotNull{&mainModule->keyArena}, NotNull{&ice})
27
);
28
cg = std::make_unique<ConstraintGenerator>(
29
mainModule,
30
NotNull{&normalizer},
31
NotNull{&typeFunctionRuntime},
32
NotNull(&moduleResolver),
33
getBuiltins(),
34
NotNull(&ice),
35
getFrontend().globals.globalScope,
36
getFrontend().globals.globalTypeFunctionScope,
37
/*prepareModuleScope*/ nullptr,
38
&logger,
39
NotNull{dfg.get()},
40
std::vector<RequireCycle>()
41
);
42
cg->visitModuleRoot(root);
43
rootScope = cg->rootScope;
44
constraints = Luau::borrowConstraints(cg->constraints);
45
}
46
47
void ConstraintGeneratorFixture::solve(const std::string& code)
48
{
49
generateConstraints(code);
50
ConstraintSolver cs{
51
NotNull{&normalizer},
52
NotNull{&typeFunctionRuntime},
53
NotNull{rootScope},
54
constraints,
55
NotNull{&cg->scopeToFunction},
56
mainModule,
57
NotNull(&moduleResolver),
58
{},
59
&logger,
60
NotNull{dfg.get()},
61
{}
62
};
63
64
cs.run();
65
}
66
67
} // namespace Luau
68
69