2022-09-15 23:38:17 +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"
|
|
|
|
|
2023-01-06 21:14:35 +00:00
|
|
|
#include "Luau/TypeReduction.h"
|
|
|
|
|
2022-09-15 23:38:17 +01:00
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
ConstraintGraphBuilderFixture::ConstraintGraphBuilderFixture()
|
|
|
|
: Fixture()
|
|
|
|
, mainModule(new Module)
|
|
|
|
, forceTheFlag{"DebugLuauDeferredConstraintResolution", true}
|
|
|
|
{
|
2023-01-06 21:14:35 +00:00
|
|
|
mainModule->reduction = std::make_unique<TypeReduction>(NotNull{&mainModule->internalTypes}, builtinTypes, NotNull{&ice});
|
|
|
|
|
2023-03-17 19:20:37 +00:00
|
|
|
BlockedType::DEPRECATED_nextIndex = 0;
|
2022-09-15 23:38:17 +01:00
|
|
|
BlockedTypePack::nextIndex = 0;
|
|
|
|
}
|
|
|
|
|
2022-10-21 18:54:01 +01:00
|
|
|
void ConstraintGraphBuilderFixture::generateConstraints(const std::string& code)
|
|
|
|
{
|
|
|
|
AstStatBlock* root = parse(code);
|
|
|
|
dfg = std::make_unique<DataFlowGraph>(DataFlowGraphBuilder::build(root, NotNull{&ice}));
|
2023-01-04 20:53:17 +00:00
|
|
|
cgb = std::make_unique<ConstraintGraphBuilder>("MainModule", mainModule, &arena, NotNull(&moduleResolver), builtinTypes, NotNull(&ice),
|
2023-03-10 20:21:07 +00:00
|
|
|
frontend.globals.globalScope, &logger, NotNull{dfg.get()});
|
2022-10-21 18:54:01 +01:00
|
|
|
cgb->visit(root);
|
|
|
|
rootScope = cgb->rootScope;
|
2022-11-10 22:53:13 +00:00
|
|
|
constraints = Luau::borrowConstraints(cgb->constraints);
|
2022-10-21 18:54:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConstraintGraphBuilderFixture::solve(const std::string& code)
|
|
|
|
{
|
|
|
|
generateConstraints(code);
|
2023-03-31 19:42:49 +01:00
|
|
|
ConstraintSolver cs{NotNull{&normalizer}, NotNull{rootScope}, constraints, "MainModule", NotNull(&moduleResolver), {}, &logger};
|
2022-10-21 18:54:01 +01:00
|
|
|
cs.run();
|
|
|
|
}
|
|
|
|
|
2022-10-14 20:48:41 +01:00
|
|
|
} // namespace Luau
|