@@ -151,22 +151,29 @@ irgen::getTypeAndGenericSignatureForManglingOutlineFunction(SILType type) {
151151}
152152
153153bool TypeInfo::withWitnessableMetadataCollector (
154- IRGenFunction &IGF, SILType T, LayoutIsNeeded_t needsLayout ,
154+ IRGenFunction &IGF, SILType T, LayoutIsNeeded_t mayNeedLayout ,
155155 DeinitIsNeeded_t needsDeinit,
156156 llvm::function_ref<void (OutliningMetadataCollector &)> invocation) const {
157+ bool needsCollector = false ;
158+ LayoutIsNeeded_t needsLayout = LayoutIsNotNeeded;
157159 if (!T.hasLocalArchetype () &&
158160 !IGF.outliningCanCallValueWitnesses ()) {
159- OutliningMetadataCollector collector (IGF, needsLayout, needsDeinit) ;
161+ needsCollector = true ;
160162 if (T.hasArchetype ()) {
161- collectMetadataForOutlining (collector, T) ;
163+ needsLayout = LayoutIsNeeded ;
162164 }
163- invocation (collector);
164- return true ;
165+ } else if (!T.hasArchetype ()) {
166+ needsCollector = true ;
167+ // The implementation will call vwt in this case.
168+ needsLayout = LayoutIsNotNeeded;
165169 }
166170
167- if (!T.hasArchetype ()) {
168- // The implementation will call vwt in this case.
171+ if (needsCollector) {
169172 OutliningMetadataCollector collector (IGF, needsLayout, needsDeinit);
173+ if (needsDeinit || needsLayout) {
174+ // Only collect if anything would be collected.
175+ collectMetadataForOutlining (collector, T);
176+ }
170177 invocation (collector);
171178 return true ;
172179 }
@@ -198,10 +205,8 @@ void TypeInfo::callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
198205}
199206
200207void OutliningMetadataCollector::emitCallToOutlinedCopy (
201- Address dest, Address src,
202- SILType T, const TypeInfo &ti,
203- IsInitialization_t isInit, IsTake_t isTake) const {
204- assert (needsLayout);
208+ Address dest, Address src, SILType T, const TypeInfo &ti,
209+ IsInitialization_t isInit, IsTake_t isTake) const {
205210 assert (!needsDeinit);
206211 llvm::SmallVector<llvm::Value *, 4 > args;
207212 args.push_back (IGF.Builder .CreateElementBitCast (src, ti.getStorageType ())
@@ -387,8 +392,7 @@ void TypeInfo::callOutlinedDestroy(IRGenFunction &IGF,
387392}
388393
389394void OutliningMetadataCollector::emitCallToOutlinedDestroy (
390- Address addr, SILType T, const TypeInfo &ti) const {
391- assert (needsLayout);
395+ Address addr, SILType T, const TypeInfo &ti) const {
392396 assert (needsDeinit);
393397 llvm::SmallVector<llvm::Value *, 4 > args;
394398 args.push_back (IGF.Builder .CreateElementBitCast (addr, ti.getStorageType ())
0 commit comments