Skip to content

Commit 2f9a90d

Browse files
committed
[semantic-sil] objc_{existential_,}metatype_to_object should be treated as owned.
Metatypes in SIL are trivial, until we conver them to objects (mainly for cases where one converts the metatype to an object for use in objc). Thus these conversion functions must be treated as returning an @owned value.
1 parent 8a7e535 commit 2f9a90d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/SIL/SILValue.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ CONSTANT_OWNERSHIP_INST(Owned, LoadWeak)
188188
CONSTANT_OWNERSHIP_INST(Owned, PartialApply)
189189
CONSTANT_OWNERSHIP_INST(Owned, StrongPin)
190190
CONSTANT_OWNERSHIP_INST(Owned, ThinToThickFunction)
191+
192+
// One would think that these /should/ be unowned. In truth they are owned since
193+
// objc metatypes do not go through the retain/release fast path. In their
194+
// implementations of retain/release nothing happens, so this is safe.
195+
//
196+
// You could even have an optimization that just always removed retain/release
197+
// operations on these objects.
198+
CONSTANT_OWNERSHIP_INST(Owned, ObjCExistentialMetatypeToObject)
199+
CONSTANT_OWNERSHIP_INST(Owned, ObjCMetatypeToObject)
200+
191201
// All addresses have trivial ownership. The values stored at the address may
192202
// not though.
193203
CONSTANT_OWNERSHIP_INST(Trivial, AddressToPointer)
@@ -214,9 +224,6 @@ CONSTANT_OWNERSHIP_INST(Trivial, MarkFunctionEscape)
214224
CONSTANT_OWNERSHIP_INST(Trivial, MarkUninitialized)
215225
CONSTANT_OWNERSHIP_INST(Trivial, MarkUninitializedBehavior)
216226
CONSTANT_OWNERSHIP_INST(Trivial, Metatype)
217-
CONSTANT_OWNERSHIP_INST(Trivial,
218-
ObjCExistentialMetatypeToObject) // Is this right?
219-
CONSTANT_OWNERSHIP_INST(Trivial, ObjCMetatypeToObject) // Is this right?
220227
CONSTANT_OWNERSHIP_INST(Trivial, ObjCProtocol) // Is this right?
221228
CONSTANT_OWNERSHIP_INST(Trivial, ObjCToThickMetatype)
222229
CONSTANT_OWNERSHIP_INST(Trivial, OpenExistentialAddr)

0 commit comments

Comments
 (0)