Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtree update of rust-analyzer #118365

Merged
merged 49 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3e4de96
override language client
jprochazk Oct 28, 2023
c566136
add configuration option
jprochazk Nov 7, 2023
0647b64
ensure renames happen after edit
pascalkuthe Nov 10, 2023
6705860
FIxed typo in highlight_related.rs
RunDevelopment Nov 13, 2023
0d147b3
detect internal error via `error.code` instead of error message
jprochazk Nov 15, 2023
9c8727e
Update editors/code/package.json
jprochazk Nov 15, 2023
cfc881a
fix missing assoc item
Young-Flash Nov 16, 2023
e95ec55
fix: better resolve assoc item with type bound
Austaras Nov 2, 2023
59f5d51
Merge commit '141fc695dca1df7cfc3c9803972ec19bb178dcbc' into sync-fro…
lnicola Nov 16, 2023
6a0e02d
Merge branch 'master' into sync-from-rust
lnicola Nov 17, 2023
bc97821
Auto merge of #15917 - lnicola:sync-from-rust, r=lnicola
bors Nov 17, 2023
808f668
address comment
Austaras Nov 17, 2023
1cbda61
chore: add use case for `PathSegment::qualifying_trait`
Young-Flash Nov 17, 2023
a54c0da
Remove debugging code in path resolution
lnicola Nov 17, 2023
255eed4
Auto merge of #15925 - lnicola:pathres-nodebug, r=lnicola
bors Nov 17, 2023
3751429
Auto merge of #15885 - RunDevelopment:patch-1, r=lnicola
bors Nov 20, 2023
1a5cee1
Auto merge of #15911 - Young-Flash:fix_missing_assoc_item, r=lnicola
bors Nov 20, 2023
2e7e8cc
Auto merge of #15940 - pascalkuthe:fix_rename, r=Veykril
bors Nov 21, 2023
8d3522e
Auto merge of #15825 - Austaras:master, r=flodiebold
bors Nov 21, 2023
9f8191b
Update Arch Linux package URL in manual.adoc
brunobell Nov 21, 2023
91b3148
Auto merge of #15944 - brunobell:patch-1, r=lnicola
bors Nov 21, 2023
4513651
Auto merge of #15921 - Young-Flash:tmp, r=Veykril
bors Nov 21, 2023
81c2d35
Cancelable Initialization
schrieveslaach Nov 14, 2023
7ceefc7
Auto merge of #15894 - schrieveslaach:cancelable-initialization, r=Ve…
bors Nov 22, 2023
886eaa0
Relaxation for crate graph mergin
alibektas Sep 24, 2023
7e4aad5
v2
alibektas Oct 15, 2023
25e990d
v3
alibektas Nov 8, 2023
74d8fdc
Update test data for crate deduping
alibektas Nov 11, 2023
f79e818
v3
alibektas Nov 21, 2023
736994f
Make test cases simpler
alibektas Nov 23, 2023
ba1b080
Precede paths with $ROOT$
alibektas Nov 23, 2023
cccc7ca
Auto merge of #15754 - alibektas:15656/linked_projects_are_local_too,…
bors Nov 23, 2023
615abb3
Improve completion label details display
ahlinc Nov 24, 2023
f0adf8c
Update tests
ahlinc Nov 24, 2023
8733728
Auto merge of #15956 - ahlinc:label-detail, r=lnicola
bors Nov 24, 2023
fec3828
Auto merge of #15846 - jprochazk:disable-error-notification, r=Veykril
bors Nov 24, 2023
b68f531
Replace `option.map(cond) == Some(true)` with `option.is_some_and(cond)`
dtolnay Nov 24, 2023
34cffbf
Auto merge of #15960 - dtolnay-contrib:issomeand, r=lnicola
bors Nov 24, 2023
94cea46
fix: add fallback for completion label details
ahlinc Nov 24, 2023
35da60a
Auto merge of #15962 - ahlinc:label-datail2, r=lnicola
bors Nov 25, 2023
fa74ac8
Bump ra-ap-rustc_parse_format
lnicola Nov 25, 2023
c01679e
Bump ra-ap-rustc_lexer
lnicola Nov 25, 2023
aadeb66
Bump ra-ap-rustc_index and ra-ap-rustc_abi
lnicola Nov 25, 2023
fc880be
Bump chalk
lnicola Nov 25, 2023
79ec2c5
Auto merge of #15964 - lnicola:bump-deps, r=lnicola
bors Nov 25, 2023
3ccde00
Switch to our own salsa fork
lnicola Nov 26, 2023
237712f
Auto merge of #15967 - lnicola:salsa-fork, r=lnicola
bors Nov 26, 2023
0c96252
Merge commit '237712fa314237e428e7ef2ab83b979f928a43a1' into sync-fro…
lnicola Nov 27, 2023
d036daa
Remove instant from EXCEPTIONS_RUST_ANALYZER
lnicola Nov 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 123 additions & 181 deletions src/tools/rust-analyzer/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/base-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rust-version.workspace = true
doctest = false

