@@ -728,17 +728,22 @@ static SILValue emitCodeForSymbolicValue(SymbolicValue symVal,
728
728
SILModule &module = builder.getModule ();
729
729
SymbolicClosure *closure = symVal.getClosure ();
730
730
SILValue resultVal;
731
- if (!closure-> hasOnlyConstantCaptures ()) {
732
- // If the closure captures a value that is not a constant, it should only
733
- // come from the caller of the log call. Therefore, assert this and reuse
734
- // the closure value .
735
- SingleValueInstruction *originalClosureInst = closure->getClosureInst ();
736
- SILFunction &fun = builder.getFunction ();
737
- assert (originalClosureInst->getFunction () == &fun &&
738
- " closure with non-constant captures not defined in this function " );
739
- // Copy the closure, since the returned value must be owned .
731
+
732
+ // If the closure was created in the context of this function where the code
733
+ // is generated, reuse the original closure value (after extending its
734
+ // lifetime by copying) .
735
+ SingleValueInstruction *originalClosureInst = closure->getClosureInst ();
736
+ SILFunction &fun = builder.getFunction ();
737
+ if (originalClosureInst->getFunction () == &fun) {
738
+ // Copy the closure, since the returned value must be owned and the
739
+ // closure's lifetime must be extended until this point .
740
740
resultVal = makeOwnedCopyOfSILValue (originalClosureInst, fun);
741
741
} else {
742
+ // If the closure captures a value that is not a constant, it should only
743
+ // come from the caller of the log call. It should be handled by the then
744
+ // case and we should never reach here. Assert this.
745
+ assert (closure->hasOnlyConstantCaptures () &&
746
+ " closure with non-constant captures not defined in this function" );
742
747
SubstitutionMap callSubstMap = closure->getCallSubstitutionMap ();
743
748
ArrayRef<SymbolicClosureArgument> captures = closure->getCaptures ();
744
749
// Recursively emit code for all captured values which must be mapped to a
0 commit comments