Use triomphe Arc

This commit is contained in:
Laurențiu Nicola 2023-05-02 17:12:22 +03:00
parent a7168a8c6f
commit 7197a27028
94 changed files with 331 additions and 257 deletions

19
Cargo.lock generated
View file

@ -94,6 +94,7 @@ dependencies = [
"stdx",
"syntax",
"test-utils",
"triomphe",
"tt",
"vfs",
]
@ -498,6 +499,7 @@ dependencies = [
"smallvec",
"stdx",
"syntax",
"triomphe",
"tt",
]
@ -534,6 +536,7 @@ dependencies = [
"syntax",
"test-utils",
"tracing",
"triomphe",
"tt",
]
@ -558,6 +561,7 @@ dependencies = [
"stdx",
"syntax",
"tracing",
"triomphe",
"tt",
]
@ -595,6 +599,7 @@ dependencies = [
"tracing",
"tracing-subscriber",
"tracing-tree",
"triomphe",
"typed-arena",
]
@ -656,6 +661,7 @@ dependencies = [
"text-edit",
"toolchain",
"tracing",
"triomphe",
"url",
]
@ -724,6 +730,7 @@ dependencies = [
"test-utils",
"text-edit",
"tracing",
"triomphe",
"xshell",
]
@ -761,6 +768,7 @@ dependencies = [
"syntax",
"test-utils",
"text-edit",
"triomphe",
]
[[package]]
@ -820,6 +828,7 @@ dependencies = [
"hashbrown",
"once_cell",
"rustc-hash",
"triomphe",
]
[[package]]
@ -1234,6 +1243,7 @@ dependencies = [
"snap",
"stdx",
"tracing",
"triomphe",
"tt",
]
@ -1315,6 +1325,7 @@ dependencies = [
"stdx",
"toolchain",
"tracing",
"triomphe",
]
[[package]]
@ -1484,6 +1495,7 @@ dependencies = [
"tracing-log",
"tracing-subscriber",
"tracing-tree",
"triomphe",
"tt",
"vfs",
"vfs-notify",
@ -1730,6 +1742,7 @@ dependencies = [
"stdx",
"test-utils",
"text-edit",
"triomphe",
"ungrammar",
]
@ -1939,6 +1952,12 @@ dependencies = [
"tracing-subscriber",
]
[[package]]
name = "triomphe"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1ee9bd9239c339d714d657fac840c6d2a4f9c45f4f9ec7b0975113458be78db"
[[package]]
name = "tt"
version = "0.0.0"

View file

@ -81,3 +81,4 @@ smol_str = "0.2.0"
# the following crates are pinned to prevent us from pulling in syn 2 until all our dependencies have moved
serde = { version = "=1.0.156", features = ["derive"] }
serde_json = "1.0.94"
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }

View file

@ -15,6 +15,8 @@ doctest = false
salsa = "0.17.0-pre.2"
rustc-hash = "1.1.0"
triomphe.workspace = true
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
# local deps

View file

@ -1,9 +1,10 @@
//! Defines a unit of change that can applied to the database to get the next
//! state. Changes are transactional.
use std::{fmt, sync::Arc};
use std::fmt;
use salsa::Durability;
use triomphe::Arc;
use vfs::FileId;
use crate::{CrateGraph, ProcMacros, SourceDatabaseExt, SourceRoot, SourceRootId};

View file

