Skip to content

Commit 43eccd2

Browse files
authored
[naga] Remove naga::path_like. Use String instead. (#8284)
Delete the `naga::path_like` module, and simply using `String` and `str` instead. Nothing in Naga uses `Path` or `PathBuf` methods; indeed, Naga only converts these values back and forth from string-like types with `to_string_lossy` and `into`, such that using string-like, rather than path-like, types actually simplifies the code. This also avoids dead code warnings starting in Rust 1.89 that would otherwise require distracting `#[cfg_attr]` conditionals.
1 parent 5b194ec commit 43eccd2

File tree

9 files changed

+20
-274
lines changed

9 files changed

+20
-274
lines changed

naga-cli/src/bin/naga.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ fn run() -> anyhow::Result<()> {
452452
params.spv_in = naga::front::spv::Options {
453453
adjust_coordinate_space: !args.keep_coordinate_space,
454454
strict_capabilities: false,
455-
block_ctx_dump_prefix: args.block_ctx_dir.clone().map(Into::into),
455+
block_ctx_dump_prefix: args.block_ctx_dir.clone(),
456456
};
457457

458458
params.entry_point.clone_from(&args.entry_point);
@@ -482,7 +482,7 @@ fn run() -> anyhow::Result<()> {
482482
params.compact = args.compact;
483483

484484
if args.bulk_validate {
485-
return bulk_validate(args, &params);
485+
return bulk_validate(&args, &params);
486486
}
487487

488488
let mut files = args.files.iter();
@@ -498,6 +498,8 @@ fn run() -> anyhow::Result<()> {
498498
return Err(CliError("Input file path is not specified").into());
499499
};
500500

501+
let file_name = input_path.to_string_lossy();
502+
501503
params.input_kind = args.input_kind;
502504
params.shader_stage = args.shader_stage;
503505

@@ -516,7 +518,7 @@ fn run() -> anyhow::Result<()> {
516518
.set(naga::back::spv::WriterFlags::DEBUG, true);
517519
params.spv_out.debug_info = Some(naga::back::spv::DebugInfo {
518520
source_code: input_text,
519-
file_name: input_path.into(),
521+
file_name: &file_name,
520522
language,
521523
})
522524
} else {
@@ -913,9 +915,9 @@ fn write_output(
913915
Ok(())
914916
}
915917

916-
fn bulk_validate(args: Args, params: &Parameters) -> anyhow::Result<()> {
918+
fn bulk_validate(args: &Args, params: &Parameters) -> anyhow::Result<()> {
917919
let mut invalid = vec![];
918-
for input_path in args.files {
920+
for input_path in &args.files {
919921
let path = Path::new(&input_path);
920922
let input = fs::read(path)?;
921923

naga/src/back/spv/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use spirv::Word;
2626
use thiserror::Error;
2727

2828
use crate::arena::{Handle, HandleVec};
29-
use crate::path_like::PathLikeRef;
3029
use crate::proc::{BoundsCheckPolicies, TypeResolution};
3130

3231
#[derive(Clone)]
@@ -96,7 +95,7 @@ impl IdGenerator {
9695
#[derive(Debug, Clone)]
9796
pub struct DebugInfo<'a> {
9897
pub source_code: &'a str,
99-
pub file_name: PathLikeRef<'a>,
98+
pub file_name: &'a str,
10099
pub language: SourceLanguage,
101100
}
102101

naga/src/back/spv/writer.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use super::{
1414
use crate::{
1515
arena::{Handle, HandleVec, UniqueArena},
1616
back::spv::{BindingInfo, WrappedFunction},
17-
path_like::PathLike,
1817
proc::{Alignment, TypeResolution},
1918
valid::{FunctionInfo, ModuleInfo},
2019
};
@@ -2519,10 +2518,8 @@ impl Writer {
25192518
if self.flags.contains(WriterFlags::DEBUG) {
25202519
if let Some(debug_info) = debug_info.as_ref() {
25212520
let source_file_id = self.id_gen.next();
2522-
self.debugs.push(Instruction::string(
2523-
&debug_info.file_name.to_string_lossy(),
2524-
source_file_id,
2525-
));
2521+
self.debugs
2522+
.push(Instruction::string(debug_info.file_name, source_file_id));
25262523

25272524
debug_info_inner = Some(DebugInfoInner {
25282525
source_code: debug_info.source_code,

naga/src/front/spv/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use petgraph::graphmap::GraphMap;
4444
use super::atomic_upgrade::Upgrades;
4545
use crate::{
4646
arena::{Arena, Handle, UniqueArena},
47-
path_like::PathLikeOwned,
4847
proc::{Alignment, Layouter},
4948
FastHashMap, FastHashSet, FastIndexMap,
5049
};
@@ -384,7 +383,7 @@ pub struct Options {
384383
pub adjust_coordinate_space: bool,
385384
/// Only allow shaders with the known set of capabilities.
386385
pub strict_capabilities: bool,
387-
pub block_ctx_dump_prefix: Option<PathLikeOwned>,
386+
pub block_ctx_dump_prefix: Option<String>,
388387
}
389388

390389
impl Default for Options {

naga/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ pub mod front;
116116
pub mod ir;
117117
pub mod keywords;
118118
mod non_max_u32;
119-
mod path_like;
120119
pub mod proc;
121120
mod racy_lock;
122121
mod span;

naga/src/path_like.rs

Lines changed: 0 additions & 238 deletions
This file was deleted.

naga/src/span.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloc::{
66
};
77
use core::{error::Error, fmt, ops::Range};
88

9-
use crate::{error::replace_control_chars, path_like::PathLike, Arena, Handle, UniqueArena};
9+
use crate::{error::replace_control_chars, Arena, Handle, UniqueArena};
1010

1111
/// A source code span, used for error reporting.
1212
#[derive(Clone, Copy, Debug, PartialEq, Default)]
@@ -283,14 +283,12 @@ impl<E> WithSpan<E> {
283283

284284
/// Emits a summary of the error to standard error stream.
285285
#[cfg(feature = "stderr")]
286-
pub fn emit_to_stderr_with_path<P>(&self, source: &str, path: P)
286+
pub fn emit_to_stderr_with_path(&self, source: &str, path: &str)
287287
where
288288
E: Error,
289-
P: PathLike,
290289
{
291290
use codespan_reporting::{files, term};
292291

293-
let path = path.to_string_lossy();
294292
let files = files::SimpleFile::new(path, replace_control_chars(source));
295293
let config = term::Config::default();
296294

@@ -315,14 +313,12 @@ impl<E> WithSpan<E> {
315313
}
316314

317315
/// Emits a summary of the error to a string.
318-
pub fn emit_to_string_with_path<P>(&self, source: &str, path: P) -> String
316+
pub fn emit_to_string_with_path(&self, source: &str, path: &str) -> String
319317
where
320318
E: Error,
321-
P: PathLike,
322319
{
323320
use codespan_reporting::{files, term};
324321

325-
let path = path.to_string_lossy();
326322
let files = files::SimpleFile::new(path, replace_control_chars(source));
327323
let config = term::Config::default();
328324

0 commit comments

Comments
 (0)