Skip to content

Commit

Permalink
This is part of a series of commits to remove reference forwarding
Browse files Browse the repository at this point in the history
for some of the ARC entry points. rdar://22724641. After this commit,
swift_unknownRetain will forward no reference.

Swift SVN r32083
  • Loading branch information
trentxintong committed Sep 18, 2015
1 parent dca508b commit 6fe7d89
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions include/swift/Runtime/HeapObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ extern "C" void *swift_bridgeObjectRetain_n(void *value, int n);

/// Increment the strong retain count of an object which might not be a native
/// Swift object.
extern "C" void *swift_unknownRetain(void *value);
extern "C" void swift_unknownRetain(void *value);
/// Increment the strong retain count of an object which might not be a native
/// Swift object by n.
extern "C" void *swift_unknownRetain_n(void *value, int n);
extern "C" void swift_unknownRetain_n(void *value, int n);

#else

Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ FUNCTION(FixLifetime, swift_fixLifetime, RuntimeCC,
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void *swift_unknownRetain(void *ptr);
// void swift_unknownRetain(void *ptr);
FUNCTION(UnknownRetain, swift_unknownRetain, RuntimeCC,
RETURNS(RefCountedPtrTy),
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/runtime/MetadataImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ struct ObjCWeakRetainableBox :
struct UnknownRetainableBox : RetainableBoxBase<UnknownRetainableBox, void*> {
static void *retain(void *obj) {
#if SWIFT_OBJC_INTEROP
return swift_unknownRetain(obj);
swift_unknownRetain(obj);
return obj;
#else
swift_retain(static_cast<HeapObject *>(obj));
return static_cast<HeapObject *>(obj);
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/runtime/Reflection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ AnyReturn swift_MagicMirrorData_objcValue(HeapObject *owner,
void *object = *reinterpret_cast<void * const *>(value);
auto isa = _swift_getClass(object);
result.Type = swift_getObjCClassMetadata(isa);
*reinterpret_cast<void **>(&result.Buffer) = swift_unknownRetain(object);
swift_unknownRetain(object);
*reinterpret_cast<void **>(&result.Buffer) = object;
return AnyReturn(result);
}
#endif
Expand Down
18 changes: 8 additions & 10 deletions stdlib/public/runtime/SwiftObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,14 @@ static bool usesNativeSwiftReferenceCounting_unowned(const void *object) {
return usesNativeSwiftReferenceCounting_allocated(object);
}

void *swift::swift_unknownRetain_n(void *object, int n) {
void *objc_ret = nullptr;
if (isObjCTaggedPointerOrNull(object)) return object;
void swift::swift_unknownRetain_n(void *object, int n) {
if (isObjCTaggedPointerOrNull(object)) return;
if (usesNativeSwiftReferenceCounting_allocated(object)) {
swift_retain_n(static_cast<HeapObject *>(object), n);
return static_cast<HeapObject *>(object);
return;
}
for (int i = 0; i < n; ++i)
objc_ret = objc_retain(static_cast<id>(object));
return objc_ret;
objc_retain(static_cast<id>(object));
}

void swift::swift_unknownRelease_n(void *object, int n) {
Expand All @@ -586,13 +584,13 @@ static bool usesNativeSwiftReferenceCounting_unowned(const void *object) {
objc_release(static_cast<id>(object));
}

void *swift::swift_unknownRetain(void *object) {
if (isObjCTaggedPointerOrNull(object)) return object;
void swift::swift_unknownRetain(void *object) {
if (isObjCTaggedPointerOrNull(object)) return;
if (usesNativeSwiftReferenceCounting_allocated(object)) {
swift_retain(static_cast<HeapObject *>(object));
return static_cast<HeapObject *>(object);
return;
}
return objc_retain(static_cast<id>(object));
objc_retain(static_cast<id>(object));
}

void swift::swift_unknownRelease(void *object) {
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/class_bounded_generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func class_bounded_archetype_method<T : ClassBoundBinary>(x: T, y: T) {
x.classBoundBinaryMethod(y)
// CHECK: [[WITNESS_ENTRY:%.*]] = getelementptr inbounds i8*, i8** %T.ClassBoundBinary, i32 1
// CHECK: [[WITNESS:%.*]] = load i8*, i8** [[WITNESS_ENTRY]], align 8
// CHECK: call void bitcast (%swift.refcounted* (%swift.refcounted*)* @swift_unknownRetain to void (%objc_object*)*)(%objc_object* [[Y:%.*]])
// CHECK: call void bitcast (void (%swift.refcounted*)* @swift_unknownRetain to void (%objc_object*)*)(%objc_object* [[Y:%.*]])
// CHECK: [[WITNESS_FUNC:%.*]] = bitcast i8* [[WITNESS]] to void (%objc_object*, %objc_object*, %swift.type*)
// CHECK: call void [[WITNESS_FUNC]](%objc_object* [[Y]], %objc_object* %0, %swift.type* {{.*}})
}
Expand Down
10 changes: 5 additions & 5 deletions test/LLVMPasses/basic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target triple = "x86_64-apple-macosx10.9"
%objc_object = type opaque
%swift.bridge = type opaque

declare %swift.refcounted* @swift_unknownRetain(%swift.refcounted*)
declare void @swift_unknownRetain(%swift.refcounted*)
declare void @swift_unknownRelease(%swift.refcounted*)
declare %objc_object* @objc_retain(%objc_object*)
declare void @objc_release(%objc_object*)
Expand All @@ -32,13 +32,13 @@ define void @trivial_retain_release(%swift.refcounted* %P, %objc_object* %O, %sw
entry:
tail call void @swift_retain(%swift.refcounted* %P)
tail call void @swift_release(%swift.refcounted* %P) nounwind
%0 = tail call %swift.refcounted* @swift_unknownRetain(%swift.refcounted* %P)
tail call void @swift_unknownRetain(%swift.refcounted* %P)
tail call void @swift_unknownRelease(%swift.refcounted* %P)
tail call %objc_object* @objc_retain(%objc_object* %O)
tail call void @objc_release(%objc_object* %O)
%v = tail call %swift.bridge* @swift_bridgeObjectRetain(%swift.bridge* %B)
tail call void @swift_bridgeObjectRelease(%swift.bridge* %v)
call void @user(%swift.refcounted* %0) nounwind
call void @user(%swift.refcounted* %P) nounwind
ret void
}

Expand Down Expand Up @@ -79,7 +79,7 @@ entry:
define void @swiftunknown_retain_release_null() {
entry:
tail call void @swift_unknownRelease(%swift.refcounted* null)
tail call %swift.refcounted* @swift_unknownRetain(%swift.refcounted* null) nounwind
tail call void @swift_unknownRetain(%swift.refcounted* null) nounwind
ret void
}

Expand Down Expand Up @@ -115,7 +115,7 @@ define void @swift_fixLifetimeTest(%swift.refcounted* %A) {
; CHECK: ret
define void @move_retain_across_unknown_retain(%swift.refcounted* %A, %swift.refcounted* %B) {
tail call void @swift_retain(%swift.refcounted* %A)
tail call %swift.refcounted* @swift_unknownRetain(%swift.refcounted* %B)
tail call void @swift_unknownRetain(%swift.refcounted* %B)
tail call void @swift_release(%swift.refcounted* %A) nounwind
ret void
}
Expand Down
6 changes: 2 additions & 4 deletions unittests/runtime/Refcounting.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ - (void) dealloc {

TEST(RefcountingTest, objc_unknown_retain_release_n) {
auto object = make_objc_object();
auto retainResult = swift_unknownRetain_n(object, 32);
EXPECT_EQ(object, retainResult);
retainResult = swift_unknownRetain(object);
EXPECT_EQ(object, retainResult);
swift_unknownRetain_n(object, 32);
swift_unknownRetain(object);
swift_unknownRelease_n(object, 31);
swift_unknownRelease(object);
swift_unknownRelease_n(object, 1);
Expand Down

0 comments on commit 6fe7d89

Please sign in to comment.