Retire HirVec.

This commit is contained in:
Camille GILLOT
2019-12-01 17:21:00 +01:00
parent aa3678d4f4
commit e2c9dd7a10
6 changed files with 37 additions and 56 deletions
+27 -37
View File
@@ -38,7 +38,6 @@
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
use crate::hir::map::{DefKey, DefPathData, Definitions};
use crate::hir::ptr::P;
use crate::hir::HirVec;
use crate::hir::{self, ParamName};
use crate::hir::{ConstArg, GenericArg};
use crate::lint;
@@ -540,7 +539,7 @@ fn visit_ty(&mut self, t: &'tcx Ty) {
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
let module = self.lower_mod(&c.module);
let attrs = self.arena.alloc_from_iter(self.lower_attrs(&c.attrs).into_iter());
let attrs = self.lower_attrs(&c.attrs);
let body_ids = body_ids(&self.bodies);
self.resolver.definitions().init_node_id_to_hir_id_mapping(self.node_id_to_hir_id);
@@ -958,14 +957,10 @@ fn def_key(&mut self, id: DefId) -> DefKey {
}
}
fn lower_attrs_arena(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
fn lower_attrs(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a)))
}
fn lower_attrs(&mut self, attrs: &[Attribute]) -> hir::HirVec<Attribute> {
attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into()
}
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
// Note that we explicitly do not walk the path. Since we don't really
// lower attributes (we use the AST version) there is nowhere to keep
@@ -1225,25 +1220,21 @@ fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) ->
};
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
}
TyKind::BareFn(ref f) => {
self.with_in_scope_lifetime_defs(&f.generic_params, |this| {
this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
generic_params: this.lower_generic_params(
&f.generic_params,
&NodeMap::default(),
ImplTraitContext::disallowed(),
),
unsafety: f.unsafety,
abi: this.lower_extern(f.ext),
decl: this.lower_fn_decl(&f.decl, None, false, None),
param_names: this.arena.alloc_from_iter(
this.lower_fn_params_to_names(&f.decl).into_iter(),
),
}))
})
TyKind::BareFn(ref f) => self.with_in_scope_lifetime_defs(&f.generic_params, |this| {
this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
generic_params: this.lower_generic_params(
&f.generic_params,
&NodeMap::default(),
ImplTraitContext::disallowed(),
),
unsafety: f.unsafety,
abi: this.lower_extern(f.ext),
decl: this.lower_fn_decl(&f.decl, None, false, None),
param_names: this.lower_fn_params_to_names(&f.decl),
}))
})
}
}),
TyKind::Never => hir::TyKind::Never,
TyKind::Tup(ref tys) => {
hir::TyKind::Tup(self.arena.alloc_from_iter(
@@ -1412,7 +1403,6 @@ fn lower_opaque_impl_trait(
opaque_ty_def_index,
&hir_bounds,
);
let lifetime_defs = self.arena.alloc_from_iter(lifetime_defs.into_iter());
debug!("lower_opaque_impl_trait: lifetimes={:#?}", lifetimes,);
@@ -1473,7 +1463,7 @@ fn lifetimes_from_impl_trait_bounds(
opaque_ty_id: NodeId,
parent_index: DefIndex,
bounds: hir::GenericBounds<'hir>,
) -> (&'hir [hir::GenericArg<'hir>], HirVec<hir::GenericParam<'hir>>) {
) -> (&'hir [hir::GenericArg<'hir>], &'hir [hir::GenericParam<'hir>]) {
debug!(
"lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
parent_index={:?}, \
@@ -1640,7 +1630,10 @@ fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) {
let ImplTraitLifetimeCollector { output_lifetimes, output_lifetime_params, .. } =
lifetime_collector;
(self.arena.alloc_from_iter(output_lifetimes), output_lifetime_params.into())
(
self.arena.alloc_from_iter(output_lifetimes),
self.arena.alloc_from_iter(output_lifetime_params),
)
}
fn lower_qpath(
@@ -2075,7 +2068,7 @@ fn lower_parenthesized_parameter_data(
)
}
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
// as they are not explicit in HIR/Ty function signatures.
// (instead, the `c_variadic` flag is set to `true`)
@@ -2083,13 +2076,10 @@ fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
if decl.c_variadic() {
inputs = &inputs[..inputs.len() - 1];
}
inputs
.iter()
.map(|param| match param.pat.kind {
PatKind::Ident(_, ident, _) => ident,
_ => Ident::new(kw::Invalid, param.pat.span),
})
.collect()
self.arena.alloc_from_iter(inputs.iter().map(|param| match param.pat.kind {
PatKind::Ident(_, ident, _) => ident,
_ => Ident::new(kw::Invalid, param.pat.span),
}))
}
// Lowers a function declaration.
@@ -2571,7 +2561,7 @@ fn lower_generic_param(
name,
span: param.ident.span,
pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
attrs: self.lower_attrs_arena(&param.attrs),
attrs: self.lower_attrs(&param.attrs),
bounds: self.arena.alloc_from_iter(bounds),
kind,
}
+1 -1
View File
@@ -464,7 +464,7 @@ fn wrap_in_try_constructor(
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
hir::Arm {
hir_id: self.next_id(),
attrs: self.lower_attrs_arena(&arm.attrs),
attrs: self.lower_attrs(&arm.attrs),
pat: self.lower_pat(&arm.pat),
guard: match arm.guard {
Some(ref x) => Some(hir::Guard::If(self.lower_expr(x))),
+7 -9
View File
@@ -226,7 +226,7 @@ fn lower_item_id_use_tree(
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item<'hir>> {
let mut ident = i.ident;
let mut vis = self.lower_visibility(&i.vis, None);
let attrs = self.lower_attrs_arena(&i.attrs);
let attrs = self.lower_attrs(&i.attrs);
if let ItemKind::MacroDef(ref def) = i.kind {
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
@@ -660,7 +660,7 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
hir::ForeignItem {
hir_id: self.lower_node_id(i.id),
ident: i.ident,
attrs: self.lower_attrs_arena(&i.attrs),
attrs: self.lower_attrs(&i.attrs),
kind: match i.kind {
ForeignItemKind::Fn(ref fdec, ref generics) => {
let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
@@ -675,7 +675,6 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
)
},
);
let fn_args = self.arena.alloc_from_iter(fn_args.into_iter());
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
}
@@ -704,7 +703,7 @@ fn lower_global_asm(&mut self, ga: &GlobalAsm) -> &'hir hir::GlobalAsm {
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
hir::Variant {
attrs: self.lower_attrs_arena(&v.attrs),
attrs: self.lower_attrs(&v.attrs),
data: self.lower_variant_data(&v.data),
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
id: self.lower_node_id(v.id),
@@ -752,7 +751,7 @@ fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::Stru
},
vis: self.lower_visibility(&f.vis, None),
ty,
attrs: self.lower_attrs_arena(&f.attrs),
attrs: self.lower_attrs(&f.attrs),
}
}
@@ -773,7 +772,6 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
}
AssocItemKind::Fn(ref sig, None) => {
let names = self.lower_fn_params_to_names(&sig.decl);
let names: &[Ident] = self.arena.alloc_from_iter(names.into_iter());
let (generics, sig) =
self.lower_method_sig(&i.generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
@@ -800,7 +798,7 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
hir::TraitItem {
hir_id: self.lower_node_id(i.id),
ident: i.ident,
attrs: self.lower_attrs_arena(&i.attrs),
attrs: self.lower_attrs(&i.attrs),
generics,
kind,
span: i.span,
@@ -887,7 +885,7 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
hir::ImplItem {
hir_id: self.lower_node_id(i.id),
ident: i.ident,
attrs: self.lower_attrs_arena(&i.attrs),
attrs: self.lower_attrs(&i.attrs),
generics,
vis: self.lower_visibility(&i.vis, None),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
@@ -994,7 +992,7 @@ fn lower_body(
fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
hir::Param {
attrs: self.lower_attrs_arena(&param.attrs),
attrs: self.lower_attrs(&param.attrs),
hir_id: self.lower_node_id(param.id),
pat: self.lower_pat(&param.pat),
span: param.span,
-7
View File
@@ -10,7 +10,6 @@
use crate::hir::def::{DefKind, Res};
use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
use crate::hir::ptr::P;
use crate::mir::mono::Linkage;
use crate::ty::query::Providers;
use crate::ty::AdtKind;
@@ -35,12 +34,6 @@
use syntax_pos::symbol::{kw, sym, Symbol};
use syntax_pos::{MultiSpan, Span, DUMMY_SP};
/// HIR doesn't commit to a concrete storage type and has its own alias for a vector.
/// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar
/// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead
/// of `Vec` to avoid keeping extra capacity.
pub type HirVec<T> = P<[T]>;
pub mod check_attr;
pub mod def;
pub mod def_id;
+1 -1
View File
@@ -474,7 +474,7 @@ fn build_macro(cx: &DocContext<'_>, did: DefId, name: ast::Name) -> clean::ItemE
let imported_from = cx.tcx.original_crate_name(did.krate);
match cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())) {
LoadedMacro::MacroDef(def, _) => {
let matchers: hir::HirVec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {
let matchers: Vec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {
let tts: Vec<_> = def.body.inner_tokens().into_trees().collect();
tts.chunks(4).map(|arm| arm[0].span()).collect()
} else {
+1 -1
View File
@@ -230,7 +230,7 @@ pub struct Macro<'hir> {
pub def_id: hir::def_id::DefId,
pub attrs: &'hir [ast::Attribute],
pub whence: Span,
pub matchers: hir::HirVec<Span>,
pub matchers: Vec<Span>,
pub imported_from: Option<Name>,
}