mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
7105c81579
# What's changed? * Fixed a bug in type cloning by maintaining persistent types. * We now parse imprecise integer literals to report the imprecision as a warning to developers. * Add a compiler flag to specify the name of the statistics output file. ### New type solver * Renamed `ConstraintGraphBuilder` to `ConstraintGenerator` * LValues now take into account the type being assigned during constraint generation. * Normalization performance has been improved by 33% by replacing the an internal usage of `std::unordered_set` with `DenseHashMap`. * Normalization now has a helper to identify types that are equivalent to `unknown`, which is being used to fix some bugs in subtyping. * Uses of the old unifier in the new type solver have been eliminated. * Improved error explanations for subtyping errors in `TypeChecker2`. ### Native code generation * Expanded some of the statistics recorded during compilation to include the number of instructions and blocks. * Introduce instruction and block count limiters for controlling what bytecode is translated into native code. * Implement code generation for byteswap instruction. ### Internal Contributors Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Lily Brown <lbrown@roblox.com>
69 lines
1.5 KiB
C++
69 lines
1.5 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 "Fixture.h"
|
|
#include "doctest.h"
|
|
|
|
LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution);
|
|
|
|
using namespace Luau;
|
|
|
|
static TypeId requireBinding(Scope* scope, const char* name)
|
|
{
|
|
auto b = linearSearchForBinding(scope, name);
|
|
LUAU_ASSERT(b.has_value());
|
|
return *b;
|
|
}
|
|
|
|
TEST_SUITE_BEGIN("ConstraintSolver");
|
|
|
|
TEST_CASE_FIXTURE(ConstraintGeneratorFixture, "hello")
|
|
{
|
|
solve(R"(
|
|
local a = 55
|
|
local b = a
|
|
)");
|
|
|
|
TypeId bType = requireBinding(rootScope, "b");
|
|
|
|
CHECK("number" == toString(bType));
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(ConstraintGeneratorFixture, "generic_function")
|
|
{
|
|
solve(R"(
|
|
local function id(a)
|
|
return a
|
|
end
|
|
)");
|
|
|
|
TypeId idType = requireBinding(rootScope, "id");
|
|
|
|
CHECK("<a>(a) -> a" == toString(idType));
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(ConstraintGeneratorFixture, "proper_let_generalization")
|
|
{
|
|
solve(R"(
|
|
local function a(c)
|
|
local function d(e)
|
|
return c
|
|
end
|
|
|
|
return d
|
|
end
|
|
|
|
local b = a(5)
|
|
)");
|
|
|
|
TypeId idType = requireBinding(rootScope, "b");
|
|
|
|
ToStringOptions opts;
|
|
|
|
if (FFlag::DebugLuauDeferredConstraintResolution)
|
|
CHECK("(unknown) -> number" == toString(idType, opts));
|
|
else
|
|
CHECK("<a>(a) -> number" == toString(idType, opts));
|
|
}
|
|
|
|
TEST_SUITE_END();
|