Skip to content

Commit 0724573

Browse files
Move a few more types to rustc_type_ir
1 parent 5e91c4e commit 0724573

File tree

9 files changed

+426
-265
lines changed

9 files changed

+426
-265
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4314,6 +4314,7 @@ dependencies = [
43144314
"bitflags",
43154315
"rustc_data_structures",
43164316
"rustc_index",
4317+
"rustc_macros",
43174318
"rustc_serialize",
43184319
]
43194320

compiler/rustc_middle/src/infer/unify_key.rs

+3-50
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ty::{self, FloatVarValue, InferConst, IntVarValue, Ty, TyCtxt};
1+
use crate::ty::{self, InferConst, Ty, TyCtxt};
22
use rustc_data_structures::snapshot_vec;
33
use rustc_data_structures::undo_log::UndoLogs;
44
use rustc_data_structures::unify::{
@@ -15,36 +15,6 @@ pub trait ToType {
1515
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>;
1616
}
1717

18-
/// Raw `TyVid` are used as the unification key for `sub_relations`;
19-
/// they carry no values.
20-
impl UnifyKey for ty::TyVid {
21-
type Value = ();
22-
fn index(&self) -> u32 {
23-
self.index
24-
}
25-
fn from_index(i: u32) -> ty::TyVid {
26-
ty::TyVid { index: i }
27-
}
28-
fn tag() -> &'static str {
29-
"TyVid"
30-
}
31-
}
32-
33-
impl UnifyKey for ty::IntVid {
34-
type Value = Option<IntVarValue>;
35-
fn index(&self) -> u32 {
36-
self.index
37-
}
38-
fn from_index(i: u32) -> ty::IntVid {
39-
ty::IntVid { index: i }
40-
}
41-
fn tag() -> &'static str {
42-
"IntVid"
43-
}
44-
}
45-
46-
impl EqUnifyValue for IntVarValue {}
47-
4818
#[derive(PartialEq, Copy, Clone, Debug)]
4919
pub struct RegionVidKey {
5020
/// The minimum region vid in the unification set. This is needed
@@ -80,7 +50,7 @@ impl UnifyKey for ty::RegionVid {
8050
}
8151
}
8252

