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

Adds lint for public function ABI change #546

Merged
merged 8 commits into from
Oct 8, 2023

Conversation

samuelrayment
Copy link
Contributor

Adds a new lint for extern function ABI changes.

I've left the unwind cases for now (this can be the next lint). If you'd like any more examples please let me know. This hopefully closes the first bullet point on this issue: #503

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

This is in very good shape, and I'm looking forward to merging it soon! Just a couple of minor tweaks and suggestions to further improve it and it's good to go — should only take just another minute of your time or so.

Thanks for putting this together! 🚀

Comment on lines 20 to 23
span_: span @optional {
filename @output
begin_line @output
}
Copy link
Owner

Choose a reason for hiding this comment

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

Probably best if we grab the span info of the current function (instead of the baseline) so we can point to the file+line in the current code where the user should look.


pub extern "Rust" fn implicit_c_function_becomes_rust() -> () {}

pub extern "Rust" fn rust_function_remains_rust() -> () {}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggestion for a couple more cases here:

  • an explicitly-Rust ABI function remains Rust ABI but implicitly so, by removing the extern "Rust"
  • the same thing in the opposite direction: adding explicit Rust ABI to an already implicitly-Rust ABI function

These cases are important guards against possible false-positives, which are very annoying for users and so are at least as important to protect against as the test cases for true-positives that make sure our functionality continues to work.

"public": "public",
"zero": 0,
},
error_message: "A publicly-visible function changed it's ABI type.",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
error_message: "A publicly-visible function changed it's ABI type.",
error_message: "A publicly-visible function changed its ABI.",

Copy link
Owner

Choose a reason for hiding this comment

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

Just consistency with the text below.

"zero": 0,
},
error_message: "A publicly-visible function changed it's ABI type.",
per_result_error_template: Some("function {{join \"::\" path}} changed ABI type from {{abi_name}} to {{new_abi_name}} in {{span_filename}}:{{span_begin_line}}"),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
per_result_error_template: Some("function {{join \"::\" path}} changed ABI type from {{abi_name}} to {{new_abi_name}} in {{span_filename}}:{{span_begin_line}}"),
per_result_error_template: Some("{{join \"::\" path}} changed ABI from {{abi_name}} to {{new_abi_name}} in {{span_filename}}:{{span_begin_line}}"),

We really want to try to fit this on one line in the terminal, so brevity is everything.

Comment on lines 40 to 46
abi @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
name @filter(op: "=", value: ["%name"])
}

new_abi_: abi {
name @output
}
Copy link
Owner

Choose a reason for hiding this comment

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

Functions are guaranteed to have exactly one ABI: we see this in the Trustfall schema where the ABI edge is defined abi: FunctionAbi! meaning exactly one neighboring vertex.

That makes this combination of query clauses equivalent to:

Suggested change
abi @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
name @filter(op: "=", value: ["%name"])
}
new_abi_: abi {
name @output
}
new_abi_: abi {
name @filter(op: "!=", value: ["%name"]) @output
}

In the original, we say a combination of "there is no matching ABI" + "get the actual ABI here." In the revised version I'm suggesting, we just say "the ABI that exists is not a match." This is the same thing when there's exactly one ABI, no more and no less. If there could be zero or more than one ABI, that wouldn't be equivalent and we'd need a structure like the original one here.

src/lints/pub_function_changed_abi.ron Outdated Show resolved Hide resolved
@samuelrayment
Copy link
Contributor Author

Actually I'm not sure about the convention for the lint name.

I went with: pub_function_changed_abi but I've noticed the existing function lints omit the pub_. pub_static_missing does exist though, is there a convention for the pub_ prefix?

@obi1kenobi
Copy link
Owner

Actually I'm not sure about the convention for the lint name.

I went with: pub_function_changed_abi but I've noticed the existing function lints omit the pub_. pub_static_missing does exist though, is there a convention for the pub_ prefix?

Oof, we don't have any official convention but we probably should. Let's omit pub to stay consistent with the function lints. pub_static_missing should probably become static_missing as well — PR welcome and much appreciated if you'd like to put one together.

@obi1kenobi
Copy link
Owner

Heads up that I'm planning to publish a new release soon, probably on Sunday. I'd be happy to merge and ship this new lint, but it's also totally okay if we don't get it there in time. I just wanted to let you know my plans so you don't feel surprised to see it 👍 Thanks again for contributing!

@samuelrayment
Copy link
Contributor Author

pub_ prefix now removed from the filenames and lint name.

@obi1kenobi
Copy link
Owner

Awesome stuff, merging! Thanks for putting it together, much appreciated 🚀

@obi1kenobi obi1kenobi merged commit c30bf3a into obi1kenobi:main Oct 8, 2023
32 checks passed
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