Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,13 @@ pub fn compile_no_check(

let SsaProgramArtifact { program, debug, warnings, names, brillig_names, error_types, .. } =
if options.minimal_ssa {
create_program_with_minimal_passes(program, &ssa_evaluator_options)?
create_program_with_minimal_passes(
program,
&ssa_evaluator_options,
&context.file_manager,
)?
} else {
create_program(program, &ssa_evaluator_options)?
create_program(program, &ssa_evaluator_options, Some(&context.file_manager))?
};

let abi = gen_abi(context, &main_function, return_visibility, error_types);
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cfg-if.workspace = true
smallvec = { version = "1.13.2", features = ["serde"] }
vec-collections = "0.4.3"
petgraph.workspace = true
fm.workspace = true

[dev-dependencies]
proptest.workspace = true
Expand Down
2 changes: 0 additions & 2 deletions compiler/noirc_evaluator/src/acir/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ fn brillig_stdlib_calls_with_regular_brillig_call() {
let ssa = builder.finish();
// We need to generate Brillig artifacts for the regular Brillig function and pass them to the ACIR generation pass.
let brillig = ssa.to_brillig(&BrilligOptions::default());
println!("{}", ssa);

let (acir_functions, brillig_functions, _, _) = ssa
.generate_entry_point_index()
Expand Down Expand Up @@ -645,7 +644,6 @@ fn brillig_stdlib_calls_with_multiple_acir_calls() {
let ssa = builder.finish();
// We need to generate Brillig artifacts for the regular Brillig function and pass them to the ACIR generation pass.
let brillig = ssa.to_brillig(&BrilligOptions::default());
println!("{}", ssa);

let (acir_functions, brillig_functions, _, _) = ssa
.generate_entry_point_index()
Expand Down
49 changes: 35 additions & 14 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ where
let ssa_gen_span_guard = ssa_gen_span.enter();
let mut builder = builder.with_skip_passes(options.skip_passes.clone()).run_passes(primary)?;
let passed = std::mem::take(&mut builder.passed);
let files = builder.files;
let mut ssa = builder.finish();

let mut ssa_level_warnings = vec![];
Expand All @@ -300,12 +301,16 @@ where
let ssa_gen_span = span!(Level::TRACE, "ssa_generation");
let ssa_gen_span_guard = ssa_gen_span.enter();

let mut ssa =
SsaBuilder::from_ssa(ssa, options.ssa_logging.clone(), options.print_codegen_timings)
.with_passed(passed)
.with_skip_passes(options.skip_passes.clone())
.run_passes(&secondary(&brillig))?
.finish();
let mut ssa = SsaBuilder::from_ssa(
ssa,
options.ssa_logging.clone(),
options.print_codegen_timings,
files,
)
.with_passed(passed)
.with_skip_passes(options.skip_passes.clone())
.run_passes(&secondary(&brillig))?
.finish();

if !options.skip_underconstrained_check {
ssa_level_warnings.extend(time(
Expand Down Expand Up @@ -353,6 +358,7 @@ pub fn optimize_into_acir<S>(
options: &SsaEvaluatorOptions,
primary: &[SsaPass],
secondary: S,
files: Option<&fm::FileManager>,
) -> Result<ArtifactsAndWarnings, RuntimeError>
where
S: for<'b> Fn(&'b Brillig) -> Vec<SsaPass<'b>>,
Expand All @@ -362,6 +368,7 @@ where
options.ssa_logging.clone(),
options.print_codegen_timings,
&options.emit_ssa,
files,
)?;

optimize_ssa_builder_into_acir(builder, options, primary, secondary)
Expand Down Expand Up @@ -436,8 +443,9 @@ impl SsaProgramArtifact {
pub fn create_program(
program: Program,
options: &SsaEvaluatorOptions,
files: Option<&fm::FileManager>,
) -> Result<SsaProgramArtifact, RuntimeError> {
create_program_with_passes(program, options, &primary_passes(options), secondary_passes)
create_program_with_passes(program, options, &primary_passes(options), secondary_passes, files)
}

/// Compiles the [`Program`] into [`ACIR`][acvm::acir::circuit::Program] using the minimum amount of SSA passes.
Expand All @@ -448,6 +456,7 @@ pub fn create_program(
pub fn create_program_with_minimal_passes(
program: Program,
options: &SsaEvaluatorOptions,
files: &fm::FileManager,
) -> Result<SsaProgramArtifact, RuntimeError> {
for func in &program.functions {
assert!(
Expand All @@ -456,7 +465,7 @@ pub fn create_program_with_minimal_passes(
func.name
);
}
create_program_with_passes(program, options, &minimal_passes(), |_| vec![])
create_program_with_passes(program, options, &minimal_passes(), |_| vec![], Some(files))
}

/// Compiles the [`Program`] into [`ACIR`][acvm::acir::circuit::Program] by running it through
Expand All @@ -467,6 +476,7 @@ pub fn create_program_with_passes<S>(
options: &SsaEvaluatorOptions,
primary: &[SsaPass],
secondary: S,
files: Option<&fm::FileManager>,
) -> Result<SsaProgramArtifact, RuntimeError>
where
S: for<'b> Fn(&'b Brillig) -> Vec<SsaPass<'b>>,
Expand All @@ -480,7 +490,7 @@ where
let ArtifactsAndWarnings(
(generated_acirs, generated_brillig, brillig_function_names, error_types),
ssa_level_warnings,
) = optimize_into_acir(program, options, primary, secondary)?;
) = optimize_into_acir(program, options, primary, secondary, files)?;

assert_eq!(
generated_acirs.len(),
Expand Down Expand Up @@ -630,7 +640,7 @@ fn split_public_and_private_inputs(
}

// This is just a convenience object to bundle the ssa with `print_ssa_passes` for debug printing.
pub struct SsaBuilder {
pub struct SsaBuilder<'local> {
/// The SSA being built; it is the input and the output of every pass ran by the builder.
pub ssa: Ssa,
/// Options to control which SSA passes to print.
Expand All @@ -642,14 +652,19 @@ pub struct SsaBuilder {
pub passed: HashMap<String, usize>,
/// List of SSA pass message fragments that we want to skip, for testing purposes.
pub skip_passes: Vec<String>,

/// Providing a file manager is optional - if provided it can be used to print source
/// locations along with each ssa instructions when debugging.
pub files: Option<&'local fm::FileManager>,
}

impl SsaBuilder {
impl<'local> SsaBuilder<'local> {
pub fn from_program(
program: Program,
ssa_logging: SsaLogging,
print_codegen_timings: bool,
emit_ssa: &Option<PathBuf>,
files: Option<&'local fm::FileManager>,
) -> Result<Self, RuntimeError> {
let ssa = ssa_gen::generate_ssa(program)?;
if let Some(emit_ssa) = emit_ssa {
Expand All @@ -661,14 +676,20 @@ impl SsaBuilder {
let ssa_path = emit_ssa.with_extension("ssa.json");
write_to_file(&serde_json::to_vec(&ssa).unwrap(), &ssa_path);
}
Ok(Self::from_ssa(ssa, ssa_logging, print_codegen_timings).print("Initial SSA"))
Ok(Self::from_ssa(ssa, ssa_logging, print_codegen_timings, files).print("Initial SSA"))
}

pub fn from_ssa(ssa: Ssa, ssa_logging: SsaLogging, print_codegen_timings: bool) -> Self {
pub fn from_ssa(
ssa: Ssa,
ssa_logging: SsaLogging,
print_codegen_timings: bool,
files: Option<&'local fm::FileManager>,
) -> Self {
Self {
ssa_logging,
print_codegen_timings,
ssa,
files,
passed: Default::default(),
skip_passes: Default::default(),
}
Expand Down Expand Up @@ -745,7 +766,7 @@ impl SsaBuilder {
};

if print_ssa_pass {
println!("After {msg}:\n{}", self.ssa);
println!("After {msg}:\n{}", self.ssa.print_with(self.files));
}
self
}
Expand Down
Loading
Loading