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