Skip to content

Commit 8df4a58

Browse files
committed
Auto merge of #143565 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents c720f49 + 1cf9a7b commit 8df4a58

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

src/tools/rust-analyzer/Cargo.lock

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,6 @@ dependencies = [
569569
"hashbrown 0.15.4",
570570
]
571571

572-
[[package]]
573-
name = "heck"
574-
version = "0.5.0"
575-
source = "registry+https://github.com/rust-lang/crates.io-index"
576-
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
577-
578572
[[package]]
579573
name = "hermit-abi"
580574
version = "0.5.2"
@@ -1020,6 +1014,15 @@ dependencies = [
10201014
"triomphe",
10211015
]
10221016

1017+
[[package]]
1018+
name = "intrusive-collections"
1019+
version = "0.9.7"
1020+
source = "registry+https://github.com/rust-lang/crates.io-index"
1021+
checksum = "189d0897e4cbe8c75efedf3502c18c887b05046e59d28404d4d8e46cbc4d1e86"
1022+
dependencies = [
1023+
"memoffset",
1024+
]
1025+
10231026
[[package]]
10241027
name = "itertools"
10251028
version = "0.12.1"
@@ -1427,6 +1430,16 @@ dependencies = [
14271430
"num-traits",
14281431
]
14291432

1433+
[[package]]
1434+
name = "papaya"
1435+
version = "0.2.3"
1436+
source = "registry+https://github.com/rust-lang/crates.io-index"
1437+
checksum = "f92dd0b07c53a0a0c764db2ace8c541dc47320dad97c2200c2a637ab9dd2328f"
1438+
dependencies = [
1439+
"equivalent",
1440+
"seize",
1441+
]
1442+
14301443
[[package]]
14311444
name = "parking_lot"
14321445
version = "0.12.4"
@@ -1955,16 +1968,18 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
19551968

19561969
[[package]]
19571970
name = "salsa"
1958-
version = "0.22.0"
1971+
version = "0.23.0"
19591972
source = "registry+https://github.com/rust-lang/crates.io-index"
1960-
checksum = "c8fff508e3d6ef42a32607f7538e17171a877a12015e32036f46e99d00c95781"
1973+
checksum = "2e235afdb8e510f38a07138fbe5a0b64691894358a9c0cbd813b1aade110efc9"
19611974
dependencies = [
19621975
"boxcar",
19631976
"crossbeam-queue",
1964-
"dashmap",
1977+
"crossbeam-utils",
19651978
"hashbrown 0.15.4",
19661979
"hashlink",
19671980
"indexmap",
1981+
"intrusive-collections",
1982+
"papaya",
19681983
"parking_lot",
19691984
"portable-atomic",
19701985
"rayon",
@@ -1978,17 +1993,16 @@ dependencies = [
19781993

19791994
[[package]]
19801995
name = "salsa-macro-rules"
1981-
version = "0.22.0"
1996+
version = "0.23.0"
19821997
source = "registry+https://github.com/rust-lang/crates.io-index"
1983-
checksum = "8ea72b3c06f2ce6350fe3a0eeb7aaaf842d1d8352b706973c19c4f02e298a87c"
1998+
checksum = "2edb86a7e9c91f6d30c9ce054312721dbe773a162db27bbfae834d16177b30ce"
19841999

19852000
[[package]]
19862001
name = "salsa-macros"
1987-
version = "0.22.0"
2002+
version = "0.23.0"
19882003
source = "registry+https://github.com/rust-lang/crates.io-index"
1989-
checksum = "0ce92025bc160b27814a207cb78d680973af17f863c7f4fc56cf3a535e22f378"
2004+
checksum = "d0778d6e209051bc4e75acfe83bcd7848601ec3dbe9c3dbb982829020e9128af"
19902005
dependencies = [
1991-
"heck",
19922006
"proc-macro2",
19932007
"quote",
19942008
"syn",
@@ -2025,6 +2039,16 @@ version = "1.2.0"
20252039
source = "registry+https://github.com/rust-lang/crates.io-index"
20262040
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
20272041

2042+
[[package]]
2043+
name = "seize"
2044+
version = "0.5.0"
2045+
source = "registry+https://github.com/rust-lang/crates.io-index"
2046+
checksum = "e4b8d813387d566f627f3ea1b914c068aac94c40ae27ec43f5f33bde65abefe7"
2047+
dependencies = [
2048+
"libc",
2049+
"windows-sys 0.52.0",
2050+
]
2051+
20282052
[[package]]
20292053
name = "semver"
20302054
version = "1.0.26"

src/tools/rust-analyzer/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" }

src/tools/rust-analyzer/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);

src/tools/rust-analyzer/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,

src/tools/rust-analyzer/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> {

src/tools/rust-analyzer/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)]

src/tools/rust-analyzer/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());

src/tools/rust-analyzer/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)