@noir-lang/noir_wasm 0.24.0-16d5f18.nightly → 0.24.0-21fc4b8.nightly

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/dist/node/main.js CHANGED
@@ -202,19 +202,18 @@ function _assertClass(instance, klass) {
202
202
  * This is a method that exposes the same API as `compile`
203
203
  * But uses the Context based APi internally
204
204
  * @param {string} entry_point
205
- * @param {boolean | undefined} contracts
206
205
  * @param {DependencyGraph | undefined} dependency_graph
207
206
  * @param {PathToFileSourceMap} file_source_map
208
- * @returns {CompileResult}
207
+ * @returns {ProgramCompileResult}
209
208
  */
210
- module.exports.compile_ = function(entry_point, contracts, dependency_graph, file_source_map) {
209
+ module.exports.compile_program_ = function(entry_point, dependency_graph, file_source_map) {
211
210
  try {
212
211
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
213
212
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
214
213
  const len0 = WASM_VECTOR_LEN;
215
214
  _assertClass(file_source_map, PathToFileSourceMap);
216
215
  var ptr1 = file_source_map.__destroy_into_raw();
217
- wasm.compile_(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
216
+ wasm.compile_program_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
218
217
  var r0 = getInt32Memory0()[retptr / 4 + 0];
219
218
  var r1 = getInt32Memory0()[retptr / 4 + 1];
220
219
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -228,37 +227,73 @@ module.exports.compile_ = function(entry_point, contracts, dependency_graph, fil
228
227
  };
229
228
 
230
229
  /**
231
- * @param {string} level
230
+ * This is a method that exposes the same API as `compile`
231
+ * But uses the Context based APi internally
232
+ * @param {string} entry_point
233
+ * @param {DependencyGraph | undefined} dependency_graph
234
+ * @param {PathToFileSourceMap} file_source_map
235
+ * @returns {ContractCompileResult}
232
236
  */
233
- module.exports.init_log_level = function(level) {
234
- const ptr0 = passStringToWasm0(level, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
235
- const len0 = WASM_VECTOR_LEN;
236
- wasm.init_log_level(ptr0, len0);
237
+ module.exports.compile_contract_ = function(entry_point, dependency_graph, file_source_map) {
238
+ try {
239
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
240
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
241
+ const len0 = WASM_VECTOR_LEN;
242
+ _assertClass(file_source_map, PathToFileSourceMap);
243
+ var ptr1 = file_source_map.__destroy_into_raw();
244
+ wasm.compile_contract_(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
245
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
246
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
247
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
248
+ if (r2) {
249
+ throw takeObject(r1);
250
+ }
251
+ return takeObject(r0);
252
+ } finally {
253
+ wasm.__wbindgen_add_to_stack_pointer(16);
254
+ }
237
255
  };
238
256
 
239
257
  /**
240
- * @returns {any}
258
+ * @param {string} entry_point
259
+ * @param {DependencyGraph | undefined} dependency_graph
260
+ * @param {PathToFileSourceMap} file_source_map
261
+ * @returns {ProgramCompileResult}
241
262
  */
242
- module.exports.build_info = function() {
243
- const ret = wasm.build_info();
244
- return takeObject(ret);
263
+ module.exports.compile_program = function(entry_point, dependency_graph, file_source_map) {
264
+ try {
265
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
266
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ _assertClass(file_source_map, PathToFileSourceMap);
269
+ var ptr1 = file_source_map.__destroy_into_raw();
270
+ wasm.compile_program(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
271
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
272
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
273
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
274
+ if (r2) {
275
+ throw takeObject(r1);
276
+ }
277
+ return takeObject(r0);
278
+ } finally {
279
+ wasm.__wbindgen_add_to_stack_pointer(16);
280
+ }
245
281
  };
246
282
 
247
283
  /**
248
284
  * @param {string} entry_point
249
- * @param {boolean | undefined} contracts
250
285
  * @param {DependencyGraph | undefined} dependency_graph
251
286
  * @param {PathToFileSourceMap} file_source_map
252
- * @returns {CompileResult}
287
+ * @returns {ContractCompileResult}
253
288
  */
254
- module.exports.compile = function(entry_point, contracts, dependency_graph, file_source_map) {
289
+ module.exports.compile_contract = function(entry_point, dependency_graph, file_source_map) {
255
290
  try {
256
291
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
257
292
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
258
293
  const len0 = WASM_VECTOR_LEN;
259
294
  _assertClass(file_source_map, PathToFileSourceMap);
260
295
  var ptr1 = file_source_map.__destroy_into_raw();
261
- wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
296
+ wasm.compile_contract(retptr, ptr0, len0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
262
297
  var r0 = getInt32Memory0()[retptr / 4 + 0];
263
298
  var r1 = getInt32Memory0()[retptr / 4 + 1];
264
299
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -271,6 +306,23 @@ module.exports.compile = function(entry_point, contracts, dependency_graph, file
271
306
  }
272
307
  };
273
308
 
309
+ /**
310
+ * @param {string} level
311
+ */
312
+ module.exports.init_log_level = function(level) {
313
+ const ptr0 = passStringToWasm0(level, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
314
+ const len0 = WASM_VECTOR_LEN;
315
+ wasm.init_log_level(ptr0, len0);
316
+ };
317
+
318
+ /**
319
+ * @returns {any}
320
+ */
321
+ module.exports.build_info = function() {
322
+ const ret = wasm.build_info();
323
+ return takeObject(ret);
324
+ };
325
+
274
326
  function handleError(f, args) {
275
327
  try {
276
328
  return f.apply(this, args);
@@ -357,7 +409,7 @@ class CompilerContext {
357
409
  }
358
410
  /**
359
411
  * @param {number} program_width
360
- * @returns {CompileResult}
412
+ * @returns {ProgramCompileResult}
361
413
  */
362
414
  compile_program(program_width) {
363
415
  try {
@@ -377,7 +429,7 @@ class CompilerContext {
377
429
  }
378
430
  /**
379
431
  * @param {number} program_width
380
- * @returns {CompileResult}
432
+ * @returns {ContractCompileResult}
381
433
  */
382
434
  compile_contract(program_width) {
383
435
  try {
@@ -476,13 +528,13 @@ module.exports.__wbindgen_is_undefined = function(arg0) {
476
528
  return ret;
477
529
  };
478
530
 
479
- module.exports.__wbg_constructor_e8767839abf8a966 = function(arg0) {
480
- const ret = new Error(takeObject(arg0));
531
+ module.exports.__wbg_constructor_05d6d198f3477d6f = function() {
532
+ const ret = new Object();
481
533
  return addHeapObject(ret);
482
534
  };
483
535
 
484
- module.exports.__wbg_constructor_05d6d198f3477d6f = function() {
485
- const ret = new Object();
536
+ module.exports.__wbg_constructor_e8767839abf8a966 = function(arg0) {
537
+ const ret = new Error(takeObject(arg0));
486
538
  return addHeapObject(ret);
487
539
  };
488
540
 
@@ -1159,18 +1211,54 @@ class NoirWasmCompiler {
1159
1211
  /**
1160
1212
  * Compile EntryPoint
1161
1213
  */
1214
+ async compile_program() {
1215
+ console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1216
+ if (this.#package.getType() !== 'bin') {
1217
+ throw new Error(`Expected to find package type "bin" but found ${this.#package.getType()}`);
1218
+ }
1219
+ await this.#dependencyManager.resolveDependencies();
1220
+ this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1221
+ try {
1222
+ const entrypoint = this.#package.getEntryPointPath();
1223
+ const deps = {
1224
+ /* eslint-disable camelcase */
1225
+ root_dependencies: this.#dependencyManager.getEntrypointDependencies(),
1226
+ library_dependencies: this.#dependencyManager.getLibraryDependencies(),
1227
+ /* eslint-enable camelcase */
1228
+ };
1229
+ const packageSources = await this.#package.getSources(this.#fm);
1230
+ const librarySources = (await Promise.all(this.#dependencyManager
1231
+ .getLibraries()
1232
+ .map(async ([alias, library]) => await library.package.getSources(this.#fm, alias)))).flat();
1233
+ [...packageSources, ...librarySources].forEach((sourceFile) => {
1234
+ this.#debugLog(`Adding source ${sourceFile.path}`);
1235
+ this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1236
+ });
1237
+ const result = this.#wasmCompiler.compile_program(entrypoint, deps, this.#sourceMap);
1238
+ return result;
1239
+ }
1240
+ catch (err) {
1241
+ if (err instanceof Error && err.name === 'CompileError') {
1242
+ const logs = await this.#processCompileError(err);
1243
+ for (const log of logs) {
1244
+ this.#log(log);
1245
+ }
1246
+ throw new Error(logs.join('\n'));
1247
+ }
1248
+ throw err;
1249
+ }
1250
+ }
1162
1251
  /**
1163
1252
  * Compile EntryPoint
1164
1253
  */
1165
- async compile() {
1254
+ async compile_contract() {
1166
1255
  console.log(`Compiling at ${this.#package.getEntryPointPath()}`);
1167
- if (!(this.#package.getType() === 'contract' || this.#package.getType() === 'bin')) {
1168
- throw new Error(`Only supports compiling "contract" and "bin" package types (${this.#package.getType()})`);
1256
+ if (this.#package.getType() !== 'contract') {
1257
+ throw new Error(`Expected to find package type "contract" but found ${this.#package.getType()}`);
1169
1258
  }
1170
1259
  await this.#dependencyManager.resolveDependencies();
1171
1260
  this.#debugLog(`Dependencies: ${this.#dependencyManager.getPackageNames().join(', ')}`);
1172
1261
  try {
1173
- const isContract = this.#package.getType() === 'contract';
1174
1262
  const entrypoint = this.#package.getEntryPointPath();
1175
1263
  const deps = {
1176
1264
  /* eslint-disable camelcase */
@@ -1186,10 +1274,7 @@ class NoirWasmCompiler {
1186
1274
  this.#debugLog(`Adding source ${sourceFile.path}`);
1187
1275
  this.#sourceMap.add_source_code(sourceFile.path, sourceFile.source);
1188
1276
  });
1189
- const result = this.#wasmCompiler.compile(entrypoint, isContract, deps, this.#sourceMap);
1190
- if ((isContract && !('contract' in result)) || (!isContract && !('program' in result))) {
1191
- throw new Error('Invalid compilation result');
1192
- }
1277
+ const result = this.#wasmCompiler.compile_contract(entrypoint, deps, this.#sourceMap);
1193
1278
  return result;
1194
1279
  }
1195
1280
  catch (err) {
@@ -12738,7 +12823,7 @@ var exports = __webpack_exports__;
12738
12823
  \***********************/
12739
12824
 
12740
12825
  Object.defineProperty(exports, "__esModule", ({ value: true }));
12741
- exports.inflateDebugSymbols = exports.createFileManager = exports.compile = void 0;
12826
+ exports.inflateDebugSymbols = exports.createFileManager = exports.compile_contract = exports.compile_program = exports.compile = void 0;
12742
12827
  const nodejs_file_manager_1 = __webpack_require__(/*! ./noir/file-manager/nodejs-file-manager */ "./src/noir/file-manager/nodejs-file-manager.ts");
12743
12828
  const noir_wasm_compiler_1 = __webpack_require__(/*! ./noir/noir-wasm-compiler */ "./src/noir/noir-wasm-compiler.ts");
12744
12829
  const debug_1 = __webpack_require__(/*! ./noir/debug */ "./src/noir/debug.ts");
@@ -12755,30 +12840,71 @@ Object.defineProperty(exports, "inflateDebugSymbols", ({ enumerable: true, get:
12755
12840
  * ```typescript
12756
12841
  * // Node.js
12757
12842
  *
12758
- * import { compile, createFileManager } from '@noir-lang/noir_wasm';
12843
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12844
+ *
12845
+ * const fm = createFileManager(myProjectPath);
12846
+ * const myCompiledCode = await compile_program(fm);
12847
+ * ```
12848
+ *
12849
+ * ```typescript
12850
+ * // Browser
12851
+ *
12852
+ * import { compile_program, createFileManager } from '@noir-lang/noir_wasm';
12853
+ *
12854
+ * const fm = createFileManager('/');
12855
+ * for (const path of files) {
12856
+ * await fm.writeFile(path, await getFileAsStream(path));
12857
+ * }
12858
+ * const myCompiledCode = await compile_program(fm);
12859
+ * ```
12860
+ */
12861
+ async function compile_program(fileManager, projectPath, logFn, debugLogFn) {
12862
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12863
+ return await compiler.compile_program();
12864
+ }
12865
+ exports.compile = compile_program;
12866
+ exports.compile_program = compile_program;
12867
+ /**
12868
+ * Compiles a Noir project
12869
+ *
12870
+ * @param fileManager - The file manager to use
12871
+ * @param projectPath - The path to the project inside the file manager. Defaults to the root of the file manager
12872
+ * @param logFn - A logging function. If not provided, console.log will be used
12873
+ * @param debugLogFn - A debug logging function. If not provided, logFn will be used
12874
+ *
12875
+ * @example
12876
+ * ```typescript
12877
+ * // Node.js
12878
+ *
12879
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12759
12880
  *
12760
12881
  * const fm = createFileManager(myProjectPath);
12761
- * const myCompiledCode = await compile(fm);
12882
+ * const myCompiledCode = await compile_contract(fm);
12762
12883
  * ```
12763
12884
  *
12764
12885
  * ```typescript
12765
12886
  * // Browser
12766
12887
  *
12767
- * import { compile, createFileManager } from '@noir-lang/noir_wasm';
12888
+ * import { compile_contract, createFileManager } from '@noir-lang/noir_wasm';
12768
12889
  *
12769
12890
  * const fm = createFileManager('/');
12770
12891
  * for (const path of files) {
12771
12892
  * await fm.writeFile(path, await getFileAsStream(path));
12772
12893
  * }
12773
- * const myCompiledCode = await compile(fm);
12894
+ * const myCompiledCode = await compile_contract(fm);
12774
12895
  * ```
12775
12896
  */
12776
- async function compile(fileManager, projectPath, logFn, debugLogFn) {
12897
+ async function compile_contract(fileManager, projectPath, logFn, debugLogFn) {
12898
+ const compiler = await setup_compiler(fileManager, projectPath, logFn, debugLogFn);
12899
+ return await compiler.compile_contract();
12900
+ }
12901
+ exports.compile_contract = compile_contract;
12902
+ async function setup_compiler(fileManager, projectPath, logFn, debugLogFn) {
12777
12903
  if (logFn && !debugLogFn) {
12778
12904
  debugLogFn = logFn;
12779
12905
  }
12780
12906
  const cjs = await __webpack_require__(/*! ../build/cjs */ "./build/cjs/index.js");
12781
- const compiler = await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12907
+ return await noir_wasm_compiler_1.NoirWasmCompiler.new(fileManager, projectPath ?? fileManager.getDataDir(), cjs, new cjs.PathToFileSourceMap(), {
12782
12908
  log: logFn ??
12783
12909
  function (msg, data) {
12784
12910
  if (data) {
@@ -12798,9 +12924,7 @@ async function compile(fileManager, projectPath, logFn, debugLogFn) {
12798
12924
  }
12799
12925
  },
12800
12926
  });
12801
- return await compiler.compile();
12802
12927
  }
12803
- exports.compile = compile;
12804
12928
  const createFileManager = nodejs_file_manager_1.createNodejsFileManager;
12805
12929
  exports.createFileManager = createFileManager;
12806
12930