Skip to content

Commit 741001d

Browse files
committed
[semantic-sil] ObjC metatypes as metatypes are trivial. Only once converted to objects do they have @owned ownership.
This commit cleans up a few places in bridging code, where we were treating metatypes as if they had non-invalid cleanups. rdar://29791263
1 parent 554bc78 commit 741001d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,11 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
925925
objcMetaType = CanExistentialMetatypeType::get(type,
926926
MetatypeRepresentation::ObjC);
927927
}
928-
selfMetaObjC = ManagedValue(
929-
SGF.B.emitThickToObjCMetatype(
930-
loc, selfMeta.getValue(),
931-
SGF.SGM.getLoweredType(objcMetaType)),
932-
selfMeta.getCleanup());
928+
// ObjC metatypes are trivial and thus do not have a cleanup. Only if we
929+
// convert them to an object do they become non-trivial.
930+
assert(!selfMeta.hasCleanup());
931+
selfMetaObjC = ManagedValue::forUnmanaged(SGF.B.emitThickToObjCMetatype(
932+
loc, selfMeta.getValue(), SGF.SGM.getLoweredType(objcMetaType)));
933933
}
934934

935935
// Allocate the object.

lib/SILGen/SILGenBridging.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &gen,
457457
if (bridgedMetaTy->getRepresentation() == MetatypeRepresentation::ObjC) {
458458
SILValue native = gen.B.emitThickToObjCMetatype(loc, v.getValue(),
459459
SILType::getPrimitiveObjectType(loweredBridgedTy));
460-
return ManagedValue(native, v.getCleanup());
460+
// *NOTE*: ObjCMetatypes are trivial types. They only gain ARC semantics
461+
// when they are converted to an object via objc_metatype_to_object.
462+
assert(!v.hasCleanup() &&
463+
"Metatypes are trivial and thus should not have cleanups");
464+
return ManagedValue::forUnmanaged(native);
461465
}
462466
}
463467

@@ -710,7 +714,11 @@ static ManagedValue emitCBridgedToNativeValue(SILGenFunction &gen,
710714
if (bridgedMetaTy->getRepresentation() == MetatypeRepresentation::ObjC) {
711715
SILValue native = gen.B.emitObjCToThickMetatype(loc, v.getValue(),
712716
gen.getLoweredType(loweredNativeTy));
713-
return ManagedValue(native, v.getCleanup());
717+
// *NOTE*: ObjCMetatypes are trivial types. They only gain ARC semantics
718+
// when they are converted to an object via objc_metatype_to_object.
719+
assert(!v.hasCleanup() && "Metatypes are trivial and should not have "
720+
"cleanups");
721+
return ManagedValue::forUnmanaged(native);
714722
}
715723
}
716724

0 commit comments

Comments
 (0)