File tree Expand file tree Collapse file tree 5 files changed +39
-2
lines changed Expand file tree Collapse file tree 5 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -356,6 +356,9 @@ class RootProtocolConformance : public ProtocolConformance {
356
356
357
357
bool isInvalid () const ;
358
358
359
+ // / Whether this conformance is weak-imported.
360
+ bool isWeakImported (ModuleDecl *fromModule) const ;
361
+
359
362
bool hasWitness (ValueDecl *requirement) const ;
360
363
Witness getWitness (ValueDecl *requirement, LazyResolver *resolver) const ;
361
364
Original file line number Diff line number Diff line change @@ -392,6 +392,29 @@ SourceLoc RootProtocolConformance::getLoc() const {
392
392
ROOT_CONFORMANCE_SUBCLASS_DISPATCH (getLoc, ())
393
393
}
394
394
395
+ bool RootProtocolConformance::isWeakImported (ModuleDecl *fromModule) const {
396
+ auto *dc = getDeclContext ();
397
+ if (dc->getParentModule () == fromModule)
398
+ return false ;
399
+
400
+ // If the protocol is weak imported, so are any conformances to it.
401
+ if (getProtocol ()->isWeakImported (fromModule))
402
+ return true ;
403
+
404
+ // If the conforming type is weak imported, so are any of its conformances.
405
+ if (auto *nominal = getType ()->getAnyNominal ())
406
+ if (nominal->isWeakImported (fromModule))
407
+ return true ;
408
+
409
+ // If the conformance is declared in an extension with the @_weakLinked
410
+ // attribute, it is weak imported.
411
+ if (auto *ext = dyn_cast<ExtensionDecl>(dc))
412
+ if (ext->isWeakImported (fromModule))
413
+ return true ;
414
+
415
+ return false ;
416
+ }
417
+
395
418
bool RootProtocolConformance::hasWitness (ValueDecl *requirement) const {
396
419
ROOT_CONFORMANCE_SUBCLASS_DISPATCH (hasWitness, (requirement))
397
420
}
Original file line number Diff line number Diff line change @@ -917,6 +917,11 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
917
917
case Kind::DynamicallyReplaceableFunctionImpl:
918
918
return getDecl ()->isWeakImported (module );
919
919
920
+ case Kind::ProtocolWitnessTable:
921
+ case Kind::ProtocolConformanceDescriptor:
922
+ return getProtocolConformance ()->getRootConformance ()
923
+ ->isWeakImported (module );
924
+
920
925
// TODO: Revisit some of the below, for weak conformances.
921
926
case Kind::TypeMetadataPattern:
922
927
case Kind::TypeMetadataInstantiationCache:
@@ -925,12 +930,10 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
925
930
case Kind::TypeMetadataCompletionFunction:
926
931
case Kind::ExtensionDescriptor:
927
932
case Kind::AnonymousDescriptor:
928
- case Kind::ProtocolWitnessTable:
929
933
case Kind::ProtocolWitnessTablePattern:
930
934
case Kind::GenericProtocolWitnessTableInstantiationFunction:
931
935
case Kind::AssociatedTypeWitnessTableAccessFunction:
932
936
case Kind::ReflectionAssociatedTypeDescriptor:
933
- case Kind::ProtocolConformanceDescriptor:
934
937
case Kind::ProtocolWitnessTableLazyAccessFunction:
935
938
case Kind::ProtocolWitnessTableLazyCacheVariable:
936
939
case Kind::ValueWitness:
Original file line number Diff line number Diff line change @@ -118,3 +118,6 @@ public protocol ProtocolWithWeakMembers {
118
118
extension ProtocolWithWeakMembers {
119
119
@_weakLinked public func f( ) { }
120
120
}
121
+
122
+ public protocol BaseP { }
123
+ @_weakLinked extension S : BaseP { }
Original file line number Diff line number Diff line change @@ -170,3 +170,8 @@ class WeakGenericSub: GenericC<Int> {
170
170
// CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper8GenericCCfd"
171
171
}
172
172
}
173
+
174
+ protocol RefinesP : BaseP { }
175
+
176
+ // CHECK-DAG: @"$s25weak_import_native_helper1SVAA5BasePAAWP" = extern_weak global i8*
177
+ extension S : RefinesP { }
You can’t perform that action at this time.
0 commit comments