Skip to content

Commit a0c20d5

Browse files
committed
Auto merge of rust-lang#122628 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer`
2 parents ecdea9e + 20ecf07 commit a0c20d5

File tree

153 files changed

+3374
-1917
lines changed

Some content is hidden

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

153 files changed

+3374
-1917
lines changed

src/tools/rust-analyzer/.github/workflows/release.yaml

-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
- os: ubuntu-20.04
3737
target: x86_64-unknown-linux-gnu
3838
code-target: linux-x64
39-
container: ubuntu:18.04
4039
- os: ubuntu-20.04
4140
target: aarch64-unknown-linux-gnu
4241
code-target: linux-arm64
@@ -63,14 +62,6 @@ jobs:
6362
with:
6463
fetch-depth: ${{ env.FETCH_DEPTH }}
6564

66-
- name: Install toolchain dependencies
67-
if: matrix.container == 'ubuntu:18.04'
68-
shell: bash
69-
run: |
70-
apt-get update && apt-get install -y build-essential curl
71-
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
72-
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
73-
7465
- name: Install Rust toolchain
7566
run: |
7667
rustup update --no-self-update stable

src/tools/rust-analyzer/Cargo.lock

+12-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ version = "0.0.0"
7171
dependencies = [
7272
"cfg",
7373
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
74+
"lz4_flex",
7475
"rustc-hash",
7576
"salsa",
7677
"semver",
@@ -134,9 +135,9 @@ dependencies = [
134135

135136
[[package]]
136137
name = "cc"
137-
version = "1.0.89"
138+
version = "1.0.90"
138139
source = "registry+https://github.com/rust-lang/crates.io-index"
139-
checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723"
140+
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
140141

141142
[[package]]
142143
name = "cfg"
@@ -874,9 +875,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
874875

875876
[[package]]
876877
name = "libloading"
877-
version = "0.8.2"
878+
version = "0.8.3"
878879
source = "registry+https://github.com/rust-lang/crates.io-index"
879-
checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164"
880+
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
880881
dependencies = [
881882
"cfg-if",
882883
"windows-targets 0.52.4",
@@ -992,6 +993,12 @@ dependencies = [
992993
"url",
993994
]
994995

996+
[[package]]
997+
name = "lz4_flex"
998+
version = "0.11.2"
999+
source = "registry+https://github.com/rust-lang/crates.io-index"
1000+
checksum = "912b45c753ff5f7f5208307e8ace7d2a2e30d024e26d3509f3dce546c044ce15"
1001+
9951002
[[package]]
9961003
name = "mbe"
9971004
version = "0.0.0"
@@ -1597,6 +1604,7 @@ dependencies = [
15971604
"rayon",
15981605
"rustc-hash",
15991606
"scip",
1607+
"semver",
16001608
"serde",
16011609
"serde_json",
16021610
"sourcegen",

src/tools/rust-analyzer/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ anyhow = "1.0.75"
105105
arrayvec = "0.7.4"
106106
bitflags = "2.4.1"
107107
cargo_metadata = "0.18.1"
108+
chalk-solve = { version = "0.96.0", default-features = false }
109+
chalk-ir = "0.96.0"
110+
chalk-recursive = { version = "0.96.0", default-features = false }
111+
chalk-derive = "0.96.0"
108112
command-group = "2.0.1"
109113
crossbeam-channel = "0.5.8"
110114
dissimilar = "1.0.7"

src/tools/rust-analyzer/crates/base-db/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ rust-version.workspace = true
1212
doctest = false
1313

1414
[dependencies]
15+
lz4_flex = { version = "0.11", default-features = false }
16+
1517
la-arena.workspace = true
1618
salsa.workspace = true
1719
rustc-hash.workspace = true

src/tools/rust-analyzer/crates/base-db/src/change.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use salsa::Durability;
77
use triomphe::Arc;
88
use vfs::FileId;
99

10-
use crate::{CrateGraph, SourceDatabaseExt, SourceRoot, SourceRootId};
10+
use crate::{CrateGraph, SourceDatabaseExt, SourceDatabaseExt2, SourceRoot, SourceRootId};
1111

1212
/// Encapsulate a bunch of raw `.set` calls on the database.
1313
#[derive(Default)]
1414
pub struct FileChange {
1515
pub roots: Option<Vec<SourceRoot>>,
16-
pub files_changed: Vec<(FileId, Option<Arc<str>>)>,
16+
pub files_changed: Vec<(FileId, Option<String>)>,
1717
pub crate_graph: Option<CrateGraph>,
1818
}
1919

@@ -42,7 +42,7 @@ impl FileChange {
4242
self.roots = Some(roots);
4343
}
4444

45-
pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) {
45+
pub fn change_file(&mut self, file_id: FileId, new_text: Option<String>) {
4646
self.files_changed.push((file_id, new_text))
4747
}
4848

@@ -68,8 +68,8 @@ impl FileChange {
6868
let source_root = db.source_root(source_root_id);
6969
let durability = durability(&source_root);
7070
// XXX: can't actually remove the file, just reset the text
71-
let text = text.unwrap_or_else(|| Arc::from(""));
72-
db.set_file_text_with_durability(file_id, text, durability)
71+
let text = text.unwrap_or_default();
72+
db.set_file_text_with_durability(file_id, &text, durability)
7373
}
7474
if let Some(crate_graph) = self.crate_graph {
7575
db.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH);

src/tools/rust-analyzer/crates/base-db/src/lib.rs

+43
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod input;
77

88
use std::panic;
99

10+
use salsa::Durability;
1011
use syntax::{ast, Parse, SourceFile};
1112
use triomphe::Arc;
1213

@@ -42,6 +43,7 @@ pub trait Upcast<T: ?Sized> {
4243
fn upcast(&self) -> &T;
4344
}
4445

46+
pub const DEFAULT_FILE_TEXT_LRU_CAP: usize = 16;
4547
pub const DEFAULT_PARSE_LRU_CAP: usize = 128;
4648
pub const DEFAULT_BORROWCK_LRU_CAP: usize = 1024;
4749

@@ -89,7 +91,10 @@ fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
8991
#[salsa::query_group(SourceDatabaseExtStorage)]
9092
pub trait SourceDatabaseExt: SourceDatabase {
9193
#[salsa::input]
94+
fn compressed_file_text(&self, file_id: FileId) -> Arc<[u8]>;
95+
9296
fn file_text(&self, file_id: FileId) -> Arc<str>;
97+
9398
/// Path to a file, relative to the root of its source root.
9499
/// Source root of the file.
95100
#[salsa::input]
@@ -101,6 +106,44 @@ pub trait SourceDatabaseExt: SourceDatabase {
101106
fn source_root_crates(&self, id: SourceRootId) -> Arc<[CrateId]>;
102107
}
103108

109+
fn file_text(db: &dyn SourceDatabaseExt, file_id: FileId) -> Arc<str> {
110+
let bytes = db.compressed_file_text(file_id);
111+
let bytes =
112+
lz4_flex::decompress_size_prepended(&bytes).expect("lz4 decompression should not fail");
113+
let text = std::str::from_utf8(&bytes).expect("file contents should be valid UTF-8");
114+
Arc::from(text)
115+
}
116+
117+
pub trait SourceDatabaseExt2 {
118+
fn set_file_text(&mut self, file_id: FileId, text: &str) {
119+
self.set_file_text_with_durability(file_id, text, Durability::LOW);
120+
}
121+
122+
fn set_file_text_with_durability(
123+
&mut self,
124+
file_id: FileId,
125+
text: &str,
126+
durability: Durability,
127+
);
128+
}
129+
130+
impl<Db: ?Sized + SourceDatabaseExt> SourceDatabaseExt2 for Db {
131+
fn set_file_text_with_durability(
132+
&mut self,
133+
file_id: FileId,
134+
text: &str,
135+
durability: Durability,
136+
) {
137+
let bytes = text.as_bytes();
138+
let compressed = lz4_flex::compress_prepend_size(bytes);
139+
self.set_compressed_file_text_with_durability(
140+
file_id,
141+
Arc::from(compressed.as_slice()),
142+
durability,
143+
)
144+
}
145+
}
146+
104147
fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<[CrateId]> {
105148
let graph = db.crate_graph();
106149
let mut crates = graph

src/tools/rust-analyzer/crates/cfg/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ mbe.workspace = true
3131
syntax.workspace = true
3232

3333
[lints]
34-
workspace = true
34+
workspace = true

src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl CfgExpr {
4747
pub fn parse<S>(tt: &tt::Subtree<S>) -> CfgExpr {
4848
next_cfg_expr(&mut tt.token_trees.iter()).unwrap_or(CfgExpr::Invalid)
4949
}
50+
5051
/// Fold the cfg by querying all basic `Atom` and `KeyValue` predicates.
5152
pub fn fold(&self, query: &dyn Fn(&CfgAtom) -> bool) -> Option<bool> {
5253
match self {
@@ -62,7 +63,6 @@ impl CfgExpr {
6263
}
6364
}
6465
}
65-
6666
fn next_cfg_expr<S>(it: &mut SliceIter<'_, tt::TokenTree<S>>) -> Option<CfgExpr> {
6767
let name = match it.next() {
6868
None => return None,

src/tools/rust-analyzer/crates/flycheck/src/test_runner.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ pub enum CargoTestMessage {
2828
},
2929
Suite,
3030
Finished,
31+
Custom {
32+
text: String,
33+
},
3134
}
3235

3336
impl ParseFromLine for CargoTestMessage {
34-
fn from_line(line: &str, error: &mut String) -> Option<Self> {
37+
fn from_line(line: &str, _: &mut String) -> Option<Self> {
3538
let mut deserializer = serde_json::Deserializer::from_str(line);
3639
deserializer.disable_recursion_limit();
3740
if let Ok(message) = CargoTestMessage::deserialize(&mut deserializer) {
3841
return Some(message);
3942
}
4043

41-
error.push_str(line);
42-
error.push('\n');
43-
None
44+
Some(CargoTestMessage::Custom { text: line.to_owned() })
4445
}
4546

4647
fn from_eof() -> Option<Self> {

src/tools/rust-analyzer/crates/hir-def/src/body.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::ops::Index;
1010

1111
use base_db::CrateId;
1212
use cfg::{CfgExpr, CfgOptions};
13-
use either::Either;
1413
use hir_expand::{name::Name, HirFileId, InFile};
1514
use la_arena::{Arena, ArenaMap};
1615
use rustc_hash::FxHashMap;
@@ -45,7 +44,8 @@ pub struct Body {
4544
///
4645
/// If this `Body` is for the body of a constant, this will just be
4746
/// empty.
48-
pub params: Vec<PatId>,
47+
pub params: Box<[PatId]>,
48+
pub self_param: Option<BindingId>,
4949
/// The `ExprId` of the actual body expression.
5050
pub body_expr: ExprId,
5151
/// Block expressions in this body that may contain inner items.
@@ -55,14 +55,15 @@ pub struct Body {
5555
pub type ExprPtr = AstPtr<ast::Expr>;
5656
pub type ExprSource = InFile<ExprPtr>;
5757

58-
pub type PatPtr = AstPtr<Either<ast::Pat, ast::SelfParam>>;
58+
pub type PatPtr = AstPtr<ast::Pat>;
5959
pub type PatSource = InFile<PatPtr>;
6060

6161
pub type LabelPtr = AstPtr<ast::Label>;
6262
pub type LabelSource = InFile<LabelPtr>;
6363

6464
pub type FieldPtr = AstPtr<ast::RecordExprField>;
6565
pub type FieldSource = InFile<FieldPtr>;
66+
6667
pub type PatFieldPtr = AstPtr<ast::RecordPatField>;
6768
pub type PatFieldSource = InFile<PatFieldPtr>;
6869

@@ -88,6 +89,8 @@ pub struct BodySourceMap {
8889
label_map: FxHashMap<LabelSource, LabelId>,
8990
label_map_back: ArenaMap<LabelId, LabelSource>,
9091

92+
self_param: Option<InFile<AstPtr<ast::SelfParam>>>,
93+
9194
/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
9295
/// Instead, we use id of expression (`92`) to identify the field.
9396
field_map_back: FxHashMap<ExprId, FieldSource>,
@@ -215,18 +218,18 @@ impl Body {
215218
fn shrink_to_fit(&mut self) {
216219
let Self {
217220
body_expr: _,
221+
params: _,
222+
self_param: _,
218223
block_scopes,
219224
exprs,
220225
labels,
221-
params,
222226
pats,
223227
bindings,
224228
binding_owners,
225229
} = self;
226230
block_scopes.shrink_to_fit();
227231
exprs.shrink_to_fit();
228232
labels.shrink_to_fit();
229-
params.shrink_to_fit();
230233
pats.shrink_to_fit();
231234
bindings.shrink_to_fit();
232235
binding_owners.shrink_to_fit();
@@ -297,6 +300,7 @@ impl Default for Body {
297300
params: Default::default(),
298301
block_scopes: Default::default(),
299302
binding_owners: Default::default(),
303+
self_param: Default::default(),
300304
}
301305
}
302306
}
@@ -354,14 +358,12 @@ impl BodySourceMap {
354358
self.pat_map_back.get(pat).cloned().ok_or(SyntheticSyntax)
355359
}
356360

357-
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
358-
let src = node.map(|it| AstPtr::new(it).wrap_left());
359-
self.pat_map.get(&src).cloned()
361+
pub fn self_param_syntax(&self) -> Option<InFile<AstPtr<ast::SelfParam>>> {
362+
self.self_param
360363
}
361364

362-
pub fn node_self_param(&self, node: InFile<&ast::SelfParam>) -> Option<PatId> {
363-
let src = node.map(|it| AstPtr::new(it).wrap_right());
364-
self.pat_map.get(&src).cloned()
365+
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
366+
self.pat_map.get(&node.map(AstPtr::new)).cloned()
365367
}
366368

367369
pub fn label_syntax(&self, label: LabelId) -> LabelSource {
@@ -401,6 +403,7 @@ impl BodySourceMap {
401403

402404
fn shrink_to_fit(&mut self) {
403405
let Self {
406+
self_param: _,
404407
expr_map,
405408
expr_map_back,
406409
pat_map,

0 commit comments

Comments
 (0)