Skip to content

Commit 9c9a046

Browse files
committed
Convert dyn AstConv to AstConv
I expect this to have a perf impact because I think this is responsible for lowering types from hir, and that the reason that lowering builtin derives is slow is because the paths are longer. That lead me to find this, which I'm not sure if this is on the hot path or not. If it is, this should certainly be a perf win.
1 parent b2c51ca commit 9c9a046

File tree

14 files changed

+2805
-2836
lines changed

14 files changed

+2805
-2836
lines changed

compiler/rustc_typeck/src/astconv/errors.rs

+328-333
Large diffs are not rendered by default.

compiler/rustc_typeck/src/astconv/generics.rs

+442-483
Large diffs are not rendered by default.

compiler/rustc_typeck/src/astconv/mod.rs

+1,968-1,956
Large diffs are not rendered by default.

compiler/rustc_typeck/src/check/closure.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
44

5-
use crate::astconv::AstConv;
5+
use crate::astconv::{self, AstConv};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::DefId;
88
use rustc_hir::lang_items::LangItem;
@@ -538,17 +538,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
538538
decl: &hir::FnDecl<'_>,
539539
body: &hir::Body<'_>,
540540
) -> ty::PolyFnSig<'tcx> {
541-
let astconv: &dyn AstConv<'_> = self;
542-
543541
debug!(
544542
"supplied_sig_of_closure(decl={:?}, body.generator_kind={:?})",
545543
decl, body.generator_kind,
546544
);
547545

548546
// First, convert the types that the user supplied (if any).
549-
let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));
547+
let supplied_arguments = decl.inputs.iter().map(|a| astconv::ast_ty_to_ty(self, a));
550548
let supplied_return = match decl.output {
551-
hir::FnRetTy::Return(ref output) => astconv.ast_ty_to_ty(&output),
549+
hir::FnRetTy::Return(ref output) => astconv::ast_ty_to_ty(self, &output),
552550
hir::FnRetTy::DefaultReturn(_) => match body.generator_kind {
553551
// In the case of the async block that we create for a function body,
554552
// we expect the return type of the block to match that of the enclosing
@@ -563,11 +561,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563561
// easily (and locally) prove that we
564562
// *have* reported an
565563
// error. --nikomatsakis
566-
astconv.ty_infer(None, decl.output.span())
564+
self.ty_infer(None, decl.output.span())
567565
})
568566
}
569567

570-
_ => astconv.ty_infer(None, decl.output.span()),
568+
_ => self.ty_infer(None, decl.output.span()),
571569
},
572570
};
573571

