Skip to content

[cxx-interop][IRGen] Walk initializer decls when walking constructor decls #41584

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 1 commit into from
Mar 14, 2022

Conversation

bulbazord
Copy link
Contributor

This addresses SR-15272.

When you have a function (e.g. 'foo') which is used in a constructor
initializer (e.g. constructor of some class 'Bar'), and you use the
constructor from swift code without directly using the function (e.g.
Bar's ctor is used from swift but foo isn't, foo is used from Bar's ctor),
you will get a link error. My fix is as follows:

When walking the clangAST to be imported, make sure you look at each
CXXCtorInitializer for each CXXConstructorDecl you see.

@plotfi
Copy link
Contributor

plotfi commented Feb 28, 2022

Nice work @bulbazord.

@hyp @zoecarver

@bulbazord
Copy link
Contributor Author

For more context, see: #39551

@zoecarver
Copy link
Contributor

I was under the impression that #35056 fixed this. This test fails on main?

@bulbazord
Copy link
Contributor Author

I was under the impression that #35056 fixed this. This test fails on main?

The test added in this PR fails on main (at least on my machine). I believe the key difference here is that that patch visits CXXConstructExprs and not CXXConstructDecls. My understanding is that in the test I have written, there are no CXXConstructExprs to be walked in the clangAST, but there is definitely a CXXConstructDecl.

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally. Looks like this is actually an issue.

It's odd that the decl finder doesn't visit the inits already. Anyway, this looks great. Thank you for fixing it.

@zoecarver
Copy link
Contributor

My understanding is that in the test I have written, there are no CXXConstructExprs to be walked in the clangAST, but there is definitely a CXXConstructDecl.

Hmm I suppose that makes sense. This was probably something the Google folks overlooked in their patch, as I suspect they meant to test this case. Thank you for explaining :)

@zoecarver
Copy link
Contributor

I'll trigger the bots once that test is fixed.

Sorry if this is a big ask, but it looks like a lot of similar things are already tested in class/inline-function-codegen/constructor-calls-whatever.swift. Can you factor your tests into those tests, I really want to keep the tests as organized as possible. Especially as more people start contributing.

@zoecarver zoecarver added the c++ interop Feature: Interoperability with C++ label Feb 28, 2022
@bulbazord bulbazord force-pushed the implicit-inline-initializers branch from c21199e to 855d9b1 Compare February 28, 2022 23:55
@bulbazord
Copy link
Contributor Author

@zoecarver I went ahead and merged what I had with the tests in class/inline-function-codegen/constructor-calls-XXX.swift tests. Let me know if there's anything else you'd like to see changed.

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful. Thank you!

@zoecarver
Copy link
Contributor

@swift-ci please test.

@bulbazord bulbazord force-pushed the implicit-inline-initializers branch from 855d9b1 to a7e5caa Compare March 1, 2022 17:03
@bulbazord
Copy link
Contributor Author

Modified the tests to fix the windows failure. Hopefully things are good now. Could you retrigger the tests @zoecarver?

@zoecarver
Copy link
Contributor

@swift-ci please test.

@drodriguez
Copy link
Contributor

@swift-ci please smoke test

This addresses SR-15272.

When you have a function (e.g. 'foo') which is used in a constructor
initializer (e.g. constructor of some class 'Bar'), and you use the
constructor from swift code without directly using the function (e.g.
Bar's ctor is used from swift but foo isn't, foo is used from Bar's ctor),
you will get a link error. My fix is as follows:

When walking the clangAST to be imported, make sure you look at each
CXXCtorInitializer for each CXXConstructorDecl you see.
@bulbazord bulbazord force-pushed the implicit-inline-initializers branch from a7e5caa to edbb448 Compare March 9, 2022 19:30
@bulbazord
Copy link
Contributor Author

I believe I've fixed the windows test (2 characters were swapped in the mangled name, whoops!).
I hope it works and can go in soon!

@drodriguez
Copy link
Contributor

@swift-ci please smoke test

@drodriguez
Copy link
Contributor

@swift-ci please test Linux platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants