2021-10-29 16:25:12 -04:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/TypeVar.h"
|
|
|
|
|
2021-11-04 22:42:00 -04:00
|
|
|
LUAU_FASTFLAG(LuauShareTxnSeen);
|
|
|
|
|
2021-10-29 16:25:12 -04:00
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
// Log of where what TypeIds we are rebinding and what they used to be
|
|
|
|
struct TxnLog
|
|
|
|
{
|
2021-11-04 22:42:00 -04:00
|
|
|
TxnLog()
|
|
|
|
: originalSeenSize(0)
|
|
|
|
, ownedSeen()
|
|
|
|
, sharedSeen(&ownedSeen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit TxnLog(std::vector<std::pair<TypeId, TypeId>>* sharedSeen)
|
|
|
|
: originalSeenSize(sharedSeen->size())
|
|
|
|
, ownedSeen()
|
|
|
|
, sharedSeen(sharedSeen)
|
|
|
|
{
|
|
|
|
}
|
2021-10-29 16:25:12 -04:00
|
|
|
|
2021-11-04 22:42:00 -04:00
|
|
|
explicit TxnLog(const std::vector<std::pair<TypeId, TypeId>>& ownedSeen)
|
|
|
|
: originalSeenSize(ownedSeen.size())
|
|
|
|
, ownedSeen(ownedSeen)
|
|
|
|
, sharedSeen(nullptr)
|
2021-10-29 16:25:12 -04:00
|
|
|
{
|
2021-11-04 22:42:00 -04:00
|
|
|
// This is deprecated!
|
|
|
|
LUAU_ASSERT(!FFlag::LuauShareTxnSeen);
|
2021-10-29 16:25:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TxnLog(const TxnLog&) = delete;
|
|
|
|
TxnLog& operator=(const TxnLog&) = delete;
|
|
|
|
|
|
|
|
TxnLog(TxnLog&&) = default;
|
|
|
|
TxnLog& operator=(TxnLog&&) = default;
|
|
|
|
|
|
|
|
void operator()(TypeId a);
|
|
|
|
void operator()(TypePackId a);
|
|
|
|
void operator()(TableTypeVar* a);
|
|
|
|
|
|
|
|
void rollback();
|
|
|
|
|
|
|
|
void concat(TxnLog rhs);
|
|
|
|
|
|
|
|
bool haveSeen(TypeId lhs, TypeId rhs);
|
|
|
|
void pushSeen(TypeId lhs, TypeId rhs);
|
|
|
|
void popSeen(TypeId lhs, TypeId rhs);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<std::pair<TypeId, TypeVar>> typeVarChanges;
|
|
|
|
std::vector<std::pair<TypePackId, TypePackVar>> typePackChanges;
|
|
|
|
std::vector<std::pair<TableTypeVar*, std::optional<TypeId>>> tableChanges;
|
2021-11-04 22:42:00 -04:00
|
|
|
size_t originalSeenSize;
|
2021-10-29 16:25:12 -04:00
|
|
|
|
|
|
|
public:
|
2021-11-04 22:42:00 -04:00
|
|
|
std::vector<std::pair<TypeId, TypeId>> ownedSeen; // used to avoid infinite recursion when types are cyclic
|
|
|
|
std::vector<std::pair<TypeId, TypeId>>* sharedSeen; // shared with all the descendent logs
|
2021-10-29 16:25:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Luau
|