Skip to content

Commit a8921b7

Browse files
committed
Make AST lowering a query.
1 parent 24be7ce commit a8921b7

File tree

20 files changed

+122
-155
lines changed

20 files changed

+122
-155
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,7 @@ name = "rustc_hir"
38093809
version = "0.0.0"
38103810
dependencies = [
38113811
"odht",
3812+
"rustc_arena",
38123813
"rustc_ast",
38133814
"rustc_data_structures",
38143815
"rustc_error_messages",

compiler/rustc_ast_lowering/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_target::asm;
1616
use std::collections::hash_map::Entry;
1717
use std::fmt::Write;
1818

19-
impl<'a, 'hir> LoweringContext<'a, 'hir> {
19+
impl<'hir> LoweringContext<'hir> {
2020
crate fn lower_inline_asm(&mut self, sp: Span, asm: &InlineAsm) -> &'hir hir::InlineAsm<'hir> {
2121
// Rustdoc needs to support asm! from foreign architectures: don't try
2222
// lowering the register constraints in this case.

compiler/rustc_ast_lowering/src/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::{sym, DesugaringKind};
66

77
use smallvec::SmallVec;
88

9-
impl<'a, 'hir> LoweringContext<'a, 'hir> {
9+
impl<'hir> LoweringContext<'hir> {
1010
pub(super) fn lower_block(
1111
&mut self,
1212
b: &Block,

compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
1616
use rustc_span::symbol::{sym, Ident};
1717
use rustc_span::DUMMY_SP;
1818

19-
impl<'hir> LoweringContext<'_, 'hir> {
19+
impl<'hir> LoweringContext<'hir> {
2020
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
2121
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
2222
}
@@ -947,7 +947,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
947947
whole_span: Span,
948948
) -> hir::ExprKind<'hir> {
949949
// Return early in case of an ordinary assignment.
950-
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool {
950+
fn is_ordinary(lower_ctx: &mut LoweringContext<'_>, lhs: &Expr) -> bool {
951951
match &lhs.kind {
952952
ExprKind::Array(..)
953953
| ExprKind::Struct(..)

compiler/rustc_ast_lowering/src/item.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::ResolverAstLoweringExt;
22
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
3-
use super::{LoweringContext, ParamMode};
4-
use crate::{Arena, FnDeclKind};
3+
use super::{FnDeclKind, LoweringContext, ParamMode};
54

65
use rustc_ast::ptr::P;
76
use rustc_ast::visit::AssocCtxt;
@@ -12,12 +11,9 @@ use rustc_errors::struct_span_err;
1211
use rustc_hir as hir;
1312
use rustc_hir::def::{DefKind, Res};
1413
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
15-
use rustc_hir::definitions::Definitions;
1614
use rustc_index::vec::{Idx, IndexVec};
17-
use rustc_middle::ty::ResolverOutputs;
18-
use rustc_session::cstore::CrateStoreDyn;
15+
use rustc_middle::ty::{ResolverOutputs, TyCtxt};
1916
use rustc_session::utils::NtToTokenstream;
20-
use rustc_session::Session;
2117
use rustc_span::source_map::DesugaringKind;
2218
use rustc_span::symbol::{kw, sym, Ident};
2319
use rustc_span::Span;
@@ -28,12 +24,9 @@ use tracing::debug;
2824
use std::iter;
2925

3026
pub(super) struct ItemLowerer<'a, 'hir> {
31-
pub(super) sess: &'a Session,
32-
pub(super) definitions: &'a mut Definitions,
33-
pub(super) cstore: &'a CrateStoreDyn,
34-
pub(super) resolver: &'a mut ResolverOutputs,
27+
pub(super) tcx: TyCtxt<'hir>,
28+
pub(super) resolver: &'hir ResolverOutputs,
3529
pub(super) nt_to_tokenstream: NtToTokenstream,
36-
pub(super) arena: &'hir Arena<'hir>,
3730
pub(super) ast_index: &'a IndexVec<LocalDefId, AstOwner<'a>>,
3831
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
3932
}
@@ -62,17 +55,16 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6255
fn with_lctx(
6356
&mut self,
6457
owner: NodeId,
65-
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
58+
f: impl FnOnce(&mut LoweringContext<'hir>) -> hir::OwnerNode<'hir>,
6659
) {
6760
let next_node_id = self.resolver.next_node_id;
6861
let mut lctx = LoweringContext {
6962
// Pseudo-globals.
70-
sess: &self.sess,
71-
definitions: self.definitions,
72-
cstore: self.cstore,
63+
tcx: self.tcx,
64+
sess: &self.tcx.sess,
7365
resolver: self.resolver,
7466
nt_to_tokenstream: self.nt_to_tokenstream,
75-
arena: self.arena,
67+
arena: self.tcx.hir_arena,
7668

7769
// HirId handling.
7870
bodies: Vec::new(),
@@ -145,7 +137,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
145137
let def_id = self.resolver.node_id_to_def_id[&item.id];
146138

147139
let parent_id = {
148-
let parent = self.definitions.def_key(def_id).parent;
140+
let parent = self.tcx.hir().def_key(def_id).parent;
149141
let local_def_index = parent.unwrap();
150142
LocalDefId { local_def_index }
151143
};
@@ -174,7 +166,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
174166
}
175167
}
176168

177-
impl<'hir> LoweringContext<'_, 'hir> {
169+
impl<'hir> LoweringContext<'hir> {
178170
pub(super) fn lower_mod(&mut self, items: &[P<Item>], spans: &ModSpans) -> hir::Mod<'hir> {
179171
hir::Mod {
180172
spans: hir::ModSpans {
@@ -1429,7 +1421,7 @@ pub(super) struct GenericsCtor<'hir> {
14291421
}
14301422

14311423
impl<'hir> GenericsCtor<'hir> {
1432-
pub(super) fn into_generics(self, arena: &'hir Arena<'hir>) -> hir::Generics<'hir> {
1424+
pub(super) fn into_generics(self, arena: &'hir hir::Arena<'hir>) -> hir::Generics<'hir> {
14331425
hir::Generics {
14341426
params: arena.alloc_from_iter(self.params),
14351427
where_clause: self.where_clause,

0 commit comments

Comments
 (0)