Skip to content

[semantic-sil] ObjC metatypes as metatypes are trivial. Only once converted to objects do they have @owned ownership. #6833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,11 +925,11 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
objcMetaType = CanExistentialMetatypeType::get(type,
MetatypeRepresentation::ObjC);
}
selfMetaObjC = ManagedValue(
SGF.B.emitThickToObjCMetatype(
loc, selfMeta.getValue(),
SGF.SGM.getLoweredType(objcMetaType)),
selfMeta.getCleanup());
// ObjC metatypes are trivial and thus do not have a cleanup. Only if we
// convert them to an object do they become non-trivial.
assert(!selfMeta.hasCleanup());
selfMetaObjC = ManagedValue::forUnmanaged(SGF.B.emitThickToObjCMetatype(
loc, selfMeta.getValue(), SGF.SGM.getLoweredType(objcMetaType)));
}

// Allocate the object.
Expand Down
12 changes: 10 additions & 2 deletions lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,11 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &gen,
if (bridgedMetaTy->getRepresentation() == MetatypeRepresentation::ObjC) {
SILValue native = gen.B.emitThickToObjCMetatype(loc, v.getValue(),
SILType::getPrimitiveObjectType(loweredBridgedTy));
return ManagedValue(native, v.getCleanup());
// *NOTE*: ObjCMetatypes are trivial types. They only gain ARC semantics
// when they are converted to an object via objc_metatype_to_object.
assert(!v.hasCleanup() &&
"Metatypes are trivial and thus should not have cleanups");
return ManagedValue::forUnmanaged(native);
}
}

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

Expand Down