2022-05-20 01:02:24 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
|
|
|
|
#include "Luau/TypeArena.h"
|
|
|
|
|
|
|
|
LUAU_FASTFLAGVARIABLE(DebugLuauFreezeArena, false);
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
void TypeArena::clear()
|
|
|
|
{
|
2023-01-04 20:53:17 +00:00
|
|
|
types.clear();
|
2022-05-20 01:02:24 +01:00
|
|
|
typePacks.clear();
|
|
|
|
}
|
|
|
|
|
2023-01-04 20:53:17 +00:00
|
|
|
TypeId TypeArena::addTV(Type&& tv)
|
2022-05-20 01:02:24 +01:00
|
|
|
{
|
2023-01-04 20:53:17 +00:00
|
|
|
TypeId allocated = types.allocate(std::move(tv));
|
2022-05-20 01:02:24 +01:00
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeId TypeArena::freshType(TypeLevel level)
|
|
|
|
{
|
2023-01-04 20:53:17 +00:00
|
|
|
TypeId allocated = types.allocate(FreeType{level});
|
2022-05-20 01:02:24 +01:00
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
2022-09-02 00:14:03 +01:00
|
|
|
TypeId TypeArena::freshType(Scope* scope)
|
|
|
|
{
|
2023-01-04 20:53:17 +00:00
|
|
|
TypeId allocated = types.allocate(FreeType{scope});
|
2022-09-02 00:14:03 +01:00
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
2022-09-29 23:23:10 +01:00
|
|
|
TypeId TypeArena::freshType(Scope* scope, TypeLevel level)
|
|
|
|
{
|
2023-01-04 20:53:17 +00:00
|
|
|
TypeId allocated = types.allocate(FreeType{scope, level});
|
2022-09-29 23:23:10 +01:00
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
2022-09-08 23:14:25 +01:00
|
|
|
TypePackId TypeArena::freshTypePack(Scope* scope)
|
|
|
|
{
|
|
|
|
TypePackId allocated = typePacks.allocate(FreeTypePack{scope});
|
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
2022-05-20 01:02:24 +01:00
|
|
|
TypePackId TypeArena::addTypePack(std::initializer_list<TypeId> types)
|
|
|
|
{
|
|
|
|
TypePackId allocated = typePacks.allocate(TypePack{std::move(types)});
|
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
2022-09-02 00:14:03 +01:00
|
|
|
TypePackId TypeArena::addTypePack(std::vector<TypeId> types, std::optional<TypePackId> tail)
|
2022-05-20 01:02:24 +01:00
|
|
|
{
|
2022-09-02 00:14:03 +01:00
|
|
|
TypePackId allocated = typePacks.allocate(TypePack{std::move(types), tail});
|
2022-05-20 01:02:24 +01:00
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
TypePackId TypeArena::addTypePack(TypePack tp)
|
|
|
|
{
|
|
|
|
TypePackId allocated = typePacks.allocate(std::move(tp));
|
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
TypePackId TypeArena::addTypePack(TypePackVar tp)
|
|
|
|
{
|
|
|
|
TypePackId allocated = typePacks.allocate(std::move(tp));
|
|
|
|
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
|
|
|
|
return allocated;
|
|
|
|
}
|
|
|
|
|
2024-07-19 19:20:47 +01:00
|
|
|
TypeId TypeArena::addTypeFunction(const TypeFunction& function, std::initializer_list<TypeId> types)
|
2024-04-19 22:48:02 +01:00
|
|
|
{
|
2024-07-19 19:20:47 +01:00
|
|
|
return addType(TypeFunctionInstanceType{function, std::move(types)});
|
2024-04-19 22:48:02 +01:00
|
|
|
}
|
|
|
|
|
2024-07-19 19:20:47 +01:00
|
|
|
TypeId TypeArena::addTypeFunction(const TypeFunction& function, std::vector<TypeId> typeArguments, std::vector<TypePackId> packArguments)
|
2024-04-19 22:48:02 +01:00
|
|
|
{
|
2024-07-19 19:20:47 +01:00
|
|
|
return addType(TypeFunctionInstanceType{function, std::move(typeArguments), std::move(packArguments)});
|
2024-04-19 22:48:02 +01:00
|
|
|
}
|
|
|
|
|
2024-07-19 19:20:47 +01:00
|
|
|
TypePackId TypeArena::addTypePackFunction(const TypePackFunction& function, std::initializer_list<TypeId> types)
|
2024-04-19 22:48:02 +01:00
|
|
|
{
|
2024-07-19 19:20:47 +01:00
|
|
|
return addTypePack(TypeFunctionInstanceTypePack{NotNull{&function}, std::move(types)});
|
2024-04-19 22:48:02 +01:00
|
|
|
}
|
|
|
|
|
2024-07-19 19:20:47 +01:00
|
|
|
TypePackId TypeArena::addTypePackFunction(const TypePackFunction& function, std::vector<TypeId> typeArguments, std::vector<TypePackId> packArguments)
|
2024-04-19 22:48:02 +01:00
|
|
|
{
|
2024-07-19 19:20:47 +01:00
|
|
|
return addTypePack(TypeFunctionInstanceTypePack{NotNull{&function}, std::move(typeArguments), std::move(packArguments)});
|
2024-04-19 22:48:02 +01:00
|
|
|
}
|
|
|
|
|
2022-05-20 01:02:24 +01:00
|
|
|
void freeze(TypeArena& arena)
|
|
|
|
{
|
|
|
|
if (!FFlag::DebugLuauFreezeArena)
|
|
|
|
return;
|
|
|
|
|
2023-01-04 20:53:17 +00:00
|
|
|
arena.types.freeze();
|
2022-05-20 01:02:24 +01:00
|
|
|
arena.typePacks.freeze();
|
|
|
|
}
|
|
|
|
|
|
|
|
void unfreeze(TypeArena& arena)
|
|
|
|
{
|
|
|
|
if (!FFlag::DebugLuauFreezeArena)
|
|
|
|
return;
|
|
|
|
|
2023-01-04 20:53:17 +00:00
|
|
|
arena.types.unfreeze();
|
2022-05-20 01:02:24 +01:00
|
|
|
arena.typePacks.unfreeze();
|
|
|
|
}
|
|
|
|
|
2022-05-26 23:08:16 +01:00
|
|
|
} // namespace Luau
|