-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
patchable-function-entry: Add unstable compiler flag and attribute #124741
patchable-function-entry: Add unstable compiler flag and attribute #124741
Conversation
I am very unsure about the error handling in codegen_attrs.rs Creating a new error type seemed a bit too much for those errors. |
This comment has been minimized.
This comment has been minimized.
3faed1a
to
894acb1
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a2f3275
to
b093958
Compare
This comment has been minimized.
This comment has been minimized.
b093958
to
adaf72d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8c53256
to
316bd64
Compare
As author of the RFC and the two commits cherry-picked over, this LGTM (there's a bit of grunge in the git history with an unresolved conflict in the rebase, but it gets cleaned up by the last commit). |
for item in l { | ||
if let Some((sym, lit)) = item.name_value_literal() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we switch off name_value_literal()
? It looks like you've re-implemented it by first extracting out the symbol manually (even if name_value_literal()
doesn't work for some reason, you should consider symbol_or_empty()
rather than the first two steps). I do see that you can no longer directly call it on the item
and would need to use if let Some((sym, lit)) = item.meta_item().and_then(|mi| mi.name_value_literal()) {
, but it seems like it'd be a lot shorter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for suggesting symbol_or_empty! I found name_or_empty, which was probably what you meant and it allowed me to get rid of that ugly span parsing.
I also took the oppurtunity add better error diagnostics, when parsing fails.
316bd64
to
df751da
Compare
src/doc/unstable-book/src/compiler-flags/patchable-function-entry.md
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
21f138e
to
bd412f6
Compare
src/doc/unstable-book/src/compiler-flags/patchable-function-entry.md
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cg_llvm and cg_ssa changes to the actual codegen, and the attendant FileCheck, look good to me. I'd like it if a T-compiler reviewer gave their formal opinion on the diagnostics code given I'm not as familiar with most of the diagnostics code, and the diagnostics in the codegen parts are usually quite... sparse.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #126914) made this pull request unmergeable. Please resolve the merge conflicts. |
`-Z patchable-function-entry` works like `-fpatchable-function-entry` on clang/gcc. The arguments are total nop count and function offset. See MCP rust-lang/compiler-team#704
See [RFC](https://github.com/maurer/rust-rfcs/blob/patchable-function-entry/text/0000-patchable-function-entry.md) (yet to be numbered) TODO before submission: * Needs an RFC * Improve error reporting for malformed attributes
b91a3aa
to
4f5069f
Compare
This comment has been minimized.
This comment has been minimized.
4f5069f
to
7c56398
Compare
let mut entry = None; | ||
for item in l { | ||
let Some(meta_item) = item.meta_item() else { | ||
tcx.dcx().span_err(item.span(), "Expected name value pair."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference, the message format doesn't use title-case nor periods. Maybe we should, but let's remain consistent with what we already have:
tcx.dcx().span_err(item.span(), "Expected name value pair."); | |
tcx.dcx().span_err(item.span(), "expected name value pair"); |
tcx.dcx().span_err( | ||
item.span(), | ||
format!( | ||
"Unexpected parameter name. Allowed names: {}, {}", | ||
sym::prefix_nops, | ||
sym::entry_nops | ||
), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tcx.dcx().span_err( | |
item.span(), | |
format!( | |
"Unexpected parameter name. Allowed names: {}, {}", | |
sym::prefix_nops, | |
sym::entry_nops | |
), | |
); | |
tcx.dcx().struct_span_err( | |
item.span(), | |
"unexpected parameter name" | |
).span_label( | |
item.span(), | |
format!( | |
"expected {} or {}", | |
sym::prefix_nops, | |
sym::entry_nops | |
), | |
).emit(); |
}; | ||
|
||
let Some(name_value_lit) = meta_item.name_value_literal() else { | ||
tcx.dcx().span_err(item.span(), "Expected name value pair."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tcx.dcx().span_err(item.span(), "Expected name value pair."); | |
tcx.dcx().span_err(item.span(), "expected name value pair"); |
tcx.dcx().span_err( | ||
name_value_lit.span, | ||
"Expected integer value between 0 and 255.", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tcx.dcx().span_err( | |
name_value_lit.span, | |
"Expected integer value between 0 and 255.", | |
); | |
tcx.dcx().struct_span_err( | |
name_value_lit.span, | |
"integer value out of range", | |
).span_label( | |
name_value_lit.span, | |
"value must be between `0` and `255`", | |
).emit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message would also be triggered when passing in a string, so the suggested wording might be a bit weird in that case. Do you think it makes sense to make the check for the string seperate again or is this just a minor issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is worth it to be more accurate whenever possible. you can make this be
tcx.dcx().span_err( | |
name_value_lit.span, | |
"Expected integer value between 0 and 255.", | |
); | |
let mut err = tcx.dcx().struct_span_err( | |
name_value_lit.span, | |
"invalid literal value", | |
); | |
if is_numeric { | |
err.span_label( | |
name_value_lit.span, | |
"value must be between `0` and `255`" | |
); | |
} else if is_str { | |
err.span_label( | |
name_value_lit.span, | |
"some appropriate message" | |
); | |
} | |
// Are there other cases to handle? can we hit this error without a numeric or str literal? | |
err.emit(); |
} | ||
|
||
if let (None, None) = (prefix, entry) { | ||
tcx.dcx().span_err(attr.span, "Must specify at least one parameter."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tcx.dcx().span_err(attr.span, "Must specify at least one parameter."); | |
tcx.dcx().span_err(attr.span, "must specify at least one parameter"); |
@@ -813,6 +813,10 @@ fn test_unstable_options_tracking_hash() { | |||
tracked!(packed_bundled_libs, true); | |||
tracked!(panic_abort_tests, true); | |||
tracked!(panic_in_drop, PanicStrategy::Abort); | |||
tracked!( | |||
patchable_function_entry, | |||
PatchableFunctionEntry::from_total_and_prefix_nops(10, 5).expect("total >= prefix") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message in expect
needs to be the description of the condition that wasn't met.
PatchableFunctionEntry::from_total_and_prefix_nops(10, 5).expect("total >= prefix") | |
PatchableFunctionEntry::from_total_and_prefix_nops(10, 5).expect("total < prefix") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if I understood you correctly, but to get a value the condition 'total >=prefix' must be true. The panic would happen if that condition is false. So I'd think it would be correct as written?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if total < prefix
is that at runtime we'll get a panic that looks like the following:
thread 'main' panicked at compiler/rustc_interface/src/tests.rs:818:8:
total >= prefix
Instead we should provide additional context beyond that. Having said that, this is a nitpick to make it easier for people to understand that happened in this test, it's not a deal breaker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PatchableFunctionEntry::from_total_and_prefix_nops(10, 5).expect("total >= prefix") | |
PatchableFunctionEntry::from_total_and_prefix_nops(10, 5).expect("total must be greater than prefix") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just unwrap, this is just a test, really, and the condition is trivially obviously true.
cool, thanks! @bors r=estebank,workingjubilee rollup |
…s-pr, r=estebank,workingjubilee patchable-function-entry: Add unstable compiler flag and attribute Tracking issue: rust-lang#123115 Add the -Z patchable-function-entry compiler flag and the #[patchable_function_entry(prefix_nops = m, entry_nops = n)] attribute. Rebased and adjusted the canditate implementation to match changes in the RFC.
…s-pr, r=estebank,workingjubilee patchable-function-entry: Add unstable compiler flag and attribute Tracking issue: rust-lang#123115 Add the -Z patchable-function-entry compiler flag and the #[patchable_function_entry(prefix_nops = m, entry_nops = n)] attribute. Rebased and adjusted the canditate implementation to match changes in the RFC.
…s-pr, r=estebank,workingjubilee patchable-function-entry: Add unstable compiler flag and attribute Tracking issue: rust-lang#123115 Add the -Z patchable-function-entry compiler flag and the #[patchable_function_entry(prefix_nops = m, entry_nops = n)] attribute. Rebased and adjusted the canditate implementation to match changes in the RFC.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#124741 (patchable-function-entry: Add unstable compiler flag and attribute) - rust-lang#126470 (make cargo submodule optional) - rust-lang#126701 (ignore `llvm::Lld` if lld is not enabled) - rust-lang#126956 (core: avoid `extern type`s in formatting infrastructure) - rust-lang#126970 (Simplify `str::clone_into`) - rust-lang#127058 (Tighten `fn_decl_span` for async blocks) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#124741 (patchable-function-entry: Add unstable compiler flag and attribute) - rust-lang#126470 (make cargo submodule optional) - rust-lang#126956 (core: avoid `extern type`s in formatting infrastructure) - rust-lang#126970 (Simplify `str::clone_into`) - rust-lang#127022 (Support fetching `Attribute` of items.) - rust-lang#127058 (Tighten `fn_decl_span` for async blocks) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124741 - nebulark:patchable-function-entries-pr, r=estebank,workingjubilee patchable-function-entry: Add unstable compiler flag and attribute Tracking issue: rust-lang#123115 Add the -Z patchable-function-entry compiler flag and the #[patchable_function_entry(prefix_nops = m, entry_nops = n)] attribute. Rebased and adjusted the canditate implementation to match changes in the RFC.
Tracking issue: #123115
Add the -Z patchable-function-entry compiler flag and the #[patchable_function_entry(prefix_nops = m, entry_nops = n)] attribute.
Rebased and adjusted the canditate implementation to match changes in the RFC.