@@ -862,6 +862,18 @@ class IRGenSILFunction :
862
862
return VarDecl->getInterfaceType ()->hasTypeParameter ();
863
863
}
864
864
865
+ // / Force all archetypes referenced by the type to be bound by this point.
866
+ // / TODO: just make sure that we have a path to them that the debug info
867
+ // / can follow.
868
+ void bindArchetypes (swift::Type Ty) {
869
+ auto runtimeTy = getRuntimeReifiedType (IGM, Ty->getCanonicalType ());
870
+ if (!IGM.IRGen .Opts .shouldOptimize () && runtimeTy->hasArchetype ())
871
+ runtimeTy.visit ([&](CanType t) {
872
+ if (auto archetype = dyn_cast<ArchetypeType>(t))
873
+ emitTypeMetadataRef (archetype);
874
+ });
875
+ }
876
+
865
877
// / Emit debug info for a function argument or a local variable.
866
878
template <typename StorageType>
867
879
void emitDebugVariableDeclaration (StorageType Storage,
@@ -872,23 +884,11 @@ class IRGenSILFunction :
872
884
StringRef Name,
873
885
unsigned ArgNo = 0 ,
874
886
IndirectionKind Indirection = DirectValue) {
875
- // Force all archetypes referenced by the type to be bound by this point.
876
- // TODO: just make sure that we have a path to them that the debug info
877
- // can follow.
878
-
879
887
// FIXME: The debug info type of all inlined instances of a variable must be
880
888
// the same as the type of the abstract variable.
881
889
if (isInlinedGeneric (VarDecl, DS))
882
890
return ;
883
891
884
- auto runtimeTy = getRuntimeReifiedType (IGM,
885
- Ty.getType ()->getCanonicalType ());
886
- if (!IGM.IRGen .Opts .shouldOptimize () && runtimeTy->hasArchetype ())
887
- runtimeTy.visit ([&](CanType t) {
888
- if (auto archetype = dyn_cast<ArchetypeType>(t))
889
- emitTypeMetadataRef (archetype);
890
- });
891
-
892
892
assert (IGM.DebugInfo && " debug info not enabled" );
893
893
if (ArgNo) {
894
894
PrologueLocation AutoRestore (IGM.DebugInfo , Builder);
@@ -3636,6 +3636,8 @@ void IRGenSILFunction::emitErrorResultVar(SILResultInfo ErrorInfo,
3636
3636
auto Storage =
3637
3637
emitShadowCopyIfNeeded (ErrorResultSlot.getAddress (), getDebugScope (),
3638
3638
Var->Name , Var->ArgNo , false );
3639
+ if (!IGM.DebugInfo )
3640
+ return ;
3639
3641
DebugTypeInfo DTI (nullptr , nullptr , ErrorInfo.getType (),
3640
3642
ErrorResultSlot->getType (), IGM.getPointerSize (),
3641
3643
IGM.getPointerAlignment (), true );
@@ -3645,9 +3647,6 @@ void IRGenSILFunction::emitErrorResultVar(SILResultInfo ErrorInfo,
3645
3647
}
3646
3648
3647
3649
void IRGenSILFunction::visitDebugValueInst (DebugValueInst *i) {
3648
- if (!IGM.DebugInfo )
3649
- return ;
3650
-
3651
3650
if (i->getDebugScope ()->getInlinedFunction ()->isTransparent ())
3652
3651
return ;
3653
3652
@@ -3686,14 +3685,15 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
3686
3685
llvm::SmallVector<llvm::Value *, 8 > Copy;
3687
3686
emitShadowCopyIfNeeded (SILVal, i->getDebugScope (), Name, VarInfo->ArgNo ,
3688
3687
IsAnonymous, Copy);
3688
+ bindArchetypes (DbgTy.getType ());
3689
+ if (!IGM.DebugInfo )
3690
+ return ;
3691
+
3689
3692
emitDebugVariableDeclaration (Copy, DbgTy, SILTy, i->getDebugScope (),
3690
3693
i->getDecl (), Name, VarInfo->ArgNo );
3691
3694
}
3692
3695
3693
3696
void IRGenSILFunction::visitDebugValueAddrInst (DebugValueAddrInst *i) {
3694
- if (!IGM.DebugInfo )
3695
- return ;
3696
-
3697
3697
if (i->getDebugScope ()->getInlinedFunction ()->isTransparent ())
3698
3698
return ;
3699
3699
@@ -3723,6 +3723,10 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
3723
3723
auto DbgTy = DebugTypeInfo::getLocalVariable (
3724
3724
CurSILFn->getDeclContext (), CurSILFn->getGenericEnvironment (), Decl,
3725
3725
RealType, getTypeInfo (SILVal->getType ()), Unwrap);
3726
+ bindArchetypes (DbgTy.getType ());
3727
+ if (!IGM.DebugInfo )
3728
+ return ;
3729
+
3726
3730
// Put the value's address into a stack slot at -Onone and emit a debug
3727
3731
// intrinsic.
3728
3732
emitDebugVariableDeclaration (
@@ -3994,26 +3998,29 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
3994
3998
Indirection = IndirectValue;
3995
3999
}
3996
4000
3997
- if (IGM.DebugInfo && Decl) {
3998
- // Ignore compiler-generated patterns but not optional bindings.
3999
- if (auto *Pattern = Decl->getParentPattern ())
4000
- if (Pattern->isImplicit () &&
4001
- Pattern->getKind () != PatternKind::OptionalSome)
4002
- return ;
4001
+ if (!Decl)
4002
+ return ;
4003
4003
4004
- SILType SILTy = i->getType ();
4005
- auto RealType = SILTy.getASTType ();
4006
- auto DbgTy = DebugTypeInfo::getLocalVariable (
4007
- CurSILFn->getDeclContext (), CurSILFn->getGenericEnvironment (), Decl,
4008
- RealType, type, false );
4004
+ // Ignore compiler-generated patterns but not optional bindings.
4005
+ if (auto *Pattern = Decl->getParentPattern ())
4006
+ if (Pattern->isImplicit () &&
4007
+ Pattern->getKind () != PatternKind::OptionalSome)
4008
+ return ;
4009
+
4010
+ SILType SILTy = i->getType ();
4011
+ auto RealType = SILTy.getASTType ();
4012
+ auto DbgTy = DebugTypeInfo::getLocalVariable (
4013
+ CurSILFn->getDeclContext (), CurSILFn->getGenericEnvironment (), Decl,
4014
+ RealType, type, false );
4009
4015
4010
- // FIXME: This is working around the inverse special case in LLDB.
4011
- if (DbgTy.isImplicitlyIndirect ())
4012
- Indirection = DirectValue;
4016
+ // FIXME: This is working around the inverse special case in LLDB.
4017
+ if (DbgTy.isImplicitlyIndirect ())
4018
+ Indirection = DirectValue;
4013
4019
4020
+ bindArchetypes (DbgTy.getType ());
4021
+ if (IGM.DebugInfo )
4014
4022
emitDebugVariableDeclaration (addr, DbgTy, SILTy, DS, Decl, Name,
4015
4023
VarInfo->ArgNo , Indirection);
4016
- }
4017
4024
}
4018
4025
4019
4026
void IRGenSILFunction::visitAllocStackInst (swift::AllocStackInst *i) {
@@ -4184,34 +4191,39 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
4184
4191
4185
4192
if (i->getDebugScope ()->getInlinedFunction ()->isTransparent ())
4186
4193
return ;
4187
-
4188
- if (IGM.DebugInfo && Decl) {
4189
- // FIXME: This is a workaround to not produce local variables for
4190
- // capture list arguments like "[weak self]". The better solution
4191
- // would be to require all variables to be described with a
4192
- // SILDebugValue(Addr) and then not describe capture list
4193
- // arguments.
4194
- if (Name == IGM.Context .Id_self .str ())
4195
- return ;
4196
4194
4197
- assert (i->getBoxType ()->getLayout ()->getFields ().size () == 1
4198
- && " box for a local variable should only have one field" );
4199
- auto SILTy = i->getBoxType ()->getFieldType (IGM.getSILModule (), 0 );
4200
- auto RealType = SILTy.getASTType ();
4201
- auto DbgTy = DebugTypeInfo::getLocalVariable (
4202
- CurSILFn->getDeclContext (), CurSILFn->getGenericEnvironment (), Decl,
4203
- RealType, type, /* Unwrap=*/ false );
4195
+ if (!Decl)
4196
+ return ;
4197
+ // FIXME: This is a workaround to not produce local variables for
4198
+ // capture list arguments like "[weak self]". The better solution
4199
+ // would be to require all variables to be described with a
4200
+ // SILDebugValue(Addr) and then not describe capture list
4201
+ // arguments.
4202
+ if (Name == IGM.Context .Id_self .str ())
4203
+ return ;
4204
4204
4205
- if (isInlinedGeneric (Decl, i->getDebugScope ()))
4206
- return ;
4205
+ assert (i->getBoxType ()->getLayout ()->getFields ().size () == 1 &&
4206
+ " box for a local variable should only have one field" );
4207
+ auto SILTy = i->getBoxType ()->getFieldType (IGM.getSILModule (), 0 );
4208
+ auto RealType = SILTy.getASTType ();
4209
+ auto DbgTy = DebugTypeInfo::getLocalVariable (
4210
+ CurSILFn->getDeclContext (), CurSILFn->getGenericEnvironment (), Decl,
4211
+ RealType, type, /* Unwrap=*/ false );
4207
4212
4208
- IGM.DebugInfo ->emitVariableDeclaration (
4209
- Builder,
4210
- emitShadowCopyIfNeeded (boxWithAddr.getAddress (), i->getDebugScope (),
4211
- Name, 0 , IsAnonymous),
4212
- DbgTy, i->getDebugScope (), Decl, Name, 0 ,
4213
- DbgTy.isImplicitlyIndirect () ? DirectValue : IndirectValue);
4214
- }
4213
+ if (isInlinedGeneric (Decl, i->getDebugScope ()))
4214
+ return ;
4215
+
4216
+ auto Storage = emitShadowCopyIfNeeded (
4217
+ boxWithAddr.getAddress (), i->getDebugScope (), Name, 0 , IsAnonymous);
4218
+
4219
+ if (!IGM.DebugInfo )
4220
+ return ;
4221
+
4222
+ IGM.DebugInfo ->emitVariableDeclaration (
4223
+ Builder,
4224
+ Storage,
4225
+ DbgTy, i->getDebugScope (), Decl, Name, 0 ,
4226
+ DbgTy.isImplicitlyIndirect () ? DirectValue : IndirectValue);
4215
4227
}
4216
4228
4217
4229
void IRGenSILFunction::visitProjectBoxInst (swift::ProjectBoxInst *i) {
@@ -4773,6 +4785,7 @@ void IRGenSILFunction::visitObjCExistentialMetatypeToObjectInst(
4773
4785
to.add (value);
4774
4786
setLoweredExplosion (i, to);
4775
4787
}
4788
+
4776
4789
void IRGenSILFunction::visitObjCProtocolInst (ObjCProtocolInst *i) {
4777
4790
// Get the protocol reference.
4778
4791
llvm::Value *protoRef = emitReferenceToObjCProtocol (*this , i->getProtocol ());
0 commit comments