-
Notifications
You must be signed in to change notification settings - Fork 13.5k
evaluate_goal
avoid unnecessary step
#142774
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
This comment has been minimized.
This comment has been minimized.
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
); | ||
canonical_goal_evaluation.query_result(canonical_response); | ||
goal_evaluation.canonical_goal_evaluation(canonical_goal_evaluation); |
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.
hmm, now that I understand the various new_foo
/foo
APIs on ProofTreeBuilder
I have questions 😆
- could these be one function taking a closure and thus being more of a transaction? The current use cases seem to say so, but I'm guessing there will be more uses and you want to keep a more general API?
- some doc comments would have helped (at least linking functions together that belong together)
- some functions take
&mut self
but do not need it canonical_goal_evalution
mutatingself
seems surprising. I would have expected something withapply
orfinish
in the name
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.
could these be one function taking a closure and thus being more of a transaction? The current use cases seem to say so, but I'm guessing there will be more uses and you want to keep a more general API?
this concrete case yes, ignoring the issue of this potentially being a perf hit 🤔 I think it should be fine... I personally feel slightly iffy about having proof tree stuff be "in control of the control flow", but expect that using closures hare is easier to read
some functions take &mut self but do not need it
unsurprising :3
canonical_goal_evalution
mutatingself
seems surprising. I would have expected something withapply
orfinish
in the name
I agree, ideally we just have WipGoalEvaluation
be the Root
and not have a separate root state.
Mind pushing these cleanups until after #142735/to not do them in this PR? I am changing the control flow inside of the search graph and don't fully know how this will impact stuff.
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.
Absolutely. I just wanted to understand things xD
let response = match canonical_result { | ||
Err(e) => return Err(e), | ||
Ok(response) => response, | ||
}; |
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.
let response = match canonical_result { | |
Err(e) => return Err(e), | |
Ok(response) => response, | |
}; | |
let response = canonical_result? |
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.
considered it, i actually kinda feel like explicitly matching is better than using ?
on a local 🤔 but fine to apply this if u think it's significantly better :3
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 do think it is, but I understand verbosity as a signal that something unusual is going on can be useful. I just see this getting changed as a drive by in the future without a comment, and if you add a comment to the one liner you have as much signal as the expanded version
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.
r=me once base PR lands
This comment has been minimized.
This comment has been minimized.
@bors2 try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
`evaluate_goal` avoid unnecessary step based on #142617. This does not mess with the debug logging for the trait solver and is a very nice cleanup for #142735. E.g. for ```rust #[derive(Clone)] struct Wrapper<T>(T); #[derive(Clone)] struct Nested; // using a separate type to avoid the fast paths fn is_clone<T: Clone>() {} fn main() { is_clone::<Wrapper<Nested>>(); } ``` We get the following proof tree with `RUSTC_LOG=rustc_type_ir::search_graph=debug,rustc_next_trait_solver=debug` ``` rustc_next_trait_solver::solve::eval_ctxt::evaluate_root_goal goal=Goal { param_env: ParamEnv { caller_bounds: [] }, predicate: Binder { value: TraitPredicate(<Wrapper<Nested> as std::clone::Clone>, polarity:Positive), bound_vars: [] } }, generate_proof_tree=No, span=src/main.rs:7:5: 7:34 (#0), stalled_on=None rustc_type_ir::search_graph::evaluate_goal input=CanonicalQueryInput { canonical: Canonical { value: QueryInput { goal: Goal { param_env: ParamEnv { caller_bounds: [] }, predicate: Binder { value: TraitPredicate(<Wrapper<Nested> as std::clone::Clone>, polarity:Positive), bound_vars: [] } }, predefined_opaques_in_body: PredefinedOpaques(PredefinedOpaquesData { opaque_types: [] }) }, max_universe: U0, variables: [] }, typing_mode: Analysis { defining_opaque_types_and_generators: [] } }, step_kind_from_parent=Unknown rustc_next_trait_solver::solve::eval_ctxt::probe::enter source=Impl(DefId(0:10 ~ main[21d2]::{impl#0})) rustc_next_trait_solver::solve::eval_ctxt::add_goal source=ImplWhereBound, goal=Goal { param_env: ParamEnv { caller_bounds: [] }, predicate: Binder { value: TraitPredicate(<_ as std::marker::Sized>, polarity:Positive), bound_vars: [] } } rustc_next_trait_solver::solve::eval_ctxt::add_goal source=ImplWhereBound, goal=Goal { param_env: ParamEnv { caller_bounds: [] }, predicate: Binder { value: TraitPredicate(<_ as std::clone::Clone>, polarity:Positive), bound_vars: [] } } rustc_type_ir::search_graph::evaluate_goal input=CanonicalQueryInput { canonical: Canonical { value: QueryInput { goal: Goal { param_env: ParamEnv { caller_bounds: [] }, predicate: Binder { value: TraitPredicate(<Nested as std::clone::Clone>, polarity:Positive), bound_vars: [] } }, predefined_opaques_in_body: PredefinedOpaques(PredefinedOpaquesData { opaque_types: [] }) }, max_universe: U0, variables: [] }, typing_mode: Analysis { defining_opaque_types_and_generators: [] } }, step_kind_from_parent=Unknown 0ms DEBUG rustc_type_ir::search_graph global cache hit, required_depth=0 0ms DEBUG rustc_type_ir::search_graph return=Ok(Canonical { value: Response { certainty: Yes, var_values: CanonicalVarValues { var_values: [] }, external_constraints: ExternalConstraints(ExternalConstraintsData { region_constraints: [], opaque_types: [], normalization_nested_goals: NestedNormalizationGoals([]) }) }, max_universe: U0, variables: [] }) rustc_next_trait_solver::solve::eval_ctxt::probe::enter source=BuiltinImpl(Misc) rustc_next_trait_solver::solve::trait_goals::merge_trait_candidates candidates=[Candidate { source: Impl(DefId(0:10 ~ main[21d2]::{impl#0})), result: Canonical { value: Response { certainty: Yes, var_values: CanonicalVarValues { var_values: [] }, external_constraints: ExternalConstraints(ExternalConstraintsData { region_constraints: [], opaque_types: [], normalization_nested_goals: NestedNormalizationGoals([]) }) }, max_universe: U0, variables: [] } }] 0ms DEBUG rustc_next_trait_solver::solve::trait_goals return=Ok((Canonical { value: Response { certainty: Yes, var_values: CanonicalVarValues { var_values: [] }, external_constraints: ExternalConstraints(ExternalConstraintsData { region_constraints: [], opaque_types: [], normalization_nested_goals: NestedNormalizationGoals([]) }) }, max_universe: U0, variables: [] }, Some(Misc))) 0ms DEBUG rustc_type_ir::search_graph insert global cache, evaluation_result=EvaluationResult { encountered_overflow: false, required_depth: 1, heads: CycleHeads { heads: {} }, nested_goals: NestedGoals { nested_goals: {} }, result: Ok(Canonical { value: Response { certainty: Yes, var_values: CanonicalVarValues { var_values: [] }, external_constraints: ExternalConstraints(ExternalConstraintsData { region_constraints: [], opaque_types: [], normalization_nested_goals: NestedNormalizationGoals([]) }) }, max_universe: U0, variables: [] }) } 0ms DEBUG rustc_type_ir::search_graph return=Ok(Canonical { value: Response { certainty: Yes, var_values: CanonicalVarValues { var_values: [] }, external_constraints: ExternalConstraints(ExternalConstraintsData { region_constraints: [], opaque_types: [], normalization_nested_goals: NestedNormalizationGoals([]) }) }, max_universe: U0, variables: [] }) ```
Queued 9101c8e with parent 22be76b, future comparison URL. |
based on #142617.
This does not mess with the debug logging for the trait solver and is a very nice cleanup for #142735. E.g. for
We get the following proof tree with
RUSTC_LOG=rustc_type_ir::search_graph=debug,rustc_next_trait_solver=debug