@@ -72,13 +72,29 @@ SILFunction::create(SILModule &M, SILLinkage linkage, StringRef name,
72
72
name = entry->getKey ();
73
73
}
74
74
75
- auto fn = new (M) SILFunction (M, linkage, name, loweredType, genericEnv, loc,
75
+ SILFunction *fn = M.removeFromZombieList (name);
76
+ if (fn) {
77
+ // Resurrect a zombie function.
78
+ // This happens for example if a specialized function gets dead and gets
79
+ // deleted. And afterwards the same specialization is created again.
80
+ fn->init (linkage, name, loweredType, genericEnv, loc, isBareSILFunction,
81
+ isTrans, isSerialized, entryCount, isThunk, classSubclassScope,
82
+ inlineStrategy, E, debugScope, isDynamic, isExactSelfClass);
83
+ assert (fn->empty ());
84
+ } else {
85
+ fn = new (M) SILFunction (M, linkage, name, loweredType, genericEnv, loc,
76
86
isBareSILFunction, isTrans, isSerialized,
77
87
entryCount, isThunk, classSubclassScope,
78
- inlineStrategy, E, insertBefore, debugScope,
88
+ inlineStrategy, E, debugScope,
79
89
isDynamic, isExactSelfClass);
80
-
90
+ }
81
91
if (entry) entry->setValue (fn);
92
+
93
+ if (insertBefore)
94
+ M.functions .insert (SILModule::iterator (insertBefore), fn);
95
+ else
96
+ M.functions .push_back (fn);
97
+
82
98
return fn;
83
99
}
84
100
@@ -90,41 +106,60 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage, StringRef Name,
90
106
ProfileCounter entryCount, IsThunk_t isThunk,
91
107
SubclassScope classSubclassScope,
92
108
Inline_t inlineStrategy, EffectsKind E,
93
- SILFunction *InsertBefore,
94
109
const SILDebugScope *DebugScope,
95
110
IsDynamicallyReplaceable_t isDynamic,
96
111
IsExactSelfClass_t isExactSelfClass)
97
- : Module(Module), Name(Name), LoweredType(LoweredType),
98
- GenericEnv(genericEnv), SpecializationInfo(nullptr ),
99
- EntryCount(entryCount),
100
- Availability(AvailabilityContext::alwaysAvailable()),
101
- Bare(isBareSILFunction), Transparent(isTrans),
102
- Serialized(isSerialized), Thunk(isThunk),
103
- ClassSubclassScope(unsigned (classSubclassScope)), GlobalInitFlag(false ),
104
- InlineStrategy(inlineStrategy), Linkage(unsigned (Linkage)),
105
- HasCReferences(false ), IsWeakImported(false ),
106
- IsDynamicReplaceable(isDynamic),
107
- ExactSelfClass(isExactSelfClass),
108
- Inlined(false ), Zombie(false ), HasOwnership(true ),
109
- WasDeserializedCanonical(false ), IsWithoutActuallyEscapingThunk(false ),
110
- OptMode(unsigned (OptimizationMode::NotSet)),
111
- EffectsKindAttr(unsigned (E)) {
112
- assert (!Transparent || !IsDynamicReplaceable);
113
- validateSubclassScope (classSubclassScope, isThunk, nullptr );
114
- setDebugScope (DebugScope);
115
-
116
- if (InsertBefore)
117
- Module.functions .insert (SILModule::iterator (InsertBefore), this );
118
- else
119
- Module.functions .push_back (this );
120
-
121
- Module.removeFromZombieList (Name);
122
-
112
+ : Module(Module), Availability(AvailabilityContext::alwaysAvailable()) {
113
+ init (Linkage, Name, LoweredType, genericEnv, Loc, isBareSILFunction, isTrans,
114
+ isSerialized, entryCount, isThunk, classSubclassScope, inlineStrategy,
115
+ E, DebugScope, isDynamic, isExactSelfClass);
116
+
123
117
// Set our BB list to have this function as its parent. This enables us to
124
118
// splice efficiently basic blocks in between functions.
125
119
BlockList.Parent = this ;
126
120
}
127
121
122
+ void SILFunction::init (SILLinkage Linkage, StringRef Name,
123
+ CanSILFunctionType LoweredType,
124
+ GenericEnvironment *genericEnv,
125
+ Optional<SILLocation> Loc, IsBare_t isBareSILFunction,
126
+ IsTransparent_t isTrans, IsSerialized_t isSerialized,
127
+ ProfileCounter entryCount, IsThunk_t isThunk,
128
+ SubclassScope classSubclassScope,
129
+ Inline_t inlineStrategy, EffectsKind E,
130
+ const SILDebugScope *DebugScope,
131
+ IsDynamicallyReplaceable_t isDynamic,
132
+ IsExactSelfClass_t isExactSelfClass) {
133
+ this ->Name = Name;
134
+ this ->LoweredType = LoweredType;
135
+ this ->GenericEnv = genericEnv;
136
+ this ->SpecializationInfo = nullptr ;
137
+ this ->EntryCount = entryCount;
138
+ this ->Availability = AvailabilityContext::alwaysAvailable ();
139
+ this ->Bare = isBareSILFunction;
140
+ this ->Transparent = isTrans;
141
+ this ->Serialized = isSerialized;
142
+ this ->Thunk = isThunk;
143
+ this ->ClassSubclassScope = unsigned (classSubclassScope);
144
+ this ->GlobalInitFlag = false ;
145
+ this ->InlineStrategy = inlineStrategy;
146
+ this ->Linkage = unsigned (Linkage);
147
+ this ->HasCReferences = false ;
148
+ this ->IsWeakImported = false ;
149
+ this ->IsDynamicReplaceable = isDynamic;
150
+ this ->ExactSelfClass = isExactSelfClass;
151
+ this ->Inlined = false ;
152
+ this ->Zombie = false ;
153
+ this ->HasOwnership = true ,
154
+ this ->WasDeserializedCanonical = false ;
155
+ this ->IsWithoutActuallyEscapingThunk = false ;
156
+ this ->OptMode = unsigned (OptimizationMode::NotSet);
157
+ this ->EffectsKindAttr = unsigned (E);
158
+ assert (!Transparent || !IsDynamicReplaceable);
159
+ validateSubclassScope (classSubclassScope, isThunk, nullptr );
160
+ setDebugScope (DebugScope);
161
+ }
162
+
128
163
SILFunction::~SILFunction () {
129
164
// If the function is recursive, a function_ref inst inside of the function
130
165
// will give the function a non-zero ref count triggering the assertion. Thus
0 commit comments