Skip to content

Commit 2660d5d

Browse files
authored
Rollup merge of rust-lang#113987 - compiler-errors:comments, r=lcnr
Comment stuff in the new solver r? `@lcnr`
2 parents 15c7234 + 3ad3bb6 commit 2660d5d

File tree

8 files changed

+64
-16
lines changed

8 files changed

+64
-16
lines changed

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
//! Implements the `AliasRelate` goal, which is used when unifying aliases.
2+
//! Doing this via a separate goal is called "deferred alias relation" and part
3+
//! of our more general approach to "lazy normalization".
4+
//!
5+
//! This goal, e.g. `A alias-relate B`, may be satisfied by one of three branches:
6+
//! * normalizes-to: If `A` is a projection, we can prove the equivalent
7+
//! projection predicate with B as the right-hand side of the projection.
8+
//! This goal is computed in both directions, if both are aliases.
9+
//! * subst-relate: Equate `A` and `B` by their substs, if they're both
10+
//! aliases with the same def-id.
11+
//! * bidirectional-normalizes-to: If `A` and `B` are both projections, and both
12+
//! may apply, then we can compute the "intersection" of both normalizes-to by
13+
//! performing them together. This is used specifically to resolve ambiguities.
114
use super::{EvalCtxt, SolverMode};
215
use rustc_infer::traits::query::NoSolution;
316
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
@@ -118,6 +131,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
118131
})
119132
}
120133

134+
// Computes the normalizes-to branch, with side-effects. This must be performed
135+
// in a probe in order to not taint the evaluation context.
121136
fn normalizes_to_inner(
122137
&mut self,
123138
param_env: ty::ParamEnv<'tcx>,
@@ -127,9 +142,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
127142
invert: Invert,
128143
) -> Result<(), NoSolution> {
129144
let other = match direction {
130-
// This is purely an optimization.
145+
// This is purely an optimization. No need to instantiate a new
146+
// infer var and equate the RHS to it.
131147
ty::AliasRelationDirection::Equate => other,
132148

149+
// Instantiate an infer var and subtype our RHS to it, so that we
150+
// properly represent a subtype relation between the LHS and RHS
151+
// of the goal.
133152
ty::AliasRelationDirection::Subtype => {
134153
let fresh = self.next_term_infer_of_kind(other);
135154
let (sub, sup) = match invert {

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Code which is used by built-in goals that match "structurally", such a auto
2+
//! traits, `Copy`/`Clone`.
13
use rustc_data_structures::fx::FxHashMap;
24
use rustc_hir::{def_id::DefId, Movability, Mutability};
35
use rustc_infer::traits::query::NoSolution;

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/// Canonicalization is used to separate some goal from its context,
2-
/// throwing away unnecessary information in the process.
3-
///
4-
/// This is necessary to cache goals containing inference variables
5-
/// and placeholders without restricting them to the current `InferCtxt`.
6-
///
7-
/// Canonicalization is fairly involved, for more details see the relevant
8-
/// section of the [rustc-dev-guide][c].
9-
///
10-
/// [c]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html
1+
//! Canonicalization is used to separate some goal from its context,
2+
//! throwing away unnecessary information in the process.
3+
//!
4+
//! This is necessary to cache goals containing inference variables
5+
//! and placeholders without restricting them to the current `InferCtxt`.
6+
//!
7+
//! Canonicalization is fairly involved, for more details see the relevant
8+
//! section of the [rustc-dev-guide][c].
9+
//!
10+
//! [c]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html
1111
use super::{CanonicalInput, Certainty, EvalCtxt, Goal};
1212
use crate::solve::canonicalize::{CanonicalizeMode, Canonicalizer};
1313
use crate::solve::{CanonicalResponse, QueryResult, Response};
@@ -135,6 +135,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
135135
)
136136
}
137137

138+
/// Computes the region constraints and *new* opaque types registered when
139+
/// proving a goal.
140+
///
141+
/// If an opaque was already constrained before proving this goal, then the
142+
/// external constraints do not need to record that opaque, since if it is
143+
/// further constrained by inference, that will be passed back in the var
144+
/// values.
138145
#[instrument(level = "debug", skip(self), ret)]
139146
fn compute_external_query_constraints(&self) -> Result<ExternalConstraints<'tcx>, NoSolution> {
140147
// We only check for leaks from universes which were entered inside

compiler/rustc_trait_selection/src/solve/inherent_projection.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Computes a normalizes-to (projection) goal for inherent associated types,
2+
//! `#![feature(inherent_associated_type)]`. Since astconv already determines
3+
//! which impl the IAT is being projected from, we just:
4+
//! 1. instantiate substs,
5+
//! 2. equate the self type, and
6+
//! 3. instantiate and register where clauses.
17
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
28
use rustc_middle::ty;
39

compiler/rustc_trait_selection/src/solve/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
//! The new trait solver, currently still WIP.
1+
//! The next-generation trait solver, currently still WIP.
22
//!
3-
//! As a user of the trait system, you can use `TyCtxt::evaluate_goal` to
4-
//! interact with this solver.
3+
//! As a user of rust, you can use `-Ztrait-solver=next` or `next-coherence`
4+
//! to enable the new trait solver always, or just within coherence, respectively.
5+
//!
6+
//! As a developer of rustc, you shouldn't be using the new trait
7+
//! solver without asking the trait-system-refactor-initiative, but it can
8+
//! be enabled with `InferCtxtBuilder::with_next_trait_solver`. This will
9+
//! ensure that trait solving using that inference context will be routed
10+
//! to the new trait solver.
511
//!
612
//! For a high-level overview of how this solver works, check out the relevant
713
//! section of the rustc-dev-guide.
814
//!
915
//! FIXME(@lcnr): Write that section. If you read this before then ask me
1016
//! about it on zulip.
11-
1217
use rustc_hir::def_id::DefId;
1318
use rustc_infer::infer::canonical::{Canonical, CanonicalVarValues};
1419
use rustc_infer::traits::query::NoSolution;

compiler/rustc_trait_selection/src/solve/normalize.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub(crate) fn deeply_normalize<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
2828
/// its input to be already fully resolved.
2929
///
3030
/// Additionally takes a list of universes which represents the binders which have been
31-
/// entered before passing `value` to the function.
31+
/// entered before passing `value` to the function. This is currently needed for
32+
/// `normalize_erasing_regions`, which skips binders as it walks through a type.
3233
pub(crate) fn deeply_normalize_with_skipped_universes<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
3334
at: At<'_, 'tcx>,
3435
value: T,

compiler/rustc_trait_selection/src/solve/opaques.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Computes a normalizes-to (projection) goal for opaque types. This goal
2+
//! behaves differently depending on the param-env's reveal mode and whether
3+
//! the opaque is in a defining scope.
14
use rustc_middle::traits::query::NoSolution;
25
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
36
use rustc_middle::traits::Reveal;

compiler/rustc_trait_selection/src/solve/weak_types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! Computes a normalizes-to (projection) goal for inherent associated types,
2+
//! `#![feature(lazy_type_alias)]` and `#![feature(type_alias_impl_trait)]`.
3+
//!
4+
//! Since a weak alias is not ambiguous, this just computes the `type_of` of
5+
//! the alias and registers the where-clauses of the type alias.
16
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
27
use rustc_middle::ty;
38

0 commit comments

Comments
 (0)