Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/include/Luau/Clone.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include <Luau/NotNull.h>
5
#include "Luau/TypeArena.h"
6
#include "Luau/Type.h"
7
#include "Luau/Scope.h"
8
9
#include <unordered_map>
10
11
namespace Luau
12
{
13
14
// Only exposed so they can be unit tested.
15
using SeenTypes = std::unordered_map<TypeId, TypeId>;
16
using SeenTypePacks = std::unordered_map<TypePackId, TypePackId>;
17
18
struct CloneState
19
{
20
NotNull<BuiltinTypes> builtinTypes;
21
22
SeenTypes seenTypes;
23
SeenTypePacks seenTypePacks;
24
};
25
26
/** `shallowClone` will make a copy of only the _top level_ constructor of the type,
27
* while `clone` will make a deep copy of the entire type and its every component.
28
*
29
* Be mindful about which behavior you actually _want_.
30
*
31
* Persistent types are not cloned as an optimization.
32
* If a type is cloned in order to mutate it, 'clonePersistentTypes' has to be set
33
*/
34
TypePackId shallowClone(TypePackId tp, TypeArena& dest, CloneState& cloneState, bool clonePersistentTypes);
35
TypeId shallowClone(TypeId typeId, TypeArena& dest, CloneState& cloneState, bool clonePersistentTypes);
36
37
TypePackId clone(TypePackId tp, TypeArena& dest, CloneState& cloneState);
38
TypeId clone(TypeId tp, TypeArena& dest, CloneState& cloneState);
39
TypeFun clone(const TypeFun& typeFun, TypeArena& dest, CloneState& cloneState);
40
Binding clone(const Binding& binding, TypeArena& dest, CloneState& cloneState);
41
42
TypePackId cloneIncremental(TypePackId tp, TypeArena& dest, CloneState& cloneState, Scope* freshScopeForFreeTypes);
43
TypeId cloneIncremental(TypeId typeId, TypeArena& dest, CloneState& cloneState, Scope* freshScopeForFreeTypes);
44
TypeFun cloneIncremental(const TypeFun& typeFun, TypeArena& dest, CloneState& cloneState, Scope* freshScopeForFreeTypes);
45
Binding cloneIncremental(const Binding& binding, TypeArena& dest, CloneState& cloneState, Scope* freshScopeForFreeTypes);
46
47
} // namespace Luau
48
49