mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Arc CrateData::cfg_options
This commit is contained in:
parent
336dee3415
commit
f3567bb604
7 changed files with 29 additions and 31 deletions
|
@ -285,10 +285,9 @@ pub struct CrateData {
|
|||
/// For purposes of analysis, crates are anonymous (only names in
|
||||
/// `Dependency` matters), this name should only be used for UI.
|
||||
pub display_name: Option<CrateDisplayName>,
|
||||
// FIXME: Arc this
|
||||
pub cfg_options: CfgOptions,
|
||||
pub cfg_options: Arc<CfgOptions>,
|
||||
/// The cfg options that could be used by the crate
|
||||
pub potential_cfg_options: Option<CfgOptions>,
|
||||
pub potential_cfg_options: Option<Arc<CfgOptions>>,
|
||||
pub env: Env,
|
||||
pub dependencies: Vec<Dependency>,
|
||||
pub origin: CrateOrigin,
|
||||
|
@ -329,8 +328,8 @@ impl CrateGraph {
|
|||
edition: Edition,
|
||||
display_name: Option<CrateDisplayName>,
|
||||
version: Option<String>,
|
||||
cfg_options: CfgOptions,
|
||||
potential_cfg_options: Option<CfgOptions>,
|
||||
cfg_options: Arc<CfgOptions>,
|
||||
potential_cfg_options: Option<Arc<CfgOptions>>,
|
||||
env: Env,
|
||||
is_proc_macro: bool,
|
||||
origin: CrateOrigin,
|
||||
|
|
|
@ -191,8 +191,6 @@ impl StructData {
|
|||
let krate = loc.container.krate;
|
||||
let item_tree = loc.id.item_tree(db);
|
||||
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
|
||||
let cfg_options = db.crate_graph()[krate].cfg_options.clone();
|
||||
|
||||
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
|
||||
|
||||
let mut flags = StructFlags::NO_FLAGS;
|
||||
|
@ -219,7 +217,7 @@ impl StructData {
|
|||
loc.id.file_id(),
|
||||
loc.container.local_id,
|
||||
&item_tree,
|
||||
&cfg_options,
|
||||
&db.crate_graph()[krate].cfg_options,
|
||||
&strukt.fields,
|
||||
None,
|
||||
);
|
||||
|
@ -248,8 +246,6 @@ impl StructData {
|
|||
let krate = loc.container.krate;
|
||||
let item_tree = loc.id.item_tree(db);
|
||||
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
|
||||
let cfg_options = db.crate_graph()[krate].cfg_options.clone();
|
||||
|
||||
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
|
||||
let mut flags = StructFlags::NO_FLAGS;
|
||||
if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() {
|
||||
|
@ -266,7 +262,7 @@ impl StructData {
|
|||
loc.id.file_id(),
|
||||
loc.container.local_id,
|
||||
&item_tree,
|
||||
&cfg_options,
|
||||
&db.crate_graph()[krate].cfg_options,
|
||||
&union.fields,
|
||||
None,
|
||||
);
|
||||
|
@ -338,7 +334,6 @@ impl EnumVariantData {
|
|||
let container = loc.parent.lookup(db).container;
|
||||
let krate = container.krate;
|
||||
let item_tree = loc.id.item_tree(db);
|
||||
let cfg_options = db.crate_graph()[krate].cfg_options.clone();
|
||||
let variant = &item_tree[loc.id.value];
|
||||
|
||||
let (var_data, diagnostics) = lower_fields(
|
||||
|
@ -347,7 +342,7 @@ impl EnumVariantData {
|
|||
loc.id.file_id(),
|
||||
container.local_id,
|
||||
&item_tree,
|
||||
&cfg_options,
|
||||
&db.crate_graph()[krate].cfg_options,
|
||||
&variant.fields,
|
||||
Some(item_tree[loc.parent.lookup(db).id.value].visibility),
|
||||
);
|
||||
|
|
|
@ -11,6 +11,7 @@ use hir_expand::{
|
|||
};
|
||||
use limit::Limit;
|
||||
use syntax::{ast, Parse};
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
attr::Attrs, db::DefDatabase, lower::LowerCtx, path::Path, AsMacroCall, MacroId, ModuleId,
|
||||
|
@ -19,7 +20,7 @@ use crate::{
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Expander {
|
||||
cfg_options: CfgOptions,
|
||||
cfg_options: Arc<CfgOptions>,
|
||||
span_map: OnceCell<SpanMap>,
|
||||
current_file_id: HirFileId,
|
||||
pub(crate) module: ModuleId,
|
||||
|
|
|
@ -260,11 +260,11 @@ impl Crate {
|
|||
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
|
||||
}
|
||||
|
||||
pub fn cfg(&self, db: &dyn HirDatabase) -> CfgOptions {
|
||||
pub fn cfg(&self, db: &dyn HirDatabase) -> Arc<CfgOptions> {
|
||||
db.crate_graph()[self.id].cfg_options.clone()
|
||||
}
|
||||
|
||||
pub fn potential_cfg(&self, db: &dyn HirDatabase) -> CfgOptions {
|
||||
pub fn potential_cfg(&self, db: &dyn HirDatabase) -> Arc<CfgOptions> {
|
||||
let data = &db.crate_graph()[self.id];
|
||||
data.potential_cfg_options.clone().unwrap_or_else(|| data.cfg_options.clone())
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ impl Analysis {
|
|||
Edition::CURRENT,
|
||||
None,
|
||||
None,
|
||||
cfg_options.clone(),
|
||||
Arc::new(cfg_options),
|
||||
None,
|
||||
Env::default(),
|
||||
false,
|
||||
|
|
|
@ -913,12 +913,14 @@ fn project_json_to_crate_graph(
|
|||
*edition,
|
||||
display_name.clone(),
|
||||
version.clone(),
|
||||
Arc::new(
|
||||
target_cfgs
|
||||
.iter()
|
||||
.chain(cfg.iter())
|
||||
.chain(iter::once(&r_a_cfg_flag))
|
||||
.cloned()
|
||||
.collect(),
|
||||
),
|
||||
None,
|
||||
env,
|
||||
*is_proc_macro,
|
||||
|
@ -1179,6 +1181,7 @@ fn detached_files_to_crate_graph(
|
|||
|
||||
let mut cfg_options = create_cfg_options(rustc_cfg);
|
||||
cfg_options.insert_atom("rust_analyzer".into());
|
||||
let cfg_options = Arc::new(cfg_options);
|
||||
|
||||
for detached_file in detached_files {
|
||||
let file_id = match load(detached_file) {
|
||||
|
@ -1380,8 +1383,8 @@ fn add_target_crate_root(
|
|||
edition,
|
||||
Some(display_name),
|
||||
Some(pkg.version.to_string()),
|
||||
cfg_options,
|
||||
potential_cfg_options,
|
||||
Arc::new(cfg_options),
|
||||
potential_cfg_options.map(Arc::new),
|
||||
env,
|
||||
matches!(kind, TargetKind::Lib { is_proc_macro: true }),
|
||||
origin,
|
||||
|
@ -1437,7 +1440,7 @@ fn sysroot_to_crate_graph(
|
|||
let diff = CfgDiff::new(vec![], vec![CfgAtom::Flag("test".into())]).unwrap();
|
||||
for (cid, c) in cg.iter_mut() {
|
||||
// uninject `test` flag so `core` keeps working.
|
||||
c.cfg_options.apply_diff(diff.clone());
|
||||
Arc::make_mut(&mut c.cfg_options).apply_diff(diff.clone());
|
||||
// patch the origin
|
||||
if c.origin.is_local() {
|
||||
let lang_crate = LangCrateOrigin::from(
|
||||
|
@ -1486,7 +1489,7 @@ fn sysroot_to_crate_graph(
|
|||
(SysrootPublicDeps { deps: pub_deps }, libproc_macro)
|
||||
}
|
||||
SysrootMode::Stitched(stitched) => {
|
||||
let cfg_options = create_cfg_options(rustc_cfg);
|
||||
let cfg_options = Arc::new(create_cfg_options(rustc_cfg));
|
||||
let sysroot_crates: FxHashMap<SysrootCrate, CrateId> = stitched
|
||||
.crates()
|
||||
.filter_map(|krate| {
|
||||
|
|
|
@ -189,8 +189,8 @@ impl ChangeFixture {
|
|||
meta.edition,
|
||||
Some(crate_name.clone().into()),
|
||||
version,
|
||||
meta.cfg.clone(),
|
||||
Some(meta.cfg),
|
||||
From::from(meta.cfg.clone()),
|
||||
Some(From::from(meta.cfg)),
|
||||
meta.env,
|
||||
false,
|
||||
origin,
|
||||
|
@ -227,8 +227,8 @@ impl ChangeFixture {
|
|||
Edition::CURRENT,
|
||||
Some(CrateName::new("test").unwrap().into()),
|
||||
None,
|
||||
default_cfg.clone(),
|
||||
Some(default_cfg),
|
||||
From::from(default_cfg.clone()),
|
||||
Some(From::from(default_cfg)),
|
||||
default_env,
|
||||
false,
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
|
|
Loading…
Reference in a new issue