Skip to content

Commit

Permalink
Auto merge of #124961 - matthiaskrgr:rollup-1jj65p6, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #124551 (Add benchmarks for `impl Debug for str`)
 - #124915 (`rustc_target` cleanups)
 - #124918 (Eliminate some `FIXME(lcnr)` comments)
 - #124927 (opt-dist: use xz2 instead of xz crate)
 - #124936 (analyse visitor: build proof tree in probe)
 - #124943 (always use `GenericArgsRef`)
 - #124955 (Use fewer origins when creating type variables.)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 10, 2024
2 parents 98dabb6 + 0ee2580 commit f7b1501
Show file tree
Hide file tree
Showing 66 changed files with 359 additions and 460 deletions.
11 changes: 1 addition & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,7 @@ dependencies = [
"tabled",
"tar",
"tempfile",
"xz",
"xz2",
"zip",
]

Expand Down Expand Up @@ -6586,15 +6586,6 @@ dependencies = [
"rustix",
]

[[package]]
name = "xz"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c887690ff2a2e233e8e49633461521f98ec57fbff9d59a884c9a4f04ec1da34"
dependencies = [
"xz2",
]

[[package]]
name = "xz2"
version = "0.1.7"
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ pub fn renumber_mir<'tcx>(
renumberer.visit_body(body);
}

// FIXME(@lcnr): A lot of these variants overlap and it seems like
// this type is only used to decide which region should be used
// as representative. This should be cleaned up.
// The fields are used only for debugging output in `sccs_info`.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub(crate) enum RegionCtxt {
Location(Location),
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::assert_matches::assert_matches;

use itertools::Itertools;
use rustc_hir as hir;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin};
use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty};
Expand Down Expand Up @@ -74,9 +73,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}),
);

let next_ty_var = || {
self.infcx.next_ty_var(TypeVariableOrigin { span: body.span, param_def_id: None })
};
let next_ty_var = || self.infcx.next_ty_var(body.span);
let output_ty = Ty::new_coroutine(
self.tcx(),
self.tcx().coroutine_for_closure(mir_def_id),
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use rustc_index::{IndexSlice, IndexVec};
use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::region_constraints::RegionConstraintData;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::{
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
};
Expand Down Expand Up @@ -2356,10 +2355,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Types with regions are comparable if they have a common super-type.
ty::RawPtr(_, _) | ty::FnPtr(_) => {
let ty_right = right.ty(body, tcx);
let common_ty = self.infcx.next_ty_var(TypeVariableOrigin {
param_def_id: None,
span: body.source_info(location).span,
});
let common_ty = self.infcx.next_ty_var(body.source_info(location).span);
self.sub_types(
ty_left,
common_ty,
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_infer::infer::{ObligationEmittingRelation, StructurallyRelateAliases};
use rustc_infer::traits::{Obligation, PredicateObligations};
Expand Down Expand Up @@ -129,10 +128,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
// by using `ty_vid rel B` and then finally and end by equating `ty_vid` to
// the opaque.
let mut enable_subtyping = |ty, opaque_is_expected| {
let ty_vid = infcx.next_ty_var_id_in_universe(
TypeVariableOrigin { param_def_id: None, span: self.span() },
ty::UniverseIndex::ROOT,
);
let ty_vid = infcx.next_ty_var_id_in_universe(self.span(), ty::UniverseIndex::ROOT);

let variance = if opaque_is_expected {
self.ambient_variance
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit;
use rustc_hir::{GenericParamKind, ImplItemKind};
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::{util, FulfillmentError};
use rustc_middle::ty::error::{ExpectedFound, TypeError};
Expand Down Expand Up @@ -800,10 +799,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
bug!("FIXME(RPITIT): error here");
}
// Replace with infer var
let infer_ty = self
.ocx
.infcx
.next_ty_var(TypeVariableOrigin { span: self.span, param_def_id: None });
let infer_ty = self.ocx.infcx.next_ty_var(self.span);
self.types.insert(proj.def_id, (infer_ty, proj.args));
// Recurse into bounds
for (pred, pred_span) in self
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::{self as hir, ExprKind, PatKind};
use rustc_hir_pretty::ty_to_string;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_middle::ty::{self, Ty};
use rustc_span::Span;
use rustc_trait_selection::traits::{
Expand Down Expand Up @@ -67,7 +66,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// arm for inconsistent arms or to the whole match when a `()` type
// is required).
Expectation::ExpectHasType(ety) if ety != tcx.types.unit => ety,
_ => self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr.span }),
_ => self.next_ty_var(expr.span),
};
CoerceMany::with_coercion_sites(coerce_first, arms)
};
Expand Down Expand Up @@ -575,8 +574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ...but otherwise we want to use any supertype of the
// scrutinee. This is sort of a workaround, see note (*) in
// `check_pat` for some details.
let scrut_ty =
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: scrut.span });
let scrut_ty = self.next_ty_var(scrut.span);
self.check_expr_has_type_or_error(scrut, scrut_ty, |_| {});
scrut_ty
}
Expand Down
16 changes: 4 additions & 12 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use rustc_hir::def_id::DefId;
use rustc_hir_analysis::autoderef::Autoderef;
use rustc_infer::{
infer,
traits::{self, Obligation},
traits::{self, Obligation, ObligationCause},
};
use rustc_infer::{infer::type_variable::TypeVariableOrigin, traits::ObligationCause};
use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
};
Expand Down Expand Up @@ -180,14 +179,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
infer::FnCall,
closure_args.coroutine_closure_sig(),
);
let tupled_upvars_ty = self
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: callee_expr.span });
let tupled_upvars_ty = self.next_ty_var(callee_expr.span);
// We may actually receive a coroutine back whose kind is different
// from the closure that this dispatched from. This is because when
// we have no captures, we automatically implement `FnOnce`. This
// impl forces the closure kind to `FnOnce` i.e. `u8`.
let kind_ty = self
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: callee_expr.span });
let kind_ty = self.next_ty_var(callee_expr.span);
let call_sig = self.tcx.mk_fn_sig(
[coroutine_closure_sig.tupled_inputs_ty],
coroutine_closure_sig.to_coroutine(
Expand Down Expand Up @@ -298,12 +295,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let Some(trait_def_id) = opt_trait_def_id else { continue };

let opt_input_type = opt_arg_exprs.map(|arg_exprs| {
Ty::new_tup_from_iter(
self.tcx,
arg_exprs.iter().map(|e| {
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: e.span })
}),
)
Ty::new_tup_from_iter(self.tcx, arg_exprs.iter().map(|e| self.next_ty_var(e.span)))
});

