Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14718 - lnicola:triomphe, r=Veykril
internal: Use `triomphe::Arc` Closes #14717
bors 2023-05-03
parent a7168a8 · parent 7197a27 · commit 9811a3a
-rw-r--r--Cargo.lock19
-rw-r--r--Cargo.toml1
-rw-r--r--crates/base-db/Cargo.toml2
-rw-r--r--crates/base-db/src/change.rs3
-rw-r--r--crates/base-db/src/fixture.rs13
-rw-r--r--crates/base-db/src/input.rs5
-rw-r--r--crates/base-db/src/lib.rs3
-rw-r--r--crates/hir-def/Cargo.toml1
-rw-r--r--crates/hir-def/src/attr.rs3
-rw-r--r--crates/hir-def/src/body.rs3
-rw-r--r--crates/hir-def/src/body/lower.rs3
-rw-r--r--crates/hir-def/src/body/scope.rs3
-rw-r--r--crates/hir-def/src/data.rs3
-rw-r--r--crates/hir-def/src/data/adt.rs3
-rw-r--r--crates/hir-def/src/db.rs3
-rw-r--r--crates/hir-def/src/generics.rs3
-rw-r--r--crates/hir-def/src/import_map.rs3
-rw-r--r--crates/hir-def/src/item_tree.rs2
-rw-r--r--crates/hir-def/src/item_tree/lower.rs2
-rw-r--r--crates/hir-def/src/lang_item.rs3
-rw-r--r--crates/hir-def/src/lib.rs6
-rw-r--r--crates/hir-def/src/lower.rs3
-rw-r--r--crates/hir-def/src/macro_expansion_tests/mod.rs4
-rw-r--r--crates/hir-def/src/nameres.rs3
-rw-r--r--crates/hir-def/src/nameres/collector.rs6
-rw-r--r--crates/hir-def/src/nameres/tests.rs3
-rw-r--r--crates/hir-def/src/nameres/tests/incremental.rs3
-rw-r--r--crates/hir-def/src/resolver.rs3
-rw-r--r--crates/hir-def/src/test_db.rs6
-rw-r--r--crates/hir-def/src/visibility.rs3
-rw-r--r--crates/hir-expand/Cargo.toml1
-rw-r--r--crates/hir-expand/src/attrs.rs101
-rw-r--r--crates/hir-expand/src/db.rs3
-rw-r--r--crates/hir-expand/src/eager.rs3
-rw-r--r--crates/hir-expand/src/hygiene.rs3
-rw-r--r--crates/hir-expand/src/lib.rs3
-rw-r--r--crates/hir-ty/Cargo.toml1
-rw-r--r--crates/hir-ty/src/autoderef.rs3
-rw-r--r--crates/hir-ty/src/chalk_db.rs4
-rw-r--r--crates/hir-ty/src/db.rs27
-rw-r--r--crates/hir-ty/src/diagnostics/expr.rs2
-rw-r--r--crates/hir-ty/src/infer.rs2
-rw-r--r--crates/hir-ty/src/infer/coerce.rs3
-rw-r--r--crates/hir-ty/src/infer/expr.rs2
-rw-r--r--crates/hir-ty/src/infer/unify.rs3
-rw-r--r--crates/hir-ty/src/interner.rs3
-rw-r--r--crates/hir-ty/src/layout.rs3
-rw-r--r--crates/hir-ty/src/layout/target.rs3
-rw-r--r--crates/hir-ty/src/lib.rs26
-rw-r--r--crates/hir-ty/src/lower.rs83
-rw-r--r--crates/hir-ty/src/method_resolution.rs11
-rw-r--r--crates/hir-ty/src/mir/borrowck.rs3
-rw-r--r--crates/hir-ty/src/mir/eval.rs3
-rw-r--r--crates/hir-ty/src/mir/lower.rs3
-rw-r--r--crates/hir-ty/src/test_db.rs6
-rw-r--r--crates/hir-ty/src/tests.rs3
-rw-r--r--crates/hir-ty/src/tests/incremental.rs3
-rw-r--r--crates/hir-ty/src/traits.rs3
-rw-r--r--crates/hir/Cargo.toml1
-rw-r--r--crates/hir/src/lib.rs3
-rw-r--r--crates/hir/src/source_analyzer.rs6
-rw-r--r--crates/ide-db/Cargo.toml1
-rw-r--r--crates/ide-db/src/apply_change.rs3
-rw-r--r--crates/ide-db/src/lib.rs3
-rw-r--r--crates/ide-db/src/search.rs3
-rw-r--r--crates/ide-db/src/symbol_index.rs2
-rw-r--r--crates/ide-ssr/Cargo.toml1
-rw-r--r--crates/ide-ssr/src/tests.rs2
-rw-r--r--crates/ide/Cargo.toml1
-rw-r--r--crates/ide/src/lib.rs3
-rw-r--r--crates/ide/src/shuffle_crate_graph.rs3
-rw-r--r--crates/ide/src/ssr.rs3
-rw-r--r--crates/ide/src/status.rs3
-rw-r--r--crates/ide/src/view_crate_graph.rs3
-rw-r--r--crates/intern/Cargo.toml1
-rw-r--r--crates/intern/src/lib.rs6
-rw-r--r--crates/proc-macro-api/Cargo.toml1
-rw-r--r--crates/proc-macro-api/src/lib.rs6
-rw-r--r--crates/project-model/Cargo.toml1
-rw-r--r--crates/project-model/src/workspace.rs5
-rw-r--r--crates/rust-analyzer/Cargo.toml1
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs3
-rw-r--r--crates/rust-analyzer/src/diagnostics.rs3
-rw-r--r--crates/rust-analyzer/src/global_state.rs9
-rw-r--r--crates/rust-analyzer/src/handlers/notification.rs3
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs8
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs3
-rw-r--r--crates/rust-analyzer/src/line_index.rs3
-rw-r--r--crates/rust-analyzer/src/lsp_utils.rs3
-rw-r--r--crates/rust-analyzer/src/main_loop.rs2
-rw-r--r--crates/rust-analyzer/src/reload.rs59
-rw-r--r--crates/rust-analyzer/src/to_proto.rs3
-rw-r--r--crates/syntax/Cargo.toml1
-rw-r--r--crates/syntax/src/lib.rs3
94 files changed, 337 insertions, 263 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e0d5878d7f..f0fe95327f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
]
@@ -1940,6 +1953,12 @@ dependencies = [
]
[[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"
dependencies = [
diff --git a/Cargo.toml b/Cargo.toml
index 985a1844c7..ef8d8c0eef 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"] }
diff --git a/crates/base-db/Cargo.toml b/crates/base-db/Cargo.toml
index c2d021c223..6001772c86 100644
--- a/crates/base-db/Cargo.toml
+++ b/crates/base-db/Cargo.toml
@@ -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
diff --git a/crates/base-db/src/change.rs b/crates/base-db/src/change.rs
index f1973a2071..2b33457b6d 100644
--- a/crates/base-db/src/change.rs
+++ b/crates/base-db/src/change.rs
@@ -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};
diff --git a/crates/base-db/src/fixture.rs b/crates/base-db/src/fixture.rs
index 1936eabdd9..e89d3ae4bb 100644
--- a/crates/base-db/src/fixture.rs
+++ b/crates/base-db/src/fixture.rs
@@ -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),
},
),
]
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs
index e6d265df67..e8d521b42f 100644
--- a/crates/base-db/src/input.rs
+++ b/crates/base-db/src/input.rs
@@ -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)]
diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs
index b65cf7341f..af204e44e6 100644
--- a/crates/base-db/src/lib.rs
+++ b/crates/base-db/src/lib.rs
@@ -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,
diff --git a/crates/hir-def/Cargo.toml b/crates/hir-def/Cargo.toml
index f4414a3e22..83c7051646 100644
--- a/crates/hir-def/Cargo.toml
+++ b/crates/hir-def/Cargo.toml
@@ -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 }
diff --git a/crates/hir-def/src/attr.rs b/crates/hir-def/src/attr.rs
index 1ebbe160b0..f93d8d5c78 100644
--- a/crates/hir-def/src/attr.rs
+++ b/crates/hir-def/src/attr.rs
@@ -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,
diff --git a/crates/hir-def/src/body.rs b/crates/hir-def/src/body.rs
index 0c0e8ac820..c2a27cd82b 100644
--- a/crates/hir-def/src/body.rs
+++ b/crates/hir-def/src/body.rs
@@ -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,
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs
index 611031eb8c..0ecad857a4 100644
--- a/crates/hir-def/src/body/lower.rs
+++ b/crates/hir-def/src/body/lower.rs
@@ -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},
diff --git a/crates/hir-def/src/body/scope.rs b/crates/hir-def/src/body/scope.rs
index 1143f666ee..0340bd18c2 100644
--- a/crates/hir-def/src/body/scope.rs
+++ b/crates/hir-def/src/body/scope.rs
@@ -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,
diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs
index 7c6c089d65..de67f0b23c 100644
--- a/crates/hir-def/src/data.rs
+++ b/crates/hir-def/src/data.rs
@@ -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,
diff --git a/crates/hir-def/src/data/adt.rs b/crates/hir-def/src/data/adt.rs
index 4eefd66d47..6db5abccc9 100644
--- a/crates/hir-def/src/data/adt.rs
+++ b/crates/hir-def/src/data/adt.rs
@@ -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},
diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs
index cc87b03eef..98db5edccc 100644
--- a/crates/hir-def/src/db.rs
+++ b/crates/hir-def/src/db.rs
@@ -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},
diff --git a/crates/hir-def/src/generics.rs b/crates/hir-def/src/generics.rs
index c766857758..c79c170963 100644
--- a/crates/hir-def/src/generics.rs
+++ b/crates/hir-def/src/generics.rs
@@ -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,
diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs
index 0480e6a51d..4ea807e7d5 100644
--- a/crates/hir-def/src/import_map.rs
+++ b/crates/hir-def/src/import_map.rs
@@ -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,
diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs
index 7f2e88e427..c332cc28c3 100644
--- a/crates/hir-def/src/item_tree.rs
+++ b/crates/hir-def/src/item_tree.rs
@@ -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,
diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs
index 457a519872..46633667ed 100644
--- a/crates/hir-def/src/item_tree/lower.rs
+++ b/crates/hir-def/src/item_tree/lower.rs
@@ -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};
diff --git a/crates/hir-def/src/lang_item.rs b/crates/hir-def/src/lang_item.rs
index 818054188b..253e2daedd 100644
--- a/crates/hir-def/src/lang_item.rs
+++ b/crates/hir-def/src/lang_item.rs
@@ -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,
diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs
index 8e69a64e7e..6638855232 100644
--- a/crates/hir-def/src/lib.rs
+++ b/crates/hir-def/src/lib.rs
@@ -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::{
diff --git a/crates/hir-def/src/lower.rs b/crates/hir-def/src/lower.rs
index 1991d547f5..af623fd0e5 100644
--- a/crates/hir-def/src/lower.rs
+++ b/crates/hir-def/src/lower.rs
@@ -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};
diff --git a/crates/hir-def/src/macro_expansion_tests/mod.rs b/crates/hir-def/src/macro_expansion_tests/mod.rs
index 552d69ca2e..c48c0c1aee 100644
--- a/crates/hir-def/src/macro_expansion_tests/mod.rs
+++ b/crates/hir-def/src/macro_expansion_tests/mod.rs
@@ -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);
diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs
index 655004dcfe..803342fdab 100644
--- a/crates/hir-def/src/nameres.rs
+++ b/crates/hir-def/src/nameres.rs
@@ -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,
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index 05d49ee814..3ec33f663a 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -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(),
diff --git a/crates/hir-def/src/nameres/tests.rs b/crates/hir-def/src/nameres/tests.rs
index 8a27c60df5..dd7c3c3630 100644
--- a/crates/hir-def/src/nameres/tests.rs
+++ b/crates/hir-def/src/nameres/tests.rs
@@ -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};
diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs
index 50751ab9c8..4931c36bbc 100644
--- a/crates/hir-def/src/nameres/tests/incremental.rs
+++ b/crates/hir-def/src/nameres/tests/incremental.rs
@@ -1,6 +1,5 @@
-use std::sync::Arc;
-
use base_db::SourceDatabaseExt;
+use triomphe::Arc;
use crate::{db::DefDatabase, AdtId, ModuleDefId};
diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs
index 12499faeb6..45ec454b9e 100644
--- a/crates/hir-def/src/resolver.rs
+++ b/crates/hir-def/src/resolver.rs
@@ -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},
diff --git a/crates/hir-def/src/test_db.rs b/crates/hir-def/src/test_db.rs
index 6bfcd90970..d4b4031364 100644
--- a/crates/hir-def/src/test_db.rs
+++ b/crates/hir-def/src/test_db.rs
@@ -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,
diff --git a/crates/hir-def/src/visibility.rs b/crates/hir-def/src/visibility.rs
index ab76ed43d3..30f48de61f 100644
--- a/crates/hir-def/src/visibility.rs
+++ b/crates/hir-def/src/visibility.rs
@@ -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,
diff --git a/crates/hir-expand/Cargo.toml b/crates/hir-expand/Cargo.toml
index 5c684be03c..40d8659f25 100644
--- a/crates/hir-expand/Cargo.toml
+++ b/crates/hir-expand/Cargo.toml
@@ -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
diff --git a/crates/hir-expand/src/attrs.rs b/crates/hir-expand/src/attrs.rs
index 17360090db..3ff18e982e 100644
--- a/crates/hir-expand/src/attrs.rs
+++ b/crates/hir-expand/src/attrs.rs
@@ -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 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_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();
+ 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 (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);
+
+ attrs.collect()
+ }
+ })
+ // FIXME: use `Arc::from_iter` when it becomes available
+ .collect::<Vec<_>>(),
+ );
RawAttrs { entries: Some(new_attrs) }
}
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index 0f9e37c833..965dfa824d 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -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,
diff --git a/crates/hir-expand/src/eager.rs b/crates/hir-expand/src/eager.rs
index d81bb64719..59a92ff0ab 100644
--- a/crates/hir-expand/src/eager.rs
+++ b/crates/hir-expand/src/eager.rs
@@ -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},
diff --git a/crates/hir-expand/src/hygiene.rs b/crates/hir-expand/src/hygiene.rs
index 9af38fed04..10f8fe9cec 100644
--- a/crates/hir-expand/src/hygiene.rs
+++ b/crates/hir-expand/src/hygiene.rs
@@ -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},
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index ce0006d842..c24887e15f 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -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,
diff --git a/crates/hir-ty/Cargo.toml b/crates/hir-ty/Cargo.toml
index 3ab7460e8c..51d69d103a 100644
--- a/crates/hir-ty/Cargo.toml
+++ b/crates/hir-ty/Cargo.toml
@@ -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 }
diff --git a/crates/hir-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs
index 37ecdc23ed..f5b3f176b1 100644
--- a/crates/hir-ty/src/autoderef.rs
+++ b/crates/hir-ty/src/autoderef.rs
@@ -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,
diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs
index b47a22c342..d68703ce1d 100644
--- a/crates/hir-ty/src/chalk_db.rs
+++ b/crates/hir-ty/src/chalk_db.rs
@@ -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![]) };
diff --git a/crates/hir-ty/src/db.rs b/crates/hir-ty/src/db.rs
index d8bd5b3481..b37d90c758 100644
--- a/crates/hir-ty/src/db.rs
+++ b/crates/hir-ty/src/db.rs
@@ -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]
diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs
index f346910da0..ab34dc88d8 100644
--- a/crates/hir-ty/src/diagnostics/expr.rs
+++ b/crates/hir-ty/src/diagnostics/expr.rs
@@ -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::{
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index ba0b6d254b..0e9b7206d0 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -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,
diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs
index d613a5ff50..e9c94449cf 100644
--- a/crates/hir-ty/src/infer/coerce.rs
+++ b/crates/hir-ty/src/infer/coerce.rs
@@ -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},
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index 06ca9b026e..96218e4fb0 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -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},
diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs
index 2988c71039..b735a11adf 100644
--- a/crates/hir-ty/src/infer/unify.rs
+++ b/crates/hir-ty/src/infer/unify.rs
@@ -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::{
diff --git a/crates/hir-ty/src/interner.rs b/crates/hir-ty/src/interner.rs
index 19bb7f169f..89f7d9c4f4 100644
--- a/crates/hir-ty/src/interner.rs
+++ b/crates/hir-ty/src/interner.rs
@@ -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;
diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs
index ebbf16caee..f74a2253a4 100644
--- a/crates/hir-ty/src/layout.rs
+++ b/crates/hir-ty/src/layout.rs
@@ -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,
diff --git a/crates/hir-ty/src/layout/target.rs b/crates/hir-ty/src/layout/target.rs
index adfae0a1ab..04b940afbe 100644
--- a/crates/hir-ty/src/layout/target.rs
+++ b/crates/hir-ty/src/layout/target.rs
@@ -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;
diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs
index 071d95839e..6e726042f6 100644
--- a/crates/hir-ty/src/lib.rs
+++ b/crates/hir-ty/src/lib.rs
@@ -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,
}
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index 7da747b949..4000ba5c14 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -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));
-
- // 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();
+ 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))
+ })
+ // 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
}
diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs
index 159544f6dc..912efc3a89 100644
--- a/crates/hir-ty/src/method_resolution.rs
+++ b/crates/hir-ty/src/method_resolution.rs
@@ -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) {
diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs
index 7b99fbf42f..b2425d94c6 100644
--- a/crates/hir-ty/src/mir/borrowck.rs
+++ b/crates/hir-ty/src/mir/borrowck.rs
@@ -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};
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index 7ff68774bc..8ce16df829 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -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},
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index 733f58e8f6..66b1d840bd 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -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,
diff --git a/crates/hir-ty/src/test_db.rs b/crates/hir-ty/src/test_db.rs
index ca96a8d172..1276a4c5e1 100644
--- a/crates/hir-ty/src/test_db.rs
+++ b/crates/hir-ty/src/test_db.rs
@@ -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,
diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs
index af482e5cc6..a2adad3169 100644
--- a/crates/hir-ty/src/tests.rs
+++ b/crates/hir-ty/src/tests.rs
@@ -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,
diff --git a/crates/hir-ty/src/tests/incremental.rs b/crates/hir-ty/src/tests/incremental.rs
index 788eb30e28..bb15ca8c43 100644
--- a/crates/hir-ty/src/tests/incremental.rs
+++ b/crates/hir-ty/src/tests/incremental.rs
@@ -1,6 +1,5 @@
-use std::sync::Arc;
-
use base_db::{fixture::WithFixture, SourceDatabaseExt};
+use triomphe::Arc;
use crate::{db::HirDatabase, test_db::TestDB};
diff --git a/crates/hir-ty/src/traits.rs b/crates/hir-ty/src/traits.rs
index 8bc38aca47..2808fe6435 100644
--- a/crates/hir-ty/src/traits.rs
+++ b/crates/hir-ty/src/traits.rs
@@ -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,
diff --git a/crates/hir/Cargo.toml b/crates/hir/Cargo.toml
index ef40a8902d..a20aff93f1 100644
--- a/crates/hir/Cargo.toml
+++ b/crates/hir/Cargo.toml
@@ -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
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 49417d945c..d9cb2a7b6d 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -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};
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index a6a51e4907..19179d11ef 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -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,
diff --git a/crates/ide-db/Cargo.toml b/crates/ide-db/Cargo.toml
index 57daaf623d..fccd6d2b6d 100644
--- a/crates/ide-db/Cargo.toml
+++ b/crates/ide-db/Cargo.toml
@@ -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
diff --git a/crates/ide-db/src/apply_change.rs b/crates/ide-db/src/apply_change.rs
index 8d14371d03..8edda432ce 100644
--- a/crates/ide-db/src/apply_change.rs
+++ b/crates/ide-db/src/apply_change.rs
@@ -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};
diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs
index 0c6b0f20cf..5263271fa6 100644
--- a/crates/ide-db/src/lib.rs
+++ b/crates/ide-db/src/lib.rs
@@ -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};
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 2557c65a10..f58a96d595 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -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},
diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs
index a6f86c83df..fa796ae13b 100644
--- a/crates/ide-db/src/symbol_index.rs
+++ b/crates/ide-db/src/symbol_index.rs
@@ -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;
diff --git a/crates/ide-ssr/Cargo.toml b/crates/ide-ssr/Cargo.toml
index 04efa7b91d..b8625fc1be 100644
--- a/crates/ide-ssr/Cargo.toml
+++ b/crates/ide-ssr/Cargo.toml
@@ -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
diff --git a/crates/ide-ssr/src/tests.rs b/crates/ide-ssr/src/tests.rs
index 61698fca80..424ba3d7fd 100644
--- a/crates/ide-ssr/src/tests.rs
+++ b/crates/ide-ssr/src/tests.rs
@@ -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};
diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml
index 30e514e413..c3dcb60490 100644
--- a/crates/ide/Cargo.toml
+++ b/crates/ide/Cargo.toml
@@ -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
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 1af4d39265..b84d5df810 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -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};
diff --git a/crates/ide/src/shuffle_crate_graph.rs b/crates/ide/src/shuffle_crate_graph.rs
index d94b15f60c..f85700daf1 100644
--- a/crates/ide/src/shuffle_crate_graph.rs
+++ b/crates/ide/src/shuffle_crate_graph.rs
@@ -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
//
diff --git a/crates/ide/src/ssr.rs b/crates/ide/src/ssr.rs
index 497eb1cc13..deaf3c9c41 100644
--- a/crates/ide/src/ssr.rs
+++ b/crates/ide/src/ssr.rs
@@ -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;
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index 3dfbc1874b..70bff41121 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -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
//
diff --git a/crates/ide/src/view_crate_graph.rs b/crates/ide/src/view_crate_graph.rs
index 711f7e3f87..8c84461f65 100644
--- a/crates/ide/src/view_crate_graph.rs
+++ b/crates/ide/src/view_crate_graph.rs
@@ -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
//
diff --git a/crates/intern/Cargo.toml b/crates/intern/Cargo.toml
index c73c368a14..dcd0d78812 100644
--- a/crates/intern/Cargo.toml
+++ b/crates/intern/Cargo.toml
@@ -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
diff --git a/crates/intern/src/lib.rs b/crates/intern/src/lib.rs
index fb2903696b..d17eddf156 100644
--- a/crates/intern/src/lib.rs
+++ b/crates/intern/src/lib.rs
@@ -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;
}
diff --git a/crates/proc-macro-api/Cargo.toml b/crates/proc-macro-api/Cargo.toml
index e748421f6d..d3486e7557 100644
--- a/crates/proc-macro-api/Cargo.toml
+++ b/crates/proc-macro-api/Cargo.toml
@@ -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"
diff --git a/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs
index ab15f414bb..1603458f75 100644
--- a/crates/proc-macro-api/src/lib.rs
+++ b/crates/proc-macro-api/src/lib.rs
@@ -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};
diff --git a/crates/project-model/Cargo.toml b/crates/project-model/Cargo.toml
index 080b224e86..efe61eb8f6 100644
--- a/crates/project-model/Cargo.toml
+++ b/crates/project-model/Cargo.toml
@@ -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" }
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 5924287a37..bfd2cab31f 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -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
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index ea4f155bfd..c7c2e34127 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -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
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 625f1f2b19..4e8f999716 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -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};
diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs
index 83b03fe473..2edb394a0b 100644
--- a/crates/rust-analyzer/src/diagnostics.rs
+++ b/crates/rust-analyzer/src/diagnostics.rs
@@ -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;
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 07778d2b59..0f77eeae4a 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -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,
diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs
index a734f48301..ca9ea77f30 100644
--- a/crates/rust-analyzer/src/handlers/notification.rs
+++ b/crates/rust-analyzer/src/handlers/notification.rs
@@ -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::{
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index 3a208865a7..9e9dfaaf5a 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -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(), ());
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index 6a69f70962..bd9f471a46 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -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};
diff --git a/crates/rust-analyzer/src/line_index.rs b/crates/rust-analyzer/src/line_index.rs
index 791cd931d4..15450303ff 100644
--- a/crates/rust-analyzer/src/line_index.rs
+++ b/crates/rust-analyzer/src/line_index.rs
@@ -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 {
diff --git a/crates/rust-analyzer/src/lsp_utils.rs b/crates/rust-analyzer/src/lsp_utils.rs
index 12e5caf2cc..9a73da1539 100644
--- a/crates/rust-analyzer/src/lsp_utils.rs
+++ b/crates/rust-analyzer/src/lsp_utils.rs
@@ -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,
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index d3cfc5e40d..ea8dbc5438 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -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::{
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 87ec040d7b..4c76392a0e 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -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()?,
- };
-
- 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
- )
+ // 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
+ )
+ })
})
- })
- .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 }
}
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 521db6b0ca..60292d2ad1 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -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::*;
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml
index 9109507f75..ac5b3058b9 100644
--- a/crates/syntax/Cargo.toml
+++ b/crates/syntax/Cargo.toml
@@ -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
diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs
index 6f57cbad66..efbf879664 100644
--- a/crates/syntax/src/lib.rs
+++ b/crates/syntax/src/lib.rs
@@ -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},