-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Associated type resilience #19266
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
Associated type resilience #19266
Conversation
@@ -138,6 +138,10 @@ types where the metadata itself has unknown layout.) | |||
global ::= type generic-signature 'TH' // key path equality | |||
global ::= type generic-signature 'Th' // key path hasher | |||
|
|||
global ::= protocol 'TL' // protocol requirements base descriptor | |||
global ::= assoc-type-name 'Tl' // associated type descriptor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the same Tq suffix we use for method descriptors? There won't be a conflict and you'll be able to reuse l for other things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about conformances? Are we just going to say you can't add new conformance requirements after the fact, and existing conformances have a canonical ordering?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't re-use Tq
because IIUC the mangling grammar is usually not resolved this way: the suffix always (?) tells you what grammar to expect before it. Now, I am stealing several of the thunk mangling (for the requirements base, associated type, and possibly associated conformance descriptors), so perhaps I should move out to three-letter discriminators because there aren't that many of these.
Associated conformances are interesting. We need to be able to add new conformances for new defaulted associated types, but we can't add any to existing associated types. Introducing associated conformance descriptors would be the simplest way of ensuring that the addition of new requirements doesn't affect existing clients, so I was planning to investigate that next.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If new conformances are only ever added to new associated types, you might be able to get away with not giving them their own descriptors no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can find a way to consistently put them at the end, we wouldn't need descriptors for associated conformances. But that gets back to the "ABI history database" issue.
@@ -16,6 +16,7 @@ | |||
#include "IRGenModule.h" | |||
#include "swift/AST/ASTMangler.h" | |||
#include "swift/IRGen/ValueWitness.h" | |||
#include "llvm/Support/SaveAndRestore.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's used so we don't drop the protocol name in the mangling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I could mangle this as and let it drop the associated type names from the rest of the mangling.
@swift-ci please smoke test |
2584b28
to
dca37eb
Compare
Can you also add a test to validation-test/Evolution/? |
It turns out that we're already testing for reordering of associated types in https://github.com/apple/swift/blob/master/validation-test/Evolution/Inputs/protocol_reorder_requirements.swift#L29-L53; it worked before my pull request because we sorted associated types. Now we don't sort them, so it's working "for real". I have not implemented resiliently adding an associated type (yet). That will need a new test. |
@swift-ci please test |
@swift-ci please benchmark |
@swift-ci please test source compatibility |
Build failed |
Build failed |
@swift-ci please benchmark |
@swift-ci please test macOS |
Build comment file:Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Code size: Swift libraries
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the regressions before you merge the PR. Noise: Sometimes the performance results (not code size!) contain false alarms. Unexpected regressions which are marked with '(?)' are probably noise. If you see regressions which you cannot explain you can try to run the benchmarks again. If regressions still show up, please consult with the performance team (@eeckstein). Hardware Overview
|
Small code size regression, as expected. |
Build failed |
Emit associated type descriptors (as aliases) to reference each associated type requirement within a resilient protocol.
Introduce an alias that refers one element prior to the start of a protocol descriptor’s protocol requirements. This can be subtracted from an associated type descriptor address to determine the offset of the associated type accessor within a corresponding witness table. The code generation for the latter is not yet implemented.
When accessing the associated type witness metadata for a resilient protocol, compute the index based on the difference between the associated type’s descriptor and the protocol requirement base descriptor to determine the offset into the witness table.
The signature of this function pointer was incorrect, because it had not yet been updated for the metadata request/response architecture. We were getting lucky (!).
Emit associated type witnesses into resilient conformance tables, so they can be re-ordered within the protocol without breaking clients. This will (eventually) permit adding new, defaulted associated types to protocols resiliently.
…ors. When we’re creating an associated type witness metadata accessor for resilience reasons, but the associated type witness doesn’t involve any type parameters, directly form the type metadata reference (and don’t cache it). While here… update all of the IRGen/SILGen test cases perturbed by the introduction of resilient associated type access patterns.
Generic parameter references, which occur in generic requirement metadata, were hardcoding associated type indices. Instead, use relative references to associated type descriptors and perform the index calculation at runtime. Associated types can now be reordered resiliently (without relying on sorting), which is the first main step toward rdar://problem/44167982.
6527d76
to
0fa1590
Compare
@swift-ci please test |
@swift-ci please test |
@swift-ci please test macOS |
3 similar comments
@swift-ci please test macOS |
@swift-ci please test macOS |
@swift-ci please test macOS |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
Make associated types resilient against reordering, without depending on the "sorting" hack that we previously had in place. This is setting the stage to be able to resiliently add new, defaulted associated types without breaking backward compatibility.