@ -1,5 +1,5 @@
//! A set of high-level utility fixture methods to use in tests.
use std::{mem, str::FromStr, sync::Arc};
use std::{mem, str::FromStr, sync};
use cfg::CfgOptions;
use rustc_hash::FxHashMap;
@ -7,6 +7,7 @@ use test_utils::{
extract_range_or_offset, Fixture, FixtureWithProjectMeta, RangeOrOffset, CURSOR_MARKER,
ESCAPED_CURSOR_MARKER,
};
use triomphe::Arc;
use tt::token_id::{Leaf, Subtree, TokenTree};
use vfs::{file_set::FileSet, VfsPath};
@ -334,7 +335,7 @@ pub fn identity(_attr: TokenStream, item: TokenStream) -> TokenStream {
ProcMacro {
name: "identity".into(),
kind: crate::ProcMacroKind::Attr,
expander: Arc::new(IdentityProcMacroExpander),
expander: sync::Arc::new(IdentityProcMacroExpander),
},
),
(
@ -348,7 +349,7 @@ pub fn derive_identity(item: TokenStream) -> TokenStream {
ProcMacro {
name: "DeriveIdentity".into(),
kind: crate::ProcMacroKind::CustomDerive,
expander: Arc::new(IdentityProcMacroExpander),
expander: sync::Arc::new(IdentityProcMacroExpander),
},
),
(
@ -362,7 +363,7 @@ pub fn input_replace(attr: TokenStream, _item: TokenStream) -> TokenStream {
ProcMacro {
name: "input_replace".into(),
kind: crate::ProcMacroKind::Attr,
expander: Arc::new(AttributeInputReplaceProcMacroExpander),
expander: sync::Arc::new(AttributeInputReplaceProcMacroExpander),
},
),
(
@ -376,7 +377,7 @@ pub fn mirror(input: TokenStream) -> TokenStream {
ProcMacro {
name: "mirror".into(),
kind: crate::ProcMacroKind::FuncLike,
expander: Arc::new(MirrorProcMacroExpander),
expander: sync::Arc::new(MirrorProcMacroExpander),
},
),
(
@ -390,7 +391,7 @@ pub fn shorten(input: TokenStream) -> TokenStream {
ProcMacro {
name: "shorten".into(),
kind: crate::ProcMacroKind::FuncLike,
expander: Arc::new(ShortenProcMacroExpander),
expander: sync::Arc::new(ShortenProcMacroExpander),
},
),
]

View file

@ -6,12 +6,13 @@
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
//! actual IO is done and lowered to input.
use std::{fmt, mem, ops, panic::RefUnwindSafe, str::FromStr, sync::Arc};
use std::{fmt, mem, ops, panic::RefUnwindSafe, str::FromStr, sync};
use cfg::CfgOptions;
use la_arena::{Arena, Idx};
use rustc_hash::{FxHashMap, FxHashSet};
use syntax::SmolStr;
use triomphe::Arc;
use tt::token_id::Subtree;
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
@ -263,7 +264,7 @@ pub type TargetLayoutLoadResult = Result<Arc<str>, Arc<str>>;
pub struct ProcMacro {
pub name: SmolStr,
pub kind: ProcMacroKind,
pub expander: Arc<dyn ProcMacroExpander>,
pub expander: sync::Arc<dyn ProcMacroExpander>,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]

View file

@ -6,10 +6,11 @@ mod input;
mod change;
pub mod fixture;
use std::{panic, sync::Arc};
use std::panic;
use rustc_hash::FxHashSet;
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
use triomphe::Arc;
pub use crate::{
change::Change,

View file

@ -29,6 +29,7 @@ once_cell = "1.17.0"
rustc-hash = "1.1.0"
smallvec.workspace = true
tracing = "0.1.35"
triomphe.workspace = true
rustc_abi = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_abi", default-features = false }
rustc_index = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_index", default-features = false }

View file

@ -5,7 +5,7 @@ pub mod builtin;
#[cfg(test)]
mod tests;
use std::{hash::Hash, ops, sync::Arc};
use std::{hash::Hash, ops};
use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
@ -21,6 +21,7 @@ use syntax::{
ast::{self, HasAttrs, IsString},
AstPtr, AstToken, SmolStr, TextRange, TextSize,
};
use triomphe::Arc;
use crate::{
db::DefDatabase,

View file

@ -6,7 +6,7 @@ mod tests;
pub mod scope;
mod pretty;
use std::{ops::Index, sync::Arc};
use std::ops::Index;
use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
@ -16,6 +16,7 @@ use la_arena::{Arena, ArenaMap};
use profile::Count;
use rustc_hash::FxHashMap;
use syntax::{ast, AstPtr, SyntaxNodePtr};
use triomphe::Arc;
use crate::{
db::DefDatabase,

View file

@ -1,7 +1,7 @@
//! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr`
//! representation.
use std::{mem, sync::Arc};
use std::mem;
use base_db::CrateId;
use either::Either;
@ -22,6 +22,7 @@ use syntax::{
},
AstNode, AstPtr, SyntaxNodePtr,
};
use triomphe::Arc;
use crate::{
body::{Body, BodyDiagnostic, BodySourceMap, ExprPtr, LabelPtr, PatPtr},

View file

@ -1,9 +1,8 @@
//! Name resolution for expressions.
use std::sync::Arc;
use hir_expand::name::Name;
use la_arena::{Arena, Idx, IdxRange, RawIdx};
use rustc_hash::FxHashMap;
use triomphe::Arc;
use crate::{
body::Body,

View file

@ -2,14 +2,13 @@
pub mod adt;
use std::sync::Arc;
use hir_expand::{
name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefKind,
};
use intern::Interned;
use smallvec::SmallVec;
use syntax::{ast, Parse};
use triomphe::Arc;
use crate::{
attr::Attrs,

View file

@ -1,7 +1,5 @@
//! Defines hir-level representation of structs, enums and unions
use std::sync::Arc;
use base_db::CrateId;
use bitflags::bitflags;
use cfg::CfgOptions;
@ -15,6 +13,7 @@ use intern::Interned;
use la_arena::{Arena, ArenaMap};
use rustc_abi::{Align, Integer, IntegerType, ReprFlags, ReprOptions};
use syntax::ast::{self, HasName, HasVisibility};
use triomphe::Arc;
use crate::{
builtin_type::{BuiltinInt, BuiltinUint},

View file

@ -1,12 +1,11 @@
//! Defines database & queries for name resolution.
use std::sync::Arc;
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
use either::Either;
use hir_expand::{db::ExpandDatabase, HirFileId};
use intern::Interned;
use la_arena::ArenaMap;
use syntax::{ast, AstPtr};
use triomphe::Arc;
use crate::{
attr::{Attrs, AttrsWithOwner},

View file

@ -3,8 +3,6 @@
//! generic parameters. See also the `Generics` type and the `generics_of` query
//! in rustc.
use std::sync::Arc;
use base_db::FileId;
use either::Either;
use hir_expand::{
@ -16,6 +14,7 @@ use la_arena::{Arena, ArenaMap, Idx};
use once_cell::unsync::Lazy;
use stdx::impl_from;
use syntax::ast::{self, HasGenericParams, HasName, HasTypeBounds};
use triomphe::Arc;
use crate::{
child_by_source::ChildBySource,

View file

@ -1,6 +1,6 @@
//! A map of all publicly exported items in a crate.
use std::{fmt, hash::BuildHasherDefault, sync::Arc};
use std::{fmt, hash::BuildHasherDefault};
use base_db::CrateId;
use fst::{self, Streamer};
@ -8,6 +8,7 @@ use hir_expand::name::Name;
use indexmap::{map::Entry, IndexMap};
use itertools::Itertools;
use rustc_hash::{FxHashSet, FxHasher};
use triomphe::Arc;
use crate::{
db::DefDatabase, item_scope::ItemInNs, visibility::Visibility, AssocItemId, ModuleDefId,

View file

@ -40,7 +40,6 @@ use std::{
hash::{Hash, Hasher},
marker::PhantomData,
ops::Index,
sync::Arc,
};
use ast::{AstNode, HasName, StructKind};
@ -60,6 +59,7 @@ use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use stdx::never;
use syntax::{ast, match_ast, SyntaxKind};
use triomphe::Arc;
use crate::{
attr::Attrs,

View file

@ -1,6 +1,6 @@
//! AST -> `ItemTree` lowering code.
use std::{collections::hash_map::Entry, sync::Arc};
use std::collections::hash_map::Entry;
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId};
use syntax::ast::{self, HasModuleItem, HasTypeBounds};

View file

@ -2,10 +2,9 @@
//!
//! This attribute to tell the compiler about semi built-in std library
//! features, such as Fn family of traits.
use std::sync::Arc;
use rustc_hash::FxHashMap;
use syntax::SmolStr;
use triomphe::Arc;
use crate::{
db::DefDatabase, path::Path, AdtId, AssocItemId, AttrDefId, CrateId, EnumId, EnumVariantId,

View file

@ -49,6 +49,7 @@ pub mod find_path;
pub mod import_map;
pub use rustc_abi as layout;
use triomphe::Arc;
#[cfg(test)]
mod test_db;
@ -56,10 +57,7 @@ mod test_db;
mod macro_expansion_tests;
mod pretty;
use std::{
hash::{Hash, Hasher},
sync::Arc,
};
use std::hash::{Hash, Hasher};
use base_db::{impl_intern_key, salsa, CrateId, ProcMacroKind};
use hir_expand::{

View file

@ -1,9 +1,8 @@
//! Context for lowering paths.
use std::sync::Arc;
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile};
use once_cell::unsync::OnceCell;
use syntax::ast;
use triomphe::Arc;
use crate::{db::DefDatabase, path::Path};

View file

@ -14,7 +14,7 @@ mod builtin_fn_macro;
mod builtin_derive_macro;
mod proc_macros;
use std::{iter, ops::Range, sync::Arc};
use std::{iter, ops::Range, sync};
use ::mbe::TokenMap;
use base_db::{fixture::WithFixture, ProcMacro, SourceDatabase};
@ -50,7 +50,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
ProcMacro {
name: "identity_when_valid".into(),
kind: base_db::ProcMacroKind::Attr,
expander: Arc::new(IdentityWhenValidProcMacroExpander),
expander: sync::Arc::new(IdentityWhenValidProcMacroExpander),
},
)];
let db = TestDB::with_files_extra_proc_macros(ra_fixture, extra_proc_macros);

View file

@ -57,7 +57,7 @@ mod path_resolution;
#[cfg(test)]
mod tests;
use std::{cmp::Ord, ops::Deref, sync::Arc};
use std::{cmp::Ord, ops::Deref};
use base_db::{CrateId, Edition, FileId};
use hir_expand::{name::Name, InFile, MacroCallId, MacroDefId};
@ -67,6 +67,7 @@ use profile::Count;
use rustc_hash::{FxHashMap, FxHashSet};
use stdx::format_to;
use syntax::{ast, SmolStr};
use triomphe::Arc;
use crate::{
db::DefDatabase,

View file

@ -26,6 +26,7 @@ use limit::Limit;
use rustc_hash::{FxHashMap, FxHashSet};
use stdx::always;
use syntax::{ast, SmolStr};
use triomphe::Arc;
use crate::{
attr::Attrs,
@ -476,10 +477,7 @@ impl DefCollector<'_> {
directive.module_id,
MacroCallKind::Attr {
ast_id: ast_id.ast_id,
attr_args: std::sync::Arc::new((
tt::Subtree::empty(),
Default::default(),
)),
attr_args: Arc::new((tt::Subtree::empty(), Default::default())),
invoc_attr_index: attr.id,
},
attr.path().clone(),

View file

@ -4,10 +4,9 @@ mod macros;
mod mod_resolution;
mod primitives;
use std::sync::Arc;
use base_db::{fixture::WithFixture, SourceDatabase};
use expect_test::{expect, Expect};
use triomphe::Arc;
use crate::{db::DefDatabase, test_db::TestDB};

View file

@ -1,6 +1,5 @@
use std::sync::Arc;
use base_db::SourceDatabaseExt;
use triomphe::Arc;
use crate::{db::DefDatabase, AdtId, ModuleDefId};

View file

@ -1,5 +1,5 @@
//! Name resolution façade.
use std::{fmt, hash::BuildHasherDefault, sync::Arc};
use std::{fmt, hash::BuildHasherDefault};
use base_db::CrateId;
use hir_expand::name::{name, Name};
@ -7,6 +7,7 @@ use indexmap::IndexMap;
use intern::Interned;
use rustc_hash::FxHashSet;
use smallvec::{smallvec, SmallVec};
use triomphe::Arc;
use crate::{
body::scope::{ExprScopes, ScopeId},

View file

@ -1,9 +1,6 @@
//! Database used for testing `hir_def`.
use std::{
fmt, panic,
sync::{Arc, Mutex},
};
use std::{fmt, panic, sync::Mutex};
use base_db::{
salsa::{self, Durability},
@ -13,6 +10,7 @@ use base_db::{
use hir_expand::{db::ExpandDatabase, InFile};
use rustc_hash::FxHashSet;
use syntax::{algo, ast, AstNode};
use triomphe::Arc;
use crate::{
db::DefDatabase,

View file

@ -1,10 +1,11 @@
//! Defines hir-level representation of visibility (e.g. `pub` and `pub(crate)`).
use std::{iter, sync::Arc};
use std::iter;
use hir_expand::{hygiene::Hygiene, InFile};
use la_arena::ArenaMap;
use syntax::ast;
use triomphe::Arc;
use crate::{
db::DefDatabase,

View file

@ -22,6 +22,7 @@ hashbrown = { version = "0.12.1", features = [
"inline-more",
], default-features = false }
smallvec.workspace = true
triomphe.workspace = true
# local deps
stdx.workspace = true

View file

@ -1,5 +1,5 @@
//! A higher level attributes based on TokenTree, with also some shortcuts.
use std::{fmt, ops, sync::Arc};
use std::{fmt, ops};
use base_db::CrateId;
use cfg::CfgExpr;
@ -8,6 +8,7 @@ use intern::Interned;
use mbe::{syntax_node_to_token_tree, DelimiterKind, Punct};
use smallvec::{smallvec, SmallVec};
use syntax::{ast, match_ast, AstNode, SmolStr, SyntaxNode};
use triomphe::Arc;
use crate::{
db::ExpandDatabase,
@ -50,7 +51,9 @@ impl RawAttrs {
path: Interned::new(ModPath::from(crate::name!(doc))),
}),
})
.collect::<Arc<_>>();
.collect::<Vec<_>>();
// FIXME: use `Arc::from_iter` when it becomes available
let entries: Arc<[Attr]> = Arc::from(entries);
Self { entries: if entries.is_empty() { None } else { Some(entries) } }
}
@ -68,7 +71,7 @@ impl RawAttrs {
(Some(a), Some(b)) => {
let last_ast_index = a.last().map_or(0, |it| it.id.ast_index() + 1) as u32;
Self {
entries: Some(
entries: Some(Arc::from(
a.iter()
.cloned()
.chain(b.iter().map(|it| {
@ -78,8 +81,9 @@ impl RawAttrs {
<< AttrId::AST_INDEX_BITS;
it
}))
.collect(),
),
// FIXME: use `Arc::from_iter` when it becomes available
.collect::<Vec<_>>(),
)),
}
}
}
@ -96,48 +100,51 @@ impl RawAttrs {
}
let crate_graph = db.crate_graph();
let new_attrs = self
.iter()
.flat_map(|attr| -> SmallVec<[_; 1]> {
let is_cfg_attr =
attr.path.as_ident().map_or(false, |name| *name == crate::name![cfg_attr]);
if !is_cfg_attr {
return smallvec![attr.clone()];
}
let new_attrs = Arc::from(
self.iter()
.flat_map(|attr| -> SmallVec<[_; 1]> {
let is_cfg_attr =
attr.path.as_ident().map_or(false, |name| *name == crate::name![cfg_attr]);
if !is_cfg_attr {
return smallvec![attr.clone()];
}
let subtree = match attr.token_tree_value() {
Some(it) => it,
_ => return smallvec![attr.clone()],
};
let subtree = match attr.token_tree_value() {
Some(it) => it,
_ => return smallvec![attr.clone()],
};
let (cfg, parts) = match parse_cfg_attr_input(subtree) {
Some(it) => it,
None => return smallvec![attr.clone()],
};
let index = attr.id;
let attrs =
parts.enumerate().take(1 << AttrId::CFG_ATTR_BITS).filter_map(|(idx, attr)| {
let tree = Subtree {
delimiter: tt::Delimiter::unspecified(),
token_trees: attr.to_vec(),
};
// FIXME hygiene
let hygiene = Hygiene::new_unhygienic();
Attr::from_tt(db, &tree, &hygiene, index.with_cfg_attr(idx))
});
let (cfg, parts) = match parse_cfg_attr_input(subtree) {
Some(it) => it,
None => return smallvec![attr.clone()],
};
let index = attr.id;
let attrs = parts.enumerate().take(1 << AttrId::CFG_ATTR_BITS).filter_map(
|(idx, attr)| {
let tree = Subtree {
delimiter: tt::Delimiter::unspecified(),
token_trees: attr.to_vec(),
};
// FIXME hygiene
let hygiene = Hygiene::new_unhygienic();
Attr::from_tt(db, &tree, &hygiene, index.with_cfg_attr(idx))
},
);
let cfg_options = &crate_graph[krate].cfg_options;
let cfg = Subtree { delimiter: subtree.delimiter, token_trees: cfg.to_vec() };
let cfg = CfgExpr::parse(&cfg);
if cfg_options.check(&cfg) == Some(false) {
smallvec![]
} else {
cov_mark::hit!(cfg_attr_active);
let cfg_options = &crate_graph[krate].cfg_options;
let cfg = Subtree { delimiter: subtree.delimiter, token_trees: cfg.to_vec() };
let cfg = CfgExpr::parse(&cfg);
if cfg_options.check(&cfg) == Some(false) {
smallvec![]
} else {
cov_mark::hit!(cfg_attr_active);
attrs.collect()
}
})
.collect();
attrs.collect()
}
})
// FIXME: use `Arc::from_iter` when it becomes available
.collect::<Vec<_>>(),
);
RawAttrs { entries: Some(new_attrs) }
}

View file

@ -1,7 +1,5 @@
//! Defines database & queries for macro expansion.
use std::sync::Arc;
use base_db::{salsa, Edition, SourceDatabase};
use either::Either;
use limit::Limit;
@ -11,6 +9,7 @@ use syntax::{
ast::{self, HasAttrs, HasDocComments},
AstNode, GreenNode, Parse, SyntaxError, SyntaxNode, SyntaxToken, T,
};
use triomphe::Arc;
use crate::{
ast_id_map::AstIdMap, builtin_attr_macro::pseudo_derive_attr_expansion,

View file

@ -18,10 +18,9 @@
//!
//!
//! See the full discussion : <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros>
use std::sync::Arc;
use base_db::CrateId;
use syntax::{ted, Parse, SyntaxNode};
use triomphe::Arc;
use crate::{
ast::{self, AstNode},

View file

@ -2,8 +2,6 @@
//!
//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
//! this moment, this is horribly incomplete and handles only `$crate`.
use std::sync::Arc;
use base_db::CrateId;
use db::TokenExpander;
use either::Either;
@ -12,6 +10,7 @@ use syntax::{
ast::{self, HasDocComments},
AstNode, SyntaxKind, SyntaxNode, TextRange, TextSize,
};
use triomphe::Arc;
use crate::{
db::{self, ExpandDatabase},

View file

@ -24,8 +24,9 @@ use mbe::TokenMap;
pub use mbe::{Origin, ValueResult};
use ::tt::token_id as tt;
use triomphe::Arc;
use std::{fmt, hash::Hash, iter, sync::Arc};
use std::{fmt, hash::Hash, iter};
use base_db::{
impl_intern_key,

View file

@ -28,6 +28,7 @@ chalk-recursive = { version = "0.89.0", default-features = false }
chalk-derive = "0.89.0"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
once_cell = "1.17.0"
triomphe.workspace = true
typed-arena = "2.0.1"
rustc_index = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_index", default-features = false }

View file

@ -3,12 +3,11 @@
//! reference to a type with the field `bar`. This is an approximation of the
//! logic in rustc (which lives in rustc_hir_analysis/check/autoderef.rs).
use std::sync::Arc;
use chalk_ir::cast::Cast;
use hir_def::lang_item::LangItem;
use hir_expand::name::name;
use limit::Limit;
use triomphe::Arc;
use crate::{
db::HirDatabase, infer::unify::InferenceTable, Canonical, Goal, Interner, ProjectionTyExt,

View file

@ -391,7 +391,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
fn generator_datum(
&self,
id: chalk_ir::GeneratorId<Interner>,
) -> std::sync::Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
let (parent, expr) = self.db.lookup_intern_generator(id.into());
// We fill substitution with unknown type, because we only need to know whether the generic
@ -432,7 +432,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
fn generator_witness_datum(
&self,
id: chalk_ir::GeneratorId<Interner>,
) -> std::sync::Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<Interner>> {
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<Interner>> {
// FIXME: calculate inner types
let inner_types =
rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };

View file

@ -1,7 +1,7 @@
//! The home of `HirDatabase`, which is the Salsa database containing all the
//! type inference-related queries.
use std::sync::Arc;
use std::sync;
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
use hir_def::{
@ -11,6 +11,7 @@ use hir_def::{
};
use la_arena::ArenaMap;
use smallvec::SmallVec;
use triomphe::Arc;
use crate::{
chalk_db,
@ -154,24 +155,34 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
fn intern_generator(&self, id: (DefWithBodyId, ExprId)) -> InternedGeneratorId;
#[salsa::invoke(chalk_db::associated_ty_data_query)]
fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>;
fn associated_ty_data(
&self,
id: chalk_db::AssocTypeId,
) -> sync::Arc<chalk_db::AssociatedTyDatum>;
#[salsa::invoke(chalk_db::trait_datum_query)]
fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId)
-> Arc<chalk_db::TraitDatum>;
fn trait_datum(
&self,
krate: CrateId,
trait_id: chalk_db::TraitId,
) -> sync::Arc<chalk_db::TraitDatum>;
#[salsa::invoke(chalk_db::struct_datum_query)]
fn struct_datum(
&self,
krate: CrateId,
struct_id: chalk_db::AdtId,
) -> Arc<chalk_db::StructDatum>;
) -> sync::Arc<chalk_db::StructDatum>;
#[salsa::invoke(chalk_db::impl_datum_query)]
fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>;
fn impl_datum(
&self,
krate: CrateId,
impl_id: chalk_db::ImplId,
) -> sync::Arc<chalk_db::ImplDatum>;
#[salsa::invoke(chalk_db::fn_def_datum_query)]
fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc<chalk_db::FnDefDatum>;
fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> sync::Arc<chalk_db::FnDefDatum>;
#[salsa::invoke(chalk_db::fn_def_variance_query)]
fn fn_def_variance(&self, fn_def_id: FnDefId) -> chalk_db::Variances;
@ -184,7 +195,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
&self,
krate: CrateId,
id: chalk_db::AssociatedTyValueId,
) -> Arc<chalk_db::AssociatedTyValue>;
) -> sync::Arc<chalk_db::AssociatedTyValue>;
#[salsa::invoke(crate::traits::normalize_projection_query)]
#[salsa::transparent]

View file

@ -3,7 +3,6 @@
//! fields, etc.
use std::fmt;
use std::sync::Arc;
use either::Either;
use hir_def::lang_item::LangItem;
@ -12,6 +11,7 @@ use hir_def::{ItemContainerId, Lookup};
use hir_expand::name;
use itertools::Itertools;
use rustc_hash::FxHashSet;
use triomphe::Arc;
use typed_arena::Arena;
use crate::{

View file

@ -13,7 +13,6 @@
//! to certain types. To record this, we use the union-find implementation from
//! the `ena` crate, which is extracted from rustc.
use std::sync::Arc;
use std::{convert::identity, ops::Index};
use chalk_ir::{
@ -39,6 +38,7 @@ use hir_expand::name::{name, Name};
use la_arena::{ArenaMap, Entry};
use rustc_hash::{FxHashMap, FxHashSet};
use stdx::{always, never};
use triomphe::Arc;
use crate::{
db::HirDatabase, fold_tys, infer::coerce::CoerceMany, lower::ImplTraitLoweringMode,

View file

@ -5,7 +5,7 @@
//! See <https://doc.rust-lang.org/nomicon/coercions.html> and
//! `rustc_hir_analysis/check/coercion.rs`.
use std::{iter, sync::Arc};
use std::iter;
use chalk_ir::{cast::Cast, BoundVar, Goal, Mutability, TyKind, TyVariableKind};
use hir_def::{
@ -13,6 +13,7 @@ use hir_def::{
lang_item::{LangItem, LangItemTarget},
};
use stdx::always;
use triomphe::Arc;
use crate::{
autoderef::{Autoderef, AutoderefKind},

View file

@ -3,7 +3,6 @@
use std::{
iter::{repeat, repeat_with},
mem,
sync::Arc,
};
use chalk_ir::{
@ -21,6 +20,7 @@ use hir_def::{
use hir_expand::name::{name, Name};
use stdx::always;
use syntax::ast::RangeOp;
use triomphe::Arc;
use crate::{
autoderef::{builtin_deref, deref_by_trait, Autoderef},

View file

@ -1,6 +1,6 @@
//! Unification and canonicalization logic.
use std::{fmt, iter, mem, sync::Arc};
use std::{fmt, iter, mem};
use chalk_ir::{
cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy,
@ -11,6 +11,7 @@ use either::Either;
use ena::unify::UnifyKey;
use hir_expand::name;
use stdx::never;
use triomphe::Arc;
use super::{InferOk, InferResult, InferenceContext, TypeError};
use crate::{

View file

@ -7,7 +7,8 @@ use chalk_ir::{Goal, GoalData};
use hir_def::TypeAliasId;
use intern::{impl_internable, Interned};
use smallvec::SmallVec;
use std::{fmt, sync::Arc};
use std::fmt;
use triomphe::Arc;
#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct Interner;

View file

@ -1,7 +1,5 @@
//! Compute the binary representation of a type
use std::sync::Arc;
use base_db::CrateId;
use chalk_ir::{AdtId, TyKind};
use hir_def::{
@ -13,6 +11,7 @@ use hir_def::{
};
use la_arena::{Idx, RawIdx};
use stdx::never;
use triomphe::Arc;
use crate::{
consteval::try_const_usize, db::HirDatabase, infer::normalize, layout::adt::struct_variant_idx,

View file

@ -1,9 +1,8 @@
//! Target dependent parameters needed for layouts
use std::sync::Arc;
use base_db::CrateId;
use hir_def::layout::TargetDataLayout;
use triomphe::Arc;
use crate::db::HirDatabase;

View file

@ -35,7 +35,7 @@ mod tests;
#[cfg(test)]
mod test_db;
use std::{collections::HashMap, hash::Hash, sync::Arc};
use std::{collections::HashMap, hash::Hash};
use chalk_ir::{
fold::{Shift, TypeFoldable},
@ -50,6 +50,7 @@ use la_arena::{Arena, Idx};
use mir::{MirEvalError, VTableMap};
use rustc_hash::FxHashSet;
use traits::FnTrait;
use triomphe::Arc;
use utils::Generics;
use crate::{
@ -289,16 +290,19 @@ impl CallableSig {
pub fn from_fn_ptr(fn_ptr: &FnPointer) -> CallableSig {
CallableSig {
// FIXME: what to do about lifetime params? -> return PolyFnSig
params_and_return: fn_ptr
.substitution
.clone()
.shifted_out_to(Interner, DebruijnIndex::ONE)
.expect("unexpected lifetime vars in fn ptr")
.0
.as_slice(Interner)
.iter()
.map(|arg| arg.assert_ty_ref(Interner).clone())
.collect(),
// FIXME: use `Arc::from_iter` when it becomes available
params_and_return: Arc::from(
fn_ptr
.substitution
.clone()
.shifted_out_to(Interner, DebruijnIndex::ONE)
.expect("unexpected lifetime vars in fn ptr")
.0
.as_slice(Interner)
.iter()
.map(|arg| arg.assert_ty_ref(Interner).clone())
.collect::<Vec<_>>(),
),
is_varargs: fn_ptr.sig.variadic,
safety: fn_ptr.sig.safety,
}

View file

@ -8,7 +8,6 @@
use std::{
cell::{Cell, RefCell, RefMut},
iter,
sync::Arc,
};
use base_db::CrateId;
@ -39,6 +38,7 @@ use rustc_hash::FxHashSet;
use smallvec::SmallVec;
use stdx::{impl_from, never};
use syntax::ast;
use triomphe::Arc;
use crate::{
all_super_traits,
@ -1441,7 +1441,8 @@ pub(crate) fn generic_predicates_for_param_recover(
_param_id: &TypeOrConstParamId,
_assoc_name: &Option<Name>,
) -> Arc<[Binders<QuantifiedWhereClause>]> {
Arc::new([])
// FIXME: use `Arc::from_iter` when it becomes available
Arc::from(vec![])
}
pub(crate) fn trait_environment_for_body_query(
@ -1579,30 +1580,33 @@ pub(crate) fn generic_defaults_query(
let generic_params = generics(db.upcast(), def);
let parent_start_idx = generic_params.len_self();
let defaults = generic_params
.iter()
.enumerate()
.map(|(idx, (id, p))| {
let p = match p {
TypeOrConstParamData::TypeParamData(p) => p,
TypeOrConstParamData::ConstParamData(_) => {
// FIXME: implement const generic defaults
let val = unknown_const_as_generic(
db.const_param_ty(ConstParamId::from_unchecked(id)),
);
return make_binders(db, &generic_params, val);
}
};
let mut ty =
p.default.as_ref().map_or(TyKind::Error.intern(Interner), |t| ctx.lower_ty(t));
let defaults = Arc::from(
generic_params
.iter()
.enumerate()
.map(|(idx, (id, p))| {
let p = match p {
TypeOrConstParamData::TypeParamData(p) => p,
TypeOrConstParamData::ConstParamData(_) => {
// FIXME: implement const generic defaults
let val = unknown_const_as_generic(
db.const_param_ty(ConstParamId::from_unchecked(id)),
);
return make_binders(db, &generic_params, val);
}
};
let mut ty =
p.default.as_ref().map_or(TyKind::Error.intern(Interner), |t| ctx.lower_ty(t));
// Each default can only refer to previous parameters.
// Type variable default referring to parameter coming
// after it is forbidden (FIXME: report diagnostic)
ty = fallback_bound_vars(ty, idx, parent_start_idx);
crate::make_binders(db, &generic_params, ty.cast(Interner))
})
.collect();
// Each default can only refer to previous parameters.
// Type variable default referring to parameter coming
// after it is forbidden (FIXME: report diagnostic)
ty = fallback_bound_vars(ty, idx, parent_start_idx);
crate::make_binders(db, &generic_params, ty.cast(Interner))
})
// FIXME: use `Arc::from_iter` when it becomes available
.collect::<Vec<_>>(),
);
defaults
}
@ -1615,18 +1619,21 @@ pub(crate) fn generic_defaults_recover(
let generic_params = generics(db.upcast(), *def);
// FIXME: this code is not covered in tests.
// we still need one default per parameter
let defaults = generic_params
.iter_id()
.map(|id| {
let val = match id {
Either::Left(_) => {
GenericArgData::Ty(TyKind::Error.intern(Interner)).intern(Interner)
}
Either::Right(id) => unknown_const_as_generic(db.const_param_ty(id)),
};
crate::make_binders(db, &generic_params, val)
})
.collect();
let defaults = Arc::from(
generic_params
.iter_id()
.map(|id| {
let val = match id {
Either::Left(_) => {
GenericArgData::Ty(TyKind::Error.intern(Interner)).intern(Interner)
}
Either::Right(id) => unknown_const_as_generic(db.const_param_ty(id)),
};
crate::make_binders(db, &generic_params, val)
})
// FIXME: use `Arc::from_iter` when it becomes available
.collect::<Vec<_>>(),
);
defaults
}

View file

@ -2,7 +2,7 @@
//! For details about how this works in rustc, see the method lookup page in the
//! [rustc guide](https://rust-lang.github.io/rustc-guide/method-lookup.html)
//! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs.
use std::{ops::ControlFlow, sync::Arc};
use std::ops::ControlFlow;
use base_db::{CrateId, Edition};
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
@ -17,6 +17,7 @@ use hir_expand::name::Name;
use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::{smallvec, SmallVec};
use stdx::never;
use triomphe::Arc;
use crate::{
autoderef::{self, AutoderefKind},
@ -166,7 +167,13 @@ impl TraitImpls {
) -> Arc<[Arc<Self>]> {
let _p = profile::span("trait_impls_in_deps_query").detail(|| format!("{krate:?}"));
let crate_graph = db.crate_graph();
crate_graph.transitive_deps(krate).map(|krate| db.trait_impls_in_crate(krate)).collect()
// FIXME: use `Arc::from_iter` when it becomes available
Arc::from(
crate_graph
.transitive_deps(krate)
.map(|krate| db.trait_impls_in_crate(krate))
.collect::<Vec<_>>(),
)
}
fn shrink_to_fit(&mut self) {

View file

@ -3,11 +3,12 @@
// Currently it is an ad-hoc implementation, only useful for mutability analysis. Feel free to remove all of these
// if needed for implementing a proper borrow checker.
use std::{iter, sync::Arc};
use std::iter;
use hir_def::DefWithBodyId;
use la_arena::ArenaMap;
use stdx::never;
use triomphe::Arc;
use crate::{db::HirDatabase, ClosureId};

View file

@ -1,6 +1,6 @@
//! This module provides a MIR interpreter, which is used in const eval.
use std::{borrow::Cow, collections::HashMap, fmt::Write, iter, ops::Range, sync::Arc};
use std::{borrow::Cow, collections::HashMap, fmt::Write, iter, ops::Range};
use base_db::{CrateId, FileId};
use chalk_ir::{
@ -20,6 +20,7 @@ use intern::Interned;
use la_arena::ArenaMap;
use rustc_hash::FxHashMap;
use syntax::{SyntaxNodePtr, TextRange};
use triomphe::Arc;
use crate::{
consteval::{intern_const_scalar, ConstEvalError},

View file

@ -1,6 +1,6 @@
//! This module generates a polymorphic MIR from a hir body
use std::{fmt::Write, iter, mem, sync::Arc};
use std::{fmt::Write, iter, mem};
use base_db::FileId;
use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind};
@ -20,6 +20,7 @@ use hir_expand::name::Name;
use la_arena::ArenaMap;
use rustc_hash::FxHashMap;
use syntax::TextRange;
use triomphe::Arc;
use crate::{
consteval::ConstEvalError,

View file

@ -1,9 +1,6 @@
//! Database used for testing `hir`.
use std::{
fmt, panic,
sync::{Arc, Mutex},
};
use std::{fmt, panic, sync::Mutex};
use base_db::{
salsa::{self, Durability},
@ -15,6 +12,7 @@ use rustc_hash::FxHashSet;
use stdx::hash::NoHashHashMap;
use syntax::TextRange;
use test_utils::extract_annotations;
use triomphe::Arc;
#[salsa::database(
base_db::SourceDatabaseExtStorage,

View file

@ -10,7 +10,7 @@ mod display_source_code;
mod incremental;
mod diagnostics;
use std::{collections::HashMap, env, sync::Arc};
use std::{collections::HashMap, env};
use base_db::{fixture::WithFixture, FileRange, SourceDatabaseExt};
use expect_test::Expect;
@ -32,6 +32,7 @@ use syntax::{
};
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
use tracing_tree::HierarchicalLayer;
use triomphe::Arc;
use crate::{
db::HirDatabase,

View file

@ -1,6 +1,5 @@
use std::sync::Arc;
use base_db::{fixture::WithFixture, SourceDatabaseExt};
use triomphe::Arc;
use crate::{db::HirDatabase, test_db::TestDB};

View file

@ -1,6 +1,6 @@
//! Trait solving using Chalk.
use std::{env::var, sync::Arc};
use std::env::var;
use chalk_ir::GoalData;
use chalk_recursive::Cache;
@ -13,6 +13,7 @@ use hir_def::{
};
use hir_expand::name::{name, Name};
use stdx::panic_context;
use triomphe::Arc;
use crate::{
db::HirDatabase, infer::unify::InferenceTable, AliasEq, AliasTy, Canonical, DomainGoal, Goal,

View file

@ -17,6 +17,7 @@ either = "1.7.0"
arrayvec = "0.7.2"
itertools = "0.10.5"
smallvec.workspace = true
triomphe.workspace = true
once_cell = "1.17.0"
# local deps

View file

@ -33,7 +33,7 @@ pub mod symbols;
mod display;
use std::{iter, ops::ControlFlow, sync::Arc};
use std::{iter, ops::ControlFlow};
use arrayvec::ArrayVec;
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
@ -80,6 +80,7 @@ use syntax::{
ast::{self, HasAttrs as _, HasDocComments, HasName},
AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, TextRange, T,
};
use triomphe::Arc;
use crate::db::{DefDatabase, HirDatabase};

View file

@ -5,10 +5,7 @@
//!
//! So, this modules should not be used during hir construction, it exists
//! purely for "IDE needs".
use std::{
iter::{self, once},
sync::Arc,
};
use std::iter::{self, once};
use either::Either;
use hir_def::{
@ -49,6 +46,7 @@ use syntax::{
ast::{self, AstNode},
SyntaxKind, SyntaxNode, TextRange, TextSize,
};
use triomphe::Arc;
use crate::{
db::HirDatabase, semantics::PathResolution, Adt, AssocItem, BindingMode, BuiltinAttr,

View file

@ -23,6 +23,7 @@ itertools = "0.10.5"
arrayvec = "0.7.2"
indexmap = "1.9.1"
memchr = "2.5.0"
triomphe.workspace = true
# local deps
base-db.workspace = true

View file

@ -1,13 +1,12 @@
//! Applies changes to the IDE state transactionally.
use std::sync::Arc;
use base_db::{
salsa::{Database, Durability},
Change, SourceRootId,
};
use profile::{memory_usage, Bytes};
use rustc_hash::FxHashSet;
use triomphe::Arc;
use crate::{symbol_index::SymbolsDatabase, RootDatabase};

View file

@ -43,13 +43,14 @@ pub mod syntax_helpers {
pub use parser::LexedStr;
}
use std::{fmt, mem::ManuallyDrop, sync::Arc};
use std::{fmt, mem::ManuallyDrop};
use base_db::{
salsa::{self, Durability},
AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast,
};
use hir::db::{DefDatabase, ExpandDatabase, HirDatabase};
use triomphe::Arc;
use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase};
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};

View file

@ -4,7 +4,7 @@
//! get a super-set of matches. Then, we we confirm each match using precise
//! name resolution.
use std::{mem, sync::Arc};
use std::mem;
use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
use hir::{
@ -15,6 +15,7 @@ use once_cell::unsync::Lazy;
use parser::SyntaxKind;
use stdx::hash::NoHashHashMap;
use syntax::{ast, match_ast, AstNode, TextRange, TextSize};
use triomphe::Arc;
use crate::{
defs::{Definition, NameClass, NameRefClass},

View file

@ -25,7 +25,6 @@ use std::{
fmt,
hash::{Hash, Hasher},
mem,
sync::Arc,
};
use base_db::{
@ -40,6 +39,7 @@ use hir::{
};
use rayon::prelude::*;
use rustc_hash::FxHashSet;
use triomphe::Arc;
use crate::RootDatabase;

View file

@ -15,6 +15,7 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
itertools = "0.10.5"
triomphe.workspace = true
# local deps
hir.workspace = true

View file

@ -3,8 +3,8 @@ use ide_db::{
base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt},
FxHashSet,
};
use std::sync::Arc;
use test_utils::RangeOrOffset;
use triomphe::Arc;
use crate::{MatchFinder, SsrRule};

View file

@ -23,6 +23,7 @@ pulldown-cmark = { version = "0.9.1", default-features = false }
url = "2.3.1"
dot = "0.1.4"
smallvec.workspace = true
triomphe.workspace = true
# local deps
cfg.workspace = true

View file

@ -61,7 +61,7 @@ mod view_item_tree;
mod shuffle_crate_graph;
mod fetch_crates;
use std::{ffi::OsStr, sync::Arc};
use std::ffi::OsStr;
use cfg::CfgOptions;
use fetch_crates::CrateInfo;
@ -73,6 +73,7 @@ use ide_db::{
symbol_index, FxHashMap, FxIndexSet, LineIndexDatabase,
};
use syntax::SourceFile;
use triomphe::Arc;
use crate::navigation_target::{ToNav, TryToNav};

View file

@ -1,9 +1,8 @@
use std::sync::Arc;
use ide_db::{
base_db::{salsa::Durability, CrateGraph, ProcMacros, SourceDatabase},
FxHashMap, RootDatabase,
};
use triomphe::Arc;
// Feature: Shuffle Crate Graph
//

View file

@ -56,8 +56,6 @@ pub(crate) fn ssr_assists(
#[cfg(test)]
mod tests {
use std::sync::Arc;
use expect_test::expect;
use ide_assists::{Assist, AssistResolveStrategy};
use ide_db::{
@ -65,6 +63,7 @@ mod tests {
symbol_index::SymbolsDatabase,
FxHashSet, RootDatabase,
};
use triomphe::Arc;
use super::ssr_assists;

View file

@ -1,4 +1,4 @@
use std::{fmt, marker::PhantomData, sync::Arc};
use std::{fmt, marker::PhantomData};
use hir::{
db::{AstIdMapQuery, AttrsQuery, ParseMacroExpansionQuery},
@ -23,6 +23,7 @@ use profile::{memory_usage, Bytes};
use std::env;
use stdx::format_to;
use syntax::{ast, Parse, SyntaxNode};
use triomphe::Arc;
// Feature: Status
//

View file

@ -1,10 +1,9 @@
use std::sync::Arc;
use dot::{Id, LabelText};
use ide_db::{
base_db::{CrateGraph, CrateId, Dependency, SourceDatabase, SourceDatabaseExt},
FxHashSet, RootDatabase,
};
use triomphe::Arc;
// Feature: View Crate Graph
//

View file

@ -18,3 +18,4 @@ dashmap = { version = "=5.4.0", features = ["raw-api"] }
hashbrown = { version = "0.12.1", default-features = false }
once_cell = "1.17.0"
rustc-hash = "1.1.0"
triomphe.workspace = true

View file

@ -6,13 +6,13 @@ use std::{
fmt::{self, Debug, Display},
hash::{BuildHasherDefault, Hash, Hasher},
ops::Deref,
sync::Arc,
};
use dashmap::{DashMap, SharedValue};
use hashbrown::HashMap;
use once_cell::sync::OnceCell;
use rustc_hash::FxHasher;
use triomphe::Arc;
type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>;
type Guard<T> = dashmap::RwLockWriteGuard<
@ -83,7 +83,7 @@ impl<T: Internable + ?Sized> Drop for Interned<T> {
#[inline]
fn drop(&mut self) {
// When the last `Ref` is dropped, remove the object from the global map.
if Arc::strong_count(&self.arc) == 2 {
if Arc::count(&self.arc) == 2 {
// Only `self` and the global map point to the object.
self.drop_slow();
@ -102,7 +102,7 @@ impl<T: Internable + ?Sized> Interned<T> {
// FIXME: avoid double lookup
let (arc, _) = shard.get_key_value(&self.arc).expect("interned value removed prematurely");
if Arc::strong_count(arc) != 2 {
if Arc::count(arc) != 2 {
// Another thread has interned another copy
return;
}

View file

@ -22,6 +22,7 @@ object = { version = "0.30.2", default-features = false, features = [
serde.workspace = true
serde_json = { workspace = true, features = ["unbounded_depth"] }
tracing = "0.1.37"
triomphe.workspace = true
memmap2 = "0.5.4"
snap = "1.1.0"

View file

@ -12,10 +12,8 @@ mod process;
mod version;
use paths::AbsPathBuf;
use std::{
fmt, io,
sync::{Arc, Mutex},
};
use std::{fmt, io, sync::Mutex};
use triomphe::Arc;
use serde::{Deserialize, Serialize};

View file

@ -18,6 +18,7 @@ cargo_metadata = "0.15.0"
semver = "1.0.14"
serde_json.workspace = true
serde.workspace = true
triomphe.workspace = true
anyhow = "1.0.62"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }

View file

@ -2,7 +2,7 @@
//! metadata` or `rust-project.json`) into representation stored in the salsa
//! database -- `CrateGraph`.
use std::{collections::VecDeque, fmt, fs, process::Command, sync::Arc};
use std::{collections::VecDeque, fmt, fs, process::Command, sync};
use anyhow::{format_err, Context, Result};
use base_db::{
@ -14,6 +14,7 @@ use paths::{AbsPath, AbsPathBuf};
use rustc_hash::{FxHashMap, FxHashSet};
use semver::Version;
use stdx::always;
use triomphe::Arc;
use crate::{
build_scripts::BuildScriptOutput,
@ -422,7 +423,7 @@ impl ProjectWorkspace {
let outputs = &mut match WorkspaceBuildScripts::run_once(config, &cargo_ws, progress) {
Ok(it) => Ok(it.into_iter()),
// io::Error is not Clone?
Err(e) => Err(Arc::new(e)),
Err(e) => Err(sync::Arc::new(e)),
};
workspaces

View file

@ -45,6 +45,7 @@ tracing-subscriber = { version = "0.3.16", default-features = false, features =
] }
tracing-log = "0.1.3"
tracing-tree = "0.2.1"
triomphe.workspace = true
always-assert = "0.1.2"
# These dependencies are unused, but we pin them to a version here to restrict them for our transitive dependencies

View file

@ -1,6 +1,6 @@
//! Loads a Cargo project into a static instance of analysis, without support
//! for incorporating changes.
use std::{path::Path, sync::Arc};
use std::path::Path;
use anyhow::{anyhow, Result};
use crossbeam_channel::{unbounded, Receiver};
@ -11,6 +11,7 @@ use ide_db::{
};
use proc_macro_api::ProcMacroServer;
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace};
use triomphe::Arc;
use vfs::{loader::Handle, AbsPath, AbsPathBuf};
use crate::reload::{load_proc_macro, ProjectFolders, SourceRootConfig};

View file

@ -1,11 +1,12 @@
//! Book keeping for keeping diagnostics easily in sync with the client.
pub(crate) mod to_proto;
use std::{mem, sync::Arc};
use std::mem;
use ide::FileId;
use ide_db::FxHashMap;
use stdx::hash::{NoHashHashMap, NoHashHashSet};
use triomphe::Arc;
use crate::lsp_ext;

View file

@ -3,7 +3,7 @@
//!
//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`.
use std::{sync::Arc, time::Instant};
use std::time::Instant;
use crossbeam_channel::{unbounded, Receiver, Sender};
use flycheck::FlycheckHandle;
@ -15,6 +15,7 @@ use proc_macro_api::ProcMacroServer;
use project_model::{CargoWorkspace, ProjectWorkspace, Target, WorkspaceBuildScripts};
use rustc_hash::FxHashMap;
use stdx::hash::NoHashHashMap;
use triomphe::Arc;
use vfs::AnchoredPathBuf;
use crate::{
@ -161,9 +162,11 @@ impl GlobalState {
source_root_config: SourceRootConfig::default(),
proc_macro_changed: false,
proc_macro_clients: Arc::new([]),
// FIXME: use `Arc::from_iter` when it becomes available
proc_macro_clients: Arc::from(Vec::new()),
flycheck: Arc::new([]),
// FIXME: use `Arc::from_iter` when it becomes available
flycheck: Arc::from(Vec::new()),
flycheck_sender,
flycheck_receiver,

View file

@ -1,7 +1,7 @@
//! This module is responsible for implementing handlers for Language Server
//! Protocol. This module specifically handles notifications.
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use itertools::Itertools;
use lsp_types::{
@ -9,6 +9,7 @@ use lsp_types::{
DidChangeWatchedFilesParams, DidChangeWorkspaceFoldersParams, DidCloseTextDocumentParams,
DidOpenTextDocumentParams, DidSaveTextDocumentParams, WorkDoneProgressCancelParams,
};
use triomphe::Arc;
use vfs::{AbsPathBuf, ChangeKind, VfsPath};
use crate::{

View file

@ -5,7 +5,6 @@ use std::{
fs,
io::Write as _,
process::{self, Stdio},
sync::Arc,
};
use anyhow::Context;
@ -30,6 +29,7 @@ use project_model::{ManifestPath, ProjectWorkspace, TargetKind};
use serde_json::json;
use stdx::{format_to, never};
use syntax::{algo, ast, AstNode, TextRange, TextSize};
use triomphe::Arc;
use vfs::{AbsPath, AbsPathBuf, VfsPath};
use crate::{
@ -48,7 +48,8 @@ use crate::{
};
pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> Result<()> {
state.proc_macro_clients = Arc::new([]);
// FIXME: use `Arc::from_iter` when it becomes available
state.proc_macro_clients = Arc::from(Vec::new());
state.proc_macro_changed = false;
state.fetch_workspaces_queue.request_op("reload workspace request".to_string(), ());
@ -56,7 +57,8 @@ pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> Result<
}
pub(crate) fn handle_proc_macros_rebuild(state: &mut GlobalState, _: ()) -> Result<()> {
state.proc_macro_clients = Arc::new([]);
// FIXME: use `Arc::from_iter` when it becomes available
state.proc_macro_clients = Arc::from(Vec::new());
state.proc_macro_changed = false;
state.fetch_build_data_queue.request_op("rebuild proc macros request".to_string(), ());

View file

@ -10,8 +10,6 @@
//! in release mode in VS Code. There's however "rust-analyzer: Copy Run Command Line"
//! which you can use to paste the command in terminal and add `--release` manually.
use std::sync::Arc;
use ide::{CallableSnippets, Change, CompletionConfig, FilePosition, TextSize};
use ide_db::{
imports::insert_use::{ImportGranularity, InsertUseConfig},
@ -19,6 +17,7 @@ use ide_db::{
};
use project_model::CargoConfig;
use test_utils::project_root;
use triomphe::Arc;
use vfs::{AbsPathBuf, VfsPath};
use crate::cli::load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};

View file

@ -5,9 +5,8 @@
//! This module does line ending conversion and detection (so that we can
//! convert back to `\r\n` on the way out).
use std::sync::Arc;
use ide_db::line_index::WideEncoding;
use triomphe::Arc;
#[derive(Clone, Copy)]
pub enum PositionEncoding {

View file

@ -1,8 +1,9 @@
//! Utilities for LSP-related boilerplate code.
use std::{mem, ops::Range, sync::Arc};
use std::{mem, ops::Range};
use lsp_server::Notification;
use lsp_types::request::Request;
use triomphe::Arc;
use crate::{
from_proto,

View file

@ -2,7 +2,6 @@
//! requests/replies and notifications back to the client.
use std::{
fmt,
sync::Arc,
time::{Duration, Instant},
};
@ -12,6 +11,7 @@ use flycheck::FlycheckHandle;
use ide_db::base_db::{SourceDatabaseExt, VfsPath};
use lsp_server::{Connection, Notification, Request};
use lsp_types::notification::Notification as _;
use triomphe::Arc;
use vfs::FileId;
use crate::{

View file

@ -12,7 +12,7 @@
//! correct. Instead, we try to provide a best-effort service. Even if the
//! project is currently loading and we don't have a full project model, we
//! still want to respond to various requests.
use std::{collections::hash_map::Entry, iter, mem, sync::Arc};
use std::{collections::hash_map::Entry, iter, mem, sync};
use flycheck::{FlycheckConfig, FlycheckHandle};
use hir::db::DefDatabase;
@ -28,6 +28,7 @@ use itertools::Itertools;
use proc_macro_api::{MacroDylib, ProcMacroServer};
use project_model::{PackageRoot, ProjectWorkspace, WorkspaceBuildScripts};
use syntax::SmolStr;
use triomphe::Arc;
use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind};
use crate::{
@ -415,30 +416,32 @@ impl GlobalState {
if self.config.expand_proc_macros() {
tracing::info!("Spawning proc-macro servers");
self.proc_macro_clients = self
.workspaces
.iter()
.map(|ws| {
let path = match self.config.proc_macro_srv() {
Some(path) => path,
None => ws.find_sysroot_proc_macro_srv()?,
};
// FIXME: use `Arc::from_iter` when it becomes available
self.proc_macro_clients = Arc::from(
self.workspaces
.iter()
.map(|ws| {
let path = match self.config.proc_macro_srv() {
Some(path) => path,
None => ws.find_sysroot_proc_macro_srv()?,
};
tracing::info!("Using proc-macro server at {}", path.display(),);
ProcMacroServer::spawn(path.clone()).map_err(|err| {
tracing::error!(
"Failed to run proc-macro server from path {}, error: {:?}",
path.display(),
err
);
anyhow::anyhow!(
"Failed to run proc-macro server from path {}, error: {:?}",
path.display(),
err
)
tracing::info!("Using proc-macro server at {}", path.display(),);
ProcMacroServer::spawn(path.clone()).map_err(|err| {
tracing::error!(
"Failed to run proc-macro server from path {}, error: {:?}",
path.display(),
err
);
anyhow::anyhow!(
"Failed to run proc-macro server from path {}, error: {:?}",
path.display(),
err
)
})
})
})
.collect()
.collect::<Vec<_>>(),
)
};
}
@ -773,14 +776,14 @@ pub(crate) fn load_proc_macro(
proc_macro_api::ProcMacroKind::FuncLike => ProcMacroKind::FuncLike,
proc_macro_api::ProcMacroKind::Attr => ProcMacroKind::Attr,
};
let expander: Arc<dyn ProcMacroExpander> =
let expander: sync::Arc<dyn ProcMacroExpander> =
if dummy_replace.iter().any(|replace| &**replace == name) {
match kind {
ProcMacroKind::Attr => Arc::new(IdentityExpander),
_ => Arc::new(EmptyExpander),
ProcMacroKind::Attr => sync::Arc::new(IdentityExpander),
_ => sync::Arc::new(EmptyExpander),
}
} else {
Arc::new(Expander(expander))
sync::Arc::new(Expander(expander))
};
ProcMacro { name, kind, expander }
}

View file

@ -1441,9 +1441,8 @@ pub(crate) fn rename_error(err: RenameError) -> crate::LspError {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use ide::Analysis;
use triomphe::Arc;
use super::*;

View file

@ -22,6 +22,7 @@ rustc-hash = "1.1.0"
once_cell = "1.17.0"
indexmap = "1.9.1"
smol_str.workspace = true
triomphe.workspace = true
parser.workspace = true
profile.workspace = true

View file

@ -43,10 +43,11 @@ pub mod utils;
pub mod ted;
pub mod hacks;
use std::{marker::PhantomData, sync::Arc};
use std::marker::PhantomData;
use stdx::format_to;
use text_edit::Indel;
use triomphe::Arc;
pub use crate::{
ast::{AstNode, AstToken},