-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Avoid C/C++ math function ambiguity for explicit module builds on Windows #85609
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 |
|
@swift-ci please test |
| @@ -295,7 +295,11 @@ public func lgamma(_ x: ${T}) -> (${T}, Int) { | |||
| @_transparent | |||
| public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) { | |||
| var quo = Int32(0) | |||
| #if !os(Windows) | |||
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 problem should occur for any platform that doesn't differentiate long double from double right?
I think that rather than differentiating this on os(Windows), we want to use something to differentiate this based on sizeof(long double) == sizeof(double).
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.
Not exactly. This also requires another condition: the way the Windows headers declare it. This doesn't occur and the following reproducer test doesn't err on macos because the macos C++ header imports the C remquo into the std namespace for C++ rather than declaring another remquo for long double that would cause an overload with C remquo for long in Swift. I added text on it in the bug description here. So I think this is specific to Windows.
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.
Looking at that description, I think that this is the wrong solution. The problem is that corecrt_math.h does define a module, and the header being transitively imported in the headers by CxxStdlib results in the incorrect definition.
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.
My previous comment was not right. I think the headers are similar in macos. I updated the PR to explicitly call the C remquo. I think the conditions to detect long double == double case is captured by the % if T == 'Float80': 6 lines above. I think this should work.
|
@swift-ci please test |
|
@swift-ci please test |
|
@swift-ci please test |
lib/ClangImporter/ImportDecl.cpp
Outdated
| // owningModule->Directory can be null in an explicit module build | ||
| if ((!owningModule->Directory || file->getDir() == owningModule->Directory) && |
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.
| // owningModule->Directory can be null in an explicit module build | |
| if ((!owningModule->Directory || file->getDir() == owningModule->Directory) && | |
| // If we are a non-umbrella module without a canonical location the directory member may | |
| // not be populated. | |
| if (!owningModule->Directory) | |
| return nullptr; | |
| if (file->getDir() == owningModule->Directory && |
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.
Would the suggested change cause non-math functions to not be imported?
|
I think that the check should be separated as it is unrelated to the check being modified. The @ian-twilightcoder and @cachemeifyoucan might be able to shed more light on this. |
I'm not all that familiar with the |
It seems that the field is optional and not always populated. Does it make sense to ignore the check for the directory? It seems that would open us up to cases where the header may be attributed to the wrong module. Alternatively, should we bail early if the |
egorzhdan
left 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.
LGTM, although I'm not too familiar with the testing approach here!
I don't really know, @Bigcheese @vsapsai @jansvoboda11 @benlangmuir do any of you know? |
|
@ian-twilightcoder am I missing something or did you not add this The |
|
In the non-explicit module build case, the Encouraged by @benlangmuir 's comment, I removed the @swift-ci please test |
|
@swift-ci please test macos platform |
|
@swift-ci please test linux platform |
5 similar comments
|
@swift-ci please test linux platform |
|
@swift-ci please test linux platform |
|
@swift-ci please test linux platform |
|
@swift-ci please test linux platform |
|
@swift-ci please test linux platform |
|
@swift-ci please test |
|
If I remove the Maybe this was masked by this I think the original intention as in #65437 was to hide the integer versions I think removing the What do you think? @ian-twilightcoder @egorzhdan @zoecarver @benlangmuir @compnerd |
…dows This tweaks the existing logic that disables the import of the C++ math functions to avoid ambiguity with the C math functions by handling the case where the module directory can be null in explicit module builds. For swiftlang#85606
|
@swift-ci please test |
|
I changed it so it removes the Please take another look. |
compnerd
left 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 makes a lot more sense to me. Thank you!
|
This looks fine to me, but I don't understand the specific history of these changes with respect to abs/div. @egorzhdan you removed the abs/div name checks in 9b7dbf2; does this make sense to you? |
|
@swift-ci please test macos platform |
|
@swift-ci please test windows platform |
1 similar comment
|
@swift-ci please test windows platform |
|
Since no response, I think I'll merge this. Please let me know if you or anyone disagree. I'd rework it if needed |
|
Looks like this is causing test failures on FreeBSD: #86103 |
This tweaks the existing logic that disables the import of the C++
math functions to avoid ambiguity with the C math functions by
handling the case where the module directory can be null in explicit
module builds.
For #85606