mirror of
https://github.com/luau-lang/luau.git
synced 2025-08-26 11:27:08 +01:00
# What's Changed? We've been hard at work fixing bugs in the new type solver and getting it ready to go! ## Native Codegen * Specialized Luau Codegen instruction for fetching an import. As a reminder, an import is an expression like `global.thing` and covers stuff like libraries without fastcalls `coroutine.resume`) and atomic extern libraries. ## New Type Solver * Fix an issue that prevented eager generalization from working properly with OO styled code. * Avoid copying uninitialized memory in Luau attribute parsing * Improve type inference of unsealed tables. * This fixes https://github.com/luau-lang/luau/issues/1838 * and https://github.com/luau-lang/luau/issues/1859 * Infer potential singleton string keys in autocomplete when the expected index type is a union type. * Avoid creating cyclic types when reducing types of the form `t1 where t1 = refine<T, t1, Y>` * The type cloner now does the same thing for the new and old solvers. * Properly infer polarity (aka variance) for divergent table properties. (ie tables whose read type and write type are not the same) * Crash fixes. --------- Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Co-authored-by: Alexander Youngblood <ayoungblood@roblox.com> Co-authored-by: Menarul Alam <malam@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
69 lines
2 KiB
C++
69 lines
2 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#include "ConstraintGeneratorFixture.h"
|
|
#include "ScopedFlags.h"
|
|
|
|
LUAU_FASTFLAG(LuauSolverV2);
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
ConstraintGeneratorFixture::ConstraintGeneratorFixture()
|
|
: Fixture()
|
|
, mainModule(new Module)
|
|
, simplifier(newSimplifier(NotNull{&arena}, getBuiltins()))
|
|
, forceTheFlag{FFlag::LuauSolverV2, true}
|
|
{
|
|
getFrontend(); // Force the frontend to exist in the constructor.
|
|
mainModule->name = "MainModule";
|
|
mainModule->humanReadableName = "MainModule";
|
|
|
|
BlockedTypePack::nextIndex = 0;
|
|
}
|
|
|
|
void ConstraintGeneratorFixture::generateConstraints(const std::string& code)
|
|
{
|
|
AstStatBlock* root = parse(code);
|
|
dfg = std::make_unique<DataFlowGraph>(
|
|
DataFlowGraphBuilder::build(root, NotNull{&mainModule->defArena}, NotNull{&mainModule->keyArena}, NotNull{&ice})
|
|
);
|
|
cg = std::make_unique<ConstraintGenerator>(
|
|
mainModule,
|
|
NotNull{&normalizer},
|
|
NotNull{simplifier.get()},
|
|
NotNull{&typeFunctionRuntime},
|
|
NotNull(&moduleResolver),
|
|
getBuiltins(),
|
|
NotNull(&ice),
|
|
getFrontend().globals.globalScope,
|
|
getFrontend().globals.globalTypeFunctionScope,
|
|
/*prepareModuleScope*/ nullptr,
|
|
&logger,
|
|
NotNull{dfg.get()},
|
|
std::vector<RequireCycle>()
|
|
);
|
|
cg->visitModuleRoot(root);
|
|
rootScope = cg->rootScope;
|
|
constraints = Luau::borrowConstraints(cg->constraints);
|
|
}
|
|
|
|
void ConstraintGeneratorFixture::solve(const std::string& code)
|
|
{
|
|
generateConstraints(code);
|
|
ConstraintSolver cs{
|
|
NotNull{&normalizer},
|
|
NotNull{simplifier.get()},
|
|
NotNull{&typeFunctionRuntime},
|
|
NotNull{rootScope},
|
|
constraints,
|
|
NotNull{&cg->scopeToFunction},
|
|
"MainModule",
|
|
NotNull(&moduleResolver),
|
|
{},
|
|
&logger,
|
|
NotNull{dfg.get()},
|
|
{}};
|
|
|
|
cs.run();
|
|
}
|
|
|
|
} // namespace Luau
|