Skip to content

Commit 762c7d8

Browse files
committed
Auto merge of #13409 - Muscraft:rename-config, r=epage
chore: Rename `Config` to `GlobalContext` This PR : - renames `Config` to `GlobalContext` - it also renames its references to `gctx` (including lifetimes) - This was done to reflect better what it really is at this point - renames (and moves) `core::compiler::context::Context` to `core::compiler::build_runner::BuildRunner` - [Suggested here](#13409 (comment)) I believe I got all references to `Config` removed, Everything is on `GlobalContext`, but I could've missed renaming a variable or lifetime somewhere. I tried to find all references to `config: &GlobalContext` and rename them and I think I did so successfully. I also renamed all `'cfg` to `'gctx`. Note: I explicitly did not rename any files or paths as I was unsure about the best way to do this. ### How to Review this PR Take your time (and many breaks)! I am sorry. I am also sorry for the very brief description, looking at words and thinking about them has become hard... I need to not look at words for a while... <hr> As a complete side note, I honestly don't know if `config`, `Config`, `ctx`, or `Context` are really words at this point.
2 parents 3209eae + 118afd0 commit 762c7d8

File tree

172 files changed

+3565
-3401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+3565
-3401
lines changed

benches/benchsuite/benches/global_cache_tracker.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use cargo::core::global_cache_tracker::{self, DeferredGlobalLastUse, GlobalCacheTracker};
44
use cargo::util::cache_lock::CacheLockMode;
55
use cargo::util::interning::InternedString;
6-
use cargo::util::Config;
6+
use cargo::util::GlobalContext;
77
use criterion::{criterion_group, criterion_main, Criterion};
88
use std::fs;
99
use std::path::{Path, PathBuf};
@@ -25,63 +25,62 @@ fn cargo_home() -> PathBuf {
2525
p
2626
}
2727

28-
fn initialize_config() -> Config {
28+
fn initialize_context() -> GlobalContext {
2929
// Set up config.
3030
let shell = cargo::core::Shell::new();
3131
let homedir = cargo_home();
3232
if !homedir.exists() {
3333
fs::create_dir_all(&homedir).unwrap();
3434
}
3535
let cwd = homedir.clone();
36-
let mut config = Config::new(shell, cwd, homedir);
37-
config.nightly_features_allowed = true;
38-
config.set_search_stop_path(root());
39-
config
40-
.configure(
41-
0,
42-
false,
43-
None,
44-
false,
45-
false,
46-
false,
47-
&None,
48-
&["gc".to_string()],
49-
&[],
50-
)
51-
.unwrap();
36+
let mut gctx = GlobalContext::new(shell, cwd, homedir);
37+
gctx.nightly_features_allowed = true;
38+
gctx.set_search_stop_path(root());
39+
gctx.configure(
40+
0,
41+
false,
42+
None,
43+
false,
44+
false,
45+
false,
46+
&None,
47+
&["gc".to_string()],
48+
&[],
49+
)
50+
.unwrap();
5251
// Set up database sample.
53-
let db_path = GlobalCacheTracker::db_path(&config).into_path_unlocked();
52+
let db_path = GlobalCacheTracker::db_path(&gctx).into_path_unlocked();
5453
if db_path.exists() {
5554
fs::remove_file(&db_path).unwrap();
5655
}
5756
let sample = Path::new(env!("CARGO_MANIFEST_DIR")).join(GLOBAL_CACHE_SAMPLE);
5857
fs::copy(sample, &db_path).unwrap();
59-
config
58+
gctx
6059
}
6160

6261
/// Benchmarks how long it takes to initialize `GlobalCacheTracker` with an already
6362
/// existing full database.
6463
fn global_tracker_init(c: &mut Criterion) {
65-
let config = initialize_config();
66-
let _lock = config
64+
let gctx = initialize_context();
65+
let _lock = gctx
6766
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
6867
.unwrap();
6968
c.bench_function("global_tracker_init", |b| {
7069
b.iter(|| {
71-
GlobalCacheTracker::new(&config).unwrap();
70+
GlobalCacheTracker::new(&gctx).unwrap();
7271
})
7372
});
7473
}
7574

7675
/// Benchmarks how long it takes to save a `GlobalCacheTracker` when there are zero
7776
/// updates.
7877
fn global_tracker_empty_save(c: &mut Criterion) {
79-
let config = initialize_config();
80-
let _lock = config
78+
let gctx = initialize_context();
79+
let _lock = gctx
8180
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
8281
.unwrap();
8382
let mut deferred = DeferredGlobalLastUse::new();
84-
let mut tracker = GlobalCacheTracker::new(&config).unwrap();
83+
let mut tracker = GlobalCacheTracker::new(&gctx).unwrap();
8584

8685
c.bench_function("global_tracker_empty_save", |b| {
8786
b.iter(|| {
@@ -112,12 +111,12 @@ fn load_random_sample() -> Vec<(InternedString, InternedString, u64)> {
112111
/// This runs for different sizes of number of crates to update (selecting
113112
/// from the random sample stored on disk).
114113
fn global_tracker_update(c: &mut Criterion) {
115-
let config = initialize_config();
116-
let _lock = config
114+
let gctx = initialize_context();
115+
let _lock = gctx
117116
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
118117
.unwrap();
119118
let sample = Path::new(env!("CARGO_MANIFEST_DIR")).join(GLOBAL_CACHE_SAMPLE);
120-
let db_path = GlobalCacheTracker::db_path(&config).into_path_unlocked();
119+
let db_path = GlobalCacheTracker::db_path(&gctx).into_path_unlocked();
121120

122121
let random_sample = load_random_sample();
123122

@@ -129,7 +128,7 @@ fn global_tracker_update(c: &mut Criterion) {
129128

130129
fs::copy(&sample, &db_path).unwrap();
131130
let mut deferred = DeferredGlobalLastUse::new();
132-
let mut tracker = GlobalCacheTracker::new(&config).unwrap();
131+
let mut tracker = GlobalCacheTracker::new(&gctx).unwrap();
133132
group.bench_with_input(size.to_string(), &size, |b, &size| {
134133
b.iter(|| {
135134
for (encoded_registry_name, name, size) in &random_sample[..size] {

benches/benchsuite/benches/resolve.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ use cargo::core::resolver::features::{FeatureOpts, FeatureResolver};
44
use cargo::core::resolver::{CliFeatures, ForceAllTargets, HasDevUnits, ResolveBehavior};
55
use cargo::core::{PackageIdSpec, Workspace};
66
use cargo::ops::WorkspaceResolve;
7-
use cargo::Config;
7+
use cargo::GlobalContext;
88
use criterion::{criterion_group, criterion_main, Criterion};
99
use std::path::Path;
1010

11-
struct ResolveInfo<'cfg> {
12-
ws: Workspace<'cfg>,
11+
struct ResolveInfo<'gctx> {
12+
ws: Workspace<'gctx>,
1313
requested_kinds: [CompileKind; 1],
14-
target_data: RustcTargetData<'cfg>,
14+
target_data: RustcTargetData<'gctx>,
1515
cli_features: CliFeatures,
1616
specs: Vec<PackageIdSpec>,
1717
has_dev_units: HasDevUnits,
1818
force_all_targets: ForceAllTargets,
19-
ws_resolve: WorkspaceResolve<'cfg>,
19+
ws_resolve: WorkspaceResolve<'gctx>,
2020
}
2121

2222
/// Helper for resolving a workspace. This will run the resolver once to
2323
/// download everything, and returns all the data structures that are used
2424
/// during resolution.
25-
fn do_resolve<'cfg>(config: &'cfg Config, ws_root: &Path) -> ResolveInfo<'cfg> {
25+
fn do_resolve<'gctx>(gctx: &'gctx GlobalContext, ws_root: &Path) -> ResolveInfo<'gctx> {
2626
let requested_kinds = [CompileKind::Host];
27-
let ws = Workspace::new(&ws_root.join("Cargo.toml"), config).unwrap();
27+
let ws = Workspace::new(&ws_root.join("Cargo.toml"), gctx).unwrap();
2828
let mut target_data = RustcTargetData::new(&ws, &requested_kinds).unwrap();
2929
let cli_features = CliFeatures::from_command_line(&[], false, true).unwrap();
3030
let pkgs = cargo::ops::Packages::Default;
@@ -62,7 +62,7 @@ fn resolve_ws(c: &mut Criterion) {
6262
let fixtures = fixtures!();
6363
let mut group = c.benchmark_group("resolve_ws");
6464
for (ws_name, ws_root) in fixtures.workspaces() {
65-
let config = fixtures.make_config(&ws_root);
65+
let gctx = fixtures.make_context(&ws_root);
6666
// The resolver info is initialized only once in a lazy fashion. This
6767
// allows criterion to skip this workspace if the user passes a filter
6868
// on the command-line (like `cargo bench -- resolve_ws/tikv`).
@@ -81,7 +81,7 @@ fn resolve_ws(c: &mut Criterion) {
8181
has_dev_units,
8282
force_all_targets,
8383
..
84-
} = lazy_info.get_or_insert_with(|| do_resolve(&config, &ws_root));
84+
} = lazy_info.get_or_insert_with(|| do_resolve(&gctx, &ws_root));
8585
b.iter(|| {
8686
cargo::ops::resolve_ws_with_opts(
8787
ws,
@@ -104,7 +104,7 @@ fn feature_resolver(c: &mut Criterion) {
104104
let fixtures = fixtures!();
105105
let mut group = c.benchmark_group("feature_resolver");
106106
for (ws_name, ws_root) in fixtures.workspaces() {
107-
let config = fixtures.make_config(&ws_root);
107+
let gctx = fixtures.make_context(&ws_root);
108108
let mut lazy_info = None;
109109
group.bench_function(&ws_name, |b| {
110110
let ResolveInfo {
@@ -116,7 +116,7 @@ fn feature_resolver(c: &mut Criterion) {
116116
has_dev_units,
117117
ws_resolve,
118118
..
119-
} = lazy_info.get_or_insert_with(|| do_resolve(&config, &ws_root));
119+
} = lazy_info.get_or_insert_with(|| do_resolve(&gctx, &ws_root));
120120
b.iter(|| {
121121
let feature_opts = FeatureOpts::new_behavior(ResolveBehavior::V2, *has_dev_units);
122122
FeatureResolver::resolve(

benches/benchsuite/benches/workspace_initialization.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ fn workspace_initialization(c: &mut Criterion) {
66
let fixtures = fixtures!();
77
let mut group = c.benchmark_group("workspace_initialization");
88
for (ws_name, ws_root) in fixtures.workspaces() {
9-
let config = fixtures.make_config(&ws_root);
9+
let gctx = fixtures.make_context(&ws_root);
1010
// The resolver info is initialized only once in a lazy fashion. This
1111
// allows criterion to skip this workspace if the user passes a filter
1212
// on the command-line (like `cargo bench -- workspace_initialization/tikv`).
1313
group.bench_function(ws_name, |b| {
14-
b.iter(|| Workspace::new(&ws_root.join("Cargo.toml"), &config).unwrap())
14+
b.iter(|| Workspace::new(&ws_root.join("Cargo.toml"), &gctx).unwrap())
1515
});
1616
}
1717
group.finish();

benches/benchsuite/src/bin/capture-last-use.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use cargo::core::global_cache_tracker::{self, DeferredGlobalLastUse, GlobalCacheTracker};
1616
use cargo::util::cache_lock::CacheLockMode;
1717
use cargo::util::interning::InternedString;
18-
use cargo::Config;
18+
use cargo::GlobalContext;
1919
use rand::prelude::SliceRandom;
2020
use std::collections::HashMap;
2121
use std::fs;
@@ -28,30 +28,29 @@ fn main() {
2828
let shell = cargo::core::Shell::new();
2929
let homedir = Path::new(env!("CARGO_MANIFEST_DIR")).join("global-cache-tracker");
3030
let cwd = homedir.clone();
31-
let mut config = Config::new(shell, cwd, homedir.clone());
32-
config
33-
.configure(
34-
0,
35-
false,
36-
None,
37-
false,
38-
false,
39-
false,
40-
&None,
41-
&["gc".to_string()],
42-
&[],
43-
)
44-
.unwrap();
45-
let db_path = GlobalCacheTracker::db_path(&config).into_path_unlocked();
31+
let mut gctx = GlobalContext::new(shell, cwd, homedir.clone());
32+
gctx.configure(
33+
0,
34+
false,
35+
None,
36+
false,
37+
false,
38+
false,
39+
&None,
40+
&["gc".to_string()],
41+
&[],
42+
)
43+
.unwrap();
44+
let db_path = GlobalCacheTracker::db_path(&gctx).into_path_unlocked();
4645
if db_path.exists() {
4746
fs::remove_file(&db_path).unwrap();
4847
}
4948

50-
let _lock = config
49+
let _lock = gctx
5150
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
5251
.unwrap();
5352
let mut deferred = DeferredGlobalLastUse::new();
54-
let mut tracker = GlobalCacheTracker::new(&config).unwrap();
53+
let mut tracker = GlobalCacheTracker::new(&gctx).unwrap();
5554

5655
let real_home = cargo::util::homedir(&std::env::current_dir().unwrap()).unwrap();
5756

benches/benchsuite/src/lib.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::disallowed_methods)]
22

3-
use cargo::Config;
3+
use cargo::GlobalContext;
44
use std::fs;
55
use std::path::{Path, PathBuf};
66
use std::process::Command;
@@ -175,25 +175,24 @@ impl Fixtures {
175175
.collect()
176176
}
177177

178-
/// Creates a new Config.
179-
pub fn make_config(&self, ws_root: &Path) -> Config {
178+
/// Creates a new Context.
179+
pub fn make_context(&self, ws_root: &Path) -> GlobalContext {
180180
let shell = cargo::core::Shell::new();
181-
let mut config = Config::new(shell, ws_root.to_path_buf(), self.cargo_home());
181+
let mut gctx = GlobalContext::new(shell, ws_root.to_path_buf(), self.cargo_home());
182182
// Configure is needed to set the target_dir which is needed to write
183183
// the .rustc_info.json file which is very expensive.
184-
config
185-
.configure(
186-
0,
187-
false,
188-
None,
189-
false,
190-
false,
191-
false,
192-
&Some(self.target_dir()),
193-
&[],
194-
&[],
195-
)
196-
.unwrap();
197-
config
184+
gctx.configure(
185+
0,
186+
false,
187+
None,
188+
false,
189+
false,
190+
false,
191+
&Some(self.target_dir()),
192+
&[],
193+
&[],
194+
)
195+
.unwrap();
196+
gctx
198197
}
199198
}

crates/mdman/src/hbs.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl HelperDef for OptionHelper<'_> {
9999
&self,
100100
h: &Helper<'rc>,
101101
r: &'reg Handlebars<'reg>,
102-
ctx: &'rc Context,
102+
gctx: &'rc Context,
103103
rc: &mut RenderContext<'reg, 'rc>,
104104
out: &mut dyn Output,
105105
) -> HelperResult {
@@ -137,10 +137,10 @@ impl HelperDef for OptionHelper<'_> {
137137
}
138138
};
139139
// Render the block.
140-
let block = t.renders(r, ctx, rc)?;
140+
let block = t.renders(r, gctx, rc)?;
141141

142142
// Get the name of this page.
143-
let man_name = ctx
143+
let man_name = gctx
144144
.data()
145145
.get("man_name")
146146
.expect("expected man_name in context")
@@ -167,7 +167,7 @@ impl HelperDef for ManLinkHelper<'_> {
167167
&self,
168168
h: &Helper<'rc>,
169169
_r: &'reg Handlebars<'reg>,
170-
_ctx: &'rc Context,
170+
_gctx: &'rc Context,
171171
_rc: &mut RenderContext<'reg, 'rc>,
172172
out: &mut dyn Output,
173173
) -> HelperResult {
@@ -200,7 +200,7 @@ impl HelperDef for ManLinkHelper<'_> {
200200
fn set_decorator(
201201
d: &Decorator<'_>,
202202
_: &Handlebars<'_>,
203-
_ctx: &Context,
203+
_gctx: &Context,
204204
rc: &mut RenderContext<'_, '_>,
205205
) -> Result<(), RenderError> {
206206
let data_to_set = d.hash();
@@ -212,25 +212,25 @@ fn set_decorator(
212212

213213
/// Sets a variable to a value within the context.
214214
fn set_in_context(rc: &mut RenderContext<'_, '_>, key: &str, value: serde_json::Value) {
215-
let mut ctx = match rc.context() {
215+
let mut gctx = match rc.context() {
216216
Some(c) => (*c).clone(),
217217
None => Context::wraps(serde_json::Value::Object(serde_json::Map::new())).unwrap(),
218218
};
219-
if let serde_json::Value::Object(m) = ctx.data_mut() {
219+
if let serde_json::Value::Object(m) = gctx.data_mut() {
220220
m.insert(key.to_string(), value);
221-
rc.set_context(ctx);
221+
rc.set_context(gctx);
222222
} else {
223223
panic!("expected object in context");
224224
}
225225
}
226226

227227
/// Removes a variable from the context.
228228
fn remove_from_context(rc: &mut RenderContext<'_, '_>, key: &str) {
229-
let ctx = rc.context().expect("cannot remove from null context");
230-
let mut ctx = (*ctx).clone();
231-
if let serde_json::Value::Object(m) = ctx.data_mut() {
229+
let gctx = rc.context().expect("cannot remove from null context");
230+
let mut gctx = (*gctx).clone();
231+
if let serde_json::Value::Object(m) = gctx.data_mut() {
232232
m.remove(key);
233-
rc.set_context(ctx);
233+
rc.set_context(gctx);
234234
} else {
235235
panic!("expected object in context");
236236
}

0 commit comments

Comments
 (0)