if let Some(ok) = self.lookup_method_in_trait(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use rustc_hir::def::DefKind;
use rustc_hir::intravisit::Visitor;
use rustc_hir::lang_items::LangItem;
use rustc_hir_analysis::check::{check_function_signature, forbid_intrinsic_abi};
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::RegionVariableOrigin;
use rustc_infer::traits::WellFormedLoc;
use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
Expand Down Expand Up @@ -142,7 +141,7 @@ pub(super) fn check_fn<'a, 'tcx>(
// We have special-cased the case where the function is declared
// `-> dyn Foo` and we don't actually relate it to the
// `fcx.ret_coercion`, so just instantiate a type variable.
actual_return_ty = fcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span });
actual_return_ty = fcx.next_ty_var(span);
debug!("actual_return_ty replaced with {:?}", actual_return_ty);
}

Expand Down
43 changes: 12 additions & 31 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
use rustc_infer::infer::{InferOk, InferResult};
use rustc_macros::{TypeFoldable, TypeVisitable};
Expand Down Expand Up @@ -73,8 +72,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let parent_args =
GenericArgs::identity_for_item(tcx, tcx.typeck_root_def_id(expr_def_id.to_def_id()));

let tupled_upvars_ty =
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
let tupled_upvars_ty = self.next_ty_var(expr_span);

// FIXME: We could probably actually just unify this further --
// instead of having a `FnSig` and a `Option<CoroutineTypes>`,
Expand All @@ -101,9 +99,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Create a type variable (for now) to represent the closure kind.
// It will be unified during the upvar inference phase (`upvar.rs`)
None => {
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
}
None => self.next_ty_var(expr_span),
};

