mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
rustc: remove unnecessary ItemSubsts wrapper.
This commit is contained in:
parent
a65ced5d16
commit
9eae6ba7fa
@ -19,8 +19,6 @@ use std::mem;
|
|||||||
use syntax_pos::symbol::InternedString;
|
use syntax_pos::symbol::InternedString;
|
||||||
use ty;
|
use ty;
|
||||||
|
|
||||||
impl_stable_hash_for!(struct ty::ItemSubsts<'tcx> { substs });
|
|
||||||
|
|
||||||
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for &'tcx ty::Slice<T>
|
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for &'tcx ty::Slice<T>
|
||||||
where T: HashStable<StableHashingContext<'a, 'tcx>> {
|
where T: HashStable<StableHashingContext<'a, 'tcx>> {
|
||||||
fn hash_stable<W: StableHasherResult>(&self,
|
fn hash_stable<W: StableHasherResult>(&self,
|
||||||
@ -602,7 +600,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
|
|||||||
let ty::TypeckTables {
|
let ty::TypeckTables {
|
||||||
ref type_relative_path_defs,
|
ref type_relative_path_defs,
|
||||||
ref node_types,
|
ref node_types,
|
||||||
ref item_substs,
|
ref node_substs,
|
||||||
ref adjustments,
|
ref adjustments,
|
||||||
ref method_map,
|
ref method_map,
|
||||||
ref upvar_capture_map,
|
ref upvar_capture_map,
|
||||||
@ -623,7 +621,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
|
|||||||
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
||||||
ich::hash_stable_nodemap(hcx, hasher, type_relative_path_defs);
|
ich::hash_stable_nodemap(hcx, hasher, type_relative_path_defs);
|
||||||
ich::hash_stable_nodemap(hcx, hasher, node_types);
|
ich::hash_stable_nodemap(hcx, hasher, node_types);
|
||||||
ich::hash_stable_nodemap(hcx, hasher, item_substs);
|
ich::hash_stable_nodemap(hcx, hasher, node_substs);
|
||||||
ich::hash_stable_nodemap(hcx, hasher, adjustments);
|
ich::hash_stable_nodemap(hcx, hasher, adjustments);
|
||||||
ich::hash_stable_nodemap(hcx, hasher, method_map);
|
ich::hash_stable_nodemap(hcx, hasher, method_map);
|
||||||
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
|
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
|
||||||
|
@ -218,7 +218,7 @@ pub struct TypeckTables<'tcx> {
|
|||||||
/// of this node. This only applies to nodes that refer to entities
|
/// of this node. This only applies to nodes that refer to entities
|
||||||
/// parameterized by type parameters, such as generic fns, types, or
|
/// parameterized by type parameters, such as generic fns, types, or
|
||||||
/// other items.
|
/// other items.
|
||||||
pub item_substs: NodeMap<ty::ItemSubsts<'tcx>>,
|
pub node_substs: NodeMap<&'tcx Substs<'tcx>>,
|
||||||
|
|
||||||
pub adjustments: NodeMap<ty::adjustment::Adjustment<'tcx>>,
|
pub adjustments: NodeMap<ty::adjustment::Adjustment<'tcx>>,
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ impl<'tcx> TypeckTables<'tcx> {
|
|||||||
TypeckTables {
|
TypeckTables {
|
||||||
type_relative_path_defs: NodeMap(),
|
type_relative_path_defs: NodeMap(),
|
||||||
node_types: FxHashMap(),
|
node_types: FxHashMap(),
|
||||||
item_substs: NodeMap(),
|
node_substs: NodeMap(),
|
||||||
adjustments: NodeMap(),
|
adjustments: NodeMap(),
|
||||||
method_map: FxHashMap(),
|
method_map: FxHashMap(),
|
||||||
upvar_capture_map: FxHashMap(),
|
upvar_capture_map: FxHashMap(),
|
||||||
@ -313,8 +313,8 @@ impl<'tcx> TypeckTables<'tcx> {
|
|||||||
self.node_types.get(&id).cloned()
|
self.node_types.get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_id_item_substs(&self, id: NodeId) -> Option<&'tcx Substs<'tcx>> {
|
pub fn node_substs(&self, id: NodeId) -> &'tcx Substs<'tcx> {
|
||||||
self.item_substs.get(&id).map(|ts| ts.substs)
|
self.node_substs.get(&id).cloned().unwrap_or(Substs::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
|
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
|
||||||
|
@ -1809,13 +1809,6 @@ impl<'a, 'gcx, 'tcx> FieldDef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Records the substitutions used to translate the polytype for an
|
|
||||||
/// item into the monotype of an item reference.
|
|
||||||
#[derive(Clone, RustcEncodable, RustcDecodable)]
|
|
||||||
pub struct ItemSubsts<'tcx> {
|
|
||||||
pub substs: &'tcx Substs<'tcx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
|
||||||
pub enum ClosureKind {
|
pub enum ClosureKind {
|
||||||
// Warning: Ordering is significant here! The ordering is chosen
|
// Warning: Ordering is significant here! The ordering is chosen
|
||||||
@ -1893,12 +1886,6 @@ impl<'tcx> TyS<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ItemSubsts<'tcx> {
|
|
||||||
pub fn is_noop(&self) -> bool {
|
|
||||||
self.substs.is_noop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum LvaluePreference {
|
pub enum LvaluePreference {
|
||||||
PreferMutLvalue,
|
PreferMutLvalue,
|
||||||
|
@ -220,17 +220,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Lift<'tcx> for ty::ItemSubsts<'a> {
|
|
||||||
type Lifted = ty::ItemSubsts<'tcx>;
|
|
||||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
||||||
tcx.lift(&self.substs).map(|substs| {
|
|
||||||
ty::ItemSubsts {
|
|
||||||
substs: substs
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
|
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
|
||||||
type Lifted = ty::adjustment::AutoBorrow<'tcx>;
|
type Lifted = ty::adjustment::AutoBorrow<'tcx>;
|
||||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||||
@ -654,18 +643,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ty::ItemSubsts<'tcx> {
|
|
||||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
||||||
ty::ItemSubsts {
|
|
||||||
substs: self.substs.fold_with(folder),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
||||||
self.substs.visit_with(visitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
|
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
|
||||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -361,12 +361,6 @@ impl<'tcx> fmt::Display for ty::TypeAndMut<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::ItemSubsts<'tcx> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "ItemSubsts({:?})", self.substs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
|
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
// when printing out the debug representation, we don't need
|
// when printing out the debug representation, we don't need
|
||||||
|
@ -286,8 +286,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ExprPath(ref qpath) => {
|
hir::ExprPath(ref qpath) => {
|
||||||
let substs = cx.tables.node_id_item_substs(e.id)
|
let substs = cx.tables.node_substs(e.id);
|
||||||
.unwrap_or_else(|| tcx.intern_substs(&[]));
|
|
||||||
|
|
||||||
// Avoid applying substitutions if they're empty, that'd ICE.
|
// Avoid applying substitutions if they're empty, that'd ICE.
|
||||||
let substs = if cx.substs.is_empty() {
|
let substs = if cx.substs.is_empty() {
|
||||||
|
@ -585,8 +585,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
|
|||||||
let kind = match def {
|
let kind = match def {
|
||||||
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
|
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
|
||||||
let tcx = self.tcx.global_tcx();
|
let tcx = self.tcx.global_tcx();
|
||||||
let substs = self.tables.node_id_item_substs(id)
|
let substs = self.tables.node_substs(id);
|
||||||
.unwrap_or_else(|| tcx.intern_substs(&[]));
|
|
||||||
match eval::lookup_const_by_id(tcx, def_id, substs) {
|
match eval::lookup_const_by_id(tcx, def_id, substs) {
|
||||||
Some((def_id, _substs)) => {
|
Some((def_id, _substs)) => {
|
||||||
// Enter the inlined constant's tables temporarily.
|
// Enter the inlined constant's tables temporarily.
|
||||||
|
@ -911,8 +911,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
|
|||||||
};
|
};
|
||||||
match def {
|
match def {
|
||||||
Def::Method(def_id) => {
|
Def::Method(def_id) => {
|
||||||
let substs = cx.tables.node_id_item_substs(callee.id)
|
let substs = cx.tables.node_substs(callee.id);
|
||||||
.unwrap_or_else(|| cx.tcx.intern_substs(&[]));
|
|
||||||
method_call_refers_to_method(
|
method_call_refers_to_method(
|
||||||
cx.tcx, method, def_id, substs, id)
|
cx.tcx, method, def_id, substs, id)
|
||||||
}
|
}
|
||||||
|
@ -297,8 +297,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
if let Some((adt_def, index)) = adt_data {
|
if let Some((adt_def, index)) = adt_data {
|
||||||
let substs = cx.tables().node_id_item_substs(fun.id)
|
let substs = cx.tables().node_substs(fun.id);
|
||||||
.unwrap_or_else(|| cx.tcx.intern_substs(&[]));
|
|
||||||
let field_refs = args.iter()
|
let field_refs = args.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, e)| {
|
.map(|(idx, e)| {
|
||||||
@ -735,8 +734,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||||||
expr: &'tcx hir::Expr,
|
expr: &'tcx hir::Expr,
|
||||||
def: Def)
|
def: Def)
|
||||||
-> ExprKind<'tcx> {
|
-> ExprKind<'tcx> {
|
||||||
let substs = cx.tables().node_id_item_substs(expr.id)
|
let substs = cx.tables().node_substs(expr.id);
|
||||||
.unwrap_or_else(|| cx.tcx.intern_substs(&[]));
|
|
||||||
match def {
|
match def {
|
||||||
// A regular function, constructor function or a constant.
|
// A regular function, constructor function or a constant.
|
||||||
Def::Fn(def_id) |
|
Def::Fn(def_id) |
|
||||||
|
@ -52,7 +52,7 @@ can be broken down into several distinct phases:
|
|||||||
|
|
||||||
While type checking a function, the intermediate types for the
|
While type checking a function, the intermediate types for the
|
||||||
expressions, blocks, and so forth contained within the function are
|
expressions, blocks, and so forth contained within the function are
|
||||||
stored in `fcx.node_types` and `fcx.item_substs`. These types
|
stored in `fcx.node_types` and `fcx.node_substs`. These types
|
||||||
may contain unresolved type variables. After type checking is
|
may contain unresolved type variables. After type checking is
|
||||||
complete, the functions in the writeback module are used to take the
|
complete, the functions in the writeback module are used to take the
|
||||||
types from this table, resolve them, and then write them into their
|
types from this table, resolve them, and then write them into their
|
||||||
@ -1758,14 +1758,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::ItemSubsts<'tcx>) {
|
pub fn write_substs(&self, node_id: ast::NodeId, substs: &'tcx Substs<'tcx>) {
|
||||||
if !substs.substs.is_noop() {
|
if !substs.is_noop() {
|
||||||
debug!("write_substs({}, {:?}) in fcx {}",
|
debug!("write_substs({}, {:?}) in fcx {}",
|
||||||
node_id,
|
node_id,
|
||||||
substs,
|
substs,
|
||||||
self.tag());
|
self.tag());
|
||||||
|
|
||||||
self.tables.borrow_mut().item_substs.insert(node_id, substs);
|
self.tables.borrow_mut().node_substs.insert(node_id, substs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1959,16 +1959,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn opt_node_ty_substs<F>(&self,
|
|
||||||
id: ast::NodeId,
|
|
||||||
f: F) where
|
|
||||||
F: FnOnce(&ty::ItemSubsts<'tcx>),
|
|
||||||
{
|
|
||||||
if let Some(s) = self.tables.borrow().item_substs.get(&id) {
|
|
||||||
f(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Registers an obligation for checking later, during regionck, that the type `ty` must
|
/// Registers an obligation for checking later, during regionck, that the type `ty` must
|
||||||
/// outlive the region `r`.
|
/// outlive the region `r`.
|
||||||
pub fn register_region_obligation(&self,
|
pub fn register_region_obligation(&self,
|
||||||
@ -3550,9 +3540,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
|
|
||||||
// We always require that the type provided as the value for
|
// We always require that the type provided as the value for
|
||||||
// a type parameter outlives the moment of instantiation.
|
// a type parameter outlives the moment of instantiation.
|
||||||
self.opt_node_ty_substs(expr.id, |item_substs| {
|
let substs = self.tables.borrow().node_substs(expr.id);
|
||||||
self.add_wf_bounds(&item_substs.substs, expr);
|
self.add_wf_bounds(substs, expr);
|
||||||
});
|
|
||||||
|
|
||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
@ -4375,9 +4364,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
let ty = self.local_ty(span, nid);
|
let ty = self.local_ty(span, nid);
|
||||||
let ty = self.normalize_associated_types_in(span, &ty);
|
let ty = self.normalize_associated_types_in(span, &ty);
|
||||||
self.write_ty(node_id, ty);
|
self.write_ty(node_id, ty);
|
||||||
self.write_substs(node_id, ty::ItemSubsts {
|
|
||||||
substs: self.tcx.intern_substs(&[])
|
|
||||||
});
|
|
||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -4509,9 +4495,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
debug!("instantiate_value_path: type of {:?} is {:?}",
|
debug!("instantiate_value_path: type of {:?} is {:?}",
|
||||||
node_id,
|
node_id,
|
||||||
ty_substituted);
|
ty_substituted);
|
||||||
self.write_substs(node_id, ty::ItemSubsts {
|
self.write_substs(node_id, substs);
|
||||||
substs: substs
|
|
||||||
});
|
|
||||||
ty_substituted
|
ty_substituted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,10 +608,9 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> {
|
|||||||
expr, self.repeating_scope);
|
expr, self.repeating_scope);
|
||||||
match expr.node {
|
match expr.node {
|
||||||
hir::ExprPath(_) => {
|
hir::ExprPath(_) => {
|
||||||
self.fcx.opt_node_ty_substs(expr.id, |item_substs| {
|
let substs = self.tables.borrow().node_substs(expr.id);
|
||||||
let origin = infer::ParameterOrigin::Path;
|
let origin = infer::ParameterOrigin::Path;
|
||||||
self.substs_wf_in_scope(origin, &item_substs.substs, expr.span, expr_region);
|
self.substs_wf_in_scope(origin, substs, expr.span, expr_region);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::ExprCall(ref callee, ref args) => {
|
hir::ExprCall(ref callee, ref args) => {
|
||||||
|
@ -295,14 +295,12 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||||||
debug!("Node {} has type {:?}", node_id, n_ty);
|
debug!("Node {} has type {:?}", node_id, n_ty);
|
||||||
|
|
||||||
// Resolve any substitutions
|
// Resolve any substitutions
|
||||||
self.fcx.opt_node_ty_substs(node_id, |item_substs| {
|
if let Some(&substs) = self.fcx.tables.borrow().node_substs.get(&node_id) {
|
||||||
let item_substs = self.resolve(item_substs, &span);
|
let substs = self.resolve(&substs, &span);
|
||||||
if !item_substs.is_noop() {
|
debug!("write_substs_to_tcx({}, {:?})", node_id, substs);
|
||||||
debug!("write_substs_to_tcx({}, {:?})", node_id, item_substs);
|
assert!(!substs.needs_infer());
|
||||||
assert!(!item_substs.substs.needs_infer());
|
self.tables.node_substs.insert(node_id, substs);
|
||||||
self.tables.item_substs.insert(node_id, item_substs);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_adjustments(&mut self, span: Span, node_id: ast::NodeId) {
|
fn visit_adjustments(&mut self, span: Span, node_id: ast::NodeId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user