-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[interop] clang name lookup should find declarations in inline namesp… #40127
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
Conversation
@swift-ci please test |
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.
Some suggestions for tests to add:
- Extending an inline namespace in Swift.
- A type with the same name in two inline namespaces (this might be an ODR violation...).
- A function inside of an inline namespace.
- A test for
std.inner
and a test forstd.__1.__2.inner
. - If it's allowed, an inline namespace that is at the top level.
- (Optional) a namespace inside of an inline namespace inside of a namespace.
// RUN: %target-swift-emit-ir -I %t/Inputs -enable-cxx-interop %t/test.swift | %FileCheck %t/test.swift | ||
|
||
|
||
//--- Inputs/module.modulemap |
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 love this new way to write tests :)
|
||
//--- Inputs/module.modulemap | ||
module std { | ||
header "string.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.
string.h
is a header that may already be in our search paths, so maybe another name is better.
template<class CharT> | ||
struct basic_string; | ||
|
||
typedef basic_string<char> string; | ||
|
||
template<class CharT> | ||
struct basic_string { | ||
void *p; | ||
|
||
const CharT *c_str(); | ||
}; |
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 doesn't seem like a really necessary part of the test. It's sort of complicated. It might be better to just use simple types/functions.
const CharT *c_str(); | ||
}; | ||
|
||
struct other { |
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.
Generally we use the TitleCase
format for types. I know this is a test... but might as well start off right.
|
||
} | ||
|
||
} |
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.
Can you mark these as the end of the namespaces they close?
Build failed |
Build failed |
595871f
to
1ede3ef
Compare
@swift-ci please test |
Build failed |
}); | ||
llvm::copy_if(foundDecls, std::back_inserter(filteredDecls), | ||
[clangDecl](SwiftLookupTable::SingleEntry decl) { | ||
auto foundClangDecl = decl.dyn_cast<clang::NamedDecl *>(); |
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.
Did you run into problems with this? Macros can't be members so this should be fine.
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, this broke the stdlib build.
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, that's super interesting. Do you know how it broke the build or what decl it was? I might go investigate after this lands..
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.
it was p_starttime
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.
which I believe is a macro
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.
That's super interesting... so it's a macro defined to a member of a struct. I guess this is the correct way to handle this...
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 wish this could just be a ranges::filter(isa-named-decl) | ranges::filter(...)
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.
Thank you for overhauling the test. They look great now!
Build failed |
1ede3ef
to
34656fd
Compare
@swift-ci please test |
Build failed |
34656fd
to
71e9119
Compare
@swift-ci please test |
// declarations due to inline namespaces. We still merge in the other | ||
// entries found in the lookup table, to support finding members in | ||
// namespace extensions. | ||
if (!allFound.empty()) { |
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 you're going to duplicate the code anyway, might as well unconditionally take this path.
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.
The code isn't duplicated, the regular path does something additional - it marks the name as markLazilyComplete
in the table.
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.
OK, so, if we know that there are no lazy members (i.e., all members are in the lookup table for a given name), then we don't have to emit a namespace lookup request? Makes sense.
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.
Looks good. Thanks for the diligent updates, Alex!
Build failed |
71e9119
to
d570826
Compare
@swift-ci please test |
d570826
to
1089959
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
@hyp I don't think a source compatibility check is really necessary here. It seems very unlikely this will break source compatibility as we have few projects that use Objective-C interop and none that use C++ interop. I think the failures you're seeing for source compatibility are failing on main and will be resolved by #40143. Anyway, I think you're good to merge if you want. |
I know, I saw that the same failures are in the baseline :) I was just curious to see what the source compatibility test would do. |
I know I just approved this patch, but I also just had a thought: this will crash if someone tries to call a function in an inline namespace from the parent namespace, right? If so, that's really not a great failure mode on our part. Ideally we'd have a diagnostic, but it probably doesn't make sense to spend time adding that, as we want to fix this issue pretty soon. How hard would it be to filter out |
It produces a diagnostic , unless I'm misunderstanding your scenario. One of the test cases covers it. |
Ah, no, you're right. It doesn't crash. I was mis remembering. |
…aces