-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ClangImporter] Support Swift 5 API notes #11867
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
[ClangImporter] Support Swift 5 API notes #11867
Conversation
Preparation for making ImportNameVersion a generalized struct rather than an enum. We could have kept cramming it into a bitfield, sure, but we don't actually need this. No intended functionality change.
cb7ce40
to
dcb12e8
Compare
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.
This is getting to be a bit above my head at this point. But the code seems reasonable.
lib/ClangImporter/ImporterImpl.h
Outdated
@@ -1129,7 +1131,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation | |||
void insertMembersAndAlternates(const clang::NamedDecl *nd, | |||
SmallVectorImpl<Decl *> &members); | |||
void loadAllMembersIntoExtension(Decl *D, uint64_t extra); | |||
void addMemberAndAlternatesToExtension( | |||
bool addMemberAndAlternatesToExtension( |
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 does the return value signify? Could you add a comment?
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.
This is... more extensive than I'd expected. But, it makes sense, and looks nicely future-proofed. Thank you!
apple/swift-clang#126 |
Build failed |
@fredriss, I thought we fixed this? Did the fix not make it into swift-4.1-branch? |
@jrose-apple Swift is supposed to have it's own fix for this. The one we use on the current branch in clang won't have any effect on the swift build. |
Um. LLVM should just get this right. I'll take a look. |
We have a generic fix on master, but it wasn't cherry-picked to the current stable branch |
Hm. Any reason not to do so? Seems safe and correct. |
No reason except that we didn't seem to need it. |
apple/swift-clang#126 |
1 similar comment
apple/swift-clang#126 |
forEachDistinctName might produce the same name for Swift 4 and Swift 5, but it's possible that for some reason the name will only work in one mode or the other. In that case, even though we're trying the "same" name again, we still want to invoke the callback once more. Add a boolean return to the callback to support this. Tests to come at the end of this patch series -- this shows up when in Swift 3 mode and the canonical version for types is set to Swift 5.
...so that we don't have to keep coming back to update it every major release. And also so we can actually put methods on it instead of using free functions. No intended behavior change (yet).
*** Depends on Clang change "[APINotes] Record what version caused *** *** an annotation to get replaced." Update your Clang checkout! *** More generally, change the meaning of the SwiftVersions section in API notes to be "this version or earlier" rather than "exactly this version". We mostly get this behavior for free from the Clang-side changes, but for SwiftName and the enum annotations we look at inactive attributes as well. The latter is simple, but the former means being careful about finding the annotation we /would/ have picked, i.e. the one closest to the version we requested.
"...finally." This was technically enabled two commits ago, since nothing checks that you're not /over/ maxVersion(). This is only used for - deciding the canonical way to import renamed types - trying to import things in multiple ways ...and so there are very few observable differences, especially before anyone has added any API notes that differentiate Swift 4 and Swift 5. At some point we should start encoding name versions in the lookup tables so that we only have to try all the names /once/, but the test suite doesn't seem to get measureably slower with this change, probably because it's pretty quick to decide that most things don't have multiple names. So we can put that off until later.
dcb12e8
to
a0117b0
Compare
Passed full testing before fixing the comment. apple/swift-clang#126 |
apple/swift-clang#126 |
Refactor name importing and the ImportNameVersion type in particular to make it easier to add a new Swift version…then actually do so. This finishes off the work in #11507; we can now use -swift-version 5 end-to-end.
Depends on apple/swift-clang#122 and apple/swift-clang#123, or rather their inclusion into the Clang swift-4.1-branch. Tests pass locally, of course.