From 5c2e2d985e73b86ceb460cd82eedfd27181a8a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 2 May 2023 17:12:22 +0300 Subject: [PATCH] Use triomphe Arc --- Cargo.lock | 28 +++++ Cargo.toml | 1 + crates/base-db/Cargo.toml | 2 + crates/base-db/src/change.rs | 3 +- crates/base-db/src/fixture.rs | 13 +-- crates/base-db/src/input.rs | 5 +- crates/base-db/src/lib.rs | 3 +- crates/hir-def/Cargo.toml | 1 + crates/hir-def/src/attr.rs | 3 +- crates/hir-def/src/body.rs | 3 +- crates/hir-def/src/body/lower.rs | 3 +- crates/hir-def/src/body/scope.rs | 3 +- crates/hir-def/src/data.rs | 3 +- crates/hir-def/src/data/adt.rs | 3 +- crates/hir-def/src/db.rs | 3 +- crates/hir-def/src/generics.rs | 3 +- crates/hir-def/src/import_map.rs | 3 +- crates/hir-def/src/item_tree.rs | 2 +- crates/hir-def/src/item_tree/lower.rs | 2 +- crates/hir-def/src/lang_item.rs | 3 +- crates/hir-def/src/lib.rs | 6 +- crates/hir-def/src/lower.rs | 3 +- .../hir-def/src/macro_expansion_tests/mod.rs | 4 +- crates/hir-def/src/nameres.rs | 3 +- crates/hir-def/src/nameres/collector.rs | 6 +- crates/hir-def/src/nameres/tests.rs | 3 +- .../hir-def/src/nameres/tests/incremental.rs | 3 +- crates/hir-def/src/resolver.rs | 3 +- crates/hir-def/src/test_db.rs | 6 +- crates/hir-def/src/visibility.rs | 3 +- crates/hir-expand/Cargo.toml | 1 + crates/hir-expand/src/attrs.rs | 101 ++++++++++-------- crates/hir-expand/src/db.rs | 3 +- crates/hir-expand/src/eager.rs | 3 +- crates/hir-expand/src/hygiene.rs | 3 +- crates/hir-expand/src/lib.rs | 3 +- crates/hir-ty/Cargo.toml | 1 + crates/hir-ty/src/autoderef.rs | 3 +- crates/hir-ty/src/chalk_db.rs | 4 +- crates/hir-ty/src/db.rs | 27 +++-- crates/hir-ty/src/diagnostics/expr.rs | 2 +- crates/hir-ty/src/infer.rs | 2 +- crates/hir-ty/src/infer/coerce.rs | 3 +- crates/hir-ty/src/infer/expr.rs | 2 +- crates/hir-ty/src/infer/unify.rs | 3 +- crates/hir-ty/src/interner.rs | 3 +- crates/hir-ty/src/layout.rs | 3 +- crates/hir-ty/src/layout/target.rs | 3 +- crates/hir-ty/src/lib.rs | 26 +++-- crates/hir-ty/src/lower.rs | 83 +++++++------- crates/hir-ty/src/method_resolution.rs | 11 +- crates/hir-ty/src/mir/borrowck.rs | 3 +- crates/hir-ty/src/mir/eval.rs | 3 +- crates/hir-ty/src/mir/lower.rs | 3 +- crates/hir-ty/src/test_db.rs | 6 +- crates/hir-ty/src/tests.rs | 3 +- crates/hir-ty/src/tests/incremental.rs | 3 +- crates/hir-ty/src/traits.rs | 3 +- crates/hir/Cargo.toml | 1 + crates/hir/src/lib.rs | 3 +- crates/hir/src/source_analyzer.rs | 6 +- crates/ide-db/Cargo.toml | 1 + crates/ide-db/src/apply_change.rs | 3 +- crates/ide-db/src/lib.rs | 3 +- crates/ide-db/src/search.rs | 3 +- crates/ide-db/src/symbol_index.rs | 2 +- crates/ide-ssr/Cargo.toml | 1 + crates/ide-ssr/src/tests.rs | 2 +- crates/ide/Cargo.toml | 1 + crates/ide/src/lib.rs | 3 +- crates/ide/src/shuffle_crate_graph.rs | 3 +- crates/ide/src/ssr.rs | 3 +- crates/ide/src/status.rs | 3 +- crates/ide/src/view_crate_graph.rs | 3 +- crates/intern/Cargo.toml | 1 + crates/intern/src/lib.rs | 6 +- crates/project-model/Cargo.toml | 1 + crates/project-model/src/workspace.rs | 5 +- crates/rust-analyzer/Cargo.toml | 1 + crates/rust-analyzer/src/cli/load_cargo.rs | 3 +- crates/rust-analyzer/src/diagnostics.rs | 3 +- crates/rust-analyzer/src/global_state.rs | 9 +- .../src/handlers/notification.rs | 3 +- crates/rust-analyzer/src/handlers/request.rs | 8 +- .../src/integrated_benchmarks.rs | 3 +- crates/rust-analyzer/src/line_index.rs | 3 +- crates/rust-analyzer/src/lsp_utils.rs | 3 +- crates/rust-analyzer/src/main_loop.rs | 2 +- crates/rust-analyzer/src/reload.rs | 59 +++++----- crates/rust-analyzer/src/to_proto.rs | 3 +- crates/syntax/Cargo.toml | 1 + crates/syntax/src/lib.rs | 3 +- 92 files changed, 342 insertions(+), 260 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0d5878d7fae..8bc08d700020 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]] @@ -1315,6 +1324,7 @@ dependencies = [ "stdx", "toolchain", "tracing", + "triomphe", ] [[package]] @@ -1484,6 +1494,7 @@ dependencies = [ "tracing-log", "tracing-subscriber", "tracing-tree", + "triomphe", "tt", "vfs", "vfs-notify", @@ -1667,6 +1678,12 @@ dependencies = [ "xshell", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -1730,6 +1747,7 @@ dependencies = [ "stdx", "test-utils", "text-edit", + "triomphe", "ungrammar", ] @@ -1939,6 +1957,16 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "triomphe" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1ee9bd9239c339d714d657fac840c6d2a4f9c45f4f9ec7b0975113458be78db" +dependencies = [ + "serde", + "stable_deref_trait", +] + [[package]] name = "tt" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 985a1844c734..b3578328e446 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 = "0.1.8" diff --git a/crates/base-db/Cargo.toml b/crates/base-db/Cargo.toml index c2d021c22385..6001772c86ee 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 f1973a20714a..2b33457b6d52 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 1936eabdd9f3..e89d3ae4bb33 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 e6d265df675d..e8d521b42f86 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>; pub struct ProcMacro { pub name: SmolStr, pub kind: ProcMacroKind, - pub expander: Arc, + pub expander: sync::Arc, } #[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 b65cf7341f35..af204e44e6ee 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 f4414a3e2217..83c7051646ed 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 1ebbe160b071..f93d8d5c78e8 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 0c0e8ac8204e..c2a27cd82ba1 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 611031eb8c41..0ecad857a44f 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 1143f666eea1..0340bd18c2aa 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 7c6c089d65ba..de67f0b23cfc 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 4eefd66d4778..6db5abccc921 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 cc87b03eef7f..98db5edccc69 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 c7668577585a..c79c17096305 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 0480e6a51d31..4ea807e7d585 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 7f2e88e42752..c332cc28c3c1 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 457a519872cd..46633667ed3e 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 818054188bea..253e2daeddf6 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 8e69a64e7e9c..66388552322a 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 1991d547f5d2..af623fd0e5d4 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 552d69ca2eaf..c48c0c1aee59 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 655004dcfe2f..803342fdab50 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 05d49ee814bd..3ec33f663a3d 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 8a27c60df5c2..dd7c3c363062 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 50751ab9c89a..4931c36bbca9 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 12499faeb622..45ec454b9ebc 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 6bfcd90970dd..d4b403136429 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 ab76ed43d3a0..30f48de61f2e 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 5c684be03cf2..40d8659f25ba 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 17360090db1d..3ff18e982e18 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::>(); + .collect::>(); + // 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::>(), + )), } } } @@ -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::>(), + ); RawAttrs { entries: Some(new_attrs) } } diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs index 0f9e37c83383..965dfa824d8f 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 d81bb647194c..59a92ff0ab61 100644 --- a/crates/hir-expand/src/eager.rs +++ b/crates/hir-expand/src/eager.rs @@ -18,10 +18,9 @@ //! //! //! See the full discussion : -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 9af38fed0445..10f8fe9cec42 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 ce0006d84229..c24887e15ff1 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 3ab7460e8cd5..51d69d103ad6 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 37ecdc23edc3..f5b3f176b12e 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 b47a22c34252..d68703ce1d47 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 for ChalkContext<'a> { fn generator_datum( &self, id: chalk_ir::GeneratorId, - ) -> std::sync::Arc> { + ) -> Arc> { 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 for ChalkContext<'a> { fn generator_witness_datum( &self, id: chalk_ir::GeneratorId, - ) -> std::sync::Arc> { + ) -> Arc> { // 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 d8bd5b348178..b37d90c75895 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 { 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; + fn associated_ty_data( + &self, + id: chalk_db::AssocTypeId, + ) -> sync::Arc; #[salsa::invoke(chalk_db::trait_datum_query)] - fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId) - -> Arc; + fn trait_datum( + &self, + krate: CrateId, + trait_id: chalk_db::TraitId, + ) -> sync::Arc; #[salsa::invoke(chalk_db::struct_datum_query)] fn struct_datum( &self, krate: CrateId, struct_id: chalk_db::AdtId, - ) -> Arc; + ) -> sync::Arc; #[salsa::invoke(chalk_db::impl_datum_query)] - fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc; + fn impl_datum( + &self, + krate: CrateId, + impl_id: chalk_db::ImplId, + ) -> sync::Arc; #[salsa::invoke(chalk_db::fn_def_datum_query)] - fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc; + fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> sync::Arc; #[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 { &self, krate: CrateId, id: chalk_db::AssociatedTyValueId, - ) -> Arc; + ) -> sync::Arc; #[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 f346910da09b..ab34dc88d87b 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 ba0b6d254b79..0e9b7206d04a 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 d613a5ff5049..e9c94449cfc7 100644 --- a/crates/hir-ty/src/infer/coerce.rs +++ b/crates/hir-ty/src/infer/coerce.rs @@ -5,7 +5,7 @@ //! See 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 06ca9b026e37..96218e4fb094 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 2988c710398c..b735a11adfbf 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 19bb7f169f1c..89f7d9c4f4ab 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 ebbf16caee1e..f74a2253a424 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 adfae0a1abb3..04b940afbe8f 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 071d95839ecc..6e726042f6cf 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::>(), + ), 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 7da747b94979..4000ba5c14c5 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, ) -> Arc<[Binders]> { - 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::>(), + ); 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::>(), + ); defaults } diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index 159544f6dc0c..912efc3a8960 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]> { 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::>(), + ) } 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 7b99fbf42f01..b2425d94c61d 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 7ff68774bc98..8ce16df82958 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 733f58e8f6b0..66b1d840bdc2 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 ca96a8d17246..1276a4c5e14f 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 af482e5cc6d1..a2adad316969 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 788eb30e28cd..bb15ca8c436a 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 8bc38aca4722..2808fe64351f 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 ef40a8902d73..a20aff93f19b 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 49417d945ce0..d9cb2a7b6da3 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 a6a51e4907c4..19179d11ef89 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 57daaf623df2..fccd6d2b6db7 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 8d14371d034a..8edda432ce39 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 0c6b0f20cf51..5263271fa6f9 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 2557c65a1062..f58a96d595a8 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 a6f86c83df7a..fa796ae13b2b 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 04efa7b91d82..b8625fc1be92 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 61698fca80fe..424ba3d7fd50 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 30e514e4136a..c3dcb60490c6 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 e3900fa0d63b..4985b53c52ac 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -60,8 +60,6 @@ mod interpret_function; mod view_item_tree; mod shuffle_crate_graph; -use std::sync::Arc; - use cfg::CfgOptions; use ide_db::{ base_db::{ @@ -71,6 +69,7 @@ use ide_db::{ symbol_index, FxHashMap, 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 d94b15f60c84..f85700daf1f7 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 497eb1cc130d..deaf3c9c416b 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 3dfbc1874b3a..70bff41121d8 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 711f7e3f876f..8c84461f659f 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 c73c368a14e0..dcd0d7881255 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 fb2903696b37..d17eddf1560a 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 = DashMap, (), BuildHasherDefault>; type Guard = dashmap::RwLockWriteGuard< @@ -83,7 +83,7 @@ impl Drop for Interned { #[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 Interned { // 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/project-model/Cargo.toml b/crates/project-model/Cargo.toml index 080b224e8627..efe61eb8f68d 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 5924287a37f9..bfd2cab31fb8 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 ea4f155bfd57..c7c2e341276f 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 625f1f2b1934..4e8f99971674 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 83b03fe47362..2edb394a0b1f 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 07778d2b59f9..0f77eeae4adb 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 a734f4830109..ca9ea77f305c 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 03e08d9cdfc0..f14ad8f50cba 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -4,7 +4,6 @@ use std::{ io::Write as _, process::{self, Stdio}, - sync::Arc, }; use anyhow::Context; @@ -29,6 +28,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}; use crate::{ @@ -44,7 +44,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(), ()); @@ -52,7 +53,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 6a69f70962b4..bd9f471a46d1 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 791cd931d42a..15450303ff25 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 12e5caf2cc9e..9a73da153983 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 dc0ea0b17e09..c5f6355d43c5 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 87ec040d7b8f..4c76392a0e7f 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::>(), + ) }; } @@ -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 = + let expander: sync::Arc = 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 521db6b0ca9c..60292d2ad18c 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 9109507f75e4..ac5b3058b97a 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 6f57cbad66b1..efbf87966448 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},