Skip to content

Commit 43a5cc3

Browse files
committed
Separate the lifetime of the session and the arena in the resolver
1 parent e9ab787 commit 43a5cc3

File tree

12 files changed

+79
-70
lines changed

12 files changed

+79
-70
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ mod boxed_resolver {
8282
struct BoxedResolverInner {
8383
session: Lrc<Session>,
8484
resolver_arenas: Option<ResolverArenas<'static>>,
85-
resolver: Option<Resolver<'static>>,
85+
resolver: Option<Resolver<'static, 'static>>,
8686
_pin: PhantomPinned,
8787
}
8888

@@ -98,7 +98,10 @@ mod boxed_resolver {
9898
impl BoxedResolver {
9999
pub(super) fn new(
100100
session: Lrc<Session>,
101-
make_resolver: impl for<'a> FnOnce(&'a Session, &'a ResolverArenas<'a>) -> Resolver<'a>,
101+
make_resolver: impl for<'a, 'tcx> FnOnce(
102+
&'tcx Session,
103+
&'a ResolverArenas<'a>,
104+
) -> Resolver<'a, 'tcx>,
102105
) -> BoxedResolver {
103106
let mut boxed_resolver = Box::new(BoxedResolverInner {
104107
session,
@@ -121,7 +124,10 @@ mod boxed_resolver {
121124
}
122125
}
123126

124-
pub fn access<F: for<'a> FnOnce(&mut Resolver<'a>) -> R, R>(&mut self, f: F) -> R {
127+
pub fn access<F: for<'a, 'tcx> FnOnce(&mut Resolver<'a, 'tcx>) -> R, R>(
128+
&mut self,
129+
f: F,
130+
) -> R {
125131
// SAFETY: The resolver doesn't need to be pinned.
126132
let mut resolver = unsafe {
127133
self.0.as_mut().map_unchecked_mut(|boxed_resolver| &mut boxed_resolver.resolver)
@@ -256,7 +262,7 @@ pub fn configure_and_expand(
256262
lint_store: &LintStore,
257263
mut krate: ast::Crate,
258264
crate_name: Symbol,
259-
resolver: &mut Resolver<'_>,
265+
resolver: &mut Resolver<'_, '_>,
260266
) -> Result<ast::Crate> {
261267
trace!("configure_and_expand");
262268
pre_expansion_lint(sess, lint_store, resolver.registered_tools(), &krate, crate_name);

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span,
6565
}
6666
}
6767

68-
impl<'a> Resolver<'a> {
68+
impl<'a, 'tcx> Resolver<'a, 'tcx> {
6969
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
7070
/// otherwise, reports an error.
7171
pub(crate) fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
@@ -214,18 +214,18 @@ impl<'a> Resolver<'a> {
214214
}
215215
}
216216

217-
struct BuildReducedGraphVisitor<'a, 'b> {
218-
r: &'b mut Resolver<'a>,
217+
struct BuildReducedGraphVisitor<'a, 'b, 'tcx> {
218+
r: &'b mut Resolver<'a, 'tcx>,
219219
parent_scope: ParentScope<'a>,
220220
}
221221

222-
impl<'a> AsMut<Resolver<'a>> for BuildReducedGraphVisitor<'a, '_> {
223-
fn as_mut(&mut self) -> &mut Resolver<'a> {
222+
impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for BuildReducedGraphVisitor<'a, '_, 'tcx> {
223+
fn as_mut(&mut self) -> &mut Resolver<'a, 'tcx> {
224224
self.r
225225
}
226226
}
227227

228-
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
228+
impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
229229
fn resolve_visibility(&mut self, vis: &ast::Visibility) -> ty::Visibility {
230230
self.try_resolve_visibility(vis, true).unwrap_or_else(|err| {
231231
self.r.report_vis_error(err);
@@ -1315,7 +1315,7 @@ macro_rules! method {
13151315
};
13161316
}
13171317

1318-
impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
1318+
impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
13191319
method!(visit_expr: ast::Expr, ast::ExprKind::MacCall, walk_expr);
13201320
method!(visit_pat: ast::Pat, ast::PatKind::MacCall, walk_pat);
13211321
method!(visit_ty: ast::Ty, ast::TyKind::MacCall, walk_ty);

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ impl<'a> UnusedImport<'a> {
4949
}
5050
}
5151

52-
struct UnusedImportCheckVisitor<'a, 'b> {
53-
r: &'a mut Resolver<'b>,
52+
struct UnusedImportCheckVisitor<'a, 'b, 'tcx> {
53+
r: &'a mut Resolver<'b, 'tcx>,
5454
/// All the (so far) unused imports, grouped path list
5555
unused_imports: FxIndexMap<ast::NodeId, UnusedImport<'a>>,
5656
base_use_tree: Option<&'a ast::UseTree>,
5757
base_id: ast::NodeId,
5858
item_span: Span,
5959
}
6060

61-
impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
61+
impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
6262
// We have information about whether `use` (import) items are actually
6363
// used now. If an import is not used at all, we signal a lint error.
6464
fn check_import(&mut self, id: ast::NodeId) {
@@ -94,7 +94,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
9494
}
9595
}
9696

97-
impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
97+
impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
9898
fn visit_item(&mut self, item: &'a ast::Item) {
9999
self.item_span = item.span_with_attributes();
100100

@@ -222,7 +222,7 @@ fn calc_unused_spans(
222222
}
223223
}
224224

225-
impl Resolver<'_> {
225+
impl Resolver<'_, '_> {
226226
pub(crate) fn check_unused(&mut self, krate: &ast::Crate) {
227227
for import in self.potentially_unused_imports.iter() {
228228
match import.kind {

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::symbol::sym;
99
use rustc_span::Span;
1010

1111
pub(crate) fn collect_definitions(
12-
resolver: &mut Resolver<'_>,
12+
resolver: &mut Resolver<'_, '_>,
1313
fragment: &AstFragment,
1414
expansion: LocalExpnId,
1515
) {
@@ -18,14 +18,14 @@ pub(crate) fn collect_definitions(
1818
}
1919

2020
/// Creates `DefId`s for nodes in the AST.
21-
struct DefCollector<'a, 'b> {
22-
resolver: &'a mut Resolver<'b>,
21+
struct DefCollector<'a, 'b, 'tcx> {
22+
resolver: &'a mut Resolver<'b, 'tcx>,
2323
parent_def: LocalDefId,
2424
impl_trait_context: ImplTraitContext,
2525
expansion: LocalExpnId,
2626
}
2727

28-
impl<'a, 'b> DefCollector<'a, 'b> {
28+
impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
2929
fn create_def(&mut self, node_id: NodeId, data: DefPathData, span: Span) -> LocalDefId {
3030
let parent_def = self.parent_def;
3131
debug!("create_def(node_id={:?}, data={:?}, parent_def={:?})", node_id, data, parent_def);
@@ -81,7 +81,7 @@ impl<'a, 'b> DefCollector<'a, 'b> {
8181
}
8282
}
8383

84-
impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
84+
impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
8585
fn visit_item(&mut self, i: &'a Item) {
8686
debug!("visit_item: {:?}", i);
8787

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn reduce_impl_span_to_impl_keyword(sm: &SourceMap, impl_span: Span) -> Span {
114114
sm.span_until_whitespace(impl_span)
115115
}
116116

117-
impl<'a> Resolver<'a> {
117+
impl<'a, 'tcx> Resolver<'a, 'tcx> {
118118
pub(crate) fn report_errors(&mut self, krate: &Crate) {
119119
self.report_with_use_injections(krate);
120120

@@ -1883,7 +1883,7 @@ impl<'a> Resolver<'a> {
18831883
}
18841884
}
18851885

1886-
impl<'a, 'b> ImportResolver<'a, 'b> {
1886+
impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
18871887
/// Adds suggestions for a path that cannot be resolved.
18881888
pub(crate) fn make_path_suggestion(
18891889
&mut self,

compiler/rustc_resolve/src/effective_visibilities.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl ParentId<'_> {
2929
}
3030
}
3131

32-
pub(crate) struct EffectiveVisibilitiesVisitor<'r, 'a> {
33-
r: &'r mut Resolver<'a>,
32+
pub(crate) struct EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
33+
r: &'r mut Resolver<'a, 'tcx>,
3434
def_effective_visibilities: EffectiveVisibilities,
3535
/// While walking import chains we need to track effective visibilities per-binding, and def id
3636
/// keys in `Resolver::effective_visibilities` are not enough for that, because multiple
@@ -41,7 +41,7 @@ pub(crate) struct EffectiveVisibilitiesVisitor<'r, 'a> {
4141
changed: bool,
4242
}
4343

44-
impl Resolver<'_> {
44+
impl Resolver<'_, '_> {
4545
fn nearest_normal_mod(&mut self, def_id: LocalDefId) -> LocalDefId {
4646
self.get_nearest_non_block_module(def_id.to_def_id()).nearest_parent_mod().expect_local()
4747
}
@@ -67,18 +67,21 @@ impl Resolver<'_> {
6767
}
6868
}
6969

70-
impl<'a, 'b> IntoDefIdTree for &'b mut Resolver<'a> {
71-
type Tree = &'b Resolver<'a>;
70+
impl<'a, 'b, 'tcx> IntoDefIdTree for &'b mut Resolver<'a, 'tcx> {
71+
type Tree = &'b Resolver<'a, 'tcx>;
7272
fn tree(self) -> Self::Tree {
7373
self
7474
}
7575
}
7676

77-
impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
77+
impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
7878
/// Fills the `Resolver::effective_visibilities` table with public & exported items
7979
/// For now, this doesn't resolve macros (FIXME) and cannot resolve Impl, as we
8080
/// need access to a TyCtxt for that.
81-
pub(crate) fn compute_effective_visibilities<'c>(r: &'r mut Resolver<'a>, krate: &'c Crate) {
81+
pub(crate) fn compute_effective_visibilities<'c>(
82+
r: &'r mut Resolver<'a, 'tcx>,
83+
krate: &'c Crate,
84+
) {
8285
let mut visitor = EffectiveVisibilitiesVisitor {
8386
r,
8487
def_effective_visibilities: Default::default(),
@@ -192,7 +195,7 @@ impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
192195
}
193196
}
194197

195-
impl<'r, 'ast> Visitor<'ast> for EffectiveVisibilitiesVisitor<'ast, 'r> {
198+
impl<'r, 'ast, 'tcx> Visitor<'ast> for EffectiveVisibilitiesVisitor<'ast, 'r, 'tcx> {
196199
fn visit_item(&mut self, item: &'ast ast::Item) {
197200
let def_id = self.r.local_def_id(item.id);
198201
// Update effective visibilities of nested items.

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use RibKind::*;
2828

2929
type Visibility = ty::Visibility<LocalDefId>;
3030

31-
impl<'a> Resolver<'a> {
31+
impl<'a, 'tcx> Resolver<'a, 'tcx> {
3232
/// A generic scope visitor.
3333
/// Visits scopes in order to resolve some identifier in them or perform other actions.
3434
/// If the callback returns `Some` result, we stop visiting scopes and return it.

compiler/rustc_resolve/src/imports.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn pub_use_of_private_extern_crate_hack(import: &Import<'_>, binding: &NameBindi
225225
}
226226
}
227227

228-
impl<'a> Resolver<'a> {
228+
impl<'a, 'tcx> Resolver<'a, 'tcx> {
229229
/// Given a binding and an import that resolves to it,
230230
/// return the corresponding binding defined by the import.
231231
pub(crate) fn import(
@@ -333,7 +333,7 @@ impl<'a> Resolver<'a> {
333333
// If the resolution becomes a success, define it in the module's glob importers.
334334
fn update_resolution<T, F>(&mut self, module: Module<'a>, key: BindingKey, f: F) -> T
335335
where
336-
F: FnOnce(&mut Resolver<'a>, &mut NameResolution<'a>) -> T,
336+
F: FnOnce(&mut Resolver<'a, 'tcx>, &mut NameResolution<'a>) -> T,
337337
{
338338
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
339339
// during which the resolution might end up getting re-defined via a glob cycle.
@@ -405,11 +405,11 @@ struct UnresolvedImportError {
405405
candidates: Option<Vec<ImportSuggestion>>,
406406
}
407407

408-
pub(crate) struct ImportResolver<'a, 'b> {
409-
pub r: &'a mut Resolver<'b>,
408+
pub(crate) struct ImportResolver<'a, 'b, 'tcx> {
409+
pub r: &'a mut Resolver<'b, 'tcx>,
410410
}
411411

412-
impl<'a, 'b> ImportResolver<'a, 'b> {
412+
impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
413413
// Import resolution
414414
//
415415
// This is a fixed-point algorithm. We resolve imports until our efforts

compiler/rustc_resolve/src/late.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ enum MaybeExported<'a> {
505505
}
506506

507507
impl MaybeExported<'_> {
508-
fn eval(self, r: &Resolver<'_>) -> bool {
508+
fn eval(self, r: &Resolver<'_, '_>) -> bool {
509509
let def_id = match self {
510510
MaybeExported::Ok(node_id) => Some(r.local_def_id(node_id)),
511511
MaybeExported::Impl(Some(trait_def_id)) | MaybeExported::ImplItem(Ok(trait_def_id)) => {
@@ -584,8 +584,8 @@ struct DiagnosticMetadata<'ast> {
584584
current_elision_failures: Vec<MissingLifetime>,
585585
}
586586

587-
struct LateResolutionVisitor<'a, 'b, 'ast> {
588-
r: &'b mut Resolver<'a>,
587+
struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
588+
r: &'b mut Resolver<'a, 'tcx>,
589589

590590
/// The module that represents the current item scope.
591591
parent_scope: ParentScope<'a>,
@@ -628,7 +628,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
628628
}
629629

630630
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
631-
impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
631+
impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
632632
fn visit_attribute(&mut self, _: &'ast Attribute) {
633633
// We do not want to resolve expressions that appear in attributes,
634634
// as they do not correspond to actual code.
@@ -1199,8 +1199,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
11991199
}
12001200
}
12011201

1202-
impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1203-
fn new(resolver: &'b mut Resolver<'a>) -> LateResolutionVisitor<'a, 'b, 'ast> {
1202+
impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1203+
fn new(resolver: &'b mut Resolver<'a, 'tcx>) -> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
12041204
// During late resolution we only track the module component of the parent scope,
12051205
// although it may be useful to track other components as well for diagnostics.
12061206
let graph_root = resolver.graph_root;
@@ -2029,13 +2029,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
20292029

20302030
/// List all the lifetimes that appear in the provided type.
20312031
fn find_lifetime_for_self(&self, ty: &'ast Ty) -> Set1<LifetimeRes> {
2032-
struct SelfVisitor<'r, 'a> {
2033-
r: &'r Resolver<'a>,
2032+
struct SelfVisitor<'r, 'a, 'tcx> {
2033+
r: &'r Resolver<'a, 'tcx>,
20342034
impl_self: Option<Res>,
20352035
lifetime: Set1<LifetimeRes>,
20362036
}
20372037

2038-
impl SelfVisitor<'_, '_> {
2038+
impl SelfVisitor<'_, '_, '_> {
20392039
// Look for `self: &'a Self` - also desugared from `&'a self`,
20402040
// and if that matches, use it for elision and return early.
20412041
fn is_self_ty(&self, ty: &Ty) -> bool {
@@ -2053,7 +2053,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
20532053
}
20542054
}
20552055

2056-
impl<'a> Visitor<'a> for SelfVisitor<'_, '_> {
2056+
impl<'a> Visitor<'a> for SelfVisitor<'_, '_, '_> {
20572057
fn visit_ty(&mut self, ty: &'a Ty) {
20582058
trace!("SelfVisitor considering ty={:?}", ty);
20592059
if let TyKind::Ref(lt, ref mt) = ty.kind && self.is_self_ty(&mt.ty) {
@@ -4288,13 +4288,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
42884288
}
42894289
}
42904290

4291-
struct LifetimeCountVisitor<'a, 'b> {
4292-
r: &'b mut Resolver<'a>,
4291+
struct LifetimeCountVisitor<'a, 'b, 'tcx> {
4292+
r: &'b mut Resolver<'a, 'tcx>,
42934293
}
42944294

42954295
/// Walks the whole crate in DFS order, visiting each item, counting the declared number of
42964296
/// lifetime generic parameters.
4297-
impl<'ast> Visitor<'ast> for LifetimeCountVisitor<'_, '_> {
4297+
impl<'ast> Visitor<'ast> for LifetimeCountVisitor<'_, '_, '_> {
42984298
fn visit_item(&mut self, item: &'ast Item) {
42994299
match &item.kind {
43004300
ItemKind::TyAlias(box TyAlias { ref generics, .. })
@@ -4328,7 +4328,7 @@ impl<'ast> Visitor<'ast> for LifetimeCountVisitor<'_, '_> {
43284328
}
43294329
}
43304330

4331-
impl<'a> Resolver<'a> {
4331+
impl<'a, 'tcx> Resolver<'a, 'tcx> {
43324332
pub(crate) fn late_resolve_crate(&mut self, krate: &Crate) {
43334333
visit::walk_crate(&mut LifetimeCountVisitor { r: self }, krate);
43344334
let mut late_resolution_visitor = LateResolutionVisitor::new(self);

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl TypoCandidate {
166166
}
167167
}
168168

169-
impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
169+
impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
170170
fn def_span(&self, def_id: DefId) -> Option<Span> {
171171
match def_id.krate {
172172
LOCAL_CRATE => self.r.opt_span(def_id),
@@ -318,7 +318,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
318318
span: Span,
319319
source: PathSource<'_>,
320320
res: Option<Res>,
321-
) -> (DiagnosticBuilder<'a, ErrorGuaranteed>, Vec<ImportSuggestion>) {
321+
) -> (DiagnosticBuilder<'tcx, ErrorGuaranteed>, Vec<ImportSuggestion>) {
322322
debug!(?res, ?source);
323323
let base_error = self.make_base_error(path, span, source, res);
324324
let code = source.error_code(res.is_some());

0 commit comments

Comments
 (0)