mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Replace HashMap, HashSet with FxHashMap and FxHashSet
This commit is contained in:
parent
9b155c8976
commit
dc2b30e9b6
20 changed files with 68 additions and 49 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -540,6 +540,7 @@ dependencies = [
|
||||||
"ra_syntax 0.1.0",
|
"ra_syntax 0.1.0",
|
||||||
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"salsa 0.1.0",
|
"salsa 0.1.0",
|
||||||
"test_utils 0.1.0",
|
"test_utils 0.1.0",
|
||||||
]
|
]
|
||||||
|
@ -563,6 +564,7 @@ dependencies = [
|
||||||
"itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ra_syntax 0.1.0",
|
"ra_syntax 0.1.0",
|
||||||
|
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"test_utils 0.1.0",
|
"test_utils 0.1.0",
|
||||||
]
|
]
|
||||||
|
@ -585,6 +587,7 @@ dependencies = [
|
||||||
"ra_syntax 0.1.0",
|
"ra_syntax 0.1.0",
|
||||||
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -727,6 +730,14 @@ name = "rustc-demangle"
|
||||||
version = "0.1.9"
|
version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-hash"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_version"
|
name = "rustc_version"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
|
@ -1241,6 +1252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"checksum ron 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9fa11b7a38511d46ff1959ae46ebb60bd8a746f17bdd0206b4c8de7559ac47b"
|
"checksum ron 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9fa11b7a38511d46ff1959ae46ebb60bd8a746f17bdd0206b4c8de7559ac47b"
|
||||||
"checksum rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a1a7366ece9deee5e7df8316a136d585d5c5042854c2297f7f1aee3014c9130"
|
"checksum rowan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a1a7366ece9deee5e7df8316a136d585d5c5042854c2297f7f1aee3014c9130"
|
||||||
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
|
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
|
||||||
|
"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
|
||||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||||
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
|
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
|
||||||
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
|
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
|
||||||
|
|
|
@ -15,6 +15,7 @@ im = "12.0.0"
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
ra_editor = { path = "../ra_editor" }
|
ra_editor = { path = "../ra_editor" }
|
||||||
salsa = { path = "../salsa" }
|
salsa = { path = "../salsa" }
|
||||||
|
rustc-hash = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
|
|
@ -2,9 +2,10 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
any::Any,
|
any::Any,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
collections::hash_map::{DefaultHasher, HashMap},
|
collections::hash_map::{DefaultHasher},
|
||||||
iter,
|
iter,
|
||||||
};
|
};
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
use salsa;
|
use salsa;
|
||||||
use {FileId, imp::FileResolverImp};
|
use {FileId, imp::FileResolverImp};
|
||||||
use super::{State, Query, QueryCtx};
|
use super::{State, Query, QueryCtx};
|
||||||
|
@ -13,7 +14,7 @@ pub(super) type Data = Arc<Any + Send + Sync + 'static>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct Db {
|
pub(super) struct Db {
|
||||||
names: Arc<HashMap<salsa::QueryTypeId, &'static str>>,
|
names: Arc<FxHashMap<salsa::QueryTypeId, &'static str>>,
|
||||||
pub(super) imp: salsa::Db<State, Data>,
|
pub(super) imp: salsa::Db<State, Data>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ where
|
||||||
|
|
||||||
pub(super) struct QueryRegistry {
|
pub(super) struct QueryRegistry {
|
||||||
config: Option<salsa::QueryConfig<State, Data>>,
|
config: Option<salsa::QueryConfig<State, Data>>,
|
||||||
names: HashMap<salsa::QueryTypeId, &'static str>,
|
names: FxHashMap<salsa::QueryTypeId, &'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QueryRegistry {
|
impl QueryRegistry {
|
||||||
|
@ -109,7 +110,7 @@ impl QueryRegistry {
|
||||||
(Arc::new(res), fingerprint)
|
(Arc::new(res), fingerprint)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
let mut names = HashMap::new();
|
let mut names = FxHashMap::default();
|
||||||
names.insert(FILE_TEXT, "FILE_TEXT");
|
names.insert(FILE_TEXT, "FILE_TEXT");
|
||||||
names.insert(FILE_SET, "FILE_SET");
|
names.insert(FILE_SET, "FILE_SET");
|
||||||
QueryRegistry { config: Some(config), names }
|
QueryRegistry { config: Some(config), names }
|
||||||
|
|
|
@ -4,11 +4,12 @@ use std::{
|
||||||
atomic::{AtomicBool, Ordering::SeqCst},
|
atomic::{AtomicBool, Ordering::SeqCst},
|
||||||
},
|
},
|
||||||
fmt,
|
fmt,
|
||||||
collections::{HashSet, VecDeque},
|
collections::VecDeque,
|
||||||
iter,
|
iter,
|
||||||
};
|
};
|
||||||
|
|
||||||
use relative_path::RelativePath;
|
use relative_path::RelativePath;
|
||||||
|
use rustc_hash::FxHashSet;
|
||||||
use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name};
|
use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
TextUnit, TextRange, SmolStr, File, AstNode,
|
TextUnit, TextRange, SmolStr, File, AstNode,
|
||||||
|
@ -84,7 +85,7 @@ impl AnalysisHostImpl {
|
||||||
data.root = Arc::new(data.root.apply_changes(&mut iter::empty(), Some(resolver)));
|
data.root = Arc::new(data.root.apply_changes(&mut iter::empty(), Some(resolver)));
|
||||||
}
|
}
|
||||||
pub fn set_crate_graph(&mut self, graph: CrateGraph) {
|
pub fn set_crate_graph(&mut self, graph: CrateGraph) {
|
||||||
let mut visited = HashSet::new();
|
let mut visited = FxHashSet::default();
|
||||||
for &file_id in graph.crate_roots.values() {
|
for &file_id in graph.crate_roots.values() {
|
||||||
if !visited.insert(file_id) {
|
if !visited.insert(file_id) {
|
||||||
panic!("duplicate crate root: {:?}", file_id);
|
panic!("duplicate crate root: {:?}", file_id);
|
||||||
|
@ -168,7 +169,7 @@ impl AnalysisImpl {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let mut work = VecDeque::new();
|
let mut work = VecDeque::new();
|
||||||
work.push_back(file_id);
|
work.push_back(file_id);
|
||||||
let mut visited = HashSet::new();
|
let mut visited = FxHashSet::default();
|
||||||
while let Some(id) = work.pop_front() {
|
while let Some(id) = work.pop_front() {
|
||||||
if let Some(crate_id) = crate_graph.crate_id_for_crate_root(id) {
|
if let Some(crate_id) = crate_graph.crate_id_for_crate_root(id) {
|
||||||
res.push(crate_id);
|
res.push(crate_id);
|
||||||
|
|
|
@ -11,6 +11,7 @@ extern crate relative_path;
|
||||||
extern crate crossbeam_channel;
|
extern crate crossbeam_channel;
|
||||||
extern crate im;
|
extern crate im;
|
||||||
extern crate salsa;
|
extern crate salsa;
|
||||||
|
extern crate rustc_hash;
|
||||||
|
|
||||||
mod symbol_index;
|
mod symbol_index;
|
||||||
mod module_map;
|
mod module_map;
|
||||||
|
@ -23,13 +24,13 @@ mod descriptors;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
collections::HashMap,
|
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
};
|
};
|
||||||
|
|
||||||
use relative_path::{RelativePath, RelativePathBuf};
|
use relative_path::{RelativePath, RelativePathBuf};
|
||||||
use ra_syntax::{File, TextRange, TextUnit, AtomEdit};
|
use ra_syntax::{File, TextRange, TextUnit, AtomEdit};
|
||||||
use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp};
|
use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp};
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
pub use ra_editor::{
|
pub use ra_editor::{
|
||||||
StructureNode, LineIndex, FileSymbol,
|
StructureNode, LineIndex, FileSymbol,
|
||||||
|
@ -46,7 +47,7 @@ pub struct CrateId(pub u32);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct CrateGraph {
|
pub struct CrateGraph {
|
||||||
pub crate_roots: HashMap<CrateId, FileId>,
|
pub crate_roots: FxHashMap<CrateId, FileId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FileResolver: Debug + Send + Sync + 'static {
|
pub trait FileResolver: Debug + Send + Sync + 'static {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
panic,
|
panic,
|
||||||
};
|
};
|
||||||
|
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
use ra_editor::LineIndex;
|
use ra_editor::LineIndex;
|
||||||
use ra_syntax::File;
|
use ra_syntax::File;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ impl FileData {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ReadonlySourceRoot {
|
pub(crate) struct ReadonlySourceRoot {
|
||||||
symbol_index: Arc<SymbolIndex>,
|
symbol_index: Arc<SymbolIndex>,
|
||||||
file_map: HashMap<FileId, FileData>,
|
file_map: FxHashMap<FileId, FileData>,
|
||||||
module_tree: Arc<ModuleTreeDescriptor>,
|
module_tree: Arc<ModuleTreeDescriptor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ impl ReadonlySourceRoot {
|
||||||
let symbol_index = SymbolIndex::for_files(
|
let symbol_index = SymbolIndex::for_files(
|
||||||
modules.par_iter().map(|it| (it.0, it.1.clone()))
|
modules.par_iter().map(|it| (it.0, it.1.clone()))
|
||||||
);
|
);
|
||||||
let file_map: HashMap<FileId, FileData> = files
|
let file_map: FxHashMap<FileId, FileData> = files
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(id, text)| (id, FileData::new(text)))
|
.map(|(id, text)| (id, FileData::new(text)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
extern crate relative_path;
|
extern crate relative_path;
|
||||||
extern crate ra_analysis;
|
extern crate ra_analysis;
|
||||||
|
extern crate rustc_hash;
|
||||||
extern crate test_utils;
|
extern crate test_utils;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
collections::HashMap,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
use relative_path::{RelativePath, RelativePathBuf};
|
use relative_path::{RelativePath, RelativePathBuf};
|
||||||
use ra_analysis::{Analysis, AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId};
|
use ra_analysis::{Analysis, AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId};
|
||||||
use test_utils::assert_eq_dbg;
|
use test_utils::assert_eq_dbg;
|
||||||
|
@ -131,7 +132,7 @@ fn test_resolve_crate_root() {
|
||||||
|
|
||||||
let crate_graph = CrateGraph {
|
let crate_graph = CrateGraph {
|
||||||
crate_roots: {
|
crate_roots: {
|
||||||
let mut m = HashMap::new();
|
let mut m = FxHashMap::default();
|
||||||
m.insert(CrateId(1), FileId(1));
|
m.insert(CrateId(1), FileId(1));
|
||||||
m
|
m
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@ publish = false
|
||||||
itertools = "0.7.8"
|
itertools = "0.7.8"
|
||||||
superslice = "0.1.0"
|
superslice = "0.1.0"
|
||||||
join_to_string = "0.1.1"
|
join_to_string = "0.1.1"
|
||||||
|
rustc-hash = "1.0"
|
||||||
|
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::{HashSet, HashMap};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
File, TextUnit, AstNode, SyntaxNodeRef, SyntaxKind::*,
|
File, TextUnit, AstNode, SyntaxNodeRef, SyntaxKind::*,
|
||||||
|
@ -96,7 +96,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<Completi
|
||||||
}
|
}
|
||||||
|
|
||||||
fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
|
fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
|
||||||
let mut params = HashMap::new();
|
let mut params = FxHashMap::default();
|
||||||
for node in ctx.ancestors() {
|
for node in ctx.ancestors() {
|
||||||
let _ = visitor_ctx(&mut params)
|
let _ = visitor_ctx(&mut params)
|
||||||
.visit::<ast::Root, _>(process)
|
.visit::<ast::Root, _>(process)
|
||||||
|
@ -114,7 +114,7 @@ fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec<CompletionItem>) {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
fn process<'a, N: ast::FnDefOwner<'a>>(node: N, params: &mut HashMap<String, (u32, ast::Param<'a>)>) {
|
fn process<'a, N: ast::FnDefOwner<'a>>(node: N, params: &mut FxHashMap<String, (u32, ast::Param<'a>)>) {
|
||||||
node.functions()
|
node.functions()
|
||||||
.filter_map(|it| it.param_list())
|
.filter_map(|it| it.param_list())
|
||||||
.flat_map(|it| it.params())
|
.flat_map(|it| it.params())
|
||||||
|
@ -232,7 +232,7 @@ fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) {
|
fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) {
|
||||||
let mut shadowed = HashSet::new();
|
let mut shadowed = FxHashSet::default();
|
||||||
acc.extend(
|
acc.extend(
|
||||||
scopes.scope_chain(name_ref.syntax())
|
scopes.scope_chain(name_ref.syntax())
|
||||||
.flat_map(|scope| scopes.entries(scope).iter())
|
.flat_map(|scope| scopes.entries(scope).iter())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::HashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
File, TextRange, SyntaxNodeRef,
|
File, TextRange, SyntaxNodeRef,
|
||||||
|
@ -20,7 +20,7 @@ pub struct Fold {
|
||||||
|
|
||||||
pub fn folding_ranges(file: &File) -> Vec<Fold> {
|
pub fn folding_ranges(file: &File) -> Vec<Fold> {
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
let mut visited = HashSet::new();
|
let mut visited = FxHashSet::default();
|
||||||
|
|
||||||
for node in file.syntax().descendants() {
|
for node in file.syntax().descendants() {
|
||||||
if visited.contains(&node) {
|
if visited.contains(&node) {
|
||||||
|
@ -56,7 +56,7 @@ pub fn folding_ranges(file: &File) -> Vec<Fold> {
|
||||||
fn contiguous_range_for<'a>(
|
fn contiguous_range_for<'a>(
|
||||||
kind: SyntaxKind,
|
kind: SyntaxKind,
|
||||||
node: SyntaxNodeRef<'a>,
|
node: SyntaxNodeRef<'a>,
|
||||||
visited: &mut HashSet<SyntaxNodeRef<'a>>,
|
visited: &mut FxHashSet<SyntaxNodeRef<'a>>,
|
||||||
) -> Option<TextRange> {
|
) -> Option<TextRange> {
|
||||||
visited.insert(node);
|
visited.insert(node);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ extern crate ra_syntax;
|
||||||
extern crate superslice;
|
extern crate superslice;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate join_to_string;
|
extern crate join_to_string;
|
||||||
|
extern crate rustc_hash;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate test_utils as _test_utils;
|
extern crate test_utils as _test_utils;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
use std::{
|
use std::fmt;
|
||||||
fmt,
|
use rustc_hash::FxHashMap;
|
||||||
collections::HashMap,
|
|
||||||
};
|
|
||||||
|
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
SyntaxNodeRef, SyntaxNode, SmolStr, AstNode,
|
SyntaxNodeRef, SyntaxNode, SmolStr, AstNode,
|
||||||
|
@ -15,7 +13,7 @@ type ScopeId = usize;
|
||||||
pub struct FnScopes {
|
pub struct FnScopes {
|
||||||
pub self_param: Option<SyntaxNode>,
|
pub self_param: Option<SyntaxNode>,
|
||||||
scopes: Vec<ScopeData>,
|
scopes: Vec<ScopeData>,
|
||||||
scope_for: HashMap<SyntaxNode, ScopeId>,
|
scope_for: FxHashMap<SyntaxNode, ScopeId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FnScopes {
|
impl FnScopes {
|
||||||
|
@ -25,7 +23,7 @@ impl FnScopes {
|
||||||
.and_then(|it| it.self_param())
|
.and_then(|it| it.self_param())
|
||||||
.map(|it| it.syntax().owned()),
|
.map(|it| it.syntax().owned()),
|
||||||
scopes: Vec::new(),
|
scopes: Vec::new(),
|
||||||
scope_for: HashMap::new()
|
scope_for: FxHashMap::default()
|
||||||
};
|
};
|
||||||
let root = scopes.root_scope();
|
let root = scopes.root_scope();
|
||||||
scopes.add_params_bindings(root, fn_def.param_list());
|
scopes.add_params_bindings(root, fn_def.param_list());
|
||||||
|
@ -242,9 +240,9 @@ struct ScopeData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_local_name<'a>(name_ref: ast::NameRef, scopes: &'a FnScopes) -> Option<&'a ScopeEntry> {
|
pub fn resolve_local_name<'a>(name_ref: ast::NameRef, scopes: &'a FnScopes) -> Option<&'a ScopeEntry> {
|
||||||
use std::collections::HashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
let mut shadowed = HashSet::new();
|
let mut shadowed = FxHashSet::default();
|
||||||
let ret = scopes.scope_chain(name_ref.syntax())
|
let ret = scopes.scope_chain(name_ref.syntax())
|
||||||
.flat_map(|scope| scopes.entries(scope).iter())
|
.flat_map(|scope| scopes.entries(scope).iter())
|
||||||
.filter(|entry| shadowed.insert(entry.name()))
|
.filter(|entry| shadowed.insert(entry.name()))
|
||||||
|
|
|
@ -21,6 +21,7 @@ im = "12.0.0"
|
||||||
cargo_metadata = "0.6.0"
|
cargo_metadata = "0.6.0"
|
||||||
text_unit = { version = "0.1.2", features = ["serde"] }
|
text_unit = { version = "0.1.2", features = ["serde"] }
|
||||||
smol_str = { version = "0.1.5", features = ["serde"] }
|
smol_str = { version = "0.1.5", features = ["serde"] }
|
||||||
|
rustc-hash = "1.0"
|
||||||
|
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
ra_editor = { path = "../ra_editor" }
|
ra_editor = { path = "../ra_editor" }
|
||||||
|
|
|
@ -16,6 +16,7 @@ extern crate walkdir;
|
||||||
extern crate im;
|
extern crate im;
|
||||||
extern crate relative_path;
|
extern crate relative_path;
|
||||||
extern crate cargo_metadata;
|
extern crate cargo_metadata;
|
||||||
|
extern crate rustc_hash;
|
||||||
|
|
||||||
extern crate gen_lsp_server;
|
extern crate gen_lsp_server;
|
||||||
extern crate ra_editor;
|
extern crate ra_editor;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::{HashMap};
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use languageserver_types::{
|
use languageserver_types::{
|
||||||
Diagnostic, DiagnosticSeverity, DocumentSymbol,
|
Diagnostic, DiagnosticSeverity, DocumentSymbol,
|
||||||
|
@ -267,7 +267,7 @@ pub fn handle_runnables(
|
||||||
bin: "cargo".to_string(),
|
bin: "cargo".to_string(),
|
||||||
args,
|
args,
|
||||||
env: {
|
env: {
|
||||||
let mut m = HashMap::new();
|
let mut m = FxHashMap::default();
|
||||||
m.insert(
|
m.insert(
|
||||||
"RUST_BACKTRACE".to_string(),
|
"RUST_BACKTRACE".to_string(),
|
||||||
"short".to_string(),
|
"short".to_string(),
|
||||||
|
|
|
@ -3,7 +3,6 @@ mod subscriptions;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
collections::{HashMap},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
|
@ -15,6 +14,7 @@ use gen_lsp_server::{
|
||||||
RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode,
|
RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode,
|
||||||
handle_shutdown,
|
handle_shutdown,
|
||||||
};
|
};
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
req,
|
req,
|
||||||
|
@ -50,7 +50,7 @@ pub fn main_loop(
|
||||||
info!("server initialized, serving requests");
|
info!("server initialized, serving requests");
|
||||||
let mut state = ServerWorldState::new();
|
let mut state = ServerWorldState::new();
|
||||||
|
|
||||||
let mut pending_requests = HashMap::new();
|
let mut pending_requests = FxHashMap::default();
|
||||||
let mut subs = Subscriptions::new();
|
let mut subs = Subscriptions::new();
|
||||||
let main_res = main_loop_inner(
|
let main_res = main_loop_inner(
|
||||||
internal_mode,
|
internal_mode,
|
||||||
|
@ -95,7 +95,7 @@ fn main_loop_inner(
|
||||||
fs_worker: Worker<PathBuf, (PathBuf, Vec<FileEvent>)>,
|
fs_worker: Worker<PathBuf, (PathBuf, Vec<FileEvent>)>,
|
||||||
ws_worker: Worker<PathBuf, Result<CargoWorkspace>>,
|
ws_worker: Worker<PathBuf, Result<CargoWorkspace>>,
|
||||||
state: &mut ServerWorldState,
|
state: &mut ServerWorldState,
|
||||||
pending_requests: &mut HashMap<u64, JobHandle>,
|
pending_requests: &mut FxHashMap<u64, JobHandle>,
|
||||||
subs: &mut Subscriptions,
|
subs: &mut Subscriptions,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (libdata_sender, libdata_receiver) = unbounded();
|
let (libdata_sender, libdata_receiver) = unbounded();
|
||||||
|
@ -213,7 +213,7 @@ fn main_loop_inner(
|
||||||
fn on_task(
|
fn on_task(
|
||||||
task: Task,
|
task: Task,
|
||||||
msg_sender: &Sender<RawMessage>,
|
msg_sender: &Sender<RawMessage>,
|
||||||
pending_requests: &mut HashMap<u64, JobHandle>,
|
pending_requests: &mut FxHashMap<u64, JobHandle>,
|
||||||
) {
|
) {
|
||||||
match task {
|
match task {
|
||||||
Task::Respond(response) => {
|
Task::Respond(response) => {
|
||||||
|
@ -229,7 +229,7 @@ fn on_task(
|
||||||
|
|
||||||
fn on_request(
|
fn on_request(
|
||||||
world: &mut ServerWorldState,
|
world: &mut ServerWorldState,
|
||||||
pending_requests: &mut HashMap<u64, JobHandle>,
|
pending_requests: &mut FxHashMap<u64, JobHandle>,
|
||||||
pool: &ThreadPool,
|
pool: &ThreadPool,
|
||||||
sender: &Sender<Task>,
|
sender: &Sender<Task>,
|
||||||
req: RawRequest,
|
req: RawRequest,
|
||||||
|
@ -269,7 +269,7 @@ fn on_request(
|
||||||
fn on_notification(
|
fn on_notification(
|
||||||
msg_sender: &Sender<RawMessage>,
|
msg_sender: &Sender<RawMessage>,
|
||||||
state: &mut ServerWorldState,
|
state: &mut ServerWorldState,
|
||||||
pending_requests: &mut HashMap<u64, JobHandle>,
|
pending_requests: &mut FxHashMap<u64, JobHandle>,
|
||||||
subs: &mut Subscriptions,
|
subs: &mut Subscriptions,
|
||||||
not: RawNotification,
|
not: RawNotification,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use std::collections::HashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use ra_analysis::FileId;
|
use ra_analysis::FileId;
|
||||||
|
|
||||||
pub struct Subscriptions {
|
pub struct Subscriptions {
|
||||||
subs: HashSet<FileId>,
|
subs: FxHashSet<FileId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subscriptions {
|
impl Subscriptions {
|
||||||
pub fn new() -> Subscriptions {
|
pub fn new() -> Subscriptions {
|
||||||
Subscriptions { subs: HashSet::new() }
|
Subscriptions { subs: FxHashSet::default() }
|
||||||
}
|
}
|
||||||
pub fn add_sub(&mut self, file_id: FileId) {
|
pub fn add_sub(&mut self, file_id: FileId) {
|
||||||
self.subs.insert(file_id);
|
self.subs.insert(file_id);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use cargo_metadata::{metadata_run, CargoOpt};
|
use cargo_metadata::{metadata_run, CargoOpt};
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::SmolStr;
|
||||||
|
|
||||||
|
@ -80,11 +80,11 @@ impl CargoWorkspace {
|
||||||
true,
|
true,
|
||||||
Some(CargoOpt::AllFeatures)
|
Some(CargoOpt::AllFeatures)
|
||||||
).map_err(|e| format_err!("cargo metadata failed: {}", e))?;
|
).map_err(|e| format_err!("cargo metadata failed: {}", e))?;
|
||||||
let mut pkg_by_id = HashMap::new();
|
let mut pkg_by_id = FxHashMap::default();
|
||||||
let mut packages = Vec::new();
|
let mut packages = Vec::new();
|
||||||
let mut targets = Vec::new();
|
let mut targets = Vec::new();
|
||||||
|
|
||||||
let ws_members: HashSet<String> = meta.workspace_members
|
let ws_members: FxHashSet<String> = meta.workspace_members
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|it| it.raw)
|
.map(|it| it.raw)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::HashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use languageserver_types::{TextDocumentIdentifier, Range, Url, Position, Location};
|
use languageserver_types::{TextDocumentIdentifier, Range, Url, Position, Location};
|
||||||
use url_serde;
|
use url_serde;
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ pub struct Runnable {
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub bin: String,
|
pub bin: String,
|
||||||
pub args: Vec<String>,
|
pub args: Vec<String>,
|
||||||
pub env: HashMap<String, String>,
|
pub env: FxHashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
path::{PathBuf, Path},
|
path::{PathBuf, Path},
|
||||||
collections::HashMap,
|
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
use languageserver_types::Url;
|
use languageserver_types::Url;
|
||||||
use ra_analysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver};
|
use ra_analysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver};
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ pub struct ServerWorldState {
|
||||||
pub workspaces: Arc<Vec<CargoWorkspace>>,
|
pub workspaces: Arc<Vec<CargoWorkspace>>,
|
||||||
pub analysis_host: AnalysisHost,
|
pub analysis_host: AnalysisHost,
|
||||||
pub path_map: PathMap,
|
pub path_map: PathMap,
|
||||||
pub mem_map: HashMap<FileId, Option<String>>,
|
pub mem_map: FxHashMap<FileId, Option<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -36,7 +36,7 @@ impl ServerWorldState {
|
||||||
workspaces: Arc::new(Vec::new()),
|
workspaces: Arc::new(Vec::new()),
|
||||||
analysis_host: AnalysisHost::new(),
|
analysis_host: AnalysisHost::new(),
|
||||||
path_map: PathMap::new(),
|
path_map: PathMap::new(),
|
||||||
mem_map: HashMap::new(),
|
mem_map: FxHashMap::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn apply_fs_changes(&mut self, events: Vec<FileEvent>) {
|
pub fn apply_fs_changes(&mut self, events: Vec<FileEvent>) {
|
||||||
|
@ -121,7 +121,7 @@ impl ServerWorldState {
|
||||||
Ok(file_id)
|
Ok(file_id)
|
||||||
}
|
}
|
||||||
pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) {
|
pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) {
|
||||||
let mut crate_roots = HashMap::new();
|
let mut crate_roots = FxHashMap::default();
|
||||||
ws.iter()
|
ws.iter()
|
||||||
.flat_map(|ws| {
|
.flat_map(|ws| {
|
||||||
ws.packages()
|
ws.packages()
|
||||||
|
|
Loading…
Reference in a new issue