Skip to content

Commit 93ec7cd

Browse files
committed
Rename hygiene vars and fields to span_map
1 parent 8707c13 commit 93ec7cd

File tree

13 files changed

+85
-83
lines changed

13 files changed

+85
-83
lines changed

crates/hir-def/src/attr.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -415,35 +415,32 @@ impl AttrsWithOwner {
415415
AttrDefId::StaticId(it) => attrs_from_item_tree_assoc(db, it),
416416
AttrDefId::FunctionId(it) => attrs_from_item_tree_assoc(db, it),
417417
AttrDefId::TypeAliasId(it) => attrs_from_item_tree_assoc(db, it),
418-
AttrDefId::GenericParamId(it) => {
419-
// FIXME: we could probably just make these relative to the params?
420-
match it {
421-
GenericParamId::ConstParamId(it) => {
422-
let src = it.parent().child_source(db);
423-
RawAttrs::from_attrs_owner(
424-
db.upcast(),
425-
src.with_value(&src.value[it.local_id()]),
426-
db.span_map(src.file_id).as_ref(),
427-
)
428-
}
429-
GenericParamId::TypeParamId(it) => {
430-
let src = it.parent().child_source(db);
431-
RawAttrs::from_attrs_owner(
432-
db.upcast(),
433-
src.with_value(&src.value[it.local_id()]),
434-
db.span_map(src.file_id).as_ref(),
435-
)
436-
}
437-
GenericParamId::LifetimeParamId(it) => {
438-
let src = it.parent.child_source(db);
439-
RawAttrs::from_attrs_owner(
440-
db.upcast(),
441-
src.with_value(&src.value[it.local_id]),
442-
db.span_map(src.file_id).as_ref(),
443-
)
444-
}
418+
AttrDefId::GenericParamId(it) => match it {
419+
GenericParamId::ConstParamId(it) => {
420+
let src = it.parent().child_source(db);
421+
RawAttrs::from_attrs_owner(
422+
db.upcast(),
423+
src.with_value(&src.value[it.local_id()]),
424+
db.span_map(src.file_id).as_ref(),
425+
)
445426
}
446-
}
427+
GenericParamId::TypeParamId(it) => {
428+
let src = it.parent().child_source(db);
429+
RawAttrs::from_attrs_owner(
430+
db.upcast(),
431+
src.with_value(&src.value[it.local_id()]),
432+
db.span_map(src.file_id).as_ref(),
433+
)
434+
}
435+
GenericParamId::LifetimeParamId(it) => {
436+
let src = it.parent.child_source(db);
437+
RawAttrs::from_attrs_owner(
438+
db.upcast(),
439+
src.with_value(&src.value[it.local_id]),
440+
db.span_map(src.file_id).as_ref(),
441+
)
442+
}
443+
},
447444
AttrDefId::ExternBlockId(it) => attrs_from_item_tree_loc(db, it),
448445
AttrDefId::ExternCrateId(it) => attrs_from_item_tree_loc(db, it),
449446
AttrDefId::UseId(it) => attrs_from_item_tree_loc(db, it),

crates/hir-def/src/expander.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
#[derive(Debug)]
1919
pub struct Expander {
2020
cfg_options: CfgOptions,
21-
hygiene: SpanMap,
21+
span_map: SpanMap,
2222
krate: CrateId,
2323
pub(crate) current_file_id: HirFileId,
2424
pub(crate) module: ModuleId,
@@ -41,7 +41,7 @@ impl Expander {
4141
recursion_depth: 0,
4242
recursion_limit,
4343
cfg_options: db.crate_graph()[module.krate].cfg_options.clone(),
44-
hygiene: db.span_map(current_file_id),
44+
span_map: db.span_map(current_file_id),
4545
krate: module.krate,
4646
}
4747
}
@@ -95,7 +95,7 @@ impl Expander {
9595
}
9696

9797
pub fn exit(&mut self, db: &dyn DefDatabase, mut mark: Mark) {
98-
self.hygiene = db.span_map(mark.file_id);
98+
self.span_map = db.span_map(mark.file_id);
9999
self.current_file_id = mark.file_id;
100100
if self.recursion_depth == u32::MAX {
101101
// Recursion limit has been reached somewhere in the macro expansion tree. Reset the
@@ -110,15 +110,15 @@ impl Expander {
110110
}
111111

112112
pub fn ctx<'a>(&self, db: &'a dyn DefDatabase) -> LowerCtx<'a> {
113-
LowerCtx::new(db, self.hygiene.clone(), self.current_file_id)
113+
LowerCtx::new(db, self.span_map.clone(), self.current_file_id)
114114
}
115115

116116
pub(crate) fn to_source<T>(&self, value: T) -> InFile<T> {
117117
InFile { file_id: self.current_file_id, value }
118118
}
119119

120120
pub(crate) fn parse_attrs(&self, db: &dyn DefDatabase, owner: &dyn ast::HasAttrs) -> Attrs {
121-
Attrs::filter(db, self.krate, RawAttrs::new(db.upcast(), owner, self.hygiene.as_ref()))
121+
Attrs::filter(db, self.krate, RawAttrs::new(db.upcast(), owner, self.span_map.as_ref()))
122122
}
123123

124124
pub(crate) fn cfg_options(&self) -> &CfgOptions {
@@ -130,7 +130,7 @@ impl Expander {
130130
}
131131

132132
pub(crate) fn parse_path(&mut self, db: &dyn DefDatabase, path: ast::Path) -> Option<Path> {
133-
let ctx = LowerCtx::new(db, self.hygiene.clone(), self.current_file_id);
133+
let ctx = LowerCtx::new(db, self.span_map.clone(), self.current_file_id);
134134
Path::from_src(path, &ctx)
135135
}
136136

@@ -174,7 +174,7 @@ impl Expander {
174174
let parse = value.cast::<T>()?;
175175

176176
self.recursion_depth += 1;
177-
self.hygiene = db.span_map(file_id);
177+
self.span_map = db.span_map(file_id);
178178
let old_file_id = std::mem::replace(&mut self.current_file_id, file_id);
179179
let mark = Mark {
180180
file_id: old_file_id,

crates/hir-def/src/item_tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ impl Use {
776776
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
777777
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
778778
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
779-
let hygiene = db.span_map(file_id);
780-
let (_, source_map) = lower::lower_use_tree(db, hygiene.as_ref(), ast_use_tree)
779+
let span_map = db.span_map(file_id);
780+
let (_, source_map) = lower::lower_use_tree(db, span_map.as_ref(), ast_use_tree)
781781
.expect("failed to lower use tree");
782782
source_map[index].clone()
783783
}
@@ -791,8 +791,8 @@ impl Use {
791791
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
792792
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
793793
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
794-
let hygiene = db.span_map(file_id);
795-
lower::lower_use_tree(db, hygiene.as_ref(), ast_use_tree)
794+
let span_map = db.span_map(file_id);
795+
lower::lower_use_tree(db, span_map.as_ref(), ast_use_tree)
796796
.expect("failed to lower use tree")
797797
.1
798798
}

crates/hir-def/src/item_tree/lower.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ impl<'a> Ctx<'a> {
657657
}
658658

659659
fn lower_visibility(&mut self, item: &dyn ast::HasVisibility) -> RawVisibilityId {
660-
let vis = RawVisibility::from_ast_with_hygiene(self.db, item.visibility(), self.span_map());
660+
let vis =
661+
RawVisibility::from_ast_with_span_map(self.db, item.visibility(), self.span_map());
661662
self.data().vis.alloc(vis)
662663
}
663664

@@ -735,7 +736,7 @@ fn lower_abi(abi: ast::Abi) -> Interned<str> {
735736

736737
struct UseTreeLowering<'a> {
737738
db: &'a dyn DefDatabase,
738-
hygiene: SpanMapRef<'a>,
739+
span_map: SpanMapRef<'a>,
739740
mapping: Arena<ast::UseTree>,
740741
}
741742

@@ -748,7 +749,7 @@ impl UseTreeLowering<'_> {
748749
// E.g. `use something::{inner}` (prefix is `None`, path is `something`)
749750
// or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`)
750751
Some(path) => {
751-
match ModPath::from_src(self.db.upcast(), path, self.hygiene) {
752+
match ModPath::from_src(self.db.upcast(), path, self.span_map) {
752753
Some(it) => Some(it),
753754
None => return None, // FIXME: report errors somewhere
754755
}
@@ -767,7 +768,7 @@ impl UseTreeLowering<'_> {
767768
} else {
768769
let is_glob = tree.star_token().is_some();
769770
let path = match tree.path() {
770-
Some(path) => Some(ModPath::from_src(self.db.upcast(), path, self.hygiene)?),
771+
Some(path) => Some(ModPath::from_src(self.db.upcast(), path, self.span_map)?),
771772
None => None,
772773
};
773774
let alias = tree.rename().map(|a| {
@@ -803,10 +804,10 @@ impl UseTreeLowering<'_> {
803804

804805
pub(crate) fn lower_use_tree(
805806
db: &dyn DefDatabase,
806-
hygiene: SpanMapRef<'_>,
807+
span_map: SpanMapRef<'_>,
807808
tree: ast::UseTree,
808809
) -> Option<(UseTree, Arena<ast::UseTree>)> {
809-
let mut lowering = UseTreeLowering { db, hygiene, mapping: Arena::new() };
810+
let mut lowering = UseTreeLowering { db, span_map, mapping: Arena::new() };
810811
let tree = lowering.lower_use_tree(tree)?;
811812
Some((tree, lowering.mapping))
812813
}

crates/hir-def/src/lower.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,30 @@ use crate::{db::DefDatabase, path::Path};
1313

1414
pub struct LowerCtx<'a> {
1515
pub db: &'a dyn DefDatabase,
16-
hygiene: SpanMap,
16+
span_map: SpanMap,
1717
// FIXME: This optimization is probably pointless, ast id map should pretty much always exist anyways.
1818
ast_id_map: Option<(HirFileId, OnceCell<Arc<AstIdMap>>)>,
1919
}
2020

2121
impl<'a> LowerCtx<'a> {
22-
pub fn new(db: &'a dyn DefDatabase, hygiene: SpanMap, file_id: HirFileId) -> Self {
23-
LowerCtx { db, hygiene, ast_id_map: Some((file_id, OnceCell::new())) }
22+
pub fn new(db: &'a dyn DefDatabase, span_map: SpanMap, file_id: HirFileId) -> Self {
23+
LowerCtx { db, span_map, ast_id_map: Some((file_id, OnceCell::new())) }
2424
}
2525

2626
pub fn with_file_id(db: &'a dyn DefDatabase, file_id: HirFileId) -> Self {
27-
LowerCtx { db, hygiene: db.span_map(file_id), ast_id_map: Some((file_id, OnceCell::new())) }
27+
LowerCtx {
28+
db,
29+
span_map: db.span_map(file_id),
30+
ast_id_map: Some((file_id, OnceCell::new())),
31+
}
2832
}
2933

30-
pub fn with_hygiene(db: &'a dyn DefDatabase, hygiene: SpanMap) -> Self {
31-
LowerCtx { db, hygiene, ast_id_map: None }
34+
pub fn with_span_map(db: &'a dyn DefDatabase, span_map: SpanMap) -> Self {
35+
LowerCtx { db, span_map, ast_id_map: None }
3236
}
3337

3438
pub(crate) fn span_map(&self) -> SpanMapRef<'_> {
35-
self.hygiene.as_ref()
39+
self.span_map.as_ref()
3640
}
3741

3842
pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {

crates/hir-def/src/path/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
2626
let mut type_anchor = None;
2727
let mut segments = Vec::new();
2828
let mut generic_args = Vec::new();
29-
let hygiene = ctx.span_map();
29+
let span_map = ctx.span_map();
3030
loop {
3131
let segment = path.segment()?;
3232

@@ -39,7 +39,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
3939
let name = if name_ref.text() == "$crate" {
4040
kind = resolve_crate_root(
4141
ctx.db.upcast(),
42-
hygiene.span_for_range(name_ref.syntax().text_range()).ctx,
42+
span_map.span_for_range(name_ref.syntax().text_range()).ctx,
4343
)
4444
.map(PathKind::DollarCrate)
4545
.unwrap_or(PathKind::Crate);
@@ -159,7 +159,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
159159
// We follow what it did anyway :)
160160
if segments.len() == 1 && kind == PathKind::Plain {
161161
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
162-
let syn_ctxt = hygiene.span_for_range(path.segment()?.syntax().text_range()).ctx;
162+
let syn_ctxt = span_map.span_for_range(path.segment()?.syntax().text_range()).ctx;
163163
if let Some(macro_call_id) = ctx.db.lookup_intern_syntax_context(syn_ctxt).outer_expn {
164164
if ctx.db.lookup_intern_macro_call(macro_call_id).def.local_inner {
165165
kind = match resolve_crate_root(ctx.db.upcast(), syn_ctxt) {

crates/hir-def/src/visibility.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,30 @@ impl RawVisibility {
3434
db: &dyn DefDatabase,
3535
node: InFile<Option<ast::Visibility>>,
3636
) -> RawVisibility {
37-
Self::from_ast_with_hygiene(db, node.value, db.span_map(node.file_id).as_ref())
37+
Self::from_ast_with_span_map(db, node.value, db.span_map(node.file_id).as_ref())
3838
}
3939

40-
pub(crate) fn from_ast_with_hygiene(
40+
pub(crate) fn from_ast_with_span_map(
4141
db: &dyn DefDatabase,
4242
node: Option<ast::Visibility>,
43-
hygiene: SpanMapRef<'_>,
43+
span_map: SpanMapRef<'_>,
4444
) -> RawVisibility {
45-
Self::from_ast_with_hygiene_and_default(db, node, RawVisibility::private(), hygiene)
45+
Self::from_ast_with_span_map_and_default(db, node, RawVisibility::private(), span_map)
4646
}
4747

48-
pub(crate) fn from_ast_with_hygiene_and_default(
48+
pub(crate) fn from_ast_with_span_map_and_default(
4949
db: &dyn DefDatabase,
5050
node: Option<ast::Visibility>,
5151
default: RawVisibility,
52-
hygiene: SpanMapRef<'_>,
52+
span_map: SpanMapRef<'_>,
5353
) -> RawVisibility {
5454
let node = match node {
5555
None => return default,
5656
Some(node) => node,
5757
};
5858
match node.kind() {
5959
ast::VisibilityKind::In(path) => {
60-
let path = ModPath::from_src(db.upcast(), path, hygiene);
60+
let path = ModPath::from_src(db.upcast(), path, span_map);
6161
let path = match path {
6262
None => return RawVisibility::private(),
6363
Some(path) => path,

crates/hir-expand/src/attrs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ impl RawAttrs {
4242
pub fn new(
4343
db: &dyn ExpandDatabase,
4444
owner: &dyn ast::HasAttrs,
45-
hygiene: SpanMapRef<'_>,
45+
span_map: SpanMapRef<'_>,
4646
) -> Self {
4747
let entries = collect_attrs(owner)
4848
.filter_map(|(id, attr)| match attr {
4949
Either::Left(attr) => {
50-
attr.meta().and_then(|meta| Attr::from_src(db, meta, hygiene, id))
50+
attr.meta().and_then(|meta| Attr::from_src(db, meta, span_map, id))
5151
}
5252
Either::Right(comment) => comment.doc_comment().map(|doc| Attr {
5353
id,
5454
input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))),
5555
path: Interned::new(ModPath::from(crate::name!(doc))),
56-
ctxt: hygiene.span_for_range(comment.syntax().text_range()).ctx,
56+
ctxt: span_map.span_for_range(comment.syntax().text_range()).ctx,
5757
}),
5858
})
5959
.collect::<Vec<_>>();
@@ -66,9 +66,9 @@ impl RawAttrs {
6666
pub fn from_attrs_owner(
6767
db: &dyn ExpandDatabase,
6868
owner: InFile<&dyn ast::HasAttrs>,
69-
hygiene: SpanMapRef<'_>,
69+
span_map: SpanMapRef<'_>,
7070
) -> Self {
71-
Self::new(db, owner.value, hygiene)
71+
Self::new(db, owner.value, span_map)
7272
}
7373

7474
pub fn merge(&self, other: Self) -> Self {
@@ -216,23 +216,23 @@ impl Attr {
216216
fn from_src(
217217
db: &dyn ExpandDatabase,
218218
ast: ast::Meta,
219-
hygiene: SpanMapRef<'_>,
219+
span_map: SpanMapRef<'_>,
220220
id: AttrId,
221221
) -> Option<Attr> {
222-
let path = Interned::new(ModPath::from_src(db, ast.path()?, hygiene)?);
222+
let path = Interned::new(ModPath::from_src(db, ast.path()?, span_map)?);
223223
let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() {
224224
let value = match lit.kind() {
225225
ast::LiteralKind::String(string) => string.value()?.into(),
226226
_ => lit.syntax().first_token()?.text().trim_matches('"').into(),
227227
};
228228
Some(Interned::new(AttrInput::Literal(value)))
229229
} else if let Some(tt) = ast.token_tree() {
230-
let tree = syntax_node_to_token_tree(tt.syntax(), hygiene);
230+
let tree = syntax_node_to_token_tree(tt.syntax(), span_map);
231231
Some(Interned::new(AttrInput::TokenTree(Box::new(tree))))
232232
} else {
233233
None
234234
};
235-
Some(Attr { id, path, input, ctxt: hygiene.span_for_range(ast.syntax().text_range()).ctx })
235+
Some(Attr { id, path, input, ctxt: span_map.span_for_range(ast.syntax().text_range()).ctx })
236236
}
237237

238238
fn from_tt(db: &dyn ExpandDatabase, tt: &tt::Subtree, id: AttrId) -> Option<Attr> {

crates/hir-expand/src/eager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn lazy_expand(
127127

128128
fn eager_macro_recur(
129129
db: &dyn ExpandDatabase,
130-
hygiene: &ExpansionSpanMap,
130+
span_map: &ExpansionSpanMap,
131131
curr: InFile<SyntaxNode>,
132132
krate: CrateId,
133133
call_site: SyntaxContextId,
@@ -170,7 +170,7 @@ fn eager_macro_recur(
170170
};
171171
let def = match call
172172
.path()
173-
.and_then(|path| ModPath::from_src(db, path, SpanMapRef::ExpansionSpanMap(hygiene)))
173+
.and_then(|path| ModPath::from_src(db, path, SpanMapRef::ExpansionSpanMap(span_map)))
174174
{
175175
Some(path) => match macro_resolver(path.clone()) {
176176
Some(def) => def,

0 commit comments

Comments
 (0)