83-
impl ToType for IntVarValue {
53+
impl ToType for ty::IntVarValue {
8454
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
8555
match *self {
8656
ty::IntType(i) => tcx.mk_mach_int(i),
@@ -89,24 +59,7 @@ impl ToType for IntVarValue {
8959
}
9060
}
9161

92-
// Floating point type keys
93-
94-
impl UnifyKey for ty::FloatVid {
95-
type Value = Option<FloatVarValue>;
96-
fn index(&self) -> u32 {
97-
self.index
98-
}
99-
fn from_index(i: u32) -> ty::FloatVid {
100-
ty::FloatVid { index: i }
101-
}
102-
fn tag() -> &'static str {
103-
"FloatVid"
104-
}
105-
}
106-
107-
impl EqUnifyValue for FloatVarValue {}
108-
109-
impl ToType for FloatVarValue {
62+
impl ToType for ty::FloatVarValue {
11063
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
11164
tcx.mk_mach_float(self.0)
11265
}

compiler/rustc_middle/src/ty/diagnostics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Diagnostics related methods for `TyS`.
22
3-
use crate::ty::sty::InferTy;
43
use crate::ty::TyKind::*;
5-
use crate::ty::{TyCtxt, TyS};
4+
use crate::ty::{InferTy, TyCtxt, TyS};
65
use rustc_errors::{Applicability, DiagnosticBuilder};
76
use rustc_hir as hir;
87
use rustc_hir::def_id::DefId;

compiler/rustc_middle/src/ty/mod.rs

+4-81
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use std::ptr;
6565
use std::str;
6666

6767
pub use self::sty::BoundRegionKind::*;
68-
pub use self::sty::InferTy::*;
6968
pub use self::sty::RegionKind;
7069
pub use self::sty::RegionKind::*;
7170
pub use self::sty::TyKind::*;
@@ -74,13 +73,14 @@ pub use self::sty::{BoundRegion, BoundRegionKind, EarlyBoundRegion, FreeRegion,
7473
pub use self::sty::{CanonicalPolyFnSig, FnSig, GenSig, PolyFnSig, PolyGenSig};
7574
pub use self::sty::{ClosureSubsts, GeneratorSubsts, TypeAndMut, UpvarSubsts};
7675
pub use self::sty::{ClosureSubstsParts, GeneratorSubstsParts};
77-
pub use self::sty::{ConstVid, FloatVid, IntVid, RegionVid, TyVid};
78-
pub use self::sty::{ExistentialPredicate, InferTy, ParamConst, ParamTy, ProjectionTy};
76+
pub use self::sty::{ConstVid, RegionVid};
77+
pub use self::sty::{ExistentialPredicate, ParamConst, ParamTy, ProjectionTy};
7978
pub use self::sty::{ExistentialProjection, PolyExistentialProjection};
8079
pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
8180
pub use self::sty::{PolyTraitRef, TraitRef, TyKind};
8281
pub use crate::ty::diagnostics::*;
83-
pub use rustc_type_ir::{DebruijnIndex, TypeFlags, INNERMOST};
82+
pub use rustc_type_ir::InferTy::*;
83+
pub use rustc_type_ir::*;
8484

8585
pub use self::binding::BindingMode;
8686
pub use self::binding::BindingMode::*;
@@ -421,14 +421,6 @@ impl Visibility {
421421
}
422422
}
423423

424-
#[derive(Copy, Clone, PartialEq, TyDecodable, TyEncodable, HashStable)]
425-
pub enum Variance {
426-
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
427-
Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
428-
Contravariant, // T<A> <: T<B> iff B <: A -- e.g., function param type
429-
Bivariant, // T<A> <: T<B> -- e.g., unused type parameter
430-
}
431-
432424
/// The crate variances map is computed during typeck and contains the
433425
/// variance of every item in the local crate. You should not use it
434426
/// directly, because to do so will make your pass dependent on the
@@ -443,66 +435,6 @@ pub struct CrateVariancesMap<'tcx> {
443435
pub variances: FxHashMap<DefId, &'tcx [ty::Variance]>,
444436
}
445437

446-
impl Variance {
447-
/// `a.xform(b)` combines the variance of a context with the
448-
/// variance of a type with the following meaning. If we are in a
449-
/// context with variance `a`, and we encounter a type argument in
450-
/// a position with variance `b`, then `a.xform(b)` is the new
451-
/// variance with which the argument appears.
452-
///
453-
/// Example 1:
454-
///
455-
/// *mut Vec<i32>
456-
///
457-
/// Here, the "ambient" variance starts as covariant. `*mut T` is
458-
/// invariant with respect to `T`, so the variance in which the
459-
/// `Vec<i32>` appears is `Covariant.xform(Invariant)`, which
460-
/// yields `Invariant`. Now, the type `Vec<T>` is covariant with
461-
/// respect to its type argument `T`, and hence the variance of
462-
/// the `i32` here is `Invariant.xform(Covariant)`, which results
463-
/// (again) in `Invariant`.
464-
///
465-
/// Example 2:
466-
///
467-
/// fn(*const Vec<i32>, *mut Vec<i32)
468-
///
469-
/// The ambient variance is covariant. A `fn` type is
470-
/// contravariant with respect to its parameters, so the variance
471-
/// within which both pointer types appear is
472-
/// `Covariant.xform(Contravariant)`, or `Contravariant`. `*const
473-
/// T` is covariant with respect to `T`, so the variance within
474-
/// which the first `Vec<i32>` appears is
475-
/// `Contravariant.xform(Covariant)` or `Contravariant`. The same
476-
/// is true for its `i32` argument. In the `*mut T` case, the
477-
/// variance of `Vec<i32>` is `Contravariant.xform(Invariant)`,
478-
/// and hence the outermost type is `Invariant` with respect to
479-
/// `Vec<i32>` (and its `i32` argument).
480-
///
481-
/// Source: Figure 1 of "Taming the Wildcards:
482-
/// Combining Definition- and Use-Site Variance" published in PLDI'11.
483-
pub fn xform(self, v: ty::Variance) -> ty::Variance {
484-
match (self, v) {
485-
// Figure 1, column 1.
486-
(ty::Covariant, ty::Covariant) => ty::Covariant,
487-
(ty::Covariant, ty::Contravariant) => ty::Contravariant,
488-
(ty::Covariant, ty::Invariant) => ty::Invariant,
489-
(ty::Covariant, ty::Bivariant) => ty::Bivariant,
490-
491-
// Figure 1, column 2.
492-
(ty::Contravariant, ty::Covariant) => ty::Contravariant,
493-
(ty::Contravariant, ty::Contravariant) => ty::Covariant,
494-
(ty::Contravariant, ty::Invariant) => ty::Invariant,
495-
(ty::Contravariant, ty::Bivariant) => ty::Bivariant,
496-
497-
// Figure 1, column 3.
498-
(ty::Invariant, _) => ty::Invariant,
499-
500-
// Figure 1, column 4.
501-
(ty::Bivariant, _) => ty::Bivariant,
502-
}
503-
}
504-
}
505-
506438
// Contains information needed to resolve types and (in the future) look up
507439
// the types of AST nodes.
508440
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@@ -804,15 +736,6 @@ pub struct CaptureInfo<'tcx> {
804736
pub type UpvarListMap = FxHashMap<DefId, FxIndexMap<hir::HirId, UpvarId>>;
805737
pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;
806738

807-
#[derive(Clone, Copy, PartialEq, Eq)]
808-
pub enum IntVarValue {
809-
IntType(ast::IntTy),
810-
UintType(ast::UintTy),
811-
}
812-
813-
#[derive(Clone, Copy, PartialEq, Eq)]
814-
pub struct FloatVarValue(pub ast::FloatTy);
815-
816739
impl ty::EarlyBoundRegion {
817740
/// Does this early bound region have a name? Early bound regions normally
818741
/// always have names except when using anonymous lifetimes (`'_`).

compiler/rustc_middle/src/ty/print/pretty.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,19 @@ pub trait PrettyPrinter<'tcx>:
557557
}
558558
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
559559
ty::Infer(infer_ty) => {
560+
let verbose = self.tcx().sess.verbose();
560561
if let ty::TyVar(ty_vid) = infer_ty {
561562
if let Some(name) = self.infer_ty_name(ty_vid) {
562563
p!(write("{}", name))
563564
} else {
564-
p!(write("{}", infer_ty))
565+
if verbose {
566+
p!(write("{:?}", infer_ty))
567+
} else {
568+
p!(write("{}", infer_ty))
569+
}
565570
}
566571
} else {
567-
p!(write("{}", infer_ty))
572+
if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) }
568573
}
569574
}
570575
ty::Error(_) => p!("[type error]"),
@@ -1246,7 +1251,7 @@ pub struct FmtPrinterData<'a, 'tcx, F> {
12461251

12471252
pub region_highlight_mode: RegionHighlightMode,
12481253

1249-
pub name_resolver: Option<Box<&'a dyn Fn(ty::sty::TyVid) -> Option<String>>>,
1254+
pub name_resolver: Option<Box<&'a dyn Fn(ty::TyVid) -> Option<String>>>,
12501255
}
12511256

