Skip to content

Commit 0380869

Browse files
committed
Auto merge of rust-lang#16145 - Veykril:span-crate, r=Veykril
internal: Split out a span crate Allows getting rid of some of the dependency injection generics that my rewrite introduced
2 parents cfc959d + ec61623 commit 0380869

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+588
-514
lines changed

Cargo.lock

+19-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ proc-macro-srv-cli = { path = "./crates/proc-macro-srv-cli", version = "0.0.0" }
7171
profile = { path = "./crates/profile", version = "0.0.0" }
7272
project-model = { path = "./crates/project-model", version = "0.0.0" }
7373
sourcegen = { path = "./crates/sourcegen", version = "0.0.0" }
74+
span = { path = "./crates/span", version = "0.0.0" }
7475
stdx = { path = "./crates/stdx", version = "0.0.0" }
7576
syntax = { path = "./crates/syntax", version = "0.0.0" }
7677
test-utils = { path = "./crates/test-utils", version = "0.0.0" }

crates/base-db/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ profile.workspace = true
2323
stdx.workspace = true
2424
syntax.workspace = true
2525
test-utils.workspace = true
26-
tt.workspace = true
2726
vfs.workspace = true
27+
span.workspace = true

crates/base-db/src/lib.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
mod input;
66
mod change;
7-
pub mod span;
87

98
use std::panic;
109

1110
use rustc_hash::FxHashSet;
12-
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
11+
use syntax::{ast, Parse, SourceFile};
1312
use triomphe::Arc;
1413

1514
pub use crate::{
@@ -21,6 +20,7 @@ pub use crate::{
2120
},
2221
};
2322
pub use salsa::{self, Cancelled};
23+
pub use span::{FilePosition, FileRange};
2424
pub use vfs::{file_set::FileSet, AnchoredPath, AnchoredPathBuf, FileId, VfsPath};
2525

2626
#[macro_export]
@@ -41,18 +41,6 @@ pub trait Upcast<T: ?Sized> {
4141
fn upcast(&self) -> &T;
4242
}
4343

44-
#[derive(Clone, Copy, Debug)]
45-
pub struct FilePosition {
46-
pub file_id: FileId,
47-
pub offset: TextSize,
48-
}
49-
50-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
51-
pub struct FileRange {
52-
pub file_id: FileId,
53-
pub range: TextRange,
54-
}
55-
5644
pub const DEFAULT_PARSE_LRU_CAP: usize = 128;
5745

