-
Notifications
You must be signed in to change notification settings - Fork 13.5k
GCI: Don't evaluate the initializer of free const items that have trivially unsatisfied predicates #142293
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
base: master
Are you sure you want to change the base?
Conversation
@bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
[early rough draft] GCI: Don't evaluate free const items with impossible predicates
This comment was marked as off-topic.
This comment was marked as off-topic.
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.
We should consider moving all of these call-site checks into ctfe itself, e.g. eval_to_const_value_raw_provider
. This wont affect const patterns which go through _for_typeck
versions of the CTFE entry points.
I also then think that the impossible predicates check in that place should ICE on predicates containing non region params as that shouldn't be reachable (and if it is, then we're evaluating generic constants in places we might not want to be).
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (4151b9a): comparison URL. Overall result: no relevant changes - no action neededBenchmarking 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. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -5.1%, secondary -2.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 753.145s -> 753.291s (0.02%) |
Cargo.lock
Outdated
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 also then think that the impossible predicates check in that place should ICE on predicates containing non region params as that shouldn't be reachable (and if it is, then we're evaluating generic constants in places we might not want to be).
Adding debug_assert!(!predicates.has_non_region_param());
to fn impossible_predicates
, lead to a whole slew of test failures (I didn't complete the test run). E.g.,
Some failing tests
tests/ui/associated-consts/associated-const-marks-live-code.rs
tests/ui/async-await/async-fn-size-moved-locals.rs
tests/ui/async-await/async-fn-size-uninit-locals.rs
tests/ui/async-await/repeat_count_const_in_async_fn.rs
tests/ui/binding/match-arm-statics.rs
tests/ui/const_prop/ice-issue-96944.rs
tests/ui/consts/const-autoderef.rs
tests/ui/consts/chained-constants-stackoverflow.rs
tests/ui/consts/const-blocks/const-repeat.rs
tests/ui/consts/const-const.rs
tests/ui/consts/const-enum-cast.rs
tests/ui/consts/const-eval/strlen.rs
tests/ui/consts/const-expr-in-fixed-length-vec.rs
tests/ui/consts/const-expr-in-vec-repeat.rs
tests/ui/consts/const-fn-method.rs
tests/ui/consts/const-trait-to-trait.rs
tests/ui/consts/ice-48279.rs
tests/ui/consts/min_const_fn/min_const_fn_libstd.rs
tests/ui/consts/offset_from.rs
tests/ui/consts/ptr_comparisons.rs
tests/ui/consts/ptr_is_null.rs
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.
We should consider moving all of these call-site checks into ctfe itself, e.g.
eval_to_const_value_raw_provider
. This wont affect const patterns which go through_for_typeck
versions of the CTFE entry points.
As discussed, long term, that would be the way to go. However, it makes me uncomfortable that eval_to_const_value_raw
has so many transitive callers which I wasn't yet able to audit entirely. I know that you told me that this function should be safe to modify from a soundness perspective and you're probably right, I just haven't finished tracing the entire caller graph. WIP:
Caller graph (X called by Y)
+ eval_to_const_value_raw [eval_to_const_value_raw_provider] (???)
+-- check_crate/par_hir_body_owners/DefKind::Const (OK)
+-- const_eval_global_id (???)
+-- eval_intrinsic (OK)
+-- const_eval_poly (OK)
| +-- codegen_global_asm (OK)
| +-- check_type_defn/variants/fields [default_field_values] (OK)
| +-- check_type_defn/ty::VariantDiscr::Explicit (OK)
| +-- eval_explicit_discr (OK)
| +-- monomorphize/RootCollector/process_item/DefKind::Const (OK)
+-- const_eval_resolve (???)
| +-- Const::eval (???)
| +-- eval_mir_constant (???)
| | +... [~20 call sites] (TODO)
| +-- inline_to_global_operand/InlineAsmOperand::Const (OK)
| +-- push_stack_frame_raw/body.required_consts() (???)
| +-- try_eval_scalar... (TODO)
| +-- MIR transform/simplify_repeated_aggregate (???)
| +-- eval_constant (???)
| +-- eval_operand... (TODO)
| +-- MIR transform/ConstPropagator/visit_const_operand (???)
| +-- collect_items_of_instance/body.requires_consts() (???)
+-- const_eval_instance (???)
+-- codegen_regular_intrinsic_call (OK)
+-- codegen_intrinsic_call (OK)
+-- eval_instance (???)
+-- try_const_eval [SMIR] (???)
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.
(As an aside, even if we enriched eval_to_const_value_raw_provider
with a call to impossible_predicates
, here in mod reachable
it would be of no use to us as it uses const_eval_poly_to_alloc
which doesn't depend on that function)
498b2e2
to
380088d
Compare
Mono collector now uses Despite that, imma recheck perf cuz I removed the |
This comment has been minimized.
This comment has been minimized.
[early rough draft] GCI: Don't evaluate free const items with impossible predicates
if !self.tcx.generics_of(def_id).own_requires_monomorphization() | ||
&& !self.tcx.instantiate_and_check_impossible_predicates(( | ||
def_id, | ||
ty::GenericArgs::identity_for_item(self.tcx, def_id), |
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 should probably just copy the logic from DefKind::Enum/Struct/Union
for checking impossible preds and constructing identity args
let predicates = tcx.predicates_of(item_def_id); | ||
let predicates = predicates.instantiate_identity(tcx).predicates; | ||
|
||
// FIXME(fmease): May its result be 'incorrect' if the preds have ReEarlyBound? |
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.
Yeah I think you should be able to construct a case where an impossible pred isnt found due to a lifetime parameter. E.g. const _: usize where for<'b> [&'a u8]: Sized = ...
probably will get evaluated unless you erase regions
|
||
// FIXME(fmease): May its result be 'incorrect' if the preds have ReEarlyBound? | ||
if !traits::impossible_predicates(tcx, predicates) { | ||
// FIXME(generic_const_items): Passing empty instead of identity args is fishy but |
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 should be fixed yeah 🤔 I don't think ctfe should have to handle there being instances with wrong args
Finished benchmarking commit (10bc814): 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 (secondary -2.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -4.4%)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: 690.402s -> 688.347s (-0.30%) |
380088d
to
0e9126c
Compare
@bors2 try parent=last @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
GCI: Don't evaluate the initializer of free const items that have trivially unsatisfied predicates
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (cea506b): 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 2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -3.6%)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: 690.402s -> 687.107s (-0.48%) |
This comment was marked as resolved.
This comment was marked as resolved.
0e9126c
to
8d3bc94
Compare
PR #142893 (which conflicted with this PR / made it unmergeable) heavily affected perf. Thus I'm now retrying if this PR is still sensitive. @bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
GCI: Don't evaluate the initializer of free const items that have trivially unsatisfied predicates Part of #113521.
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (41283df): comparison URL. Overall result: no relevant changes - no action neededBenchmarking 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. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -1.5%, secondary 8.2%)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: 462.452s -> 460.902s (-0.34%) |
Part of #113521.