Skip to content

[SILGen] RuntimeMetadata: If attr is attached to a property #function… #63254

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 1 commit into from
Jan 27, 2023
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
3 changes: 3 additions & 0 deletions lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ DeclName SILGenModule::getMagicFunctionName(SILDeclRef ref) {
return getMagicFunctionName(file);
}
case SILDeclRef::Kind::RuntimeAttributeGenerator: {
if (auto *var = dyn_cast<VarDecl>(ref.getDecl()))
return var->getName();

auto *DC = dyn_cast<DeclContext>(ref.getDecl());
return getMagicFunctionName(DC ? DC : ref.getDecl()->getDeclContext());
}
Expand Down
14 changes: 9 additions & 5 deletions test/SILGen/runtime_attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct MemberTests {

@runtimeMetadata
struct Flag<U> {
init<T>(attachedTo: T, value: U) {}
init<T>(attachedTo: T, value: U, function: String = #function) {}
}

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

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