2021-10-29 21:25:12 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "Luau/TxnLog.h"
|
|
|
|
|
|
|
|
#include "Luau/TypePack.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
void TxnLog::operator()(TypeId a)
|
|
|
|
{
|
|
|
|
typeVarChanges.emplace_back(a, *a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TxnLog::operator()(TypePackId a)
|
|
|
|
{
|
|
|
|
typePackChanges.emplace_back(a, *a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TxnLog::operator()(TableTypeVar* a)
|
|
|
|
{
|
|
|
|
tableChanges.emplace_back(a, a->boundTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TxnLog::rollback()
|
|
|
|
{
|
|
|
|
for (auto it = typeVarChanges.rbegin(); it != typeVarChanges.rend(); ++it)
|
|
|
|
std::swap(*asMutable(it->first), it->second);
|
|
|
|
|
|
|
|
for (auto it = typePackChanges.rbegin(); it != typePackChanges.rend(); ++it)
|
|
|
|
std::swap(*asMutable(it->first), it->second);
|
|
|
|
|
|
|
|
for (auto it = tableChanges.rbegin(); it != tableChanges.rend(); ++it)
|
|
|
|
std::swap(it->first->boundTo, it->second);
|
2021-11-05 15:47:21 +00:00
|
|
|
|
2021-12-03 06:41:04 +00:00
|
|
|
LUAU_ASSERT(originalSeenSize <= sharedSeen->size());
|
|
|
|
sharedSeen->resize(originalSeenSize);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TxnLog::concat(TxnLog rhs)
|
|
|
|
{
|
|
|
|
typeVarChanges.insert(typeVarChanges.end(), rhs.typeVarChanges.begin(), rhs.typeVarChanges.end());
|
|
|
|
rhs.typeVarChanges.clear();
|
|
|
|
|
|
|
|
typePackChanges.insert(typePackChanges.end(), rhs.typePackChanges.begin(), rhs.typePackChanges.end());
|
|
|
|
rhs.typePackChanges.clear();
|
|
|
|
|
|
|
|
tableChanges.insert(tableChanges.end(), rhs.tableChanges.begin(), rhs.tableChanges.end());
|
|
|
|
rhs.tableChanges.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TxnLog::haveSeen(TypeId lhs, TypeId rhs)
|
|
|
|
{
|
|
|
|
const std::pair<TypeId, TypeId> sortedPair = (lhs > rhs) ? std::make_pair(lhs, rhs) : std::make_pair(rhs, lhs);
|
2021-12-03 06:41:04 +00:00
|
|
|
return (sharedSeen->end() != std::find(sharedSeen->begin(), sharedSeen->end(), sortedPair));
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TxnLog::pushSeen(TypeId lhs, TypeId rhs)
|
|
|
|
{
|
|
|
|
const std::pair<TypeId, TypeId> sortedPair = (lhs > rhs) ? std::make_pair(lhs, rhs) : std::make_pair(rhs, lhs);
|
2021-12-03 06:41:04 +00:00
|
|
|
sharedSeen->push_back(sortedPair);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TxnLog::popSeen(TypeId lhs, TypeId rhs)
|
|
|
|
{
|
|
|
|
const std::pair<TypeId, TypeId> sortedPair = (lhs > rhs) ? std::make_pair(lhs, rhs) : std::make_pair(rhs, lhs);
|
2021-12-03 06:41:04 +00:00
|
|
|
LUAU_ASSERT(sortedPair == sharedSeen->back());
|
|
|
|
sharedSeen->pop_back();
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Luau
|