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-03 17:33:19 +00:00
#include "Luau/Type.h"
2023-05-12 13:15:01 +01:00
#include "Luau/DenseHash.h"
#include <vector>
namespace Luau
{
2022-06-17 01:54:42 +01:00
struct TypeArena;
2022-07-29 04:41:13 +01:00
struct Scope;
2022-06-03 21:32:20 +01:00
2022-02-18 00:41:20 +00:00
void quantify(TypeId ty, TypeLevel level);
2023-05-12 13:15:01 +01: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