@@ -3,14 +3,14 @@ use gloo_utils::format::JsValueSerdeExt;
33use js_sys:: { JsString , Object } ;
44use nargo:: artifacts:: {
55 contract:: { ContractArtifact , ContractFunctionArtifact } ,
6- debug:: DebugArtifact ,
76 program:: ProgramArtifact ,
87} ;
98use 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 ;
1414use 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" {
7671impl 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
150143pub 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
275268pub ( 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
285273pub ( 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