Skip to content

Commit 3d19691

Browse files
committed
IRGen: Always use Swift reference counting when Obj-C interop is not available
The swift_unknown* entry points are not available on the Linux port. Previously we would still attempt to use them in a couple of cases: 1) Foreign classes 2) Existentials and archetypes 3) Optionals of boxed existentials Note that this patch changes IRGen to never emit the swift_errorRelease/Retain entry points on Linux. We would like to use them in the future if we ever adopt a tagged-pointer representation for small errors. In this case, they can be brought back, and the TypeInfo for optionals will need to be generalized to propagate the reference counting of the payload type, instead of defaulting to unknown if the payload type is not natively reference counted. A similar change will need to be made to support blocks, if we ever want to use the blocks runtime on Linux. Fixes <rdar://problem/23335318>, <rdar://problem/23335537>, <rdar://problem/23335453>.
1 parent 6402411 commit 3d19691

18 files changed

+480
-246
lines changed

lib/IRGen/GenArchetype.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ class OpaqueArchetypeTypeInfo
237237
/// A type implementation for a class archetype, that is, an archetype
238238
/// bounded by a class protocol constraint. These archetypes can be
239239
/// represented by a refcounted pointer instead of an opaque value buffer.
240-
/// We use an unknown-refcounted pointer in order to allow ObjC or Swift
241-
/// classes to conform to the type variable.
240+
/// If ObjC interop is disabled, we can use Swift refcounting entry
241+
/// points, otherwise we have to use the unknown ones.
242242
class ClassArchetypeTypeInfo
243243
: public HeapTypeInfo<ClassArchetypeTypeInfo>,
244244
public ArchetypeTypeInfoBase
@@ -314,10 +314,16 @@ const TypeInfo *TypeConverter::convertArchetypeType(ArchetypeType *archetype) {
314314
// If the archetype is class-constrained, use a class pointer
315315
// representation.
316316
if (archetype->requiresClass()) {
317-
// Fully general archetypes can't be assumed to have any particular
318-
// refcounting scheme.
319-
ReferenceCounting refcount = ReferenceCounting::Unknown;
320-
llvm::PointerType *reprTy = IGM.UnknownRefCountedPtrTy;
317+
ReferenceCounting refcount;
318+
llvm::PointerType *reprTy;
319+
320+
if (!IGM.ObjCInterop) {
321+
refcount = ReferenceCounting::Native;
322+
reprTy = IGM.RefCountedPtrTy;
323+
} else {
324+
refcount = ReferenceCounting::Unknown;
325+
reprTy = IGM.UnknownRefCountedPtrTy;
326+
}
321327

322328
// If the archetype has a superclass constraint, it has at least the
323329
// retain semantics of its superclass, and it can be represented with

lib/IRGen/GenClass.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ static ClassDecl *getRootClass(ClassDecl *theClass) {
6363
/// What reference counting mechanism does a class have?
6464
ReferenceCounting irgen::getReferenceCountingForClass(IRGenModule &IGM,
6565
ClassDecl *theClass) {
66+
// If ObjC interop is disabled, we have a Swift refcount.
67+
if (!IGM.ObjCInterop)
68+
return ReferenceCounting::Native;
69+
6670
// If the root class is implemented in swift, then we have a swift
6771
// refcount; otherwise, we have an ObjC refcount.
6872
if (hasKnownSwiftImplementation(IGM, getRootClass(theClass)))
6973
return ReferenceCounting::Native;
74+
7075
return ReferenceCounting::ObjC;
7176
}
7277

0 commit comments

Comments
 (0)