Skip to content

Commit

Permalink
Fix rebase issues and throw in a few extra trait impls
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Jan 10, 2024
1 parent 2ab38fa commit 583cd45
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
18 changes: 16 additions & 2 deletions noir/tooling/nargo/src/artifacts/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use acvm::acir::circuit::Circuit;
use noirc_abi::{Abi, ContractEvent};
use noirc_driver::{ContractFunction, ContractFunctionType};
use noirc_driver::{ContractFunction, ContractFunctionType, CompiledContract};
use serde::{Deserialize, Serialize};
use noirc_evaluator::errors::SsaReport;

Expand All @@ -27,6 +27,20 @@ pub struct ContractArtifact {
pub warnings: Vec<SsaReport>,
}

impl From<CompiledContract> for ContractArtifact {
fn from(contract: CompiledContract) -> Self {
ContractArtifact {
noir_version: contract.noir_version,
name: contract.name,
functions: contract.functions.into_iter().map(ContractFunctionArtifact::from).collect(),
events: contract.events,
file_map: contract.file_map,
warnings: contract.warnings,
}
}
}


/// Each function in the contract will be compiled as a separate noir program.
///
/// A contract function unlike a regular Noir program however can have additional properties.
Expand Down Expand Up @@ -62,7 +76,7 @@ impl From<ContractFunction> for ContractFunctionArtifact {
is_internal: func.is_internal,
abi: func.abi,
bytecode: func.bytecode,
debug_symbols: func.debug_symbols,
debug_symbols: func.debug,
}
}
}
16 changes: 15 additions & 1 deletion noir/tooling/nargo/src/artifacts/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ impl From<CompiledProgram> for ProgramArtifact {
abi: program.abi,
noir_version: program.noir_version,
bytecode: program.circuit,
debug_symbols: program.debug_info,
debug_symbols: program.debug,
file_map: program.file_map,
warnings: program.warnings,
}
}
}

impl Into<CompiledProgram> for ProgramArtifact {
fn into(self) -> CompiledProgram {
CompiledProgram {
hash: self.hash,
abi: self.abi,
noir_version: self.noir_version,
circuit: self.bytecode,
debug: self.debug_symbols,
file_map: self.file_map,
warnings: self.warnings,
}
}
}
43 changes: 4 additions & 39 deletions noir/tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::path::Path;
use acvm::ExpressionWidth;

use fm::FileManager;
use iter_extended::vecmap;
use nargo::artifacts::contract::{ContractArtifact, ContractFunctionArtifact};
use nargo::artifacts::program::ProgramArtifact;
use nargo::errors::CompileError;
use nargo::insert_all_files_for_workspace_into_file_manager;
Expand Down Expand Up @@ -175,19 +173,7 @@ fn compile_program(
let (mut context, crate_id) = prepare_package(file_manager, package);

let program_artifact_path = workspace.package_build_path(package);
let cached_program = if let Ok(program_artifact) = read_program_from_file(program_artifact_path) {
Some(CompiledProgram {
hash: program_artifact.hash,
circuit: program_artifact.bytecode,
abi: program_artifact.abi,
noir_version: program_artifact.noir_version,
debug: program_artifact.debug_symbols,
file_map: program_artifact.file_map,
warnings: program_artifact.warnings,
})
} else {
None
};
let cached_program: Option<CompiledProgram> = read_program_from_file(program_artifact_path).map(|p| p.into()).ok();

let force_recompile =
cached_program.as_ref().map_or(false, |p| p.noir_version != NOIR_ARTIFACT_VERSION_STRING);
Expand Down Expand Up @@ -247,31 +233,10 @@ pub(super) fn save_program(
}

fn save_contract(contract: CompiledContract, package: &Package, circuit_dir: &Path) {
// TODO(#1389): I wonder if it is incorrect for nargo-core to know anything about contracts.
// As can be seen here, It seems like a leaky abstraction where ContractFunctions (essentially CompiledPrograms)
// are compiled via nargo-core and then the ContractArtifact is constructed here.
// This is due to EACH function needing it's own CRS, PKey, and VKey from the backend.
let functions = vecmap(contract.functions, |func| ContractFunctionArtifact {
name: func.name,
function_type: func.function_type,
is_internal: func.is_internal,
abi: func.abi,
bytecode: func.bytecode,
debug_symbols: func.debug,
});

let contract_artifact = ContractArtifact {
noir_version: contract.noir_version,
name: contract.name,
functions,
events: contract.events,
file_map: contract.file_map,
warnings: contract.warnings,
};

let contract_name = contract.name.clone();
save_contract_to_file(
&contract_artifact,
&format!("{}-{}", package.name, contract_artifact.name),
&contract.into(),
&format!("{}-{}", package.name, contract_name),
circuit_dir,
);
}
Expand Down

0 comments on commit 583cd45

Please sign in to comment.