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

wf: check foreign fn decls for well-formedness #73323

Merged

Conversation

davidtwco
Copy link
Member

@davidtwco davidtwco commented Jun 13, 2020

Fixes #73252 and fixes #73253.

This PR extends current well-formedness checking to apply to foreign function declarations, re-using the existing machinery for regular functions. In doing this, later parts of the compiler (such as the improper_ctypes lint) can rely on being operations not failing as a result of invalid code which would normally be caught earlier.

@rust-highfive
Copy link
Collaborator

r? @ecstatic-morse

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2020
@lcnr
Copy link
Contributor

lcnr commented Jun 14, 2020

Does this also fix #73253?

If so, this is a breaking change (which we should still land IMO) and may require a crater run 😅

Even this PR doesn't change its output, can you still add this as a test?

pub trait Unsatisfied {}

#[repr(transparent)]
pub struct Foo<T: Unsatisfied>(T);

extern "C" {
    pub fn foo() -> Foo<u32>;
}

@davidtwco davidtwco force-pushed the issue-73252-wfcheck-foreign-fn-decl branch from c83d10f to 9fc57fb Compare June 14, 2020 12:57
@davidtwco
Copy link
Member Author

Does this also fix #73253?

Even this PR doesn't change its output, can you still add this as a test?

pub trait Unsatisfied {}

#[repr(transparent)]
pub struct Foo<T: Unsatisfied>(T);

extern "C" {
    pub fn foo() -> Foo<u32>;
}

This also fixes #73253, I've added that to the test.

If so, this is a breaking change (which we should still land IMO) and may require a crater run 😅

Probably, I'll wait to see what the reviewer thinks - not entirely sure what the protocol is here.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

impl looks good 👍 requires crater run IMO

@jonas-schievink
Copy link
Contributor

@bors try

Crater seems borked at the moment, but we can prepare a build.

@bors
Copy link
Contributor

bors commented Jun 25, 2020

⌛ Trying commit 9fc57fb950edf74e880a1348a2860f41d481def1 with merge aef0c51c752d86410f02b64fbda721f083f33c39...

@bors
Copy link
Contributor

bors commented Jun 25, 2020

☀️ Try build successful - checks-azure
Build commit: aef0c51c752d86410f02b64fbda721f083f33c39 (aef0c51c752d86410f02b64fbda721f083f33c39)

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Jun 25, 2020

Sorry. I seem to have missed this one. The implementation looks good, and it seems like something that we clearly want to do. I would be surprised if this broke real code, but I feel a bit uncomfortable approving unilaterally since the possibility exists. @rust-lang/compiler, does anyone object to this PR? Otherwise, r=me if there are no crater regressions.

@estebank
Copy link
Contributor

Code looks good and this is a clear fix of invalid code, but having tried something similar out for types, there is a possibility of fallout in crater run. If we find that that is the case for this as well, could we phase this in as a lint then?

@nikomatsakis
Copy link
Contributor

Definitely do a crater run. We should be able to manage a future-compatibility warning. We may want to do it anyway, but a crater run is a good first step.

@davidtwco davidtwco force-pushed the issue-73252-wfcheck-foreign-fn-decl branch from 9fc57fb to 822fe7f Compare July 8, 2020 11:52
@davidtwco
Copy link
Member Author

Rebased this to make sure it was still working - will do a try build then crater run.

@bors try

@bors
Copy link
Contributor

bors commented Jul 8, 2020

⌛ Trying commit 822fe7f00cc35bdaae86add5fe18de20631a2cfd with merge 85cc1486e1f000dce4bb8e1b3cfab2b654b102a8...

@bors
Copy link
Contributor

bors commented Jul 8, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 85cc1486e1f000dce4bb8e1b3cfab2b654b102a8 (85cc1486e1f000dce4bb8e1b3cfab2b654b102a8)

@davidtwco
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-73323 created and queued.
🤖 Automatically detected try build 85cc1486e1f000dce4bb8e1b3cfab2b654b102a8
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2020
@craterbot
Copy link
Collaborator

🚧 Experiment pr-73323 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-73323 is completed!
📊 7 regressed and 10 fixed (112019 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jul 19, 2020
@lcnr
Copy link
Contributor

lcnr commented Jul 19, 2020

It looks like all regressions are spurious to me.

This commit extends current well-formedness checking to apply to foreign
function declarations, re-using the existing machinery for regular
functions. In doing this, later parts of the compiler (such as the
`improper_ctypes` lint) can rely on being operations not failing as a
result of invalid code which would normally be caught earlier.

Signed-off-by: David Wood <[email protected]>
@davidtwco davidtwco force-pushed the issue-73252-wfcheck-foreign-fn-decl branch from 822fe7f to ceac273 Compare July 20, 2020 09:53
@davidtwco
Copy link
Member Author

Rebased this PR; I agree with @lcnr that the crater report looks good, so I'll r=ecstatic-morse after CI passes.

@davidtwco
Copy link
Member Author

@bors r=ecstatic-morse

@bors
Copy link
Contributor

bors commented Jul 20, 2020

📌 Commit ceac273 has been approved by ecstatic-morse

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 20, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 20, 2020
…arth

Rollup of 13 pull requests

Successful merges:

 - rust-lang#72714 (Fix debug assertion in typeck)
 - rust-lang#73197 (Impl Default for ranges)
 - rust-lang#73323 (wf: check foreign fn decls for well-formedness)
 - rust-lang#74051 (disallow non-static lifetimes in const generics)
 - rust-lang#74376 (test caching opt_const_param_of on disc)
 - rust-lang#74501 (Ayu theme: Use different background color for Run button)
 - rust-lang#74505 (Fix search input focus in ayu theme)
 - rust-lang#74522 (Update sanitizer docs)
 - rust-lang#74546 (Fix duplicate maybe_uninit_extra attribute)
 - rust-lang#74552 (Stabilize TAU constant.)
 - rust-lang#74555 (Improve "important traits" popup display on mobile)
 - rust-lang#74557 (Fix an ICE on an invalid `binding @ ...` in a tuple struct pattern)
 - rust-lang#74561 (update backtrace-rs)

Failed merges:

r? @ghost
@bors bors merged commit 0897bc2 into rust-lang:master Jul 21, 2020
@davidtwco davidtwco deleted the issue-73252-wfcheck-foreign-fn-decl branch July 21, 2020 09:21
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
10 participants