Skip to content

Generic metadata prespecialization: enums #29345

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

Conversation

nate-chandler
Copy link
Contributor

Continuing the work started in #28610 , prespecializes generic metadata for enums under limited circumstances. Specifically, prespecialization only occurs for usages within the same module where the type itself is defined and for specializations all of whose type arguments are themselves concrete types.

@nate-chandler nate-chandler changed the title Generic metadata prespecialization components/enums Generic metadata prespecialization: enums Jan 22, 2020
@nate-chandler
Copy link
Contributor Author

@swift-ci please smoke test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

@@ -3789,10 +3806,34 @@ namespace {

return flags;
}
};

// FIXME: Without this template typealias, the following errors are produced
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, is there a radar for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I wasn't able to minimally recreate the problem, but rdar://problem/58884416 covers this.

@@ -684,11 +684,6 @@ bool irgen::isNominalGenericContextTypeMetadataAccessTrivial(
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too conservative. nominal.isResilient(..., ResilienceExpansion::Minimal) ignores the module argument and returns true if the module is resilient.

But if its resilient and defined in the same module, you can still pre-specialize it. The resilience means the metadata is opaque across module boundaries, not within the module itself.

@slavapestov
Copy link
Contributor

I can't comment on unchanged lines in the diff, but about this part:

    // For now, to avoid statically specializing generic protocol witness
    // tables, don't statically specialize metadata for types any of whose
    // arguments are generic.
    //
    // TODO: This is more pessimistic than necessary.  Specialize even in
    //       the face of generic arguments so long as those arguments
    //       aren't required to conform to any protocols.
    //
    // TODO: Once witness tables are statically specialized, check whether the
    //       ConformanceInfo returns nullptr from tryGetConstantTable.
    //       early return.

Can you change this to use the same predicates as the code for emitting witness table references, where it decides if it should reference a witness table directly or call an accessor function? I think isDependentConformance() is the right check, or at least a starting point.


// CHECK: @"$s4main5ValueOySiGWV" = linkonce_odr hidden constant %swift.enum_vwtable { i8* bitcast ({{(%swift.opaque\* \(\[[0-9]+ x i8\]\*, \[[0-9]+ x i8\]\*, %swift.type\*\)\* @"\$[a-zA-Z0-9_]+" to i8\*|i8\* \(i8\*, i8\*, %swift.type\*\)\* @__swift_memcpy[0-9]+_[0-9]+ to i8\*)}}), i8* bitcast (void (i8*, %swift.type*)* @__swift_noop_void_return to i8*), i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy{{[0-9]+}}_{{[0-9]+}} to i8*), i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy{{[0-9]+}}_{{[0-9]+}} to i8*), i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy{{[0-9]+}}_{{[0-9]+}} to i8*), i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy{{[0-9]+}}_{{[0-9]+}} to i8*), i8* bitcast (i32 (%swift.opaque*, i32, %swift.type*)* @"$s4main5ValueOySiGwet" to i8*), i8* bitcast (void (%swift.opaque*, i32, i32, %swift.type*)* @"$s4main5ValueOySiGwst" to i8*), [[INT]] [[ALIGNMENT]], [[INT]] [[ALIGNMENT]], i32 {{[0-9]+}}, i32 0, i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @"$s4main5ValueOySiGwug" to i8*), i8* bitcast (void (%swift.opaque*, %swift.type*)* @"$s4main5ValueOySiGwup" to i8*), i8* bitcast (void (%swift.opaque*, i32, %swift.type*)* @"$s4main5ValueOySiGwui" to i8*) }, align [[ALIGNMENT]]
// CHECK: @"$s4main5ValueOySiGMf" = internal constant <{ i8**, [[INT]], %swift.type_descriptor*, %swift.type*, i64 }> <{ i8** getelementptr inbounds (%swift.enum_vwtable, %swift.enum_vwtable* @"$s4main5ValueOySiGWV", i32 0, i32 0), [[INT]] 513, %swift.type_descriptor* bitcast (<{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i8, i8, i8, i8 }>* @"$s4main5ValueOMn" to %swift.type_descriptor*), %swift.type* @"$sSiN", i64 3 }>, align [[ALIGNMENT]]
enum Value<First> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some tests that use protocol conformances, both the supported and unsupported cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm in the process of writing more.

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch from a745581 to 7e8d20c Compare January 24, 2020 02:50
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a745581219fe577a2421647048fe588ef842af5a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a745581219fe577a2421647048fe588ef842af5a

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch from 7e8d20c to 568d6da Compare January 24, 2020 21:34
@nate-chandler
Copy link
Contributor Author

@swift-ci please test linux platform

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7e8d20c67154b899f16598950b765cb69b3e0a23

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test linux platform

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 568d6dae24d88cd96983f41cd51d6cf32694e988

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch from 568d6da to a8b7f6c Compare January 24, 2020 23:11
@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test linux platform

1 similar comment
@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 568d6dae24d88cd96983f41cd51d6cf32694e988

@nate-chandler
Copy link
Contributor Author

Can you change this to use the same predicates as the code for emitting witness table references, where it decides if it should reference a witness table directly or call an accessor function? I think isDependentConformance() is the right check, or at least a starting point.

@slavapestov, thanks for pointing me at that! Is this along the lines of what you have in mind? b716235

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch from a8b7f6c to 40bc9fe Compare February 6, 2020 19:21
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 6, 2020

Build failed
Swift Test Linux Platform
Git Sha - 40bc9fe4a2d7b90388da22b856e03f9082be43b1

@swift-ci
Copy link
Contributor

swift-ci commented Feb 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - 40bc9fe4a2d7b90388da22b856e03f9082be43b1

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch 3 times, most recently from f554099 to 324f52a Compare February 6, 2020 20:35
@swift-ci
Copy link
Contributor

swift-ci commented Feb 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - 40bc9fe4a2d7b90388da22b856e03f9082be43b1

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch from cca4be0 to 63cd291 Compare February 11, 2020 01:01
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 63cd291415a97e882a5943444756334c9b23eb1b

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 63cd291415a97e882a5943444756334c9b23eb1b

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch 2 times, most recently from d957ebd to 521d8cb Compare February 11, 2020 03:38
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 63cd291415a97e882a5943444756334c9b23eb1b

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 63cd291415a97e882a5943444756334c9b23eb1b

Extracted implementation of SpecializedGenericStructMetadataBuilder into
SpecializedGenericNominalMetadataBuilderBase, a CRTP with a template
template argument for the CRTP superclass and a template argument for
the implementation.  That new type is now subclassed by
SpecializedGenericStructMetadataBuilder.  Additionally, this new type is
also subclassed by the newly added SpecializedGenericEnumMetadataBuilder
which is responsible for build the prespecialization of generic enum
metadata.

rdar://problem/56960887
@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch 2 times, most recently from 07954ac to 76eaa6d Compare February 11, 2020 22:55
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 521d8cb318a555973c89cfab23ced37879d0a6e8

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 521d8cb318a555973c89cfab23ced37879d0a6e8

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch from 76eaa6d to a2e5db2 Compare February 12, 2020 01:30
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 76eaa6d74aa67ba494e4442d6a2f124e0bcac439

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 76eaa6d74aa67ba494e4442d6a2f124e0bcac439

When a specialized usage of a generic enum occurs in the same module
where the enum was defined, directly reference the prespecialized
metadata.

rdar://problem/56994321
@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/enums branch from a2e5db2 to 40e17d9 Compare February 12, 2020 18:57
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a2e5db24f34500cd57f36f7467b1ae5b41108a61

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a2e5db24f34500cd57f36f7467b1ae5b41108a61

@nate-chandler nate-chandler merged commit b628710 into swiftlang:master Feb 12, 2020
@nate-chandler nate-chandler deleted the generic-metadata-prespecialization-components/enums branch February 12, 2020 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants