Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: Use triomphe::Arc #14718

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 2 additions & 0 deletions crates/base-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion crates/base-db/src/change.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
13 changes: 7 additions & 6 deletions crates/base-db/src/fixture.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! 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;
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};

Expand Down Expand Up @@ -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),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triomphe::Arc doesn't support trait objects

},
),
(
Expand All @@ -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),
},
),
(
Expand All @@ -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),
},
),
(
Expand All @@ -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),
},
),
(
Expand All @@ -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),
},
),
]
Expand Down
5 changes: 3 additions & 2 deletions crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/hir-def/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -21,6 +21,7 @@ use syntax::{
ast::{self, HasAttrs, IsString},
AstPtr, AstToken, SmolStr, TextRange, TextSize,
};
use triomphe::Arc;

use crate::{
db::DefDatabase,
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,6 +22,7 @@ use syntax::{
},
AstNode, AstPtr, SyntaxNodePtr,
};
use triomphe::Arc;

use crate::{
body::{Body, BodyDiagnostic, BodySourceMap, ExprPtr, LabelPtr, PatPtr},
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-def/src/body/scope.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-def/src/data/adt.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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},
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-def/src/db.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! 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};
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,
Expand Down
Loading