[dependencies]
salsa = "0.17.0-pre.2"
rust-analyzer-salsa = "0.17.0-pre.3"
rustc-hash = "1.1.0"

triomphe.workspace = true
Expand Down
28 changes: 22 additions & 6 deletions src/tools/rust-analyzer/crates/base-db/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use vfs::{file_set::FileSet, VfsPath};

use crate::{
input::{CrateName, CrateOrigin, LangCrateOrigin},
Change, CrateDisplayName, CrateGraph, CrateId, Dependency, Edition, Env, FileId, FilePosition,
FileRange, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacros, ReleaseChannel,
SourceDatabaseExt, SourceRoot, SourceRootId,
Change, CrateDisplayName, CrateGraph, CrateId, Dependency, DependencyKind, Edition, Env,
FileId, FilePosition, FileRange, ProcMacro, ProcMacroExpander, ProcMacroExpansionError,
ProcMacros, ReleaseChannel, SourceDatabaseExt, SourceRoot, SourceRootId,
};

pub const WORKSPACE: SourceRootId = SourceRootId(0);
Expand Down Expand Up @@ -237,7 +237,12 @@ impl ChangeFixture {
crate_graph
.add_dep(
from_id,
Dependency::with_prelude(CrateName::new(&to).unwrap(), to_id, prelude),
Dependency::with_prelude(
CrateName::new(&to).unwrap(),
to_id,
prelude,
DependencyKind::Normal,
),
)
.unwrap();
}
Expand Down Expand Up @@ -275,7 +280,14 @@ impl ChangeFixture {

for krate in all_crates {
crate_graph
.add_dep(krate, Dependency::new(CrateName::new("core").unwrap(), core_crate))
.add_dep(
krate,
Dependency::new(
CrateName::new("core").unwrap(),
core_crate,
DependencyKind::Normal,
),
)
.unwrap();
}
}
Expand Down Expand Up @@ -317,7 +329,11 @@ impl ChangeFixture {
crate_graph
.add_dep(
krate,
Dependency::new(CrateName::new("proc_macros").unwrap(), proc_macros_crate),
Dependency::new(
CrateName::new("proc_macros").unwrap(),
proc_macros_crate,
DependencyKind::Normal,
),
)
.unwrap();
}
Expand Down
189 changes: 161 additions & 28 deletions src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ impl CrateOrigin {
pub fn is_local(&self) -> bool {
matches!(self, CrateOrigin::Local { .. })
}

pub fn is_lib(&self) -> bool {
matches!(self, CrateOrigin::Library { .. })
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -324,6 +328,62 @@ pub struct CrateData {
pub channel: Option<ReleaseChannel>,
}

impl CrateData {
/// Check if [`other`] is almost equal to [`self`] ignoring `CrateOrigin` value.
pub fn eq_ignoring_origin_and_deps(&self, other: &CrateData, ignore_dev_deps: bool) -> bool {
// This method has some obscure bits. These are mostly there to be compliant with
// some patches. References to the patches are given.
if self.root_file_id != other.root_file_id {
return false;
}

if self.display_name != other.display_name {
return false;
}

if self.is_proc_macro != other.is_proc_macro {
return false;
}

if self.edition != other.edition {
return false;
}

if self.version != other.version {
return false;
}

let mut opts = self.cfg_options.difference(&other.cfg_options);
if let Some(it) = opts.next() {
// Don't care if rust_analyzer CfgAtom is the only cfg in the difference set of self's and other's cfgs.
// https://github.com/rust-lang/rust-analyzer/blob/0840038f02daec6ba3238f05d8caa037d28701a0/crates/project-model/src/workspace.rs#L894
if it.to_string() != "rust_analyzer" {
return false;
}

if let Some(_) = opts.next() {
return false;
}
}

if self.env != other.env {
return false;
}

let slf_deps = self.dependencies.iter();
let other_deps = other.dependencies.iter();

if ignore_dev_deps {
return slf_deps
.clone()
.filter(|it| it.kind != DependencyKind::Dev)
.eq(other_deps.clone().filter(|it| it.kind != DependencyKind::Dev));
}

slf_deps.eq(other_deps)
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Edition {
Edition2015,
Expand Down Expand Up @@ -351,26 +411,43 @@ impl Env {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum DependencyKind {
Normal,
Dev,
Build,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Dependency {
pub crate_id: CrateId,
pub name: CrateName,
kind: DependencyKind,
prelude: bool,
}

impl Dependency {
pub fn new(name: CrateName, crate_id: CrateId) -> Self {
Self { name, crate_id, prelude: true }
pub fn new(name: CrateName, crate_id: CrateId, kind: DependencyKind) -> Self {
Self { name, crate_id, prelude: true, kind }
}

pub fn with_prelude(name: CrateName, crate_id: CrateId, prelude: bool) -> Self {
Self { name, crate_id, prelude }
pub fn with_prelude(
name: CrateName,
crate_id: CrateId,
prelude: bool,
kind: DependencyKind,
) -> Self {
Self { name, crate_id, prelude, kind }
}

/// Whether this dependency is to be added to the depending crate's extern prelude.
pub fn is_prelude(&self) -> bool {
self.prelude
}

pub fn kind(&self) -> DependencyKind {
self.kind
}
}

impl CrateGraph {
Expand Down Expand Up @@ -574,23 +651,46 @@ impl CrateGraph {
pub fn extend(&mut self, mut other: CrateGraph, proc_macros: &mut ProcMacroPaths) {
let topo = other.crates_in_topological_order();
let mut id_map: FxHashMap<CrateId, CrateId> = FxHashMap::default();

for topo in topo {
let crate_data = &mut other.arena[topo];

crate_data.dependencies.iter_mut().for_each(|dep| dep.crate_id = id_map[&dep.crate_id]);
crate_data.dependencies.sort_by_key(|dep| dep.crate_id);

let res = self.arena.iter().find_map(
|(id, data)| {
if data == crate_data {
Some(id)
} else {
None
let res = self.arena.iter().find_map(|(id, data)| {
match (&data.origin, &crate_data.origin) {
(a, b) if a == b => {
if data.eq_ignoring_origin_and_deps(&crate_data, false) {
return Some((id, false));
}
}
(a @ CrateOrigin::Local { .. }, CrateOrigin::Library { .. })
| (a @ CrateOrigin::Library { .. }, CrateOrigin::Local { .. }) => {
// If the origins differ, check if the two crates are equal without
// considering the dev dependencies, if they are, they most likely are in
// different loaded workspaces which may cause issues. We keep the local
// version and discard the library one as the local version may have
// dev-dependencies that we want to keep resolving. See #15656 for more
// information.
if data.eq_ignoring_origin_and_deps(&crate_data, true) {
return Some((id, if a.is_local() { false } else { true }));
}
}
},
);
if let Some(res) = res {
(_, _) => return None,
}

None
});

if let Some((res, should_update_lib_to_local)) = res {
id_map.insert(topo, res);
if should_update_lib_to_local {
assert!(self.arena[res].origin.is_lib());
assert!(crate_data.origin.is_local());
self.arena[res].origin = crate_data.origin.clone();

// Move local's dev dependencies into the newly-local-formerly-lib crate.
self.arena[res].dependencies = crate_data.dependencies.clone();
}
} else {
let id = self.arena.alloc(crate_data.clone());
id_map.insert(topo, id);
Expand Down Expand Up @@ -636,9 +736,11 @@ impl CrateGraph {
match (cfg_if, std) {
(Some(cfg_if), Some(std)) => {
self.arena[cfg_if].dependencies.clear();
self.arena[std]
.dependencies
.push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
self.arena[std].dependencies.push(Dependency::new(
CrateName::new("cfg_if").unwrap(),
cfg_if,
DependencyKind::Normal,
));
true
}
_ => false,
Expand All @@ -658,6 +760,8 @@ impl ops::Index<CrateId> for CrateGraph {
}

impl CrateData {
/// Add a dependency to `self` without checking if the dependency
// is existent among `self.dependencies`.
fn add_dep(&mut self, dep: Dependency) {
self.dependencies.push(dep)
}
Expand Down Expand Up @@ -759,7 +863,7 @@ impl fmt::Display for CyclicDependenciesError {

#[cfg(test)]
mod tests {
use crate::CrateOrigin;
use crate::{CrateOrigin, DependencyKind};

use super::{CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId};

Expand Down Expand Up @@ -806,13 +910,22 @@ mod tests {
None,
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
.add_dep(
crate1,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_ok());
assert!(graph
.add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3))
.add_dep(
crate2,
Dependency::new(CrateName::new("crate3").unwrap(), crate3, DependencyKind::Normal)
)
.is_ok());
assert!(graph
.add_dep(crate3, Dependency::new(CrateName::new("crate1").unwrap(), crate1))
.add_dep(
crate3,
Dependency::new(CrateName::new("crate1").unwrap(), crate1, DependencyKind::Normal)
)
.is_err());
}

Expand Down Expand Up @@ -846,10 +959,16 @@ mod tests {
None,
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
.add_dep(
crate1,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_ok());
assert!(graph
.add_dep(crate2, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
.add_dep(
crate2,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_err());
}

Expand Down Expand Up @@ -896,10 +1015,16 @@ mod tests {
None,
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
.add_dep(
crate1,
Dependency::new(CrateName::new("crate2").unwrap(), crate2, DependencyKind::Normal)
)
.is_ok());
assert!(graph
.add_dep(crate2, Dependency::new(CrateName::new("crate3").unwrap(), crate3))
.add_dep(
crate2,
Dependency::new(CrateName::new("crate3").unwrap(), crate3, DependencyKind::Normal)
)
.is_ok());
}

Expand Down Expand Up @@ -935,12 +1060,20 @@ mod tests {
assert!(graph
.add_dep(
crate1,
Dependency::new(CrateName::normalize_dashes("crate-name-with-dashes"), crate2)
Dependency::new(
CrateName::normalize_dashes("crate-name-with-dashes"),
crate2,
DependencyKind::Normal
)
)
.is_ok());
assert_eq!(
graph[crate1].dependencies,
vec![Dependency::new(CrateName::new("crate_name_with_dashes").unwrap(), crate2)]
vec![Dependency::new(
CrateName::new("crate_name_with_dashes").unwrap(),
crate2,
DependencyKind::Normal
)]
);
}
}
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_hash::FxHashSet;
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
use triomphe::Arc;

pub use crate::input::DependencyKind;
pub use crate::{
change::Change,
input::{
Expand Down
7 changes: 7 additions & 0 deletions src/tools/rust-analyzer/crates/cfg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ impl CfgOptions {
self.enabled.insert(CfgAtom::KeyValue { key, value });
}

pub fn difference<'a>(
&'a self,
other: &'a CfgOptions,
) -> impl Iterator<Item = &'a CfgAtom> + 'a {
self.enabled.difference(&other.enabled)
}

pub fn apply_diff(&mut self, diff: CfgDiff) {
for atom in diff.enable {
self.enabled.insert(atom);
Expand Down
Loading
Loading