Do not deduce parameter attributes during CTFE#151842
Do not deduce parameter attributes during CTFE#151842eggyal wants to merge 1 commit intorust-lang:mainfrom
Conversation
5650820 to
ea095f5
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
ea095f5 to
de839fc
Compare
|
Note that ABI "adjustments" typically do more than just deducing parameter attributes. So if "unadjusted" just refers to the attributes, that's confusing naming. Also, having the full signature might be relevant for the UB checking that const-eval and Miri are doing. So it's at least slightly concerning that we shouldn't be able to access some of that info any more. What exactly is the difference between the signatures we obtain this way? |
|
Agreed—I'll rename to The only differences are in the attributes of indirectly-passed parameters, which will include |
|
Looking at #151748, it seems like the underlying issue is that fn_sig_of_instance looks at the body of the function. That is indeed somewhat sus -- at least all the UB-relevant information should be deducible without the body. Please extend the PR description to explain this; it currently takes a bit of digging to fiure out what problem you're actually solving. If we end up resolving this by splitting the query, it is very important that the queries have good documentation explaining their relationship. We want to avoid someone changing this code in the future in a way that removes too much information from the "unadjusted" signature. |
|
I've updated the PR description—hopefully it's now clearer? Re documentation, the "unadjusted" query (to be renamed
Happy to clarify it further if required. |
|
I've updated the documentation to:
@rustbot ready |
de839fc to
6a5ec89
Compare
This comment has been minimized.
This comment has been minimized.
`fn_abi_of_instance` can look at function bodies to deduce codegen optimization attributes (namely `ArgAttribute::ReadOnly` and `ArgAttribute::CapturesNone`) of indirectly-passed parameters. This can lead to cycles when performed during typeck, when such attributes are irrelevant. This patch breaks a subquery out from `fn_abi_of_instance`, `fn_abi_of_instance_no_deduced_attrs`, which returns the ABI before such parameter attributes are deduced; and that new subquery is used in CTFE instead.
6a5ec89 to
132a633
Compare
|
That name and PR description are much better, thank you! |
|
@bors try |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…tfe, r=<try> Do not deduce parameter attributes during CTFE
| /// to an `fn`. Indirectly-passed parameters in the returned ABI might not include all possible | ||
| /// codegen optimization attributes (such as `ReadOnly` or `CapturesNone`), as deducing these | ||
| /// requires inspection of function bodies that can lead to cycles when performed during typeck. | ||
| /// Post typeck, you should prefer the optimized ABI returned by `fn_abi_of_instance`. |
There was a problem hiding this comment.
| /// to an `fn`. Indirectly-passed parameters in the returned ABI might not include all possible | |
| /// codegen optimization attributes (such as `ReadOnly` or `CapturesNone`), as deducing these | |
| /// requires inspection of function bodies that can lead to cycles when performed during typeck. | |
| /// Post typeck, you should prefer the optimized ABI returned by `fn_abi_of_instance`. | |
| /// to an `fn`. This query does *not* look at the function body to deduce further | |
| /// attributes for function arguments as doing so can lead to cycles during typeck. | |
| /// Post typeck, you should prefer the optimized ABI returned by `fn_abi_of_instance`. |
Let's not list what exactly gets put into "deduced attrs" as that will inevitably expand in the future.
| /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for direct calls* | ||
| /// to an `fn`. Indirectly-passed parameters in the returned ABI will include applicable | ||
| /// codegen optimization attributes, including `ReadOnly` and `CapturesNone` -- deduction of | ||
| /// which requires inspection of function bodies that can lead to cycles when performed during | ||
| /// typeck. During typeck, you should therefore use instead the unoptimized ABI returned by | ||
| /// `fn_abi_of_instance_no_deduced_attrs`. |
There was a problem hiding this comment.
| /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for direct calls* | |
| /// to an `fn`. Indirectly-passed parameters in the returned ABI will include applicable | |
| /// codegen optimization attributes, including `ReadOnly` and `CapturesNone` -- deduction of | |
| /// which requires inspection of function bodies that can lead to cycles when performed during | |
| /// typeck. During typeck, you should therefore use instead the unoptimized ABI returned by | |
| /// `fn_abi_of_instance_no_deduced_attrs`. | |
| /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for direct calls* | |
| /// to an `fn`. This query looks at the function body to deduce further attributes, which | |
| /// can lead to cycles when performed during typeck. During typeck, you should therefore | |
| /// instead use `fn_abi_of_instance_no_deduced_attrs`. |
|
I gave some feedback on the comments. I have not looked at the actual code changes at all. |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (cbab83a): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 474.712s -> 472.121s (-0.55%) |
|
Error: Parsing assign command in comment failed: ...' reroll' | error: expected end of command at >| ', not quit'... Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
|
Re the performance regression, it's worth noting that these cycles currently lead to us rejecting valid programs such as can be seen in the linked issue, the simplest minimisation of which is included as a new UI test with this PR: rust/tests/ui/coroutine/avoid-query-cycle-in-ctfe.rs Lines 10 to 18 in 132a633 Accordingly I think a 0.4% mean instruction count regression in the primary suite might be acceptable in order not to continue rejecting such programs? But of course if there's a more performant solution, that would be preferable. @rustbot label: +perf-regression-triaged |
|
Since the previous command failed: @rustbot reroll |
|
This is a pretty broad regression, ISTM we should explore other ways of fixing this / ways to improve the performance of this before deciding to go with this approach. Cc @rust-lang/wg-compiler-performance |
|
r? RalfJung |
|
|
|
☔ The latest upstream changes (presumably #152089) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@rustbot author |
Ever since #103172 (cc @pcwalton),
fn_abi_of_instancemight look at a function's body to deduce certain codegen optimization attributes for its indirectly-passed parameters beyond what can be determined purely from its signature (namely todayArgAttribute::ReadOnlyandArgAttribute::CapturesNone). However, this can lead to cycles when performed during CTFE, despite such attributes being irrelevant to the evaluation result.This patch breaks a subquery out from
fn_abi_of_instance,fn_abi_of_instance_no_deduced_attrs, which returns the ABI before such parameter attributes are deduced; and that new subquery is used in CTFE instead.This is the correct fix that #151784 was (incorrectly) attempting to part-address.
Fixes #151748
r? jdonszelmann (as requested in the previous PR)