mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
721f6e10fb
Lots of things going on this week: * Fix a crash that could occur in the presence of a cyclic union. We shouldn't be creating cyclic unions, but we shouldn't be crashing when they arise either. * Minor cleanup of `luau_precall` * Internal change to make L->top handling slightly more uniform * Optimize SETGLOBAL & GETGLOBAL fallback C functions. * https://github.com/Roblox/luau/pull/929 * The syntax to the `luau-reduce` commandline tool has changed. It now accepts a script, a command to execute, and an error to search for. It no longer automatically passes the script to the command which makes it a lot more flexible. Also be warned that it edits the script it is passed **in place**. Do not point it at something that is not in source control! New solver * Switch to a greedier but more fallible algorithm for simplifying union and intersection types that are created as part of refinement calculation. This has much better and more predictable performance. * Fix a constraint cycle in recursive function calls. * Much improved inference of binary addition. Functions like `function add(x, y) return x + y end` can now be inferred without annotations. We also accurately typecheck calls to functions like this. * Many small bugfixes surrounding things like table indexers * Add support for indexers on class types. This was previously added to the old solver; we now add it to the new one for feature parity. JIT * https://github.com/Roblox/luau/pull/931 * Fuse key.value and key.tt loads for CEHCK_SLOT_MATCH in A64 * Implement remaining aliases of BFM for A64 * Implement new callinfo flag for A64 * Add instruction simplification for int->num->int conversion chains * Don't even load execdata for X64 calls * Treat opcode fallbacks the same as manually written fallbacks --------- Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
125 lines
3.0 KiB
C++
125 lines
3.0 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "doctest.h"
|
|
|
|
#include "Luau/Scope.h"
|
|
#include "Luau/ToString.h"
|
|
#include "Luau/TxnLog.h"
|
|
#include "Luau/Type.h"
|
|
#include "Luau/TypeArena.h"
|
|
|
|
#include "ScopedFlags.h"
|
|
|
|
using namespace Luau;
|
|
|
|
struct TxnLogFixture
|
|
{
|
|
TxnLog log{/*useScopes*/ true};
|
|
TxnLog log2{/*useScopes*/ true};
|
|
TypeArena arena;
|
|
BuiltinTypes builtinTypes;
|
|
|
|
ScopePtr globalScope = std::make_shared<Scope>(builtinTypes.anyTypePack);
|
|
ScopePtr childScope = std::make_shared<Scope>(globalScope);
|
|
|
|
TypeId a = arena.freshType(globalScope.get());
|
|
TypeId b = arena.freshType(globalScope.get());
|
|
TypeId c = arena.freshType(childScope.get());
|
|
|
|
TypeId g = arena.addType(GenericType{"G"});
|
|
};
|
|
|
|
TEST_SUITE_BEGIN("TxnLog");
|
|
|
|
TEST_CASE_FIXTURE(TxnLogFixture, "colliding_union_incoming_type_has_greater_scope")
|
|
{
|
|
ScopedFastFlag sff{"DebugLuauDeferredConstraintResolution", true};
|
|
|
|
log.replace(c, BoundType{a});
|
|
log2.replace(a, BoundType{c});
|
|
|
|
CHECK(nullptr != log.pending(c));
|
|
|
|
log.concatAsUnion(std::move(log2), NotNull{&arena});
|
|
|
|
// 'a has greater scope than 'c, so we expect the incoming binding of 'a to
|
|
// be discarded.
|
|
|
|
CHECK(nullptr == log.pending(a));
|
|
|
|
const PendingType* pt = log.pending(c);
|
|
REQUIRE(pt != nullptr);
|
|
|
|
CHECK(!pt->dead);
|
|
const BoundType* bt = get_if<BoundType>(&pt->pending.ty);
|
|
|
|
CHECK(a == bt->boundTo);
|
|
|
|
log.commit();
|
|
|
|
REQUIRE(get<FreeType>(a));
|
|
|
|
const BoundType* bound = get<BoundType>(c);
|
|
REQUIRE(bound);
|
|
CHECK(a == bound->boundTo);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(TxnLogFixture, "colliding_union_incoming_type_has_lesser_scope")
|
|
{
|
|
ScopedFastFlag sff{"DebugLuauDeferredConstraintResolution", true};
|
|
|
|
log.replace(a, BoundType{c});
|
|
log2.replace(c, BoundType{a});
|
|
|
|
CHECK(nullptr != log.pending(a));
|
|
|
|
log.concatAsUnion(std::move(log2), NotNull{&arena});
|
|
|
|
// 'a has greater scope than 'c, so we expect the binding of 'a to be
|
|
// discarded, and for that of 'c to be brought in.
|
|
|
|
CHECK(nullptr == log.pending(a));
|
|
|
|
const PendingType* pt = log.pending(c);
|
|
REQUIRE(pt != nullptr);
|
|
|
|
CHECK(!pt->dead);
|
|
const BoundType* bt = get_if<BoundType>(&pt->pending.ty);
|
|
|
|
CHECK(a == bt->boundTo);
|
|
|
|
log.commit();
|
|
|
|
REQUIRE(get<FreeType>(a));
|
|
|
|
const BoundType* bound = get<BoundType>(c);
|
|
REQUIRE(bound);
|
|
CHECK(a == bound->boundTo);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(TxnLogFixture, "colliding_coincident_logs_do_not_create_degenerate_unions")
|
|
{
|
|
ScopedFastFlag sff{"DebugLuauDeferredConstraintResolution", true};
|
|
|
|
log.replace(a, BoundType{b});
|
|
log2.replace(a, BoundType{b});
|
|
|
|
log.concatAsUnion(std::move(log2), NotNull{&arena});
|
|
|
|
log.commit();
|
|
|
|
CHECK("a" == toString(a));
|
|
CHECK("a" == toString(b));
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(TxnLogFixture, "replacing_persistent_types_is_allowed_but_makes_the_log_radioactive")
|
|
{
|
|
persist(g);
|
|
|
|
log.replace(g, BoundType{a});
|
|
|
|
CHECK(log.radioactive);
|
|
}
|
|
|
|
TEST_SUITE_END();
|