Skip to content

Commit ec8f7f1

Browse files
committed
Do not store debug artifact in a separate file on nargo cli compile
1 parent 563c704 commit ec8f7f1

15 files changed

Lines changed: 255 additions & 170 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ num-traits = "0.2"
123123
similar-asserts = "1.5.0"
124124
tempfile = "3.6.0"
125125
jsonrpc = { version = "0.16.0", features = ["minreq_http"] }
126+
flate2 = "1.0.24"
126127

127128
tracing = "0.1.40"
128129
tracing-web = "0.1.3"

acvm-repo/acir/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ acir_field.workspace = true
1717
brillig.workspace = true
1818
serde.workspace = true
1919
thiserror.workspace = true
20-
flate2 = "1.0.24"
20+
flate2.workspace = true
2121
bincode.workspace = true
2222
base64.workspace = true
2323

compiler/noirc_errors/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ fm.workspace = true
1515
chumsky.workspace = true
1616
serde.workspace = true
1717
serde_with = "3.2.0"
18-
tracing.workspace = true
18+
tracing.workspace = true
19+
flate2.workspace = true
20+
serde_json.workspace = true
21+
base64.workspace = true

compiler/noirc_errors/src/debug_info.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
use acvm::acir::circuit::OpcodeLocation;
22
use acvm::compiler::AcirTransformationMap;
33

4+
use base64::Engine;
5+
use flate2::read::DeflateDecoder;
6+
use flate2::write::DeflateEncoder;
7+
use flate2::Compression;
8+
use serde::Deserializer;
9+
use serde::Serializer;
410
use serde_with::serde_as;
511
use serde_with::DisplayFromStr;
612
use std::collections::BTreeMap;
713
use std::collections::HashMap;
14+
use std::io::Read;
15+
use std::io::Write;
816
use std::mem;
917

1018
use crate::Location;
11-
use serde::{Deserialize, Serialize};
19+
use serde::{
20+
de::Error as DeserializationError, ser::Error as SerializationError, Deserialize, Serialize,
21+
};
1222

1323
#[serde_as]
1424
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
@@ -86,4 +96,40 @@ impl DebugInfo {
8696

8797
counted_opcodes
8898
}
99+
100+
pub fn serialize_compressed_base64_json<S>(
101+
debug_info: &DebugInfo,
102+
s: S,
103+
) -> Result<S::Ok, S::Error>
104+
where
105+
S: Serializer,
106+
{
107+
let json_str = serde_json::to_string(debug_info).map_err(S::Error::custom)?;
108+
109+
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
110+
encoder.write_all(json_str.as_bytes()).map_err(S::Error::custom)?;
111+
let compressed_data = encoder.finish().map_err(S::Error::custom)?;
112+
113+
let encoded_b64 = base64::prelude::BASE64_STANDARD.encode(&compressed_data);
114+
s.serialize_str(&encoded_b64)
115+
}
116+
117+
pub fn deserialize_compressed_base64_json<'de, D>(
118+
deserializer: D,
119+
) -> Result<DebugInfo, D::Error>
120+
where
121+
D: Deserializer<'de>,
122+
{
123+
let encoded_b64: String = Deserialize::deserialize(deserializer)?;
124+
125+
let compressed_data =
126+
base64::prelude::BASE64_STANDARD.decode(&encoded_b64).map_err(D::Error::custom)?;
127+
128+
let mut decoder = DeflateDecoder::new(&compressed_data[..]);
129+
let mut decompressed_data = Vec::new();
130+
decoder.read_to_end(&mut decompressed_data).map_err(D::Error::custom)?;
131+
132+
let json_str = String::from_utf8(decompressed_data).map_err(D::Error::custom)?;
133+
serde_json::from_str(&json_str).map_err(D::Error::custom)
134+
}
89135
}

compiler/wasm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nargo.workspace = true
1818
noirc_driver.workspace = true
1919
noirc_frontend.workspace = true
2020
noirc_errors.workspace = true
21+
noirc_evaluator.workspace = true
2122
wasm-bindgen.workspace = true
2223
serde.workspace = true
2324
js-sys.workspace = true

compiler/wasm/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@types/mocha": "^10.0.6",
4949
"@types/mocha-each": "^2",
5050
"@types/node": "^20.10.5",
51+
"@types/pako": "^2",
5152
"@types/path-browserify": "^1",
5253
"@types/readable-stream": "^4",
5354
"@types/sinon": "^17",
@@ -75,5 +76,8 @@
7576
"url": "^0.11.3",
7677
"webpack": "^5.49.0",
7778
"webpack-cli": "^4.7.2"
79+
},
80+
"dependencies": {
81+
"pako": "^2.1.0"
7882
}
7983
}

