Skip to content

Commit 0165b98

Browse files
authored
Allow setting hash algorithm for HashSet/HashMap (#312)
* feat: allow to set the hash algorithm used by HashSet / HashMap Signed-off-by: Jérémy Audiger <[email protected]> * chore: allow implicit hasher in clippy and remove unnecessary BuildHasher trait bounds Signed-off-by: Jérémy Audiger <[email protected]> * chore: add allowances for struct_excessive_bools and struct_field_names lint checks. Signed-off-by: Jérémy Audiger <[email protected]> --------- Signed-off-by: Jérémy Audiger <[email protected]>
1 parent 8d1eb9f commit 0165b98

File tree

14 files changed

+77
-41
lines changed

14 files changed

+77
-41
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ all = { level = "warn", priority = -1 }
1616
nursery = { level = "warn", priority = -1 }
1717
cognitive_complexity = "allow"
1818
future_not_send = "allow"
19+
implicit_hasher = "allow"
1920
missing_errors_doc = "allow"
2021
missing_panics_doc = "allow"
2122
significant_drop_tightening = "allow"
23+
struct_excessive_bools = "allow"
24+
struct_field_names = "allow"
2225
too_many_lines = "allow"
2326
allow_attributes = "warn"
2427
cast_lossless = "warn"

crates/brioche-core/benches/input.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::io::Write as _;
23

34
use brioche_core::Brioche;
@@ -60,15 +61,17 @@ fn bench_input(bencher: divan::Bencher, removal: Removal) {
6061
})
6162
.bench_values(|ctx| {
6263
ctx.runtime.block_on(async {
64+
let mut saved_paths = HashMap::default();
6365
let meta = Default::default();
66+
6467
brioche_core::input::create_input(
6568
&ctx.brioche,
6669
brioche_core::input::InputOptions {
6770
input_path: &ctx.input_path,
6871
remove_input: removal.should_remove(),
6972
resource_dir: Some(&ctx.input_resources),
7073
input_resource_dirs: &[],
71-
saved_paths: &mut Default::default(),
74+
saved_paths: &mut saved_paths,
7275
meta: &meta,
7376
},
7477
)
@@ -129,15 +132,17 @@ fn bench_input_with_shared_resources(bencher: divan::Bencher, removal: Removal)
129132
})
130133
.bench_values(|ctx| {
131134
ctx.runtime.block_on(async {
135+
let mut saved_paths = HashMap::default();
132136
let meta = Default::default();
137+
133138
brioche_core::input::create_input(
134139
&ctx.brioche,
135140
brioche_core::input::InputOptions {
136141
input_path: &ctx.input_path,
137142
remove_input: removal.should_remove(),
138143
resource_dir: Some(&ctx.input_resources),
139144
input_resource_dirs: &[],
140-
saved_paths: &mut Default::default(),
145+
saved_paths: &mut saved_paths,
141146
meta: &meta,
142147
},
143148
)
@@ -245,7 +250,7 @@ fn bench_input_with_shared_ancestor_resources(bencher: divan::Bencher, removal:
245250
remove_input: removal.should_remove(),
246251
resource_dir: Some(&ctx.input_resources),
247252
input_resource_dirs: &[],
248-
saved_paths: &mut Default::default(),
253+
saved_paths: &mut HashMap::default(),
249254
meta: &meta,
250255
},
251256
)

crates/brioche-core/src/input.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub async fn create_input(
4949
let meta = options.meta.clone();
5050
move || {
5151
let mut plan = CreateInputPlan::default();
52+
let mut saved_paths = HashMap::default();
5253

5354
// Add nodes and edges for all files/directories/symlinks
5455
let root_node = add_input_plan_nodes(
@@ -57,7 +58,7 @@ pub async fn create_input(
5758
remove_input,
5859
resource_dir: resource_dir.as_deref(),
5960
input_resource_dirs: &input_resource_dirs,
60-
saved_paths: &mut Default::default(),
61+
saved_paths: &mut saved_paths,
6162
meta: &meta,
6263
},
6364
&mut plan,

crates/brioche-core/src/project/analyze.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ pub async fn analyze_project(vfs: &Vfs, project_path: &Path) -> anyhow::Result<P
199199
anyhow::Ok(expr)
200200
})
201201
.with_context(|| format!("{file_line}: invalid project export: expected assignment like `export const project = {{ ... }}`"))??;
202+
let env = HashMap::default();
202203

203-
let json = expression_to_json(&project_export_expr, &Default::default())
204+
let json = expression_to_json(&project_export_expr, &env)
204205
.with_context(|| format!("{file_line}: invalid project export"))?;
205206
anyhow::Ok((json, file_line))
206207
}).transpose()?;
@@ -354,14 +355,16 @@ pub async fn analyze_module(
354355
"invalid import path: must be within project root",
355356
);
356357

358+
let env = HashMap::default();
359+
357360
// Analyze the imported module, but start with a separate
358361
// environment
359362
let import_module_specifier = analyze_module(
360363
vfs,
361364
&import_module_path,
362365
project_path,
363366
None,
364-
&Default::default(),
367+
&env,
365368
local_modules,
366369
)
367370
.await?;

crates/brioche-core/src/project/edit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::path::Path;
23

34
use anyhow::Context as _;
@@ -78,9 +79,11 @@ pub async fn edit_project(
7879
anyhow::Ok(expr)
7980
})
8081
.with_context(|| format!("{file_line}: invalid project export: expected assignment like `export const project = {{ ... }}`"))??;
82+
let env = HashMap::default();
83+
8184
let current_project_export_json = super::analyze::expression_to_json(
8285
&biome_js_syntax::AnyJsExpression::JsObjectExpression(project_export_expr.clone()),
83-
&Default::default(),
86+
&env,
8487
)
8588
.with_context(|| format!("{file_line}: invalid project export"))?;
8689

crates/brioche-core/src/project/load.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,8 @@ async fn resolve_static(
940940
include.path(),
941941
project_root.display(),
942942
);
943+
let mut saved_paths = HashMap::default();
944+
let meta = Default::default();
943945

944946
let artifact = crate::input::create_input(
945947
brioche,
@@ -948,8 +950,8 @@ async fn resolve_static(
948950
remove_input: false,
949951
resource_dir: None,
950952
input_resource_dirs: &[],
951-
saved_paths: &mut Default::default(),
952-
meta: &Default::default(),
953+
saved_paths: &mut saved_paths,
954+
meta: &meta,
953955
},
954956
)
955957
.await?;
@@ -1020,15 +1022,18 @@ async fn resolve_static(
10201022

10211023
let artifacts = futures::stream::iter(paths)
10221024
.then(|(full_path, relative_path)| async move {
1025+
let mut saved_paths = HashMap::default();
1026+
let meta = Default::default();
1027+
10231028
let artifact = crate::input::create_input(
10241029
brioche,
10251030
crate::input::InputOptions {
10261031
input_path: &full_path,
10271032
remove_input: false,
10281033
resource_dir: None,
10291034
input_resource_dirs: &[],
1030-
saved_paths: &mut Default::default(),
1031-
meta: &Default::default(),
1035+
saved_paths: &mut saved_paths,
1036+
meta: &meta,
10321037
},
10331038
)
10341039
.await?;

crates/brioche-core/tests/input.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
collections::HashMap,
23
os::unix::prelude::PermissionsExt as _,
34
path::{Path, PathBuf},
45
sync::Arc,
@@ -16,15 +17,18 @@ async fn create_input(
1617
input_path: &Path,
1718
remove_input: bool,
1819
) -> anyhow::Result<Artifact> {
20+
let mut saved_paths = HashMap::default();
21+
let meta = Arc::new(Meta::default());
22+
1923
let artifact = brioche_core::input::create_input(
2024
brioche,
2125
brioche_core::input::InputOptions {
2226
input_path,
2327
remove_input,
2428
resource_dir: None,
2529
input_resource_dirs: &[],
26-
saved_paths: &mut Default::default(),
27-
meta: &Arc::new(Meta::default()),
30+
saved_paths: &mut saved_paths,
31+
meta: &meta,
2832
},
2933
)
3034
.await?;
@@ -39,15 +43,18 @@ async fn create_input_with_resources(
3943
input_resource_dirs: &[PathBuf],
4044
remove_input: bool,
4145
) -> anyhow::Result<Artifact> {
46+
let mut saved_paths = HashMap::default();
47+
let meta = Arc::new(Meta::default());
48+
4249
let artifact = brioche_core::input::create_input(
4350
brioche,
4451
brioche_core::input::InputOptions {
4552
input_path,
4653
remove_input,
4754
resource_dir,
4855
input_resource_dirs,
49-
saved_paths: &mut Default::default(),
50-
meta: &Arc::new(Meta::default()),
56+
saved_paths: &mut saved_paths,
57+
meta: &meta,
5158
},
5259
)
5360
.await?;

crates/brioche-core/tests/process_events.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::time::Duration;
23

34
use jiff::Zoned;
@@ -34,10 +35,10 @@ fn example_process_event_description() -> ProcessEventDescription {
3435
meta: Meta::default(),
3536
sandbox_config: SandboxExecutionConfig {
3637
sandbox_root: Default::default(),
37-
include_host_paths: Default::default(),
38+
include_host_paths: HashMap::default(),
3839
command: Default::default(),
3940
args: Default::default(),
40-
env: Default::default(),
41+
env: HashMap::default(),
4142
current_dir: Default::default(),
4243
gid_hint: 0,
4344
uid_hint: 0,

crates/brioche-core/tests/script_check.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ async fn test_check_basic_valid() -> anyhow::Result<()> {
4848
.await;
4949
let (projects, project_hash) =
5050
brioche_test_support::load_project(&brioche, &project_dir).await?;
51+
let project_hashes = HashSet::from_iter([project_hash]);
5152

5253
let result = brioche_core::script::check::check(
5354
&brioche,
5455
brioche_core::script::initialize_js_platform(),
5556
&projects,
56-
&HashSet::from_iter([project_hash]),
57+
&project_hashes,
5758
)
5859
.await?;
5960

@@ -87,12 +88,13 @@ async fn test_check_basic_invalid() -> anyhow::Result<()> {
8788
.await;
8889
let (projects, project_hash) =
8990
brioche_test_support::load_project(&brioche, &project_dir).await?;
91+
let project_hashes = HashSet::from_iter([project_hash]);
9092

9193
let result = brioche_core::script::check::check(
9294
&brioche,
9395
brioche_core::script::initialize_js_platform(),
9496
&projects,
95-
&HashSet::from_iter([project_hash]),
97+
&project_hashes,
9698
)
9799
.await?;
98100

@@ -151,12 +153,13 @@ async fn test_check_import_valid() -> anyhow::Result<()> {
151153

152154
let (projects, project_hash) =
153155
brioche_test_support::load_project(&brioche, &project_dir).await?;
156+
let project_hashes = HashSet::from_iter([project_hash]);
154157

155158
let result = brioche_core::script::check::check(
156159
&brioche,
157160
brioche_core::script::initialize_js_platform(),
158161
&projects,
159-
&HashSet::from_iter([project_hash]),
162+
&project_hashes,
160163
)
161164
.await?;
162165

@@ -191,12 +194,13 @@ async fn test_check_import_nonexistent() -> anyhow::Result<()> {
191194

192195
let (projects, project_hash) =
193196
brioche_test_support::load_project_no_validate(&brioche, &project_dir).await?;
197+
let project_hashes = HashSet::from_iter([project_hash]);
194198

195199
let result = brioche_core::script::check::check(
196200
&brioche,
197201
brioche_core::script::initialize_js_platform(),
198202
&projects,
199-
&HashSet::from_iter([project_hash]),
203+
&project_hashes,
200204
)
201205
.await?;
202206

@@ -230,12 +234,13 @@ async fn test_check_invalid_unused_var() -> anyhow::Result<()> {
230234
.await;
231235
let (projects, project_hash) =
232236
brioche_test_support::load_project(&brioche, &project_dir).await?;
237+
let project_hashes = HashSet::from_iter([project_hash]);
233238

234239
let result = brioche_core::script::check::check(
235240
&brioche,
236241
brioche_core::script::initialize_js_platform(),
237242
&projects,
238-
&HashSet::from_iter([project_hash]),
243+
&project_hashes,
239244
)
240245
.await?;
241246

@@ -276,12 +281,13 @@ async fn test_check_invalid_missing_await() -> anyhow::Result<()> {
276281
.await;
277282
let (projects, project_hash) =
278283
brioche_test_support::load_project(&brioche, &project_dir).await?;
284+
let project_hashes = HashSet::from_iter([project_hash]);
279285

280286
let result = brioche_core::script::check::check(
281287
&brioche,
282288
brioche_core::script::initialize_js_platform(),
283289
&projects,
284-
&HashSet::from_iter([project_hash]),
290+
&project_hashes,
285291
)
286292
.await?;
287293

crates/brioche/src/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ pub async fn build(
9797
}
9898

9999
if args.check {
100+
let project_hashes = HashSet::from_iter([project_hash]);
101+
100102
let checked = brioche_core::script::check::check(
101103
&brioche,
102104
js_platform,
103105
&projects,
104-
&HashSet::from_iter([project_hash]),
106+
&project_hashes,
105107
)
106108
.await?;
107109

0 commit comments

Comments
 (0)