Skip to content

Commit

Permalink
Unrolled build for rust-lang#127386
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#127386 - compiler-errors:uplift-outlives-components, r=lcnr

Uplift outlives components to `rustc_type_ir`

We need this to uplift `push_outlives_components`, since the elaborator uses `push_outlives_components` to elaborate type outlives obligations and I want to uplift elaboration.

This ends up reworking and inlining a fair portion of the `GenericArg::walk_shallow` function, whose only callsite was this one. I believe I got the logic correct, but may be worthwhile to look at it closely just in case. Unfortunately github was too dumb to understand that this is a rename + change -- I could also rework the git history to split the "copy the file over" part from the actual logical changes if that makes this easier to review.

r? lcnr
  • Loading branch information
rust-timer authored Jul 6, 2024
2 parents 8a8ad34 + c2a88ea commit 5e217c4
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 306 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
use rustc_middle::ty::{self, Region, Ty, TyCtxt};
use rustc_middle::ty::{GenericArg, GenericArgKind};
use rustc_middle::{bug, span_bug};
use rustc_span::Span;
use rustc_type_ir::outlives::{push_outlives_components, Component};
use smallvec::smallvec;

/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred
Expand Down
266 changes: 0 additions & 266 deletions compiler/rustc_infer/src/infer/outlives/components.rs

This file was deleted.

1 change: 0 additions & 1 deletion compiler/rustc_infer/src/infer/outlives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::infer::lexical_region_resolve;
use rustc_middle::traits::query::{NoSolution, OutlivesBound};
use rustc_middle::ty;

pub mod components;
pub mod env;
pub mod for_liveness;
pub mod obligations;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
//! might later infer `?U` to something like `&'b u32`, which would
//! imply that `'b: 'a`.
use crate::infer::outlives::components::{push_outlives_components, Component};
use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::outlives::verify::VerifyBoundCx;
use crate::infer::resolve::OpportunisticRegionResolver;
Expand All @@ -75,6 +74,7 @@ use rustc_middle::ty::{
};
use rustc_middle::ty::{GenericArgKind, PolyTypeOutlivesPredicate};
use rustc_span::DUMMY_SP;
use rustc_type_ir::outlives::{push_outlives_components, Component};
use smallvec::smallvec;

use super::env::OutlivesEnvironment;
Expand Down Expand Up @@ -291,7 +291,7 @@ where
fn components_must_outlive(
&mut self,
origin: infer::SubregionOrigin<'tcx>,
components: &[Component<'tcx>],
components: &[Component<TyCtxt<'tcx>>],
region: ty::Region<'tcx>,
category: ConstraintCategory<'tcx>,
) {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::infer::outlives::components::{compute_alias_components_recursive, Component};
use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::region_constraints::VerifyIfEq;
use crate::infer::{GenericKind, VerifyBound};
use rustc_data_structures::sso::SsoHashSet;
use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
use rustc_type_ir::outlives::{compute_alias_components_recursive, Component};

use smallvec::smallvec;

Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {

fn bound_from_components(
&self,
components: &[Component<'tcx>],
components: &[Component<TyCtxt<'tcx>>],
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
let mut bounds = components
Expand All @@ -158,7 +158,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {

fn bound_from_single_component(
&self,
component: &Component<'tcx>,
component: &Component<TyCtxt<'tcx>>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
match *component {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/traits/util.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use smallvec::smallvec;

use crate::infer::outlives::components::{push_outlives_components, Component};
use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation};
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::ty::ToPolyTraitRef;
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
use rustc_span::symbol::Ident;
use rustc_span::Span;
use rustc_type_ir::outlives::{push_outlives_components, Component};

pub fn anonymize_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/consts/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ pub struct Expr<'tcx> {
pub kind: ExprKind,
args: ty::GenericArgsRef<'tcx>,
}

impl<'tcx> rustc_type_ir::inherent::ExprConst<TyCtxt<'tcx>> for Expr<'tcx> {
fn args(self) -> ty::GenericArgsRef<'tcx> {
self.args
}
}

impl<'tcx> Expr<'tcx> {
pub fn new_binop(
tcx: TyCtxt<'tcx>,
Expand Down
17 changes: 0 additions & 17 deletions compiler/rustc_middle/src/ty/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,6 @@ impl<'tcx> GenericArg<'tcx> {
pub fn walk(self) -> TypeWalker<'tcx> {
TypeWalker::new(self)
}

/// Iterator that walks the immediate children of `self`. Hence
/// `Foo<Bar<i32>, u32>` yields the sequence `[Bar<i32>, u32]`
/// (but not `i32`, like `walk`).
///
/// Iterator only walks items once.
/// It accepts visited set, updates it with all visited types
/// and skips any types that are already there.
pub fn walk_shallow(
self,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> impl Iterator<Item = GenericArg<'tcx>> {
let mut stack = SmallVec::new();
push_inner(&mut stack, self);
stack.retain(|a| visited.insert(*a));
stack.into_iter()
}
}

impl<'tcx> Ty<'tcx> {
Expand Down
Loading

0 comments on commit 5e217c4

Please sign in to comment.