luau/tests/ConstraintGraphBuilderFixture.cpp

38 lines
1.4 KiB
C++
Raw Normal View History

2022-09-15 23:13:58 +01: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 22:41:03 +01:00
mainModule->name = "MainModule";
mainModule->humanReadableName = "MainModule";
2023-01-06 16:07:19 +00:00
2023-03-17 14:59:30 +00:00
BlockedType::DEPRECATED_nextIndex = 0;
2022-09-15 23:13:58 +01:00
BlockedTypePack::nextIndex = 0;
}
2022-10-21 18:33:43 +01:00
void ConstraintGraphBuilderFixture::generateConstraints(const std::string& code)
{
AstStatBlock* root = parse(code);
dfg = std::make_unique<DataFlowGraph>(DataFlowGraphBuilder::build(root, NotNull{&ice}));
cgb = std::make_unique<ConstraintGraphBuilder>(mainModule, NotNull{&normalizer}, NotNull(&moduleResolver), builtinTypes, NotNull(&ice),
2023-07-28 12:37:00 +01:00
frontend.globals.globalScope, /*prepareModuleScope*/ nullptr, &logger, NotNull{dfg.get()}, std::vector<RequireCycle>());
2022-10-21 18:33:43 +01:00
cgb->visit(root);
rootScope = cgb->rootScope;
2022-11-10 22:04:44 +00:00
constraints = Luau::borrowConstraints(cgb->constraints);
2022-10-21 18:33:43 +01:00
}
void ConstraintGraphBuilderFixture::solve(const std::string& code)
{
generateConstraints(code);
2023-07-28 12:37:00 +01:00
ConstraintSolver cs{NotNull{&normalizer}, NotNull{rootScope}, constraints, "MainModule", NotNull(&moduleResolver), {}, &logger, {}};
2022-10-21 18:33:43 +01:00
cs.run();
}
2022-10-13 23:59:53 +01:00
} // namespace Luau