From 064047795bd4615fc5fed393cdcfa14bd2f3206d Mon Sep 17 00:00:00 2001 From: Evgeny Bovykin Date: Mon, 25 Nov 2024 13:29:10 +0100 Subject: [PATCH] Make some Workspace and Context fields public (#290) * Make Context#mode field pub instead of pub(crate) This change will allow to locate the absolute paths to the generated files using Context#mode + Context#item_path * Make WorkspaceInfo#dir pub * Pub Context#split * pub mod fmt * add ordered duplicate name info --------- Co-authored-by: Millione --- pilota-build/src/lib.rs | 2 +- pilota-build/src/middle/context.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pilota-build/src/lib.rs b/pilota-build/src/lib.rs index 76bf2c02..0326c8a2 100644 --- a/pilota-build/src/lib.rs +++ b/pilota-build/src/lib.rs @@ -9,7 +9,7 @@ mod util; pub mod codegen; pub mod db; pub(crate) mod errors; -mod fmt; +pub mod fmt; mod index; mod ir; pub mod middle; diff --git a/pilota-build/src/middle/context.rs b/pilota-build/src/middle/context.rs index 28a16dd1..bb260007 100644 --- a/pilota-build/src/middle/context.rs +++ b/pilota-build/src/middle/context.rs @@ -48,7 +48,7 @@ pub enum CollectMode { #[derive(Debug)] pub struct WorkspaceInfo { - pub(crate) dir: PathBuf, + pub dir: PathBuf, pub(crate) location_map: FxHashMap, } @@ -67,14 +67,14 @@ pub struct Context { pub(crate) codegen_items: Arc<[DefId]>, pub(crate) path_resolver: Arc, pub mode: Arc, - pub(crate) split: bool, + pub split: bool, pub(crate) keep_unknown_fields: Arc>, pub location_map: Arc>, pub entry_map: Arc>>, pub plugin_gen: Arc>, pub(crate) dedups: Vec, pub(crate) common_crate_name: FastStr, - pub names: FxHashSet, + pub names: FxHashMap, } impl Clone for Context { @@ -382,8 +382,9 @@ impl ContextBuilder { cx.names.extend( map.into_iter() .filter(|(_, v)| v.len() > 1) - .flat_map(|(_, v)| v) - .collect::>(), + .map(|(_, v)| v) + .flat_map(|v| v.into_iter().enumerate().map(|(i, def_id)| (def_id, i))) + .collect::>(), ); cx } @@ -834,7 +835,7 @@ impl Context { return name.0.into(); } - if !self.change_case || self.names.contains(&def_id) { + if !self.change_case || self.names.contains_key(&def_id) { return node.name(); }