luau/Analysis/include/Luau/Quantify.h

42 lines
913 B
C
Raw Normal View History

// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once
2023-01-04 01:33:19 +08:00
#include "Luau/Type.h"
2023-05-12 20:15:01 +08:00
#include "Luau/DenseHash.h"
#include <vector>
namespace Luau
{
2022-06-17 08:54:42 +08:00
struct TypeArena;
2022-07-29 11:41:13 +08:00
struct Scope;
2022-06-04 04:32:20 +08:00
2022-02-18 08:41:20 +08:00
void quantify(TypeId ty, TypeLevel level);
2023-05-12 20:15:01 +08:00
// TODO: This is eerily similar to the pattern that NormalizedClassType
// implements. We could, and perhaps should, merge them together.
template<typename K, typename V>
struct OrderedMap
{
std::vector<K> keys;
DenseHashMap<K, V> pairings{nullptr};
void push(K k, V v)
{
keys.push_back(k);
pairings[k] = v;
}
};
struct QuantifierResult
{
TypeId result;
OrderedMap<TypeId, TypeId> insertedGenerics;
OrderedMap<TypePackId, TypePackId> insertedGenericPacks;
};
std::optional<QuantifierResult> quantify(TypeArena* arena, TypeId ty, Scope* scope);
} // namespace Luau