compiler/wasm/src/compile.rs

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use gloo_utils::format::JsValueSerdeExt;
33
use js_sys::{JsString, Object};
44
use nargo::artifacts::{
55
contract::{ContractArtifact, ContractFunctionArtifact},
6-
debug::DebugArtifact,
76
program::ProgramArtifact,
87
};
98
use noirc_driver::{
109
add_dep, compile_contract, compile_main, file_manager_with_stdlib, prepare_crate,
1110
prepare_dependency, CompileOptions, CompiledContract, CompiledProgram,
1211
NOIR_ARTIFACT_VERSION_STRING,
1312
};
13+
use noirc_evaluator::errors::SsaReport;
1414
use noirc_frontend::{
1515
graph::{CrateId, CrateName},
1616
hir::Context,
@@ -28,35 +28,30 @@ export type DependencyGraph = {
2828
library_dependencies: Readonly<Record<string, readonly string[]>>;
2929
}
3030
31-
export type CompiledContract = {
31+
export type ContractArtifact = {
3232
noir_version: string;
3333
name: string;
3434
functions: Array<any>;
3535
events: Array<any>;
36+
file_map: Record<number, any>;
3637
};
3738
38-
export type CompiledProgram = {
39+
export type ProgramArtifact = {
3940
noir_version: string;
41+
hash: number;
4042
abi: any;
4143
bytecode: string;
44+
debug_symbols: any;
45+
file_map: Record<number, any>;
4246
}
4347
44-
export type DebugArtifact = {
45-
debug_symbols: Array<any>;
46-
file_map: Record<number, any>;
47-
warnings: Array<any>;
48-
};
48+
type WarningsCompileResult = { warnings: Array<any>; };
4949
50-
export type CompileResult = (
51-
| {
52-
contract: CompiledContract;
53-
debug: DebugArtifact;
54-
}
55-
| {
56-
program: CompiledProgram;
57-
debug: DebugArtifact;
58-
}
59-
);
50+
export type ContractCompileResult = { contract: CompiledContract; } & WarningsCompileResult;
51+
52+
export type ProgramCompileResult = { program: CompiledProgram; } & WarningsCompileResult;
53+
54+
export type CompileResult = ContractCompileResult | ProgramCompileResult;
6055
"#;
6156

6257
#[wasm_bindgen]
@@ -76,38 +71,36 @@ extern "C" {
7671
impl JsCompileResult {
7772
const CONTRACT_PROP: &'static str = "contract";
7873
const PROGRAM_PROP: &'static str = "program";
79-
const DEBUG_PROP: &'static str = "debug";
74+
const WARNINGS_PROP: &'static str = "warnings";
8075

8176
pub fn new(resp: CompileResult) -> JsCompileResult {
8277
let obj = JsCompileResult::constructor();
8378
match resp {
84-
CompileResult::Contract { contract, debug } => {
79+
CompileResult::Contract { contract, warnings } => {
8580
js_sys::Reflect::set(
8681
&obj,
8782
&JsString::from(JsCompileResult::CONTRACT_PROP),
8883
&<JsValue as JsValueSerdeExt>::from_serde(&contract).unwrap(),
8984
)
9085
.unwrap();
91-
9286
js_sys::Reflect::set(
9387
&obj,
94-
&JsString::from(JsCompileResult::DEBUG_PROP),
95-
&<JsValue as JsValueSerdeExt>::from_serde(&debug).unwrap(),
88+
&JsString::from(JsCompileResult::WARNINGS_PROP),
89+
&<JsValue as JsValueSerdeExt>::from_serde(&warnings).unwrap(),
9690
)
9791
.unwrap();
9892
}
99-
CompileResult::Program { program, debug } => {
93+
CompileResult::Program { program, warnings } => {
10094
js_sys::Reflect::set(
10195
&obj,
10296
&JsString::from(JsCompileResult::PROGRAM_PROP),
10397
&<JsValue as JsValueSerdeExt>::from_serde(&program).unwrap(),
10498
)
10599
.unwrap();
106-
107100
js_sys::Reflect::set(
108101
&obj,
109-
&JsString::from(JsCompileResult::DEBUG_PROP),
110-
&<JsValue as JsValueSerdeExt>::from_serde(&debug).unwrap(),
102+
&JsString::from(JsCompileResult::WARNINGS_PROP),
103+
&<JsValue as JsValueSerdeExt>::from_serde(&warnings).unwrap(),
111104
)
112105
.unwrap();
113106
}
@@ -148,8 +141,8 @@ impl PathToFileSourceMap {
148141
}
149142

150143
pub enum CompileResult {
151-
Contract { contract: ContractArtifact, debug: DebugArtifact },
152-
Program { program: ProgramArtifact, debug: DebugArtifact },
144+
Contract { contract: ContractArtifact, warnings: Vec<SsaReport> },
145+
Program { program: ProgramArtifact, warnings: Vec<SsaReport> },
153146
}
154147

155148
#[wasm_bindgen]
@@ -273,31 +266,22 @@ fn add_noir_lib(context: &mut Context, library_name: &CrateName) -> CrateId {
273266
}
274267

275268
pub(crate) fn generate_program_artifact(program: CompiledProgram) -> CompileResult {
276-
let debug_artifact = DebugArtifact {
277-
debug_symbols: vec![program.debug.clone()],
278-
file_map: program.file_map.clone(),
279-
warnings: program.warnings.clone(),
280-
};
281-
282-
CompileResult::Program { program: program.into(), debug: debug_artifact }
269+
let warnings = program.warnings.clone();
270+
CompileResult::Program { program: program.into(), warnings }
283271
}
284272

285273
pub(crate) fn generate_contract_artifact(contract: CompiledContract) -> CompileResult {
286-
let debug_artifact = DebugArtifact {
287-
debug_symbols: contract.functions.iter().map(|function| function.debug.clone()).collect(),
288-
file_map: contract.file_map,
289-
warnings: contract.warnings,
290-
};
291274
let functions = contract.functions.into_iter().map(ContractFunctionArtifact::from).collect();
292-
275+
293276
let contract_artifact = ContractArtifact {
294277
noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
295278
name: contract.name,
296279
functions,
297280
events: contract.events,
281+
file_map: contract.file_map,
298282
};
299283

300-
CompileResult::Contract { contract: contract_artifact, debug: debug_artifact }
284+
CompileResult::Contract { contract: contract_artifact, warnings: contract.warnings }
301285
}
302286

303287
#[cfg(test)]

0 commit comments

Comments
 (0)