Skip to content

Commit

Permalink
Auto merge of rust-lang#122628 - lnicola:sync-from-ra, r=lnicola
Browse files Browse the repository at this point in the history
Subtree update of `rust-analyzer`
  • Loading branch information
bors committed Mar 17, 2024
2 parents ecdea9e + 20ecf07 commit a0c20d5
Show file tree
Hide file tree
Showing 153 changed files with 3,374 additions and 1,917 deletions.
9 changes: 0 additions & 9 deletions src/tools/rust-analyzer/.github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
- os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
code-target: linux-x64
container: ubuntu:18.04
- os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
code-target: linux-arm64
Expand All @@ -63,14 +62,6 @@ jobs:
with:
fetch-depth: ${{ env.FETCH_DEPTH }}

- name: Install toolchain dependencies
if: matrix.container == 'ubuntu:18.04'
shell: bash
run: |
apt-get update && apt-get install -y build-essential curl
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
- name: Install Rust toolchain
run: |
rustup update --no-self-update stable
Expand Down
16 changes: 12 additions & 4 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ version = "0.0.0"
dependencies = [
"cfg",
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lz4_flex",
"rustc-hash",
"salsa",
"semver",
Expand Down Expand Up @@ -134,9 +135,9 @@ dependencies = [

[[package]]
name = "cc"
version = "1.0.89"
version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723"
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"

[[package]]
name = "cfg"
Expand Down Expand Up @@ -874,9 +875,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"

[[package]]
name = "libloading"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164"
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
dependencies = [
"cfg-if",
"windows-targets 0.52.4",
Expand Down Expand Up @@ -992,6 +993,12 @@ dependencies = [
"url",
]

[[package]]
name = "lz4_flex"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "912b45c753ff5f7f5208307e8ace7d2a2e30d024e26d3509f3dce546c044ce15"

[[package]]
name = "mbe"
version = "0.0.0"
Expand Down Expand Up @@ -1597,6 +1604,7 @@ dependencies = [
"rayon",
"rustc-hash",
"scip",
"semver",
"serde",
"serde_json",
"sourcegen",
Expand Down
4 changes: 4 additions & 0 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ anyhow = "1.0.75"
arrayvec = "0.7.4"
bitflags = "2.4.1"
cargo_metadata = "0.18.1"
chalk-solve = { version = "0.96.0", default-features = false }
chalk-ir = "0.96.0"
chalk-recursive = { version = "0.96.0", default-features = false }
chalk-derive = "0.96.0"
command-group = "2.0.1"
crossbeam-channel = "0.5.8"
dissimilar = "1.0.7"
Expand Down
2 changes: 2 additions & 0 deletions src/tools/rust-analyzer/crates/base-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ rust-version.workspace = true
doctest = false

[dependencies]
lz4_flex = { version = "0.11", default-features = false }

la-arena.workspace = true
salsa.workspace = true
rustc-hash.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/crates/base-db/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use salsa::Durability;
use triomphe::Arc;
use vfs::FileId;

use crate::{CrateGraph, SourceDatabaseExt, SourceRoot, SourceRootId};
use crate::{CrateGraph, SourceDatabaseExt, SourceDatabaseExt2, SourceRoot, SourceRootId};

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

Expand Down Expand Up @@ -42,7 +42,7 @@ impl FileChange {
self.roots = Some(roots);
}

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

Expand All @@ -68,8 +68,8 @@ impl FileChange {
let source_root = db.source_root(source_root_id);
let durability = durability(&source_root);
// XXX: can't actually remove the file, just reset the text
let text = text.unwrap_or_else(|| Arc::from(""));
db.set_file_text_with_durability(file_id, text, durability)
let text = text.unwrap_or_default();
db.set_file_text_with_durability(file_id, &text, durability)
}
if let Some(crate_graph) = self.crate_graph {
db.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH);
Expand Down
43 changes: 43 additions & 0 deletions src/tools/rust-analyzer/crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod input;

use std::panic;

use salsa::Durability;
use syntax::{ast, Parse, SourceFile};
use triomphe::Arc;

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

pub const DEFAULT_FILE_TEXT_LRU_CAP: usize = 16;
pub const DEFAULT_PARSE_LRU_CAP: usize = 128;
pub const DEFAULT_BORROWCK_LRU_CAP: usize = 1024;

Expand Down Expand Up @@ -89,7 +91,10 @@ fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
#[salsa::query_group(SourceDatabaseExtStorage)]
pub trait SourceDatabaseExt: SourceDatabase {
#[salsa::input]
fn compressed_file_text(&self, file_id: FileId) -> Arc<[u8]>;

fn file_text(&self, file_id: FileId) -> Arc<str>;

/// Path to a file, relative to the root of its source root.
/// Source root of the file.
#[salsa::input]
Expand All @@ -101,6 +106,44 @@ pub trait SourceDatabaseExt: SourceDatabase {
fn source_root_crates(&self, id: SourceRootId) -> Arc<[CrateId]>;
}

fn file_text(db: &dyn SourceDatabaseExt, file_id: FileId) -> Arc<str> {
let bytes = db.compressed_file_text(file_id);
let bytes =
lz4_flex::decompress_size_prepended(&bytes).expect("lz4 decompression should not fail");
let text = std::str::from_utf8(&bytes).expect("file contents should be valid UTF-8");
Arc::from(text)
}

pub trait SourceDatabaseExt2 {
fn set_file_text(&mut self, file_id: FileId, text: &str) {
self.set_file_text_with_durability(file_id, text, Durability::LOW);
}

fn set_file_text_with_durability(
&mut self,
file_id: FileId,
text: &str,
durability: Durability,
);
}

impl<Db: ?Sized + SourceDatabaseExt> SourceDatabaseExt2 for Db {
fn set_file_text_with_durability(
&mut self,
file_id: FileId,
text: &str,
durability: Durability,
) {
let bytes = text.as_bytes();
let compressed = lz4_flex::compress_prepend_size(bytes);
self.set_compressed_file_text_with_durability(
file_id,
Arc::from(compressed.as_slice()),
durability,
)
}
}

fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<[CrateId]> {
let graph = db.crate_graph();
let mut crates = graph
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/cfg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ mbe.workspace = true
syntax.workspace = true

[lints]
workspace = true
workspace = true
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl CfgExpr {
pub fn parse<S>(tt: &tt::Subtree<S>) -> CfgExpr {
next_cfg_expr(&mut tt.token_trees.iter()).unwrap_or(CfgExpr::Invalid)
}

/// Fold the cfg by querying all basic `Atom` and `KeyValue` predicates.
pub fn fold(&self, query: &dyn Fn(&CfgAtom) -> bool) -> Option<bool> {
match self {
Expand All @@ -62,7 +63,6 @@ impl CfgExpr {
}
}
}

fn next_cfg_expr<S>(it: &mut SliceIter<'_, tt::TokenTree<S>>) -> Option<CfgExpr> {
let name = match it.next() {
None => return None,
Expand Down
9 changes: 5 additions & 4 deletions src/tools/rust-analyzer/crates/flycheck/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ pub enum CargoTestMessage {
},
Suite,
Finished,
Custom {
text: String,
},
}

impl ParseFromLine for CargoTestMessage {
fn from_line(line: &str, error: &mut String) -> Option<Self> {
fn from_line(line: &str, _: &mut String) -> Option<Self> {
let mut deserializer = serde_json::Deserializer::from_str(line);
deserializer.disable_recursion_limit();
if let Ok(message) = CargoTestMessage::deserialize(&mut deserializer) {
return Some(message);
}

error.push_str(line);
error.push('\n');
None
Some(CargoTestMessage::Custom { text: line.to_owned() })
}

fn from_eof() -> Option<Self> {
Expand Down
25 changes: 14 additions & 11 deletions src/tools/rust-analyzer/crates/hir-def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::ops::Index;

use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_expand::{name::Name, HirFileId, InFile};
use la_arena::{Arena, ArenaMap};
use rustc_hash::FxHashMap;
Expand Down Expand Up @@ -45,7 +44,8 @@ pub struct Body {
///
/// If this `Body` is for the body of a constant, this will just be
/// empty.
pub params: Vec<PatId>,
pub params: Box<[PatId]>,
pub self_param: Option<BindingId>,
/// The `ExprId` of the actual body expression.
pub body_expr: ExprId,
/// Block expressions in this body that may contain inner items.
Expand All @@ -55,14 +55,15 @@ pub struct Body {
pub type ExprPtr = AstPtr<ast::Expr>;
pub type ExprSource = InFile<ExprPtr>;

pub type PatPtr = AstPtr<Either<ast::Pat, ast::SelfParam>>;
pub type PatPtr = AstPtr<ast::Pat>;
pub type PatSource = InFile<PatPtr>;

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

pub type FieldPtr = AstPtr<ast::RecordExprField>;
pub type FieldSource = InFile<FieldPtr>;

pub type PatFieldPtr = AstPtr<ast::RecordPatField>;
pub type PatFieldSource = InFile<PatFieldPtr>;

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

self_param: Option<InFile<AstPtr<ast::SelfParam>>>,

/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
/// Instead, we use id of expression (`92`) to identify the field.
field_map_back: FxHashMap<ExprId, FieldSource>,
Expand Down Expand Up @@ -215,18 +218,18 @@ impl Body {
fn shrink_to_fit(&mut self) {
let Self {
body_expr: _,
params: _,
self_param: _,
block_scopes,
exprs,
labels,
params,
pats,
bindings,
binding_owners,
} = self;
block_scopes.shrink_to_fit();
exprs.shrink_to_fit();
labels.shrink_to_fit();
params.shrink_to_fit();
pats.shrink_to_fit();
bindings.shrink_to_fit();
binding_owners.shrink_to_fit();
Expand Down Expand Up @@ -297,6 +300,7 @@ impl Default for Body {
params: Default::default(),
block_scopes: Default::default(),
binding_owners: Default::default(),
self_param: Default::default(),
}
}
}
Expand Down Expand Up @@ -354,14 +358,12 @@ impl BodySourceMap {
self.pat_map_back.get(pat).cloned().ok_or(SyntheticSyntax)
}

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

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

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

fn shrink_to_fit(&mut self) {
let Self {
self_param: _,
expr_map,
expr_map_back,
pat_map,
Expand Down
Loading

0 comments on commit a0c20d5

Please sign in to comment.