Skip to content

[cxx-interop] Pull over fix from 8e7766b and apply to strstr, sin, an… #66896

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 8 commits into from
Jun 29, 2023

Conversation

zoecarver
Copy link
Contributor

…d cos.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves #NNNNN, fix apple/llvm-project#MMMMM.

@zoecarver zoecarver requested review from hyp and egorzhdan as code owners June 23, 2023 19:05
@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test

@zoecarver
Copy link
Contributor Author

It's so odd that the linux CI is failing like this :(

@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test

…ons.

Also add back `string.h` as a valid header and ban imports from `_SwiftConcurrencyShims`.
@zoecarver
Copy link
Contributor Author

@swift-ci please test

@@ -1,10 +0,0 @@
// RUN: %target-swift-ide-test -print-module -module-to-print=_SwiftConcurrencyShims -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@egorzhdan can you review this change. Is there some reason we'd want to import this function? It conflicts with Darwin.exit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it used from swift/stdlib/public/Concurrency/Task.swift, I wonder if _Concurrency still builds if we don't import this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think re-declaring exit() in the shim header isn't really great, it would be nice to just import Darwin.exit/Glibc.exit/etc from Task.swift and use that directly from Swift.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with either solution as long as _Concurrency builds with interop enabled 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mind taking another look?


let _ = CxxStdlib.abs(x) // expected-error {{module 'CxxStdlib' has no member named 'abs'}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting errors like this:

Darwin.pow:1:13: note: diagnostic produced elsewhere: candidate expects value of type 'Double' for parameter #1 (got 'Float')
public func pow(_: Double, _: Double) -> Double

So I figured we could just test the positive case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also testing the positive case seems more direct in terms of making sure the thing we want to work works. It also is a bit less fragile and more portable.

… conflict with declarations in the `Darwin` module; improve the test.
@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test

@@ -16,6 +16,8 @@
#ifndef SWIFT_CONCURRENCY_H
#define SWIFT_CONCURRENCY_H

#include <stdlib.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DougGregor can you please review this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I think I am not going to make this change in this PR. I'm just going to ban the one from stdlib.h. Otherwise, we will have to update SILGenModule::getExit to handle a number of modulemaps/platforms.

@zoecarver zoecarver requested a review from DougGregor June 28, 2023 16:44
extern "C" [[noreturn]]
#endif
void exit(int);

#define EXIT_SUCCESS 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I think EXIT_SUCCESS can also be removed since we now import stdlib.h where it is defined.

@zoecarver zoecarver force-pushed the fix-ambiguous-math-func branch from 21e56b2 to 50ce843 Compare June 28, 2023 17:16
@zoecarver
Copy link
Contributor Author

@egorzhdan I decided to actually just ban exit from stdlib and make everyone use the _SwiftConcurrency. Just because it was too hard to look through all the different places it might live when updating SILGenModule::getExit. WDYT? Can we just update to have everyone use the stdlib declaration after the fact?

@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test

@zoecarver zoecarver force-pushed the fix-ambiguous-math-func branch from 5718a4b to 6233a65 Compare June 29, 2023 00:20
@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test

let _ = CxxStdlib.div(x) // expected-error {{module 'CxxStdlib' has no member named 'div'}}
let _ = abs(x)
// https://github.com/apple/swift/issues/67006
// let _ = div(42, 2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect example of why we should test the positive case: div wasn't available on linux even before this patch because it's in stdlib.h. Issue filed.

@egorzhdan
Copy link
Contributor

I decided to actually just ban exit from stdlib and make everyone use the _SwiftConcurrency

Wouldn't this break existing code that uses exit if someone enables C++ interop?

@zoecarver
Copy link
Contributor Author

I decided to actually just ban exit from stdlib and make everyone use the _SwiftConcurrency

Wouldn't this break existing code that uses exit if someone enables C++ interop?

No. Everyone imports _SwiftConcurrency. You can see that exit continues to work in test/Interop/Cxx/stdlib/avoid-import-cxx-math.swift.

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.

2 participants