Skip to content

Commit

Permalink
Add function_abi_now_unwind lint and fix `function_abi_no_longer_un…
Browse files Browse the repository at this point in the history
…wind`. (#1061)

The `function_abi_no_longer_unwind` lint had false-positives since it
failed to connect the baseline and current functions by their import
paths.
  • Loading branch information
obi1kenobi authored Dec 22, 2024
1 parent f55dc22 commit 6172415
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lints/function_abi_no_longer_unwind.ron
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ SemverQuery(
name @output
new_abi_: abi {
name @tag
name @tag(name: "abi")
raw_name @output
unwind @filter(op: "!=", value: ["$true"])
}
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
filename @output
begin_line @output
Expand All @@ -34,10 +39,15 @@ SemverQuery(
visibility_limit @filter(op: "=", value: ["$public"])
abi_: abi {
name @filter(op: "=", value: ["%name"])
name @filter(op: "=", value: ["%abi"])
raw_name @output
unwind @filter(op: "=", value: ["$true"])
}
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions src/lints/function_abi_now_unwind.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
SemverQuery(
id: "function_abi_now_unwind",
human_readable_name: "function abi is now unwind-capable",
description: "A pub fn changed from an non-unwind ABI to the same-named ABI with unwind ability. This change might not be compatible with callers of this function, since they may not expect unwinding to happen here.",
required_update: Major,
lint_level: Deny,
reference_link: Some("https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html"),
query: r#"
{
CrateDiff {
current {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
name @output
new_abi_: abi {
name @tag(name: "abi")
raw_name @output
unwind @filter(op: "=", value: ["$true"])
}
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
baseline {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
abi_: abi {
name @filter(op: "=", value: ["%abi"])
raw_name @output
unwind @filter(op: "!=", value: ["$true"])
}
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"true": true,
},
error_message: "A pub fn changed from a non-unwind ABI to the same-named ABI with unwind ability. This change might not be compatible with callers of this function, since they may not expect unwinding to happen here.",
per_result_error_template: Some("{{join \"::\" path}} changed ABI from {{abi_raw_name}} to {{new_abi_raw_name}} in {{span_filename}}:{{span_begin_line}}"),
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ add_lints!(
feature_missing,
feature_not_enabled_by_default,
function_abi_no_longer_unwind,
function_abi_now_unwind,
function_changed_abi,
function_const_removed,
function_export_name_changed,
Expand Down
6 changes: 6 additions & 0 deletions test_crates/function_abi_no_longer_unwind/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
pub extern "C" fn unwind_function_becomes_non_unwind() {}

pub extern "C-unwind" fn non_unwind_function_becomes_unwind() {}

pub extern "C" fn non_unwind_function_unchanged() {}

pub extern "C-unwind" fn unwind_function_unchanged() {}
6 changes: 6 additions & 0 deletions test_crates/function_abi_no_longer_unwind/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
pub extern "C-unwind" fn unwind_function_becomes_non_unwind() {}

pub extern "C" fn non_unwind_function_becomes_unwind() {}

pub extern "C" fn non_unwind_function_unchanged() {}

pub extern "C-unwind" fn unwind_function_unchanged() {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
---
source: src/query.rs
expression: "&query_execution_results"
snapshot_kind: text
---
{
"./test_crates/function_abi_no_longer_unwind/": [
{
"abi_raw_name": String("C-unwind"),
"name": String("unwind_function_becomes_non_unwind"),
"new_abi_raw_name": String("C"),
"path": List([
String("function_abi_no_longer_unwind"),
String("unwind_function_becomes_non_unwind"),
]),
"span_begin_line": Uint64(1),
"span_filename": String("src/lib.rs"),
},
Expand Down
20 changes: 20 additions & 0 deletions test_outputs/query_execution/function_abi_now_unwind.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: src/query.rs
expression: "&query_execution_results"
snapshot_kind: text
---
{
"./test_crates/function_abi_no_longer_unwind/": [
{
"abi_raw_name": String("C"),
"name": String("non_unwind_function_becomes_unwind"),
"new_abi_raw_name": String("C-unwind"),
"path": List([
String("function_abi_no_longer_unwind"),
String("non_unwind_function_becomes_unwind"),
]),
"span_begin_line": Uint64(3),
"span_filename": String("src/lib.rs"),
},
],
}

0 comments on commit 6172415

Please sign in to comment.