12521257
impl<F> Deref for FmtPrinter<'a, 'tcx, F> {
@@ -2007,21 +2012,6 @@ define_print_and_forward_display! {
20072012
p!("fn", pretty_fn_sig(self.inputs(), self.c_variadic, self.output()));
20082013
}
20092014

2010-
ty::InferTy {
2011-
if cx.tcx().sess.verbose() {
2012-
p!(write("{:?}", self));
2013-
return Ok(cx);
2014-
}
2015-
match *self {
2016-
ty::TyVar(_) => p!("_"),
2017-
ty::IntVar(_) => p!(write("{}", "{integer}")),
2018-
ty::FloatVar(_) => p!(write("{}", "{float}")),
2019-
ty::FreshTy(v) => p!(write("FreshTy({})", v)),
2020-
ty::FreshIntTy(v) => p!(write("FreshIntTy({})", v)),
2021-
ty::FreshFloatTy(v) => p!(write("FreshFloatTy({})", v))
2022-
}
2023-
}
2024-
20252015
ty::TraitRef<'tcx> {
20262016
p!(write("<{} as {}>", self.self_ty(), self.print_only_trait_path()))
20272017
}

compiler/rustc_middle/src/ty/structural_impls.rs

+1-58
Original file line numberDiff line numberDiff line change
@@ -111,81 +111,24 @@ impl fmt::Debug for ty::FreeRegion {
111111
}
112112
}
113113

114-
impl fmt::Debug for ty::Variance {
115-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
116-
f.write_str(match *self {
117-
ty::Covariant => "+",
118-
ty::Contravariant => "-",
119-
ty::Invariant => "o",
120-
ty::Bivariant => "*",
121-
})
122-
}
123-
}
124-
125114
impl fmt::Debug for ty::FnSig<'tcx> {
126115
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127116
write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
128117
}
129118
}
130119

131-
impl fmt::Debug for ty::TyVid {
132-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133-
write!(f, "_#{}t", self.index)
134-
}
135-
}
136-
137120
impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
138121
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139122
write!(f, "_#{}c", self.index)
140123
}
141124
}
142125

143-
impl fmt::Debug for ty::IntVid {
144-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
145-
write!(f, "_#{}i", self.index)
146-
}
147-
}
148-
149-
impl fmt::Debug for ty::FloatVid {
150-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151-
write!(f, "_#{}f", self.index)
152-
}
153-
}
154-
155126
impl fmt::Debug for ty::RegionVid {
156127
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157128
write!(f, "'_#{}r", self.index())
158129
}
159130
}
160131

161-
impl fmt::Debug for ty::InferTy {
162-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
163-
match *self {
164-
ty::TyVar(ref v) => v.fmt(f),
165-
ty::IntVar(ref v) => v.fmt(f),
166-
ty::FloatVar(ref v) => v.fmt(f),
167-
ty::FreshTy(v) => write!(f, "FreshTy({:?})", v),
168-
ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
169-
ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v),
170-
}
171-
}
172-
}
173-
174-
impl fmt::Debug for ty::IntVarValue {
175-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176-
match *self {
177-
ty::IntType(ref v) => v.fmt(f),
178-
ty::UintType(ref v) => v.fmt(f),
179-
}
180-
}
181-
}
182-
183-
impl fmt::Debug for ty::FloatVarValue {
184-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
185-
self.0.fmt(f)
186-
}
187-
}
188-
189132
impl fmt::Debug for ty::TraitRef<'tcx> {
190133
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
191134
with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
@@ -274,7 +217,7 @@ TrivialTypeFoldableAndLiftImpls! {
274217
u64,
275218
String,
276219
crate::middle::region::Scope,
277-
::rustc_ast::FloatTy,
220+
crate::ty::FloatTy,
278221
::rustc_ast::InlineAsmOptions,
279222
::rustc_ast::InlineAsmTemplatePiece,
280223
::rustc_ast::NodeId,

0 commit comments

Comments
 (0)