@@ -694,16 +692,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
694692
/// so should yield an error, but returns back a signature where
695693
/// all parameters are of type `TyErr`.
696694
fn error_sig_of_closure(&self, decl: &hir::FnDecl<'_>) -> ty::PolyFnSig<'tcx> {
697-
let astconv: &dyn AstConv<'_> = self;
698-
699695
let supplied_arguments = decl.inputs.iter().map(|a| {
700696
// Convert the types that the user supplied (if any), but ignore them.
701-
astconv.ast_ty_to_ty(a);
697+
astconv::ast_ty_to_ty(self, a);
702698
self.tcx.ty_error()
703699
});
704700

705701
if let hir::FnRetTy::Return(ref output) = decl.output {
706-
astconv.ast_ty_to_ty(&output);
702+
astconv::ast_ty_to_ty(self, &output);
707703
}
708704

709705
let result = ty::Binder::dummy(self.tcx.mk_fn_sig(

compiler/rustc_typeck/src/check/coercion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
//! // and are then unable to coerce `&7i32` to `&mut i32`.
3636
//! ```
3737
38-
use crate::astconv::AstConv;
38+
use crate::astconv;
3939
use crate::check::FnCtxt;
4040
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
4141
use rustc_hir as hir;
@@ -1536,7 +1536,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15361536
if let hir::FnRetTy::Return(ty) = fn_output {
15371537
// Get the return type.
15381538
if let hir::TyKind::OpaqueDef(..) = ty.kind {
1539-
let ty = AstConv::ast_ty_to_ty(fcx, ty);
1539+
let ty = astconv::ast_ty_to_ty(fcx, ty);
15401540
// Get the `impl Trait`'s `DefId`.
15411541
if let ty::Opaque(def_id, _) = ty.kind() {
15421542
let hir_id = fcx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
@@ -1598,7 +1598,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15981598
fn is_return_ty_unsized(&self, fcx: &FnCtxt<'a, 'tcx>, blk_id: hir::HirId) -> bool {
15991599
if let Some((fn_decl, _)) = fcx.get_fn_decl(blk_id) {
16001600
if let hir::FnRetTy::Return(ty) = fn_decl.output {
1601-
let ty = AstConv::ast_ty_to_ty(fcx, ty);
1601+
let ty = astconv::ast_ty_to_ty(fcx, ty);
16021602
if let ty::Dynamic(..) = ty.kind() {
16031603
return true;
16041604
}

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::astconv::{
2-
AstConv, CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
2+
self, AstConv, CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
33
GenericArgCountResult, PathSeg,
44
};
55
use crate::check::callee::{self, DeferredCallResolution};
@@ -454,7 +454,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
454454
}
455455

456456
pub fn to_ty(&self, ast_t: &hir::Ty<'_>) -> Ty<'tcx> {
457-
let t = AstConv::ast_ty_to_ty(self, ast_t);
457+
let t = astconv::ast_ty_to_ty(self, ast_t);
458458
self.register_wf_obligation(t.into(), ast_t.span, traits::MiscObligation);
459459
t
460460
}
@@ -1144,7 +1144,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11441144
let path_segs = match res {
11451145
Res::Local(_) | Res::SelfCtor(_) => vec![],
11461146
Res::Def(kind, def_id) => {
1147-
AstConv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id)
1147+
astconv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id)
11481148
}
11491149
_ => bug!("instantiate_value_path on {:?}", res),
11501150
};
@@ -1188,7 +1188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11881188
// errors if type parameters are provided in an inappropriate place.
11891189

11901190
let generic_segs: FxHashSet<_> = path_segs.iter().map(|PathSeg(_, index)| index).collect();
1191-
let generics_has_err = AstConv::prohibit_generics(
1191+
let generics_has_err = astconv::prohibit_generics(
11921192
self,
11931193
segments.iter().enumerate().filter_map(|(index, seg)| {
11941194
if !generic_segs.contains(&index) || is_alias_variant_ctor {
@@ -1229,7 +1229,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12291229
if let GenericArgCountResult {
12301230
correct: Err(GenericArgCountMismatch { reported: Some(ErrorReported), .. }),
12311231
..
1232-
} = AstConv::check_generic_arg_count_for_call(
1232+
} = astconv::generics::check_generic_arg_count_for_call(
12331233
tcx, span, &generics, &seg, false, // `is_method_call`
12341234
) {
12351235
infer_args_for_err.insert(index);
@@ -1332,7 +1332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13321332
) -> subst::GenericArg<'tcx> {
13331333
match (&param.kind, arg) {
13341334
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
1335-
AstConv::ast_region_to_region(self.fcx, lt, Some(param)).into()
1335+
astconv::ast_region_to_region(self.fcx, lt, Some(param)).into()
13361336
}
13371337
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
13381338
self.fcx.to_ty(ty).into()
@@ -1385,7 +1385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13851385
}
13861386

13871387
let substs = self_ctor_substs.unwrap_or_else(|| {
1388-
AstConv::create_substs_for_generic_args(
1388+
astconv::generics::create_substs_for_generic_args(
13891389
tcx,
13901390
def_id,
13911391
&[][..],

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::astconv::AstConv;
1+
use crate::astconv::{self, AstConv};
22
use crate::check::coercion::CoerceMany;
33
use crate::check::method::MethodCallee;
44
use crate::check::Expectation::*;
@@ -860,7 +860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
860860
match *qpath {
861861
QPath::Resolved(ref maybe_qself, ref path) => {
862862
let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself));
863-
let ty = AstConv::res_to_ty(self, self_ty, path, true);
863+
let ty = astconv::res_to_ty(self, self_ty, path, true);
864864
(path.res, ty)
865865
}
866866
QPath::TypeRelative(ref qself, ref segment) => {
@@ -872,7 +872,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
872872
Res::Err
873873
};
874874
let result =
875-
AstConv::associated_path_to_ty(self, hir_id, path_span, ty, res, segment, true);
875+
astconv::associated_path_to_ty(self, hir_id, path_span, ty, res, segment, true);
876876
let ty = result.map(|(ty, _, _)| ty).unwrap_or_else(|_| self.tcx().ty_error());
877877
let result = result.map(|(_, kind, def_id)| (kind, def_id));
878878

@@ -985,7 +985,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
985985
// would trigger in `is_send::<T::AssocType>();`
986986
// from `typeck-default-trait-impl-assoc-type.rs`.
987987
} else {
988-
let ty = AstConv::ast_ty_to_ty(self, hir_ty);
988+
let ty = astconv::ast_ty_to_ty(self, hir_ty);
989989
let ty = self.resolve_vars_if_possible(ty);
990990
if ty == predicate.self_ty() {
991991
error.obligation.cause.make_mut().span = hir_ty.span;

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use _impl::*;
66
pub use checks::*;
77
pub use suggestions::*;
88

9-
use crate::astconv::AstConv;
9+
use crate::astconv::{self, AstConv};
1010
use crate::check::coercion::DynamicCoerceMany;
1111
use crate::check::{Diverges, EnclosingBreakables, Inherited, UnsafetyState};
1212

@@ -265,7 +265,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
265265
poly_trait_ref,
266266
);
267267

268-
let item_substs = <dyn AstConv<'tcx>>::create_substs_for_associated_item(
268+
let item_substs = astconv::create_substs_for_associated_item(
269269
self,
270270
self.tcx,
271271
span,

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::FnCtxt;
2-
use crate::astconv::AstConv;
2+
use crate::astconv;
33

44
use rustc_ast::util::parser::ExprPrecedence;
55
use rustc_span::{self, Span};
@@ -419,7 +419,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
419419
// are not, the expectation must have been caused by something else.
420420
debug!("suggest_missing_return_type: return type {:?} node {:?}", ty, ty.kind);
421421
let sp = ty.span;
422-
let ty = AstConv::ast_ty_to_ty(self, ty);
422+
let ty = astconv::ast_ty_to_ty(self, ty);
423423
debug!("suggest_missing_return_type: return type {:?}", ty);
424424
debug!("suggest_missing_return_type: expected type {:?}", ty);
425425
if ty.kind() == expected.kind() {

compiler/rustc_typeck/src/check/method/confirm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{probe, MethodCallee};
22

3-
use crate::astconv::{AstConv, CreateSubstsForGenericArgsCtxt};
3+
use crate::astconv::{self, CreateSubstsForGenericArgsCtxt};
44
use crate::check::{callee, FnCtxt};
55
use crate::hir::def_id::DefId;
66
use crate::hir::GenericArg;
@@ -298,7 +298,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
298298
// If they were not explicitly supplied, just construct fresh
299299
// variables.
300300
let generics = self.tcx.generics_of(pick.item.def_id);
301-
let arg_count_correct = AstConv::check_generic_arg_count_for_call(
301+
let arg_count_correct = astconv::generics::check_generic_arg_count_for_call(
302302
self.tcx, self.span, &generics, &seg, true, // `is_method_call`
303303
);
304304

@@ -331,7 +331,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
331331
) -> subst::GenericArg<'tcx> {
332332
match (&param.kind, arg) {
333333
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
334-
AstConv::ast_region_to_region(self.cfcx.fcx, lt, Some(param)).into()
334+
astconv::ast_region_to_region(self.cfcx.fcx, lt, Some(param)).into()
335335
}
336336
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
337337
self.cfcx.to_ty(ty).into()
@@ -352,7 +352,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
352352
self.cfcx.var_for_def(self.cfcx.span, param)
353353
}
354354
}
355-
AstConv::create_substs_for_generic_args(
355+
astconv::generics::create_substs_for_generic_args(
356356
self.tcx,
357357
pick.item.def_id,
358358
parent_substs,

compiler/rustc_typeck/src/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub use expectation::Expectation;
9999
pub use fn_ctxt::*;
100100
pub use inherited::{Inherited, InheritedBuilder};
101101

102-
use crate::astconv::AstConv;
102+
use crate::astconv::{self, AstConv};
103103
use crate::check::gather_locals::GatherLocalsVisitor;
104104
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
105105
use rustc_errors::{pluralize, struct_span_err, Applicability};
@@ -495,7 +495,7 @@ fn typeck_with_fallback<'tcx>(
495495
let fcx = if let (Some(header), Some(decl)) = (fn_header, fn_decl) {
496496
let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() {
497497
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
498-
AstConv::ty_of_fn(
498+
astconv::ty_of_fn(
499499
&fcx,
500500
header.unsafety,
501501
header.abi,
@@ -526,7 +526,7 @@ fn typeck_with_fallback<'tcx>(
526526
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
527527
let expected_type = body_ty
528528
.and_then(|ty| match ty.kind {
529-
hir::TyKind::Infer => Some(AstConv::ast_ty_to_ty(&fcx, ty)),
529+
hir::TyKind::Infer => Some(astconv::ast_ty_to_ty(&fcx, ty)),
530530
_ => None,
531531
})
532532
.unwrap_or_else(|| match tcx.hir().get(id) {

0 commit comments

Comments
 (0)