-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[C++ Interop] Cache failed imports. #36747
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
base: main
Are you sure you want to change the base?
Conversation
@swift-ci Please smoke test |
Hey Thomas! This looks great. I have a few comments on the implementation, but let's run the tests first. IIRC there are some visitors that need to be updated as well. Thanks again for the contribution! @swift-ci please smoke test. |
It looks like those test failures are unrelated, so I guess I was wrong, the passes are all OK (which is good!). |
lib/ClangImporter/ImporterImpl.h
Outdated
@@ -418,6 +418,9 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation | |||
/// Mapping of already-imported declarations. | |||
llvm::DenseMap<std::pair<const clang::Decl *, Version>, Decl *> ImportedDecls; | |||
|
|||
/// Set of failed-imported declarations. | |||
llvm::DenseSet<std::pair<const clang::Decl *, Version>> FailedImportedDecls; |
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.
So, I think the main question here is whether we want to have both FailedImportedDecls
and ImportedDecls
or just put everything in ImportedDecls
. I think it might be a bit simpler just to have one place where everything cached (especially because it is sometimes checked in the individual visitors).
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.
Sure, I wasn't sure if we wanted to modify ImportedDecls or just importedDeclCached so I opted for importDeclCached initially because it appeared more local (used in ~4 places while ImportedDecls in ~30).
However I suppose we can store a nullptr in the map, and then importDeclCached would return None if not found and a nullptr if found and failed.
Is there a way to check which tests are supposed to fail so I can make sure I didn't break any of the new ones? |
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.
Thanks again for working on this! This change looks great. The last thing to do is please squash all your commits into one which describes the patch as a whole. (You can use git rebase -i main
). Once you force push a new patch I'll test it and land it.
There are no tests that are supposed to fail. Unfortunately, some tests still fail. (One of these is the one that was failing last time: the infamous lldb failure, which I think/hope is on someone's to-do list.) If it looks like the failures are unrelated, just re-trigger the CI, and it usually passes the second time. |
@swift-ci please smoke test and merge. |
@swift-ci please smoke test. |
@swift-ci please test Windows. |
1 similar comment
@swift-ci please test Windows. |
@swift-ci test Windows platform. |
@swift-ci please smoke test macOS. |
1 similar comment
@swift-ci please smoke test macOS. |
@swift-ci test Windows platform. |
Windows, at least, should be fixed now. @swift-ci test Windows platform. |
@swift-ci please smoke test macOS. |
@thomassw66 I really don't think the LLDB failure is related, but it is odd that the bot has now failed four times in a row with that test failure. Can you try running that test locally and see if it fails? |
Hey I got my stuff setup up on MacOS, and ran
But this isn't the LLDB test that is failing. What is the command to run the LLDB test suite? |
@thomassw66 I think you can pass @swift-ci please smoke test macOS. |
Hmm It doesn't seem to repro locally, but I agree it seems that it wouldn't break CI 5 times if it wasn't actually broken.
|
Actually sorry scratch that. I've got it repro-ing locally but I had to get the flags right.
However it appears that the issue repros on my branch as well as the main branch. |
update: Actually it doesn't appear to be repro-ing in the main branch so it looks like this is caused by my change |
@thomassw66 sorry for the slow reply. Thanks for looking into it locally! Are you sure the test ran? Maybe it wasn't supported for some reason? Can you add something like In the meantime, I'll run the bots once more, just to rule that out. @swift-ci please smoke test macOS. |
@swift-ci please smoke test macOS. |
@swift-ci please smoke test. |
Is there anything I can do to help here with this PR? Also I was curious, can this caching of failed imports be used to avoid codegening decls at the same location that are dependent? For instance in #37265 I have a not-so-good work around for an issue I've run into where certain anonymous unions fail to import, but there are FieldDecls/IndirectFieldDecls at the same location that also should not be imported that depend on those failed imports. |
Inspired by swiftlang#36747. I thought I'd go a little further. I have found there is quite a lot of usage of dyn_cast_or_null in place of checking for nullptr or using an optional. I think using an llvm::Optional<T> is a lot cleaner.
…ess. As per SR-14137 this caches entries in ImportedDecls even when the import failed. Also have to mention I did this based on Thomas's PR swiftlang#36747. This should help us better handle complex templates and dependant types.
Cached failed import Decl's and modify importDeclCached api to return an optional.
Resolves SR-14137. https://bugs.swift.org/browse/SR-14137