refactor: Remove unnecessary Arc

This commit is contained in:
Lukas Wirth 2025-03-15 17:16:13 +01:00
parent 7edfeb9674
commit b5eedad8e3
11 changed files with 22 additions and 26 deletions

View file

@ -89,7 +89,7 @@ impl ops::Index<CrateBuilderId> for CrateGraphBuilder {
pub struct CrateBuilder {
pub basic: CrateDataBuilder,
pub extra: ExtraCrateData,
pub cfg_options: Arc<CfgOptions>,
pub cfg_options: CfgOptions,
pub env: Env,
ws_data: Arc<CrateWorkspaceData>,
}
@ -403,9 +403,8 @@ pub struct Crate {
// This is in `Arc` because it is shared for all crates in a workspace.
#[return_ref]
pub workspace_data: Arc<CrateWorkspaceData>,
// FIXME: Remove this `Arc`.
#[return_ref]
pub cfg_options: Arc<CfgOptions>,
pub cfg_options: CfgOptions,
#[return_ref]
pub env: Env,
}
@ -421,7 +420,7 @@ impl CrateGraphBuilder {
edition: Edition,
display_name: Option<CrateDisplayName>,
version: Option<String>,
cfg_options: Arc<CfgOptions>,
cfg_options: CfgOptions,
potential_cfg_options: Option<CfgOptions>,
mut env: Env,
origin: CrateOrigin,

View file

@ -11,7 +11,6 @@ use hir_expand::{
};
use span::{Edition, SyntaxContext};
use syntax::{Parse, ast};
use triomphe::Arc;
use crate::type_ref::{TypesMap, TypesSourceMap};
use crate::{
@ -21,7 +20,6 @@ use crate::{
#[derive(Debug)]
pub struct Expander {
cfg_options: Arc<CfgOptions>,
span_map: OnceCell<SpanMap>,
current_file_id: HirFileId,
pub(crate) module: ModuleId,
@ -44,7 +42,6 @@ impl Expander {
module,
recursion_depth: 0,
recursion_limit,
cfg_options: Arc::clone(module.krate.cfg_options(db)),
span_map: OnceCell::new(),
}
}
@ -141,8 +138,8 @@ impl Expander {
)
}
pub(crate) fn cfg_options(&self) -> &CfgOptions {
&self.cfg_options
pub(crate) fn cfg_options<'db>(&self, db: &'db dyn DefDatabase) -> &'db CfgOptions {
self.module.krate.cfg_options(db)
}
pub fn current_file_id(&self) -> HirFileId {

View file

@ -1894,14 +1894,14 @@ impl ExprCollector<'_> {
fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<()> {
match self.expander.parse_attrs(self.db, owner).cfg() {
Some(cfg) => {
if self.expander.cfg_options().check(&cfg) != Some(false) {
if self.expander.cfg_options(self.db).check(&cfg) != Some(false) {
return Some(());
}
self.source_map.diagnostics.push(ExpressionStoreDiagnostics::InactiveCode {
node: self.expander.in_file(SyntaxNodePtr::new(owner.syntax())),
cfg,
opts: self.expander.cfg_options().clone(),
opts: self.expander.cfg_options(self.db).clone(),
});
None

View file

@ -167,13 +167,13 @@ impl<'a> AssocItemCollector<'a> {
'items: for &item in assoc_items {
let attrs = item_tree.attrs(self.db, self.module_id.krate, ModItem::from(item).into());
if !attrs.is_cfg_enabled(self.expander.cfg_options()) {
if !attrs.is_cfg_enabled(self.expander.cfg_options(self.db)) {
self.diagnostics.push(DefDiagnostic::unconfigured_code(
self.module_id.local_id,
tree_id,
ModItem::from(item).into(),
attrs.cfg().unwrap(),
self.expander.cfg_options().clone(),
self.expander.cfg_options(self.db).clone(),
));
continue;
}

View file

@ -58,7 +58,7 @@ pub const BAZ: u32 = 0;
Edition::CURRENT,
Some(CrateDisplayName::from_canonical_name(crate_name)),
None,
Arc::default(),
Default::default(),
None,
Env::default(),
CrateOrigin::Local { repo: None, name: Some(Symbol::intern(crate_name)) },

View file

@ -1226,7 +1226,7 @@ impl HirDisplay for Ty {
TyKind::Adt(AdtId(def_id), parameters) => {
f.start_location_link((*def_id).into());
match f.display_kind {
DisplayKind::Diagnostics { .. } | DisplayKind::Test { .. } => {
DisplayKind::Diagnostics | DisplayKind::Test => {
let name = match *def_id {
hir_def::AdtId::StructId(it) => db.struct_data(it).name.clone(),
hir_def::AdtId::UnionId(it) => db.union_data(it).name.clone(),

View file

@ -276,8 +276,8 @@ impl Crate {
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
}
pub fn cfg(&self, db: &dyn HirDatabase) -> Arc<CfgOptions> {
Arc::clone(self.id.cfg_options(db))
pub fn cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {
self.id.cfg_options(db)
}
pub fn potential_cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {

View file

@ -250,7 +250,7 @@ impl Analysis {
Edition::CURRENT,
None,
None,
Arc::new(cfg_options),
cfg_options,
None,
Env::default(),
CrateOrigin::Local { repo: None, name: None },

View file

@ -1051,7 +1051,7 @@ fn project_json_to_crate_graph(
*edition,
display_name.clone(),
version.clone(),
Arc::new(cfg_options),
cfg_options,
None,
env,
if let Some(name) = display_name.clone() {
@ -1341,7 +1341,7 @@ fn detached_file_to_crate_graph(
}
cfg_options.insert_atom(sym::rust_analyzer.clone());
override_cfg.apply(&mut cfg_options, "");
let cfg_options = Arc::new(cfg_options);
let cfg_options = cfg_options;
let file_id = match load(detached_file) {
Some(file_id) => file_id,
@ -1526,7 +1526,7 @@ fn add_target_crate_root(
edition,
Some(CrateDisplayName::from_canonical_name(cargo_name)),
Some(pkg.version.to_string()),
Arc::new(cfg_options),
cfg_options,
potential_cfg_options,
env,
origin,
@ -1680,13 +1680,13 @@ fn sysroot_to_crate_graph(
extend_crate_graph_with_sysroot(crate_graph, sysroot_cg, sysroot_pm)
}
RustLibSrcWorkspace::Stitched(stitched) => {
let cfg_options = Arc::new({
let cfg_options = {
let mut cfg_options = CfgOptions::default();
cfg_options.extend(rustc_cfg);
cfg_options.insert_atom(sym::debug_assertions.clone());
cfg_options.insert_atom(sym::miri.clone());
cfg_options
});
};
let sysroot_crates: FxHashMap<
crate::sysroot::stitched::RustLibSrcCrate,
CrateBuilderId,

View file

@ -18,7 +18,7 @@ impl salsa::Database for LoggerDb {
let event = event();
match event.kind {
salsa::EventKind::WillExecute { .. }
| salsa::EventKind::WillCheckCancellation { .. }
| salsa::EventKind::WillCheckCancellation
| salsa::EventKind::DidValidateMemoizedValue { .. }
| salsa::EventKind::WillDiscardStaleOutput { .. }
| salsa::EventKind::DidDiscard { .. } => {

View file

@ -207,7 +207,7 @@ impl ChangeFixture {
meta.edition,
Some(crate_name.clone().into()),
version,
From::from(meta.cfg.clone()),
meta.cfg.clone(),
Some(meta.cfg),
meta.env,
origin,
@ -247,7 +247,7 @@ impl ChangeFixture {
Edition::CURRENT,
Some(CrateName::new("ra_test_fixture").unwrap().into()),
None,
From::from(default_cfg.clone()),
default_cfg.clone(),
Some(default_cfg),
default_env,
CrateOrigin::Local { repo: None, name: None },