luau/Analysis/include/Luau/Clone.h

44 lines
1.4 KiB
C
Raw Normal View History

2022-04-07 13:53:47 -07:00
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once
2022-10-21 10:33:43 -07:00
#include <Luau/NotNull.h>
2022-05-19 16:46:52 -07:00
#include "Luau/TypeArena.h"
2023-01-03 19:33:19 +02:00
#include "Luau/Type.h"
2025-02-07 13:04:46 -08:00
#include "Luau/Scope.h"
2022-04-07 13:53:47 -07:00
#include <unordered_map>
namespace Luau
{
// Only exposed so they can be unit tested.
using SeenTypes = std::unordered_map<TypeId, TypeId>;
using SeenTypePacks = std::unordered_map<TypePackId, TypePackId>;
struct CloneState
{
2023-08-11 15:55:30 +03:00
NotNull<BuiltinTypes> builtinTypes;
2022-04-14 14:57:15 -07:00
SeenTypes seenTypes;
SeenTypePacks seenTypePacks;
2022-04-07 13:53:47 -07:00
};
2024-10-25 09:46:08 -07:00
/** `shallowClone` will make a copy of only the _top level_ constructor of the type,
* while `clone` will make a deep copy of the entire type and its every component.
*
* Be mindful about which behavior you actually _want_.
2025-02-07 13:04:46 -08:00
*
* Persistent types are not cloned as an optimization.
* If a type is cloned in order to mutate it, 'ignorePersistent' has to be set
2024-10-25 09:46:08 -07:00
*/
2025-02-07 13:04:46 -08:00
TypePackId shallowClone(TypePackId tp, TypeArena& dest, CloneState& cloneState, bool ignorePersistent = false);
TypeId shallowClone(TypeId typeId, TypeArena& dest, CloneState& cloneState, bool ignorePersistent = false);
2024-10-25 09:46:08 -07:00
2022-04-14 14:57:15 -07:00
TypePackId clone(TypePackId tp, TypeArena& dest, CloneState& cloneState);
TypeId clone(TypeId tp, TypeArena& dest, CloneState& cloneState);
TypeFun clone(const TypeFun& typeFun, TypeArena& dest, CloneState& cloneState);
2025-02-07 13:04:46 -08:00
Binding clone(const Binding& binding, TypeArena& dest, CloneState& cloneState);
2022-04-07 13:53:47 -07:00
} // namespace Luau