mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Merge #270
270: Checks r=matklad a=matklad I see occasional panics when binding sources. Hopefully this assertions will make it clear where do the panics come from/ Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
77b70fcfd4
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -697,6 +697,7 @@ dependencies = [
|
||||
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"test_utils 0.1.0",
|
||||
"text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -1103,6 +1104,14 @@ dependencies = [
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "threadpool"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.40"
|
||||
@ -1414,6 +1423,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f"
|
||||
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
|
||||
"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
|
||||
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
|
||||
"checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77"
|
||||
|
@ -110,16 +110,32 @@ pub struct SourceItemId {
|
||||
}
|
||||
|
||||
/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back.
|
||||
#[derive(Debug, PartialEq, Eq, Default)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct SourceFileItems {
|
||||
file_id: FileId,
|
||||
arena: Arena<SyntaxNode>,
|
||||
}
|
||||
|
||||
impl SourceFileItems {
|
||||
fn new(file_id: FileId) -> SourceFileItems {
|
||||
SourceFileItems {
|
||||
file_id,
|
||||
arena: Arena::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId {
|
||||
self.arena.alloc(item)
|
||||
}
|
||||
pub fn id_of(&self, item: SyntaxNodeRef) -> SourceFileItemId {
|
||||
pub fn id_of(&self, file_id: FileId, item: SyntaxNodeRef) -> SourceFileItemId {
|
||||
assert_eq!(
|
||||
self.file_id, file_id,
|
||||
"SourceFileItems: wrong file, expected {:?}, got {:?}",
|
||||
self.file_id, file_id
|
||||
);
|
||||
self.id_of_unchecked(item)
|
||||
}
|
||||
fn id_of_unchecked(&self, item: SyntaxNodeRef) -> SourceFileItemId {
|
||||
let (id, _item) = self
|
||||
.arena
|
||||
.iter()
|
||||
|
@ -280,7 +280,7 @@ impl ModuleSource {
|
||||
) -> ModuleSource {
|
||||
assert!(!m.has_semi());
|
||||
let file_items = db.file_items(file_id);
|
||||
let item_id = file_items.id_of(m.syntax());
|
||||
let item_id = file_items.id_of(file_id, m.syntax());
|
||||
ModuleSource::new(file_id, item_id)
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ impl InputModuleItems {
|
||||
}
|
||||
|
||||
fn add_use_item(&mut self, file_items: &SourceFileItems, item: ast::UseItem) {
|
||||
let file_item_id = file_items.id_of(item.syntax());
|
||||
let file_item_id = file_items.id_of_unchecked(item.syntax());
|
||||
let start_offset = item.syntax().range().start();
|
||||
Path::expand_use_item(item, |path, range| {
|
||||
let kind = match range {
|
||||
@ -188,7 +188,7 @@ impl ModuleItem {
|
||||
let name = item.name()?.text();
|
||||
let kind = item.syntax().kind();
|
||||
let vis = Vis::Other;
|
||||
let id = file_items.id_of(item.syntax());
|
||||
let id = file_items.id_of_unchecked(item.syntax());
|
||||
let res = ModuleItem {
|
||||
id,
|
||||
name,
|
||||
|
@ -36,7 +36,7 @@ pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
|
||||
}
|
||||
|
||||
pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> {
|
||||
let mut res = SourceFileItems::default();
|
||||
let mut res = SourceFileItems::new(file_id);
|
||||
let source_file = db.source_file(file_id);
|
||||
res.alloc(source_file.syntax().owned());
|
||||
let source_file = source_file.borrowed();
|
||||
|
@ -75,7 +75,7 @@ pub fn function_from_source(
|
||||
) -> Cancelable<Option<Function>> {
|
||||
let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?);
|
||||
let file_items = db.file_items(file_id);
|
||||
let item_id = file_items.id_of(fn_def.syntax());
|
||||
let item_id = file_items.id_of(file_id, fn_def.syntax());
|
||||
let source_item_id = SourceItemId { file_id, item_id };
|
||||
let def_loc = DefLoc {
|
||||
kind: DefKind::Function,
|
||||
|
@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
rayon = "1.0.2"
|
||||
threadpool = "1.7.1"
|
||||
relative-path = "0.4.0"
|
||||
failure = "0.1.2"
|
||||
failure_derive = "0.1.2"
|
||||
|
@ -9,7 +9,8 @@ use gen_lsp_server::{
|
||||
};
|
||||
use languageserver_types::NumberOrString;
|
||||
use ra_analysis::{Canceled, FileId, LibraryData};
|
||||
use rayon::{self, ThreadPool};
|
||||
use rayon;
|
||||
use threadpool::ThreadPool;
|
||||
use rustc_hash::FxHashSet;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use failure::{format_err, bail};
|
||||
@ -54,11 +55,7 @@ pub fn main_loop(
|
||||
msg_receiver: &Receiver<RawMessage>,
|
||||
msg_sender: &Sender<RawMessage>,
|
||||
) -> Result<()> {
|
||||
let pool = rayon::ThreadPoolBuilder::new()
|
||||
.num_threads(4)
|
||||
.panic_handler(|_| log::error!("thread panicked :("))
|
||||
.build()
|
||||
.unwrap();
|
||||
let pool = ThreadPool::new(8);
|
||||
let (task_sender, task_receiver) = unbounded::<Task>();
|
||||
let (fs_worker, fs_watcher) = vfs::roots_loader();
|
||||
let (ws_worker, ws_watcher) = workspace_loader();
|
||||
@ -155,7 +152,7 @@ fn main_loop_inner(
|
||||
} else {
|
||||
let (files, resolver) = state.events_to_files(events);
|
||||
let sender = libdata_sender.clone();
|
||||
pool.spawn(move || {
|
||||
pool.execute(move || {
|
||||
let start = ::std::time::Instant::now();
|
||||
log::info!("indexing {} ... ", root.display());
|
||||
let data = LibraryData::prepare(files, resolver);
|
||||
@ -402,7 +399,7 @@ impl<'a> PoolDispatcher<'a> {
|
||||
Ok((id, params)) => {
|
||||
let world = self.world.snapshot();
|
||||
let sender = self.sender.clone();
|
||||
self.pool.spawn(move || {
|
||||
self.pool.execute(move || {
|
||||
let resp = match f(world, params) {
|
||||
Ok(resp) => RawResponse::ok::<R>(id, &resp),
|
||||
Err(e) => match e.downcast::<LspError>() {
|
||||
@ -452,7 +449,7 @@ fn update_file_notifications_on_threadpool(
|
||||
sender: Sender<Task>,
|
||||
subscriptions: Vec<FileId>,
|
||||
) {
|
||||
pool.spawn(move || {
|
||||
pool.execute(move || {
|
||||
for file_id in subscriptions {
|
||||
match handlers::publish_diagnostics(&world, file_id) {
|
||||
Err(e) => {
|
||||
|
Loading…
Reference in New Issue
Block a user