luau/Analysis/include/Luau/TypeArena.h

53 lines
1.2 KiB
C
Raw Normal View History

2022-05-19 20:02:24 -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/TypedAllocator.h"
#include "Luau/Type.h"
2022-05-19 20:02:24 -04:00
#include "Luau/TypePack.h"
#include <vector>
namespace Luau
{
struct TypeArena
{
TypedAllocator<Type> types;
2022-05-19 20:02:24 -04:00
TypedAllocator<TypePackVar> typePacks;
void clear();
template<typename T>
TypeId addType(T tv)
{
if constexpr (std::is_same_v<T, UnionType>)
2022-05-19 20:02:24 -04:00
LUAU_ASSERT(tv.options.size() >= 2);
return addTV(Type(std::move(tv)));
2022-05-19 20:02:24 -04:00
}
TypeId addTV(Type&& tv);
2022-05-19 20:02:24 -04:00
TypeId freshType(TypeLevel level);
TypeId freshType(Scope* scope);
TypeId freshType(Scope* scope, TypeLevel level);
2022-05-19 20:02:24 -04:00
TypePackId freshTypePack(Scope* scope);
2022-05-19 20:02:24 -04:00
TypePackId addTypePack(std::initializer_list<TypeId> types);
TypePackId addTypePack(std::vector<TypeId> types, std::optional<TypePackId> tail = {});
2022-05-19 20:02:24 -04:00
TypePackId addTypePack(TypePack pack);
TypePackId addTypePack(TypePackVar pack);
2022-06-30 19:52:43 -04:00
template<typename T>
TypePackId addTypePack(T tp)
{
return addTypePack(TypePackVar(std::move(tp)));
}
2022-05-19 20:02:24 -04:00
};
void freeze(TypeArena& arena);
void unfreeze(TypeArena& arena);
} // namespace Luau