Skip to content
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

Add support for the thiscall ABI #1065

Merged
merged 1 commit into from
Oct 10, 2017
Merged

Conversation

liranringel
Copy link
Contributor

@liranringel liranringel commented Oct 9, 2017

Fixes #541

The thiscall ABI is experimental, so in order to use it nightly is required and also the following statement:
#![feature(abi_thiscall)]
That's a problem because the tests_expectations crate (in the tests folder) tries to compile it (and stable is required).

@highfive
Copy link

highfive commented Oct 9, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@pepyakin
Copy link
Contributor

pepyakin commented Oct 9, 2017

Hello @liranringel ! Thanks for your PR!

Unfortunately, we don't have nightly tests at the moment. But I believe that we should start to run them eventually. For example we have const_fn but we don't test it yet! And there are a few more features that we might want to emit in nightly.

I'm not sure what is the best possible way here.
@fitzgen maybe it is OK to land this without tests?

@fitzgen
Copy link
Member

fitzgen commented Oct 9, 2017

For now, it is OK to land this without tests in CI, so long as the emitted bindings contain things that we can look at if/when the emitted bindings change in the future and verify that the changes look right or wrong manually. For this PR concretely, that would be the extern "fastcall" { ... } bit in the new expectations file.

Eventually, we should be running rustc nightly tests in CI. I don't want to combinatorially explode our CI test jobs more than we already have, so let's not run all of our many test jobs in both stable and nightly. Instead, I think it makes sense to have just one more CI job that does expectations tests in nightly (since non-nightly can be used to verify that generated bindings aren't changing, and we just need nightly for compiling code with nightly features).


When I said "For now, it is OK to land this without tests," I intentionally qualified that with "in CI." We can land tests that don't run in CI yet, but exist and can run locally:

  • Add a new nightly feature to tests/expectations/Cargo.toml
  • Add --raw-line '#![cfg(feature = "nightly")]' to the // bindgen-flags in the new test header introduced in this PR
  • Add --raw-line '#![cfg(feature(abi_thiscall))]' as well

Then, running

$ cd tests/expectations
$ cargo test --features nightly

should run this test locally!

When we eventually add nightly CI, we can make it use the same feature.


Ok, looking at the PR now :)

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Overall, this is much more straightforward than I feared it might be :)


We have the concept of the "rust target" and its associated supported features. See for example

We use these to avoid generating bindings that require nightly features for the targeted Rust version/channel.

We should leverage this infrastructure for "thiscall" as well:

  • First, we should define a thiscall_abi feature, that is only supported in the nightly rust target.

  • Second, inside impl Codegen for Function, if we see a "thiscall" ABI, and ctx.options().rust_features().thiscall_abi() is not true, then we should warn!("skipping function with thiscall ABI that isn't supported by the configured Rust target") and avoid generating any bindings for the function.

  • Same as the last bullet but for impl TryToRustTy for FunctionSig

  • Finally, we should have two versions of the new test: one that targets nightly, and has the cfg options to enable the "thiscall" ABI, and another that targets Rust stable 1.0. We just want to make sure we don't panic or generate bad bindings in the latter case.


Thanks a bunch @liranringel ! If anything doesn't make sense, let me know and I can try and elucidate :)

@liranringel
Copy link
Contributor Author

@fitzgen thanks for the comprehensive explanation.
How could I make the expectation file that has the cfg option to enable the thiscall ABI? It's just generated by bindgen, isn't it?

@fitzgen
Copy link
Member

fitzgen commented Oct 10, 2017

How could I make the expectation file that has the cfg option to enable the thiscall ABI? It's just generated by bindgen, isn't it?

This is what the --raw-line flags I mentioned are for: they pass the given contents directly though, into the generated bindings, so we can add the cfgs that way.

  • Add --raw-line '#![cfg(feature = "nightly")]' to the // bindgen-flags in the new test header introduced in this PR
  • Add --raw-line '#![cfg(feature(abi_thiscall))]' as well

Make sense?

@liranringel liranringel force-pushed the thiscall branch 3 times, most recently from 8c02105 to 9b95ce6 Compare October 10, 2017 00:44
@liranringel
Copy link
Contributor Author

Yes, you may check it.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

👍 perfect! Thanks @liranringel !

@fitzgen
Copy link
Member

fitzgen commented Oct 10, 2017

@bors-servo r+

@bors-servo
Copy link

📌 Commit 9b95ce6 has been approved by fitzgen

@bors-servo
Copy link

⌛ Testing commit 9b95ce6 with merge c744e68...

bors-servo pushed a commit that referenced this pull request Oct 10, 2017
Add support for the thiscall ABI

Fixes #541

The thiscall ABI is experimental, so in order to use it nightly is required and also the following statement:
`#![feature(abi_thiscall)]`
That's a problem because the `tests_expectations` crate (in the tests folder) tries to compile it (and stable is required).
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: fitzgen
Pushing c744e68 to master...

@bors-servo bors-servo merged commit 9b95ce6 into rust-lang:master Oct 10, 2017
@liranringel liranringel deleted the thiscall branch October 10, 2017 18:13
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.

None yet

5 participants