Skip to content

Commit f558447

Browse files
authored
Merge pull request #63254 from xedin/runtime-attr-#function-behavior
[SILGen] RuntimeMetadata: If attr is attached to a property #function…
2 parents 24d39f6 + 33a78ad commit f558447

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ DeclName SILGenModule::getMagicFunctionName(SILDeclRef ref) {
150150
return getMagicFunctionName(file);
151151
}
152152
case SILDeclRef::Kind::RuntimeAttributeGenerator: {
153+
if (auto *var = dyn_cast<VarDecl>(ref.getDecl()))
154+
return var->getName();
155+
153156
auto *DC = dyn_cast<DeclContext>(ref.getDecl());
154157
return getMagicFunctionName(DC ? DC : ref.getDecl()->getDeclContext());
155158
}

test/SILGen/runtime_attributes.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct MemberTests {
6868

6969
@runtimeMetadata
7070
struct Flag<U> {
71-
init<T>(attachedTo: T, value: U) {}
71+
init<T>(attachedTo: T, value: U, function: String = #function) {}
7272
}
7373

7474
struct TestSelfUse {
@@ -84,8 +84,10 @@ struct TestSelfUse {
8484
// CHECK-NEXT: end_access [[PROP_ACCESS]] : $*Int
8585
// CHECK: [[PROP_VAL_COPY:%.*]] = alloc_stack $Int
8686
// CHECK: store [[PROP_VALUE]] to [trivial] [[PROP_VAL_COPY]] : $*Int
87-
// CHECK: [[FLAG_INIT_REF:%.*]] = function_ref @$s18runtime_attributes4FlagV10attachedTo5valueACyxGqd___xtclufC
88-
// CHECK-NEXT: {{.*}} = apply [[FLAG_INIT_REF]]<Int, WritableKeyPath<TestSelfUse, String>>({{.*}}, [[PROP_VAL_COPY]], {{.*}})
87+
// CHECK: [[FUNC_NAME:%.*]] = string_literal utf8 "x"
88+
// CHECK: [[FUNC_NAME_STR:%.*]] = apply {{.*}}([[FUNC_NAME]], {{.*}})
89+
// CHECK: [[FLAG_INIT_REF:%.*]] = function_ref @$s18runtime_attributes4FlagV10attachedTo5value8functionACyxGqd___xSStclufC
90+
// CHECK-NEXT: {{.*}} = apply [[FLAG_INIT_REF]]<Int, WritableKeyPath<TestSelfUse, String>>({{.*}}, [[PROP_VAL_COPY]], [[FUNC_NAME_STR]], {{.*}})
8991
@Flag(value: Self.answer) var x: String = ""
9092

9193
// CHECK-LABEL: sil hidden [runtime_accessible] [ossa] @$s18runtime_attributes11TestSelfUseV4testyycvpfaAA4Flag : $@convention(thin) () -> @out Optional<Flag<String>>
@@ -97,7 +99,9 @@ struct TestSelfUse {
9799
// CHECK-NEXT: end_access [[PROP_ACCESS]] : $*String
98100
// CHECK: [[PROP_VAL_COPY:%.*]] = alloc_stack $String
99101
// CHECK: store [[PROP_VALUE]] to [init] [[PROP_VAL_COPY]] : $*String
100-
// CHECK: [[FLAG_INIT_REF:%.*]] = function_ref @$s18runtime_attributes4FlagV10attachedTo5valueACyxGqd___xtclufC
101-
// CHECK-NEXT: {{.*}} = apply [[FLAG_INIT_REF]]<String, (TestSelfUse) -> ()>({{.*}}, [[PROP_VAL_COPY]], {{.*}})
102+
// CHECK: [[FUNC_NAME:%.*]] = string_literal utf8 "test()"
103+
// CHECK: [[FUNC_NAME_STR:%.*]] = apply {{.*}}([[FUNC_NAME]], {{.*}})
104+
// CHECK: [[FLAG_INIT_REF:%.*]] = function_ref @$s18runtime_attributes4FlagV10attachedTo5value8functionACyxGqd___xSStclufC
105+
// CHECK-NEXT: {{.*}} = apply [[FLAG_INIT_REF]]<String, (TestSelfUse) -> ()>({{.*}}, [[PROP_VAL_COPY]], [[FUNC_NAME_STR]], {{.*}})
102106
@Flag(value: Self.question) func test() {}
103107
}

0 commit comments

Comments
 (0)