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
|
2023-11-04 07:45:04 +08:00
|
|
|
#include "ConstraintGeneratorFixture.h"
|
2023-12-02 15:46:57 +08:00
|
|
|
#include "ScopedFlags.h"
|
|
|
|
|
2024-08-31 04:16:51 +08:00
|
|
|
LUAU_FASTFLAG(LuauSolverV2);
|
2022-09-16 06:38:17 +08:00
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2023-11-04 07:45:04 +08:00
|
|
|
ConstraintGeneratorFixture::ConstraintGeneratorFixture()
|
2022-09-16 06:38:17 +08:00
|
|
|
: Fixture()
|
|
|
|
, mainModule(new Module)
|
2024-08-31 04:16:51 +08:00
|
|
|
, forceTheFlag{FFlag::LuauSolverV2, true}
|
2022-09-16 06:38:17 +08:00
|
|
|
{
|
2023-04-22 06:14:26 +08:00
|
|
|
mainModule->name = "MainModule";
|
|
|
|
mainModule->humanReadableName = "MainModule";
|
2023-01-07 05:14:35 +08:00
|
|
|
|
2022-09-16 06:38:17 +08:00
|
|
|
BlockedTypePack::nextIndex = 0;
|
|
|
|
}
|
|
|
|
|
2023-11-04 07:45:04 +08:00
|
|
|
void ConstraintGeneratorFixture::generateConstraints(const std::string& code)
|
2022-10-22 01:54:01 +08:00
|
|
|
{
|
|
|
|
AstStatBlock* root = parse(code);
|
|
|
|
dfg = std::make_unique<DataFlowGraph>(DataFlowGraphBuilder::build(root, NotNull{&ice}));
|
2024-08-02 22:30:04 +08:00
|
|
|
cg = std::make_unique<ConstraintGenerator>(
|
|
|
|
mainModule,
|
|
|
|
NotNull{&normalizer},
|
|
|
|
NotNull(&moduleResolver),
|
|
|
|
builtinTypes,
|
|
|
|
NotNull(&ice),
|
|
|
|
frontend.globals.globalScope,
|
|
|
|
/*prepareModuleScope*/ nullptr,
|
|
|
|
&logger,
|
|
|
|
NotNull{dfg.get()},
|
|
|
|
std::vector<RequireCycle>()
|
|
|
|
);
|
2023-11-04 07:45:04 +08:00
|
|
|
cg->visitModuleRoot(root);
|
|
|
|
rootScope = cg->rootScope;
|
|
|
|
constraints = Luau::borrowConstraints(cg->constraints);
|
2022-10-22 01:54:01 +08:00
|
|
|
}
|
|
|
|
|
2023-11-04 07:45:04 +08:00
|
|
|
void ConstraintGeneratorFixture::solve(const std::string& code)
|
2022-10-22 01:54:01 +08:00
|
|
|
{
|
|
|
|
generateConstraints(code);
|
2023-07-28 23:13:53 +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
|