2022-09-15 15:38:17 -07:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "ConstraintGraphBuilderFixture.h"
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
ConstraintGraphBuilderFixture::ConstraintGraphBuilderFixture()
|
|
|
|
: Fixture()
|
|
|
|
, mainModule(new Module)
|
|
|
|
, forceTheFlag{"DebugLuauDeferredConstraintResolution", true}
|
|
|
|
{
|
2023-04-21 15:14:26 -07:00
|
|
|
mainModule->name = "MainModule";
|
|
|
|
mainModule->humanReadableName = "MainModule";
|
2023-01-06 13:14:35 -08:00
|
|
|
|
2022-09-15 15:38:17 -07:00
|
|
|
BlockedTypePack::nextIndex = 0;
|
|
|
|
}
|
|
|
|
|
2022-10-21 10:54:01 -07:00
|
|
|
void ConstraintGraphBuilderFixture::generateConstraints(const std::string& code)
|
|
|
|
{
|
|
|
|
AstStatBlock* root = parse(code);
|
|
|
|
dfg = std::make_unique<DataFlowGraph>(DataFlowGraphBuilder::build(root, NotNull{&ice}));
|
2023-08-04 12:18:54 -07:00
|
|
|
cgb = std::make_unique<ConstraintGraphBuilder>(mainModule, NotNull{&normalizer}, NotNull(&moduleResolver), builtinTypes, NotNull(&ice),
|
2023-07-28 08:13:53 -07:00
|
|
|
frontend.globals.globalScope, /*prepareModuleScope*/ nullptr, &logger, NotNull{dfg.get()}, std::vector<RequireCycle>());
|
2023-09-29 18:13:05 -07:00
|
|
|
cgb->visitModuleRoot(root);
|
2022-10-21 10:54:01 -07:00
|
|
|
rootScope = cgb->rootScope;
|
2022-11-10 14:53:13 -08:00
|
|
|
constraints = Luau::borrowConstraints(cgb->constraints);
|
2022-10-21 10:54:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConstraintGraphBuilderFixture::solve(const std::string& code)
|
|
|
|
{
|
|
|
|
generateConstraints(code);
|
2023-07-28 08:13:53 -07:00
|
|
|
ConstraintSolver cs{NotNull{&normalizer}, NotNull{rootScope}, constraints, "MainModule", NotNull(&moduleResolver), {}, &logger, {}};
|
2022-10-21 10:54:01 -07:00
|
|
|
cs.run();
|
|
|
|
}
|
|
|
|
|
2022-10-14 12:48:41 -07:00
|
|
|
} // namespace Luau
|