Skip to content

[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

Merged
merged 5 commits into from
Sep 15, 2017

Conversation

jrose-apple
Copy link
Contributor

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.

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.
@jrose-apple jrose-apple force-pushed the ClangImporter-episode-V branch from cb7ce40 to dcb12e8 Compare September 12, 2017 01:09
Copy link
Member

@milseman milseman left a 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.

@@ -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(
Copy link
Member

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?

Copy link
Member

@DougGregor DougGregor left a 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!

@jrose-apple
Copy link
Contributor Author

apple/swift-clang#126
@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - dcb12e8178f54620ba23f1474cef87aa7f131370

@jrose-apple
Copy link
Contributor Author

/Users/buildnode/jenkins/workspace/swift-PR-osx/branch-master/llvm/lib/Support/Unix/Path.inc:597:7: error: 'futimens' is only available on macOS 10.13 or newer [-Werror,-Wunguarded-availability-new]
  if (::futimens(FD, Times))
      ^~~~~~~~~~

@fredriss, I thought we fixed this? Did the fix not make it into swift-4.1-branch?

@fredriss
Copy link
Contributor

@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.

@jrose-apple
Copy link
Contributor Author

Um. LLVM should just get this right. I'll take a look.

@fredriss
Copy link
Contributor

We have a generic fix on master, but it wasn't cherry-picked to the current stable branch

@jrose-apple
Copy link
Contributor Author

Hm. Any reason not to do so? Seems safe and correct.

@fredriss
Copy link
Contributor

No reason except that we didn't seem to need it.

@jrose-apple
Copy link
Contributor Author

apple/swift-clang#126
@swift-ci please test

1 similar comment
@jrose-apple
Copy link
Contributor Author

apple/swift-clang#126
@swift-ci please test

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.
@jrose-apple jrose-apple force-pushed the ClangImporter-episode-V branch from dcb12e8 to a0117b0 Compare September 15, 2017 21:30
@jrose-apple
Copy link
Contributor Author

Passed full testing before fixing the comment.

apple/swift-clang#126
@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

apple/swift-clang#126
@swift-ci Please smoke test Linux

@jrose-apple jrose-apple merged commit 82fa362 into swiftlang:master Sep 15, 2017
@jrose-apple jrose-apple deleted the ClangImporter-episode-V branch September 15, 2017 23:34
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.

5 participants