luau/tests/TxnLog.test.cpp
Vighnesh-V c755875479
Sync to upstream/release/605 (#1118)
- Implemented [Require by String with Relative
Paths](https://github.com/luau-lang/rfcs/blob/master/docs/new-require-by-string-semantics.md)
RFC
- Implemented [Require by String with
Aliases](https://github.com/luau-lang/rfcs/blob/master/docs/require-by-string-aliases.md)
RFC with support for `paths` and `alias` arrays in .luarc
- Added SUBRK and DIVRK bytecode instructions to speed up
constant-number and constant/number operations
- Added `--vector-lib`, `--vector-ctor` and `--vector-type` options to
luau-compile to support code with vectors
 
New Solver
- Correctness fixes to subtyping
- Improvements to dataflow analysis

Native Code Generation
- Added bytecode analysis pass to predict type tags used in operations
- Fixed rare cases of numerical loops being generated without an
interrupt instruction
- Restored optimization data propagation into the linear block
- Duplicate buffer length checks are optimized away

Miscellaneous
- Small performance improvements to new non-strict mode
- Introduced more scripts for fuzzing Luau and processing the results,
including fuzzer build support for CMake

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: David Cope <dcope@roblox.com>
Co-authored-by: Lily Brown <lbrown@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>

---------

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: David Cope <dcope@roblox.com>
Co-authored-by: Lily Brown <lbrown@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2023-12-01 23:46:57 -08:00

126 lines
3.2 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;
LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution)
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 = freshType(NotNull{&arena}, NotNull{&builtinTypes}, globalScope.get());
TypeId b = freshType(NotNull{&arena}, NotNull{&builtinTypes}, globalScope.get());
TypeId c = freshType(NotNull{&arena}, NotNull{&builtinTypes}, 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{FFlag::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{FFlag::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{FFlag::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();