@@ -590,6 +590,16 @@ void SILGenFunction::emitCaptures(SILLocation loc,
590590 break ;
591591 }
592592
593+ LLVM_DEBUG ({
594+ llvm::dbgs () << " JQ: emit captures running\n " ;
595+ for (auto capture : captureInfo.getCaptures ()) {
596+ llvm::dbgs () << " cap: '" << capture.getDecl ()->getName () << " '\n " ;
597+ }
598+ llvm::dbgs ()
599+ << " canGuarantee: '" << canGuarantee << " '\n "
600+ << " capCanEscape: '" << captureCanEscape << " '\n " ;
601+ });
602+
593603 auto expansion = getTypeExpansionContext ();
594604
595605 for (auto capture : captureInfo.getCaptures ()) {
@@ -609,6 +619,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
609619 if (capture.isOpaqueValue () || capture.isPackElement ()) {
610620 capturedArgs.push_back (
611621 emitRValueAsSingleValue (capture.getExpr ()).ensurePlusOne (*this , loc));
622+ LLVM_DEBUG (llvm::dbgs () << " JQ: cap emit early ret: opaque || pack\n " );
612623 continue ;
613624 }
614625
@@ -632,6 +643,52 @@ void SILGenFunction::emitCaptures(SILLocation loc,
632643 auto valueType = FunctionDC->mapTypeIntoContext (
633644 interfaceType->getReferenceStorageReferent ());
634645
646+ LLVM_DEBUG (
647+ {
648+ llvm::dbgs () << " === DEBUG: VarLocs contents for capture of '"
649+ << vd->getBaseIdentifier () << " ' ===\n " ;
650+ llvm::dbgs () << " Total entries in VarLocs: " << VarLocs.size () << " \n " ;
651+
652+ for (auto &entry : VarLocs) {
653+ auto *var = entry.first ;
654+ auto &loc = entry.second ;
655+
656+ llvm::dbgs () << " - Variable: " << var->getBaseIdentifier () << " \n " ;
657+ // llvm::errs() << " Type: " << var->getType() << "\n";
658+ llvm::dbgs () << " Value type: " << loc.value ->getType () << " \n " ;
659+ llvm::dbgs () << " Value kind: " ;
660+
661+ if (isa<SILUndef>(loc.value )) {
662+ llvm::dbgs () << " SILUndef (UNINITIALIZED)\n " ;
663+ } else if (isa<SILArgument>(loc.value )) {
664+ llvm::dbgs () << " SILArgument\n " ;
665+ } else if (isa<AllocStackInst>(loc.value )) {
666+ llvm::dbgs () << " AllocStackInst\n " ;
667+ } else if (isa<AllocBoxInst>(loc.value )) {
668+ llvm::dbgs () << " AllocBoxInst\n " ;
669+ } else {
670+ llvm::dbgs () << " some other inst\n " ;
671+ }
672+
673+ if (loc.box ) {
674+ llvm::dbgs () << " Has box: yes\n " ;
675+ }
676+
677+ llvm::dbgs () << " \n " ;
678+ }
679+
680+ llvm::dbgs () << " Looking for variable: " << vd->getBaseIdentifier () << " \n " ;
681+ auto found = VarLocs.find (vd);
682+ if (found == VarLocs.end ()) {
683+ llvm::dbgs () << " Result: NOT FOUND in VarLocs\n " ;
684+ } else {
685+ llvm::dbgs () << " Result: FOUND in VarLocs\n " ;
686+ llvm::dbgs () << " Value is undef: "
687+ << (isa<SILUndef>(found->second .value ) ? " YES" : " NO" ) << " \n " ;
688+ }
689+ llvm::dbgs () << " ===================================\n\n " ;
690+ });
691+
635692 //
636693 // If we haven't emitted the captured value yet, we're forming a closure
637694 // to a local function before all of its captures have been emitted. Eg,
@@ -695,6 +752,12 @@ void SILGenFunction::emitCaptures(SILLocation loc,
695752 // expansion context without opaque archetype substitution.
696753 auto getAddressValue = [&](SILValue entryValue, bool forceCopy,
697754 bool forLValue) -> SILValue {
755+ LLVM_DEBUG ({
756+ llvm::dbgs () << " JQ: get addr value, force copy: " << forceCopy
757+ << " , for lval: " << forLValue << " \n " ;
758+ entryValue->getDefiningInstruction ()->print (llvm::dbgs ());
759+ });
760+
698761 if (!SGM.M .useLoweredAddresses () && !forLValue && !isPack) {
699762 // In opaque values mode, addresses aren't used except by lvalues.
700763 auto &lowering = getTypeLowering (entryValue->getType ());
@@ -775,6 +838,11 @@ void SILGenFunction::emitCaptures(SILLocation loc,
775838 auto &Entry = found->second ;
776839 auto val = Entry.value ;
777840
841+ LLVM_DEBUG ({
842+ auto capKind = SGM.Types .getDeclCaptureKind (capture, expansion);
843+ llvm::dbgs () << " JQ: cap kind:: " << (unsigned )capKind << " \n " ;
844+ });
845+
778846 switch (SGM.Types .getDeclCaptureKind (capture, expansion)) {
779847 case CaptureKind::Constant: {
780848 assert (!isPack);
@@ -855,6 +923,12 @@ void SILGenFunction::emitCaptures(SILLocation loc,
855923 }
856924 capturedArgs.push_back (ManagedValue::forOwnedAddressRValue (
857925 addr, CleanupHandle::invalid ()));
926+
927+ // LLVM_DEBUG({
928+ // llvm::dbgs() << "JQ: adding escape to mark for: \n";
929+ // val->getDefiningInstruction()->print(llvm::dbgs());
930+ // });
931+ // escapesToMark.push_back(val);
858932 }
859933 break ;
860934 }
0 commit comments