Skip to content

Commit 1bc1f34

Browse files
committed
Auto merge of #143565 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents 17de998 + 0ac6559 commit 1bc1f34

File tree

83 files changed

+1281
-668
lines changed

Some content is hidden

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

83 files changed

+1281
-668
lines changed

Cargo.lock

Lines changed: 38 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ debug = 2
4949
# ungrammar = { path = "../ungrammar" }
5050

5151
# salsa = { path = "../salsa" }
52+
# salsa-macros = { path = "../salsa/components/salsa-macros" }
53+
# salsa-macro-rules = { path = "../salsa/components/salsa-macro-rules" }
5254

5355
[workspace.dependencies]
5456
# local crates
@@ -136,8 +138,8 @@ rayon = "1.10.0"
136138
rowan = "=0.15.15"
137139
# Ideally we'd not enable the macros feature but unfortunately the `tracked` attribute does not work
138140
# on impls without it
139-
salsa = { version = "0.22.0", default-features = true, features = ["rayon","salsa_unstable", "macros"] }
140-
salsa-macros = "0.22.0"
141+
salsa = { version = "0.23.0", default-features = true, features = ["rayon","salsa_unstable", "macros"] }
142+
salsa-macros = "0.23.0"
141143
semver = "1.0.26"
142144
serde = { version = "1.0.219" }
143145
serde_derive = { version = "1.0.219" }

crates/base-db/src/input.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
77
//! actual IO is done and lowered to input.
88
9+
use std::error::Error;
910
use std::hash::BuildHasherDefault;
1011
use std::{fmt, mem, ops};
1112

@@ -22,7 +23,49 @@ use vfs::{AbsPathBuf, AnchoredPath, FileId, VfsPath, file_set::FileSet};
2223

2324
use crate::{CrateWorkspaceData, EditionedFileId, FxIndexSet, RootQueryDb};
2425

25-
pub type ProcMacroPaths = FxHashMap<CrateBuilderId, Result<(String, AbsPathBuf), String>>;
26+
pub type ProcMacroPaths =
27+
FxHashMap<CrateBuilderId, Result<(String, AbsPathBuf), ProcMacroLoadingError>>;
28+
29+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
30+
pub enum ProcMacroLoadingError {
31+
Disabled,
32+
FailedToBuild,
33+
MissingDylibPath,
34+
NotYetBuilt,
35+
NoProcMacros,
36+
ProcMacroSrvError(Box<str>),
37+
}
38+
impl ProcMacroLoadingError {
39+
pub fn is_hard_error(&self) -> bool {
40+
match self {
41+
ProcMacroLoadingError::Disabled | ProcMacroLoadingError::NotYetBuilt => false,
42+
ProcMacroLoadingError::FailedToBuild
43+
| ProcMacroLoadingError::MissingDylibPath
44+
| ProcMacroLoadingError::NoProcMacros
45+
| ProcMacroLoadingError::ProcMacroSrvError(_) => true,
46+
}
47+
}
48+
}
49+
50+
impl Error for ProcMacroLoadingError {}
51+
impl fmt::Display for ProcMacroLoadingError {
52+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53+
match self {
54+
ProcMacroLoadingError::Disabled => write!(f, "proc-macro expansion is disabled"),
55+
ProcMacroLoadingError::FailedToBuild => write!(f, "proc-macro failed to build"),
56+
ProcMacroLoadingError::MissingDylibPath => {
57+
write!(f, "proc-macro crate build data is missing a dylib path")
58+
}
59+
ProcMacroLoadingError::NotYetBuilt => write!(f, "proc-macro not yet built"),
60+
ProcMacroLoadingError::NoProcMacros => {
61+
write!(f, "proc macro library has no proc macros")
62+
}
63+
ProcMacroLoadingError::ProcMacroSrvError(msg) => {
64+
write!(f, "proc macro server error: {msg}")
65+
}
66+
}
67+
}
68+
}
2669

2770
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
2871
pub struct SourceRootId(pub u32);

