Skip to content

Sema: Force synthesis of the CodingKeys nested type in EmittedMembersRequest #32824

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
Jul 11, 2020
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
8 changes: 8 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,14 @@ EmittedMembersRequest::evaluate(Evaluator &evaluator,
forceConformance(Context.getProtocol(KnownProtocolKind::Hashable));
forceConformance(Context.getProtocol(KnownProtocolKind::Differentiable));

// If the class conforms to Encodable or Decodable, even via an extension,
// the CodingKeys enum is synthesized as a member of the type itself.
// Force it into existence.
(void) evaluateOrDefault(Context.evaluator,
ResolveImplicitMemberRequest{CD,
ImplicitMemberAction::ResolveCodingKeys},
{});

// If the class has a @main attribute, we need to force synthesis of the
// $main function.
(void) evaluateOrDefault(Context.evaluator,
Expand Down
11 changes: 11 additions & 0 deletions test/SILGen/synthesized_conformance_class.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ final class Final<T> {
var x: T
init(x: T) { self.x = x }
}

// CHECK-LABEL: final class Final<T> {
// CHECK: @_hasStorage final var x: T { get set }
// CHECK: init(x: T)
Expand Down Expand Up @@ -51,6 +52,16 @@ class Nonfinal<T> {
// CHECK: func encode(to encoder: Encoder) throws
// CHECK: }

// Make sure that CodingKeys members are actually emitted.

// CHECK-LABEL: sil private [ossa] @$s29synthesized_conformance_class5FinalC10CodingKeys{{.*}}21__derived_enum_equalsySbAFyx_G_AHtFZ : $@convention(method) <T> (Final<T>.CodingKeys, Final<T>.CodingKeys, @thin Final<T>.CodingKeys.Type) -> Bool {
// CHECK-LABEL: sil private [ossa] @$s29synthesized_conformance_class5FinalC10CodingKeys{{.*}}9hashValueSivg : $@convention(method) <T> (Final<T>.CodingKeys) -> Int {
// CHECK-LABEL: sil private [ossa] @$s29synthesized_conformance_class5FinalC10CodingKeys{{.*}}4hash4intoys6HasherVz_tF : $@convention(method) <T> (@inout Hasher, Final<T>.CodingKeys) -> () {
// CHECK-LABEL: sil private [ossa] @$s29synthesized_conformance_class5FinalC10CodingKeys{{.*}}11stringValueSSvg : $@convention(method) <T> (Final<T>.CodingKeys) -> @owned String {
// CHECK-LABEL: sil private [ossa] @$s29synthesized_conformance_class5FinalC10CodingKeys{{.*}}11stringValueAFyx_GSgSS_tcfC : $@convention(method) <T> (@owned String, @thin Final<T>.CodingKeys.Type) -> Optional<Final<T>.CodingKeys> {
// CHECK-LABEL: sil private [ossa] @$s29synthesized_conformance_class5FinalC10CodingKeys{{.*}}8intValueSiSgvg : $@convention(method) <T> (Final<T>.CodingKeys) -> Optional<Int> {
// CHECK-LABEL: sil private [ossa] @$s29synthesized_conformance_class5FinalC10CodingKeys{{.*}}8intValueAFyx_GSgSi_tcfC : $@convention(method) <T> (Int, @thin Final<T>.CodingKeys.Type) -> Optional<Final<T>.CodingKeys> {

extension Final: Encodable where T: Encodable {}
// CHECK-LABEL: // Final<A>.encode(to:)
// CHECK-NEXT: sil hidden [ossa] @$s29synthesized_conformance_class5FinalCAASERzlE6encode2toys7Encoder_p_tKF : $@convention(method) <T where T : Encodable> (@in_guaranteed Encoder, @guaranteed Final<T>) -> @error Error {
Expand Down