2022-09-16 06:38:17 +08: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-22 06:14:26 +08:00
|
|
|
mainModule->name = "MainModule";
|
|
|
|
mainModule->humanReadableName = "MainModule";
|
2023-01-07 05:14:35 +08:00
|
|
|
|
2023-03-18 03:20:37 +08:00
|
|
|
BlockedType::DEPRECATED_nextIndex = 0;
|
2022-09-16 06:38:17 +08:00
|
|
|
BlockedTypePack::nextIndex = 0;
|
|
|
|
}
|
|
|
|
|
2022-10-22 01:54:01 +08:00
|
|
|
void ConstraintGraphBuilderFixture::generateConstraints(const std::string& code)
|
|
|
|
{
|
|
|
|
AstStatBlock* root = parse(code);
|
|
|
|
dfg = std::make_unique<DataFlowGraph>(DataFlowGraphBuilder::build(root, NotNull{&ice}));
|
2023-04-29 03:55:13 +08:00
|
|
|
cgb = std::make_unique<ConstraintGraphBuilder>(mainModule, &arena, NotNull(&moduleResolver), builtinTypes, NotNull(&ice),
|
|
|
|
frontend.globals.globalScope, /*prepareModuleScope*/ nullptr, &logger, NotNull{dfg.get()});
|
2022-10-22 01:54:01 +08:00
|
|
|
cgb->visit(root);
|
|
|
|
rootScope = cgb->rootScope;
|
2022-11-11 06:53:13 +08:00
|
|
|
constraints = Luau::borrowConstraints(cgb->constraints);
|
2022-10-22 01:54:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConstraintGraphBuilderFixture::solve(const std::string& code)
|
|
|
|
{
|
|
|
|
generateConstraints(code);
|
2023-04-01 02:42:49 +08:00
|
|
|
ConstraintSolver cs{NotNull{&normalizer}, NotNull{rootScope}, constraints, "MainModule", NotNull(&moduleResolver), {}, &logger};
|
2022-10-22 01:54:01 +08:00
|
|
|
cs.run();
|
|
|
|
}
|
|
|
|
|
2022-10-15 03:48:41 +08:00
|
|
|
} // namespace Luau
|