5846
pub trait FileLoader {

crates/hir-def/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mbe.workspace = true
4242
cfg.workspace = true
4343
tt.workspace = true
4444
limit.workspace = true
45+
span.workspace = true
4546

4647

4748
[dev-dependencies]

crates/hir-def/src/attr/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! Currently, it tests `#[doc(hidden)]` and `#[doc(alias)]`.
33
44
use base_db::FileId;
5-
use hir_expand::span::{RealSpanMap, SpanMapRef};
5+
use hir_expand::span_map::{RealSpanMap, SpanMapRef};
66
use mbe::syntax_node_to_token_tree;
77
use syntax::{ast, AstNode};
88

crates/hir-def/src/expander.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use base_db::CrateId;
44
use cfg::CfgOptions;
55
use drop_bomb::DropBomb;
66
use hir_expand::{
7-
attrs::RawAttrs, mod_path::ModPath, span::SpanMap, ExpandError, ExpandResult, HirFileId,
7+
attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, ExpandError, ExpandResult, HirFileId,
88
InFile, MacroCallId,
99
};
1010
use limit::Limit;

crates/hir-def/src/item_tree.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::{
4242
};
4343

4444
use ast::{AstNode, HasName, StructKind};
45-
use base_db::{span::SyntaxContextId, CrateId};
45+
use base_db::CrateId;
4646
use either::Either;
4747
use hir_expand::{
4848
ast_id_map::{AstIdNode, FileAstId},
@@ -55,6 +55,7 @@ use la_arena::{Arena, Idx, IdxRange, RawIdx};
5555
use profile::Count;
5656
use rustc_hash::FxHashMap;
5757
use smallvec::SmallVec;
58+
use span::SyntaxContextId;
5859
use stdx::never;
5960
use syntax::{ast, match_ast, SyntaxKind};
6061
use triomphe::Arc;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::collections::hash_map::Entry;
44

5-
use hir_expand::{ast_id_map::AstIdMap, span::SpanMapRef, HirFileId};
5+
use hir_expand::{ast_id_map::AstIdMap, span_map::SpanMapRef, HirFileId};
66
use syntax::ast::{self, HasModuleItem, HasTypeBounds};
77

88
use crate::{

crates/hir-def/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use std::{
6363
panic::{RefUnwindSafe, UnwindSafe},
6464
};
6565

66-
use base_db::{impl_intern_key, salsa, span::SyntaxContextId, CrateId};
66+
use base_db::{impl_intern_key, salsa, CrateId};
6767
use hir_expand::{
6868
ast_id_map::{AstIdNode, FileAstId},
6969
attrs::{Attr, AttrId, AttrInput},
@@ -80,6 +80,7 @@ use hir_expand::{
8080
use item_tree::ExternBlock;
8181
use la_arena::Idx;
8282
use nameres::DefMap;
83+
use span::SyntaxContextId;
8384
use stdx::impl_from;
8485
use syntax::{ast, AstNode};
8586

crates/hir-def/src/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cell::OnceCell;
33

44
use hir_expand::{
55
ast_id_map::{AstIdMap, AstIdNode},
6-
span::{SpanMap, SpanMapRef},
6+
span_map::{SpanMap, SpanMapRef},
77
AstId, HirFileId, InFile,
88
};
99
use syntax::ast;

crates/hir-def/src/macro_expansion_tests/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ mod proc_macros;
1616

1717
use std::{iter, ops::Range, sync};
1818

19-
use base_db::{span::SpanData, SourceDatabase};
19+
use base_db::SourceDatabase;
2020
use expect_test::Expect;
2121
use hir_expand::{
2222
db::ExpandDatabase,
2323
fixture::WithFixture,
2424
proc_macro::{ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind},
25-
span::SpanMapRef,
25+
span_map::SpanMapRef,
2626
InFile, MacroFileId, MacroFileIdExt,
2727
};
28+
use span::Span;
2829
use stdx::format_to;
2930
use syntax::{
3031
ast::{self, edit::IndentLevel},
@@ -319,9 +320,9 @@ impl ProcMacroExpander for IdentityWhenValidProcMacroExpander {
319320
subtree: &Subtree,
320321
_: Option<&Subtree>,
321322
_: &base_db::Env,
322-
_: SpanData,
323-
_: SpanData,
324-
_: SpanData,
323+
_: Span,
324+
_: Span,
325+
_: Span,
325326
) -> Result<Subtree, ProcMacroExpansionError> {
326327
let (parse, _) =
327328
::mbe::token_tree_to_syntax_node(subtree, ::mbe::TopEntryPoint::MacroItems);

crates/hir-def/src/nameres/collector.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use std::{cmp::Ordering, iter, mem};
77

8-
use base_db::{span::SyntaxContextId, CrateId, Dependency, Edition, FileId};
8+
use base_db::{CrateId, Dependency, Edition, FileId};
99
use cfg::{CfgExpr, CfgOptions};
1010
use either::Either;
1111
use hir_expand::{
@@ -23,6 +23,7 @@ use itertools::{izip, Itertools};
2323
use la_arena::Idx;
2424
use limit::Limit;
2525
use rustc_hash::{FxHashMap, FxHashSet};
26+
use span::{Span, SyntaxContextId};
2627
use stdx::always;
2728
use syntax::{ast, SmolStr};
2829
use triomphe::Arc;
@@ -86,11 +87,11 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeI
8687
// FIXME: a hacky way to create a Name from string.
8788
let name = tt::Ident {
8889
text: it.name.clone(),
89-
span: tt::SpanData {
90+
span: Span {
9091
range: syntax::TextRange::empty(syntax::TextSize::new(0)),
91-
anchor: base_db::span::SpanAnchor {
92+
anchor: span::SpanAnchor {
9293
file_id: FileId::BOGUS,
93-
ast_id: base_db::span::ROOT_ERASED_FILE_AST_ID,
94+
ast_id: span::ROOT_ERASED_FILE_AST_ID,
9495
},
9596
ctx: SyntaxContextId::ROOT,
9697
},
@@ -2095,11 +2096,11 @@ impl ModCollector<'_, '_> {
20952096
// FIXME: a hacky way to create a Name from string.
20962097
name = tt::Ident {
20972098
text: it.clone(),
2098-
span: tt::SpanData {
2099+
span: Span {
20992100
range: syntax::TextRange::empty(syntax::TextSize::new(0)),
2100-
anchor: base_db::span::SpanAnchor {
2101+
anchor: span::SpanAnchor {
21012102
file_id: FileId::BOGUS,
2102-
ast_id: base_db::span::ROOT_ERASED_FILE_AST_ID,
2103+
ast_id: span::ROOT_ERASED_FILE_AST_ID,
21032104
},
21042105
ctx: SyntaxContextId::ROOT,
21052106
},

crates/hir-def/src/visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::iter;
44

5-
use hir_expand::{span::SpanMapRef, InFile};
5+
use hir_expand::{span_map::SpanMapRef, InFile};
66
use la_arena::ArenaMap;
77
use syntax::ast;
88
use triomphe::Arc;

crates/hir-expand/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ profile.workspace = true
3232
tt.workspace = true
3333
mbe.workspace = true
3434
limit.workspace = true
35+
span.workspace = true
3536
test-utils.workspace = true
3637

3738
[dev-dependencies]

crates/hir-expand/src/ast_id_map.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
//! item as an ID. That way, id's don't change unless the set of items itself
66
//! changes.
77
8+
// FIXME: Consider moving this into the span crate
9+
810
use std::{
911
any::type_name,
1012
fmt,
@@ -17,31 +19,31 @@ use profile::Count;
1719
use rustc_hash::FxHasher;
1820
use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
1921

20-
use crate::db;
22+
use crate::db::ExpandDatabase;
2123

22-
pub use base_db::span::ErasedFileAstId;
24+
pub use span::ErasedFileAstId;
2325

2426
/// `AstId` points to an AST node in any file.
2527
///
2628
/// It is stable across reparses, and can be used as salsa key/value.
2729
pub type AstId<N> = crate::InFile<FileAstId<N>>;
2830

2931
impl<N: AstIdNode> AstId<N> {
30-
pub fn to_node(&self, db: &dyn db::ExpandDatabase) -> N {
32+
pub fn to_node(&self, db: &dyn ExpandDatabase) -> N {
3133
self.to_ptr(db).to_node(&db.parse_or_expand(self.file_id))
3234
}
33-
pub fn to_in_file_node(&self, db: &dyn db::ExpandDatabase) -> crate::InFile<N> {
35+
pub fn to_in_file_node(&self, db: &dyn ExpandDatabase) -> crate::InFile<N> {
3436
crate::InFile::new(self.file_id, self.to_ptr(db).to_node(&db.parse_or_expand(self.file_id)))
3537
}
36-
pub fn to_ptr(&self, db: &dyn db::ExpandDatabase) -> AstPtr<N> {
38+
pub fn to_ptr(&self, db: &dyn ExpandDatabase) -> AstPtr<N> {
3739
db.ast_id_map(self.file_id).get(self.value)
3840
}
3941
}
4042

4143
pub type ErasedAstId = crate::InFile<ErasedFileAstId>;
4244

4345
impl ErasedAstId {
44-
pub fn to_ptr(&self, db: &dyn db::ExpandDatabase) -> SyntaxNodePtr {
46+
pub fn to_ptr(&self, db: &dyn ExpandDatabase) -> SyntaxNodePtr {
4547
db.ast_id_map(self.file_id).get_erased(self.value)
4648
}
4749
}

crates/hir-expand/src/attrs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
//! A higher level attributes based on TokenTree, with also some shortcuts.
22
use std::{fmt, ops};
33

4-
use base_db::{span::SyntaxContextId, CrateId};
4+
use base_db::CrateId;
55
use cfg::CfgExpr;
66
use either::Either;
77
use intern::Interned;
88
use mbe::{syntax_node_to_token_tree, DelimiterKind, Punct};
99
use smallvec::{smallvec, SmallVec};
10+
use span::SyntaxContextId;
1011
use syntax::{ast, match_ast, AstNode, AstToken, SmolStr, SyntaxNode};
1112
use triomphe::Arc;
1213

1314
use crate::{
1415
db::ExpandDatabase,
1516
mod_path::ModPath,
16-
span::SpanMapRef,
17+
span_map::SpanMapRef,
1718
tt::{self, Subtree},
1819
InFile,
1920
};

0 commit comments

Comments
 (0)