Skip to content

Commit 1a3de9f

Browse files
committed
Preprocess by input reference
1 parent 2f80366 commit 1a3de9f

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

crates/compilers/src/compile/project.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ pub trait Preprocessor<C: Compiler>: Debug {
132132
fn preprocess(
133133
&self,
134134
compiler: &C,
135-
input: C::Input,
135+
input: &mut C::Input,
136136
paths: &ProjectPathsConfig<C::Language>,
137137
mocks: &mut HashSet<PathBuf>,
138-
) -> Result<C::Input>;
138+
) -> Result<()>;
139139
}
140140

141141
#[derive(Debug)]
@@ -515,8 +515,12 @@ impl<L: Language, S: CompilerSettings> CompilerSources<'_, L, S> {
515515
input.strip_prefix(project.paths.root.as_path());
516516

517517
if let Some(preprocessor) = preprocessor.as_ref() {
518-
input =
519-
preprocessor.preprocess(&project.compiler, input, &project.paths, mocks)?;
518+
preprocessor.preprocess(
519+
&project.compiler,
520+
&mut input,
521+
&project.paths,
522+
mocks,
523+
)?;
520524
}
521525

522526
jobs.push((input, profile, actually_dirty));

crates/compilers/src/preprocessor/mod.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ impl Preprocessor<SolcCompiler> for TestOptimizerPreprocessor {
6161
fn preprocess(
6262
&self,
6363
_solc: &SolcCompiler,
64-
mut input: SolcVersionedInput,
64+
input: &mut SolcVersionedInput,
6565
paths: &ProjectPathsConfig<SolcLanguage>,
6666
mocks: &mut HashSet<PathBuf>,
67-
) -> Result<SolcVersionedInput> {
67+
) -> Result<()> {
6868
let sources = &mut input.input.sources;
6969
// Skip if we are not preprocessing any tests or scripts. Avoids unnecessary AST parsing.
7070
if sources.iter().all(|(path, _)| !is_test_or_script(path, paths)) {
7171
trace!("no tests or sources to preprocess");
72-
return Ok(input);
72+
return Ok(());
7373
}
7474

7575
let sess = Session::builder().with_buffer_emitter(Default::default()).build();
@@ -123,30 +123,25 @@ impl Preprocessor<SolcCompiler> for TestOptimizerPreprocessor {
123123
return Err(SolcError::Message(err.to_string()));
124124
}
125125

126-
Ok(input)
126+
Ok(())
127127
}
128128
}
129129

130130
impl Preprocessor<MultiCompiler> for TestOptimizerPreprocessor {
131131
fn preprocess(
132132
&self,
133133
compiler: &MultiCompiler,
134-
input: <MultiCompiler as Compiler>::Input,
134+
input: &mut <MultiCompiler as Compiler>::Input,
135135
paths: &ProjectPathsConfig<MultiCompilerLanguage>,
136136
mocks: &mut HashSet<PathBuf>,
137-
) -> Result<<MultiCompiler as Compiler>::Input> {
138-
match input {
139-
MultiCompilerInput::Solc(input) => {
140-
if let Some(solc) = &compiler.solc {
141-
let paths = paths.clone().with_language::<SolcLanguage>();
142-
let input = self.preprocess(solc, input, &paths, mocks)?;
143-
Ok(MultiCompilerInput::Solc(input))
144-
} else {
145-
Ok(MultiCompilerInput::Solc(input))
146-
}
147-
}
148-
MultiCompilerInput::Vyper(input) => Ok(MultiCompilerInput::Vyper(input)),
149-
}
137+
) -> Result<()> {
138+
// Preprocess only Solc compilers.
139+
let MultiCompilerInput::Solc(input) = input else { return Ok(()) };
140+
141+
let Some(solc) = &compiler.solc else { return Ok(()) };
142+
143+
let paths = paths.clone().with_language::<SolcLanguage>();
144+
self.preprocess(solc, input, &paths, mocks)
150145
}
151146
}
152147

0 commit comments

Comments
 (0)