Skip to content

Commit

Permalink
chore: avoid manual creation of contract artifact in wasm (noir-lang#…
Browse files Browse the repository at this point in the history
…5117)

# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

We don't need to construct these manually as we have functions for this.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jun 4, 2024
1 parent 1afc6c2 commit 888b94c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
20 changes: 3 additions & 17 deletions compiler/wasm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ use fm::FileManager;
use gloo_utils::format::JsValueSerdeExt;
use js_sys::{JsString, Object};
use nargo::{
artifacts::{
contract::{ContractArtifact, ContractFunctionArtifact},
program::ProgramArtifact,
},
artifacts::{contract::ContractArtifact, program::ProgramArtifact},
parse_all,
};
use noirc_driver::{
add_dep, file_manager_with_stdlib, prepare_crate, prepare_dependency, CompileOptions,
NOIR_ARTIFACT_VERSION_STRING,
};
use noirc_evaluator::errors::SsaReport;
use noirc_frontend::{
Expand Down Expand Up @@ -220,19 +216,9 @@ pub fn compile_contract(

let optimized_contract =
nargo::ops::transform_contract(compiled_contract, compile_options.expression_width);
let warnings = optimized_contract.warnings.clone();

let functions =
optimized_contract.functions.into_iter().map(ContractFunctionArtifact::from).collect();

let contract_artifact = ContractArtifact {
noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
name: optimized_contract.name,
functions,
outputs: optimized_contract.outputs.into(),
file_map: optimized_contract.file_map,
};

Ok(JsCompileContractResult::new(contract_artifact, optimized_contract.warnings))
Ok(JsCompileContractResult::new(optimized_contract.into(), warnings))
}

fn prepare_context(
Expand Down
16 changes: 2 additions & 14 deletions compiler/wasm/src/compile_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use crate::compile::{
};
use crate::errors::{CompileError, JsCompileError};
use acvm::acir::circuit::ExpressionWidth;
use nargo::artifacts::contract::{ContractArtifact, ContractFunctionArtifact};
use nargo::parse_all;
use noirc_driver::{
add_dep, compile_contract, compile_main, prepare_crate, prepare_dependency, CompileOptions,
NOIR_ARTIFACT_VERSION_STRING,
};
use noirc_frontend::{
graph::{CrateId, CrateName},
Expand Down Expand Up @@ -148,19 +146,9 @@ impl CompilerContext {

let optimized_contract =
nargo::ops::transform_contract(compiled_contract, compile_options.expression_width);
let warnings = optimized_contract.warnings.clone();

let functions =
optimized_contract.functions.into_iter().map(ContractFunctionArtifact::from).collect();

let contract_artifact = ContractArtifact {
noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
name: optimized_contract.name,
functions,
outputs: optimized_contract.outputs.into(),
file_map: optimized_contract.file_map,
};

Ok(JsCompileContractResult::new(contract_artifact, optimized_contract.warnings))
Ok(JsCompileContractResult::new(optimized_contract.into(), warnings))
}
}

Expand Down

0 comments on commit 888b94c

Please sign in to comment.