Skip to content

🔬 introduce a canonical query for evaluate_obligation #48537

Closed
@nikomatsakis

Description

@nikomatsakis

The evaluate_obligation method of SelectionContext has the job of determining whether a given predicate may hold:

/// Evaluates whether the obligation `obligation` can be satisfied (by any means).
pub fn evaluate_obligation(&mut self,
obligation: &PredicateObligation<'tcx>)
-> bool

Building on the work in #48411, this seems like a clean place to introduce a canonical trait query. The argument to this query would be canonicalized predicate, combined with an environment:

type CanonicalPredicateGoal<'tcx> = &'tcx Canonical<ParamEnvAnd<'tcx, Predicate<'tcx>>>

The query would be something like this:

[] fn evaluate_obligation(CanonicalPredicateGoal<'tcx>) -> traits::EvaluationResult

I expect this would follow the pattern introduced in #48411, where the query is not invoked directly by end-users. Rather, they invoke a wrapper method defined on the At type, like normalize here. This method would canonicalize and invoke the underlying query.

Note that I defined the query to return a EvaluationResult, where the current method returns a bool -- this would allow the same query to be shared for evaluate_obligation_conservatively. I suggest that we rename the infcx.at().foo() methods, actually, to be something like this:

  • infcx.at(...).predicate_may_hold(predicate) (what is today evaluate_obligation)
  • infcx.at(...).predicate_must_hold(predicate) (what is today evaluate_obligation_conservatively)

Both of these would return a boolean.

Anyway, I will try to write up more comprehensive guidelines in the rustc-guide describing the pattern for trait queries, and link to them from here.

If you are interesting in this task, please feel free to ping me on gitter for more info!

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-traitsWorking group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions