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

New lint: add function_abi_no_longer_unwind lint #689

Merged
merged 8 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/lints/unwind_function_missing.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
SemverQuery(
id: "unwind_function_missing",
human_readable_name: "unwind function missing",
qstommyshu marked this conversation as resolved.
Show resolved Hide resolved
description: "pub fn changed from an unwind-capable ABI to the same-named ABI without unwind: \"C-unwind\" to \"C\"",
Copy link
Owner

Choose a reason for hiding this comment

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

We don't necessarily know that the change was specifically C-unwind to C. It's possible that the change is from a different unwind-capable ABI to its non-unwind-capable equivalent.

Copy link
Contributor Author

@qstommyshu qstommyshu Mar 11, 2024

Choose a reason for hiding this comment

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

I see, I will change the description to "pub fn changed from an unwind-capable ABI to the same-named ABI without unwind" then. So that the description doesn't specify if the change was specifically C-unwind to C to anticipate new types of unwind capable ABI being added to rust in the future (although I don't know any other unwind capable FFI other than C-unwind so far). Is this an appropriate approach to address this issue?

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds good to me!

Here are a few more unwind-capable ABIs in case you're curious: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md#other-unwind-abi-strings

If we expand the set to not-yet-stable ABIs, the set is even bigger:
https://doc.rust-lang.org/beta/unstable-book/language-features/c-unwind.html

We might want to use the RFC that introduced unwind ABIs as the reference link on line 6 btw: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md

required_update: Major,
reference_link: None,
Copy link
Owner

Choose a reason for hiding this comment

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

Please include an appropriate reference link here. Anything is better than nothing. For example, we could link to the reference page that other ABI-related lints use, if there's nothing more specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Attached the proposal to add C-unwind ABI. It contains lots of information about the design and behaviours. It also links to the RFC PR and issue to C-unwind.

query: r#"
{
CrateDiff {
baseline {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])

abi_: abi {
name @tag
raw_name @output
unwind @filter(op: "=", value: ["$true"])
}
}
}
}
current {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])

name @output

new_abi_: abi {
name @filter(op: "=", value: ["%name"])
raw_name @output
unwind @filter(op: "!=", value: ["$true"])
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"true": true,
},
error_message: "An unwind-capable ABI changed to same-named ABI without unwind",
per_result_error_template: Some("pub fn {{name}} changed ABI from {{abi_raw_name}} to {{new_abi_raw_name}} in {{span_filename}}:{{span_begin_line}}"),
)
qstommyshu marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,5 @@ add_lints!(
repr_packed_removed,
exported_function_changed_abi,
union_now_doc_hidden,
unwind_function_missing,
);
7 changes: 7 additions & 0 deletions test_crates/unwind_function_missing/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "unwind_function_missing"
version = "0.1.0"
edition = "2021"

[dependencies]
1 change: 1 addition & 0 deletions test_crates/unwind_function_missing/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub extern "C" fn unwind_function_becomes_without_unwind() -> () {}
qstommyshu marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions test_crates/unwind_function_missing/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "unwind_function_missing"
version = "0.1.0"
edition = "2021"

[dependencies]
1 change: 1 addition & 0 deletions test_crates/unwind_function_missing/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub extern "C-unwind" fn unwind_function_becomes_without_unwind() -> () {}
11 changes: 11 additions & 0 deletions test_outputs/unwind_function_missing.output.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"./test_crates/unwind_function_missing/": [
{
"abi_raw_name": String("C-unwind"),
"name": String("unwind_function_becomes_without_unwind"),
"new_abi_raw_name": String("C"),
"span_begin_line": Uint64(1),
"span_filename": String("src/lib.rs"),
},
],
}
Loading