let closure_args = ty::ClosureArgs::new(
Expand All @@ -122,10 +118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let yield_ty = match kind {
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
| hir::CoroutineKind::Coroutine(_) => {
let yield_ty = self.next_ty_var(TypeVariableOrigin {
param_def_id: None,
span: expr_span,
});
let yield_ty = self.next_ty_var(expr_span);
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
yield_ty
}
Expand All @@ -134,10 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// in this block in projection correctly. In the new trait solver, it is
// not a problem.
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
let yield_ty = self.next_ty_var(TypeVariableOrigin {
param_def_id: None,
span: expr_span,
});
let yield_ty = self.next_ty_var(expr_span);
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);

Ty::new_adt(
Expand All @@ -163,8 +153,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Resume type defaults to `()` if the coroutine has no argument.
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);

let interior =
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
let interior = self.next_ty_var(expr_span);
self.deferred_coroutine_interiors.borrow_mut().push((
expr_def_id,
body.id(),
Expand All @@ -177,7 +166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ty of `().`
let kind_ty = match kind {
hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) => {
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
self.next_ty_var(expr_span)
}
_ => tcx.types.unit,
};
Expand Down Expand Up @@ -212,23 +201,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};
// Compute all of the variables that will be used to populate the coroutine.
let resume_ty =
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
let interior =
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
let resume_ty = self.next_ty_var(expr_span);
let interior = self.next_ty_var(expr_span);

let closure_kind_ty = match expected_kind {
Some(kind) => Ty::from_closure_kind(tcx, kind),

// Create a type variable (for now) to represent the closure kind.
// It will be unified during the upvar inference phase (`upvar.rs`)
None => {
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
}
None => self.next_ty_var(expr_span),
};

let coroutine_captures_by_ref_ty =
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
let coroutine_captures_by_ref_ty = self.next_ty_var(expr_span);
let closure_args = ty::CoroutineClosureArgs::new(
tcx,
ty::CoroutineClosureArgsParts {
Expand Down Expand Up @@ -260,13 +244,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Create a type variable (for now) to represent the closure kind.
// It will be unified during the upvar inference phase (`upvar.rs`)
None => {
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
}
None => self.next_ty_var(expr_span),
};

let coroutine_upvars_ty =
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
let coroutine_upvars_ty = self.next_ty_var(expr_span);

// We need to turn the liberated signature that we got from HIR, which
// looks something like `|Args...| -> T`, into a signature that is suitable
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
use rustc_infer::traits::{IfExpressionCause, MatchExpressionArmCause};
use rustc_infer::traits::{Obligation, PredicateObligation};
Expand Down Expand Up @@ -257,11 +256,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {

if b.is_ty_var() {
// Two unresolved type variables: create a `Coerce` predicate.
let target_ty = if self.use_lub {
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.cause.span })
} else {
b
};
let target_ty = if self.use_lub { self.next_ty_var(self.cause.span) } else { b };

let mut obligations = Vec::with_capacity(2);
for &source_ty in &[a, b] {
Expand Down Expand Up @@ -557,8 +552,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// the `CoerceUnsized` target type and the expected type.
// We only have the latter, so we use an inference variable
// for the former and let type inference do the rest.
let origin = TypeVariableOrigin { param_def_id: None, span: self.cause.span };
let coerce_target = self.next_ty_var(origin);
let coerce_target = self.next_ty_var(self.cause.span);
let mut coercion = self.unify_and(coerce_target, target, |target| {
let unsize = Adjustment { kind: Adjust::Pointer(PointerCoercion::Unsize), target };
match reborrow {
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir.body(hir.maybe_body_owned_by(self.body_id).expect("expected item to have body"));
expr_finder.visit_expr(body.value);

use rustc_infer::infer::type_variable::*;
use rustc_middle::infer::unify_key::*;
// Replaces all of the variables in the given type with a fresh inference variable.
let mut fudger = BottomUpFolder {
tcx: self.tcx,
ty_op: |ty| {
if let ty::Infer(infer) = ty.kind() {
match infer {
ty::TyVar(_) => self
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: DUMMY_SP }),
ty::TyVar(_) => self.next_ty_var(DUMMY_SP),
ty::IntVar(_) => self.next_int_var(),
ty::FloatVar(_) => self.next_float_var(),
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {
Expand All @@ -353,10 +350,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
lt_op: |_| self.tcx.lifetimes.re_erased,
ct_op: |ct| {
if let ty::ConstKind::Infer(_) = ct.kind() {
self.next_const_var(
ct.ty(),
ConstVariableOrigin { param_def_id: None, span: DUMMY_SP },
)
self.next_const_var(ct.ty(), DUMMY_SP)
} else {
ct
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_typeck/src/expectation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_middle::ty::{self, Ty};
use rustc_span::Span;

Expand Down Expand Up @@ -110,7 +109,6 @@ impl<'a, 'tcx> Expectation<'tcx> {
/// Like `only_has_type`, but instead of returning `None` if no
/// hard constraint exists, creates a fresh type variable.
pub(super) fn coercion_target_type(self, fcx: &FnCtxt<'a, 'tcx>, span: Span) -> Ty<'tcx> {
self.only_has_type(fcx)
.unwrap_or_else(|| fcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span }))
self.only_has_type(fcx).unwrap_or_else(|| fcx.next_ty_var(span))
}
}
Loading

0 comments on commit f7b1501

Please sign in to comment.