crates/base-db/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ pub use crate::{
1414
input::{
1515
BuiltCrateData, BuiltDependency, Crate, CrateBuilder, CrateBuilderId, CrateDataBuilder,
1616
CrateDisplayName, CrateGraphBuilder, CrateName, CrateOrigin, CratesIdMap, CratesMap,
17-
DependencyBuilder, Env, ExtraCrateData, LangCrateOrigin, ProcMacroPaths, ReleaseChannel,
18-
SourceRoot, SourceRootId, TargetLayoutLoadResult, UniqueCrateData,
17+
DependencyBuilder, Env, ExtraCrateData, LangCrateOrigin, ProcMacroLoadingError,
18+
ProcMacroPaths, ReleaseChannel, SourceRoot, SourceRootId, TargetLayoutLoadResult,
19+
UniqueCrateData,
1920
},
2021
};
2122
use dashmap::{DashMap, mapref::entry::Entry};
@@ -33,7 +34,7 @@ pub type FxIndexSet<T> = indexmap::IndexSet<T, rustc_hash::FxBuildHasher>;
3334
#[macro_export]
3435
macro_rules! impl_intern_key {
3536
($id:ident, $loc:ident) => {
36-
#[salsa_macros::interned(no_lifetime)]
37+
#[salsa_macros::interned(no_lifetime, revisions = usize::MAX)]
3738
#[derive(PartialOrd, Ord)]
3839
pub struct $id {
3940
pub loc: $loc,
@@ -43,7 +44,7 @@ macro_rules! impl_intern_key {
4344
impl ::std::fmt::Debug for $id {
4445
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
4546
f.debug_tuple(stringify!($id))
46-
.field(&format_args!("{:04x}", self.0.as_u32()))
47+
.field(&format_args!("{:04x}", self.0.index()))
4748
.finish()
4849
}
4950
}
@@ -167,7 +168,7 @@ impl Files {
167168
}
168169
}
169170

170-
#[salsa_macros::interned(no_lifetime, debug, constructor=from_span)]
171+
#[salsa_macros::interned(no_lifetime, debug, constructor=from_span, revisions = usize::MAX)]
171172
#[derive(PartialOrd, Ord)]
172173
pub struct EditionedFileId {
173174
pub editioned_file_id: span::EditionedFileId,

crates/hir-def/src/expr_store.rs

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub type TypeSource = InFile<TypePtr>;
9393
pub type LifetimePtr = AstPtr<ast::Lifetime>;
9494
pub type LifetimeSource = InFile<LifetimePtr>;
9595

96-
#[derive(Debug, Eq, PartialEq)]
96+
#[derive(Debug, PartialEq, Eq)]
9797
pub struct ExpressionStore {
9898
pub exprs: Arena<Expr>,
9999
pub pats: Arena<Pat>,
@@ -114,7 +114,7 @@ pub struct ExpressionStore {
114114
ident_hygiene: FxHashMap<ExprOrPatId, HygieneId>,
115115
}
116116

117-
#[derive(Debug, Eq, PartialEq, Default)]
117+
#[derive(Debug, Eq, Default)]
118118
pub struct ExpressionStoreSourceMap {
119119
// AST expressions can create patterns in destructuring assignments. Therefore, `ExprSource` can also map
120120
// to `PatId`, and `PatId` can also map to `ExprSource` (the other way around is unaffected).
@@ -127,19 +127,20 @@ pub struct ExpressionStoreSourceMap {
127127
label_map: FxHashMap<LabelSource, LabelId>,
128128
label_map_back: ArenaMap<LabelId, LabelSource>,
129129

130-
binding_definitions: FxHashMap<BindingId, SmallVec<[PatId; 4]>>,
131-
132-
/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
133-
/// Instead, we use id of expression (`92`) to identify the field.
134-
field_map_back: FxHashMap<ExprId, FieldSource>,
135-
pat_field_map_back: FxHashMap<PatId, PatFieldSource>,
136-
137130
types_map_back: ArenaMap<TypeRefId, TypeSource>,
138131
types_map: FxHashMap<TypeSource, TypeRefId>,
139132

140133
lifetime_map_back: ArenaMap<LifetimeRefId, LifetimeSource>,
141134
lifetime_map: FxHashMap<LifetimeSource, LifetimeRefId>,
142135

136+
binding_definitions:
137+
ArenaMap<BindingId, SmallVec<[PatId; 2 * size_of::<usize>() / size_of::<PatId>()]>>,
138+
139+
/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
140+
/// Instead, we use id of expression (`92`) to identify the field.
141+
field_map_back: FxHashMap<ExprId, FieldSource>,
142+
pat_field_map_back: FxHashMap<PatId, PatFieldSource>,
143+
143144
template_map: Option<Box<FormatTemplate>>,
144145

145146
pub expansions: FxHashMap<InFile<MacroCallPtr>, MacroCallId>,
@@ -149,6 +150,43 @@ pub struct ExpressionStoreSourceMap {
149150
pub diagnostics: Vec<ExpressionStoreDiagnostics>,
150151
}
151152

153+
impl PartialEq for ExpressionStoreSourceMap {
154+
fn eq(&self, other: &Self) -> bool {
155+
// we only need to compare one of the two mappings
156+
// as the other is a reverse mapping and thus will compare
157+
// the same as normal mapping
158+
let Self {
159+
expr_map: _,
160+
expr_map_back,
161+
pat_map: _,
162+
pat_map_back,
163+
label_map: _,
164+
label_map_back,
165+
types_map_back,
166+
types_map: _,
167+
lifetime_map_back,
168+
lifetime_map: _,
169+
// If this changed, our pattern data must have changed
170+
binding_definitions: _,
171+
// If this changed, our expression data must have changed
172+
field_map_back: _,
173+
// If this changed, our pattern data must have changed
174+
pat_field_map_back: _,
175+
template_map,
176+
expansions,
177+
diagnostics,
178+
} = self;
179+
*expr_map_back == other.expr_map_back
180+
&& *pat_map_back == other.pat_map_back
181+
&& *label_map_back == other.label_map_back
182+
&& *types_map_back == other.types_map_back
183+
&& *lifetime_map_back == other.lifetime_map_back
184+
&& *template_map == other.template_map
185+
&& *expansions == other.expansions
186+
&& *diagnostics == other.diagnostics
187+
}
188+
}
189+
152190
/// The body of an item (function, const etc.).
153191
#[derive(Debug, Eq, PartialEq, Default)]
154192
pub struct ExpressionStoreBuilder {
@@ -698,7 +736,7 @@ impl ExpressionStoreSourceMap {
698736
}
699737

700738
pub fn patterns_for_binding(&self, binding: BindingId) -> &[PatId] {
701-
self.binding_definitions.get(&binding).map_or(&[], Deref::deref)
739+
self.binding_definitions.get(binding).map_or(&[], Deref::deref)
702740
}
703741

704742
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub enum Path {
2929
// This type is being used a lot, make sure it doesn't grow unintentionally.
3030
#[cfg(target_arch = "x86_64")]
3131
const _: () = {
32-
assert!(size_of::<Path>() == 16);
33-
assert!(size_of::<Option<Path>>() == 16);
32+
assert!(size_of::<Path>() == 24);
33+
assert!(size_of::<Option<Path>>() == 24);
3434
};
3535

3636
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

crates/hir-def/src/expr_store/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ fn foo() {
535535

536536
let resolved = scopes.resolve_name_in_scope(expr_scope, &name_ref.as_name()).unwrap();
537537
let pat_src = source_map
538-
.pat_syntax(*source_map.binding_definitions[&resolved.binding()].first().unwrap())
538+
.pat_syntax(*source_map.binding_definitions[resolved.binding()].first().unwrap())
539539
.unwrap();
540540

541541
let local_name = pat_src.value.syntax_node_ptr().to_node(file.syntax());

crates/hir-def/src/hir/type_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub enum TypeRef {
149149
}
150150

151151
#[cfg(target_arch = "x86_64")]
152-
const _: () = assert!(size_of::<TypeRef>() == 16);
152+
const _: () = assert!(size_of::<TypeRef>() == 24);
153153

154154
pub type TypeRefId = Idx<TypeRef>;
155155

0 commit comments

Comments
 (0)