AST: Fix a problem with the protocol order #80213
Open
+89
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The last step in building a generic signature is to sort the requirements. Requirements are sorted by comparing their subject types. If two requirements have the same subject type, which can only happen with conformance requirements, we break the tie by comparing protocol declarations.
We compare protocol declarations using TypeDecl::compare(), which is a shortlex order on the components of the fully qualified name of a protocol (eg, Swift.Sequence, etc.)
Ultimately, the protocol order determines mangled symbol names, the order of witness table arguments in the calling convention, the layout of existentials, and so on. While this order is part of the ABI, it has not been updated over the years for several important changes:
It did not handle module aliases; if we import a module via an alias, we should use the real module name to compare protocols, and not the aliased name. This produced inconsistent results if the same module was imported under different names, which can happen with module interface files that use module aliases.
It did not handle the
-module-abi-name
flag. Changing the ABI name of a module changes how we mangle protocol names, and the order should match the mangling.It did not use the original module name specified in the
@_originallyDefinedIn
flag, so moving a protocol between modules would change its position in the order.This PR fixes the above problems. Of course this is an ABI break, however it should have limited impact since module aliases and -module-abi-name are not widely used.
Fixes rdar://147441890.