@noir-lang/noir_js 1.0.0-beta.4-17958e3.nightly → 1.0.0-beta.4-097b116.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.
package/lib/debug.cjs CHANGED
@@ -33,22 +33,25 @@ function extractCallStack(error, debug, files) {
33
33
  * Resolves the source code locations from an array of opcode locations
34
34
  */
35
35
  function resolveOpcodeLocations(opcodeLocations, debug, files, brilligFunctionId) {
36
- return opcodeLocations.flatMap((opcodeLocation) => getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId));
37
- }
38
- /**
39
- * Extracts the call stack from the location of a failing opcode and the debug metadata.
40
- * One opcode can point to multiple calls due to inlining.
41
- */
42
- function getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId) {
43
- let callStack = debug.locations[opcodeLocation] || [];
44
- if (callStack.length === 0) {
45
- const brilligLocation = extractBrilligLocation(opcodeLocation);
46
- if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
47
- callStack = debug.brillig_locations[brilligFunctionId][brilligLocation] || [];
36
+ let locations = opcodeLocations.flatMap((opcodeLocation) => getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId));
37
+ // Adds the acir call stack if the last location is a brillig opcode
38
+ if (locations.length > 0) {
39
+ const runtimeLocations = opcodeLocations[opcodeLocations.length - 1].split('.');
40
+ if (runtimeLocations.length === 2) {
41
+ const acirCallstackId = debug.acir_locations[runtimeLocations[0]];
42
+ if (acirCallstackId !== undefined) {
43
+ const callStack = debug.location_tree.locations[acirCallstackId];
44
+ const acirCallstack = getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
45
+ locations = locations.concat(acirCallstack);
46
+ }
48
47
  }
49
48
  }
50
- return callStack.map((call) => {
51
- const { file: fileId, span } = call;
49
+ return locations;
50
+ }
51
+ function getCallStackFromLocationNode(callStack, location_tree, files) {
52
+ const result = [];
53
+ while (callStack.parent !== null) {
54
+ const { file: fileId, span } = callStack.value;
52
55
  const { path, source } = files[fileId];
53
56
  const locationText = source.substring(span.start, span.end);
54
57
  const precedingText = source.substring(0, span.start);
@@ -56,13 +59,34 @@ function getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files,
56
59
  // Lines and columns in stacks are one indexed.
57
60
  const line = previousLines.length;
58
61
  const column = previousLines[previousLines.length - 1].length + 1;
59
- return {
62
+ result.push({
60
63
  filePath: path,
61
64
  line,
62
65
  column,
63
66
  locationText,
64
- };
65
- });
67
+ });
68
+ callStack = location_tree[callStack.parent];
69
+ }
70
+ return result;
71
+ }
72
+ /**
73
+ * Extracts the call stack from the location of a failing opcode and the debug metadata.
74
+ * One opcode can point to multiple calls due to inlining.
75
+ */
76
+ function getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId) {
77
+ let callstack_id = debug.acir_locations[opcodeLocation];
78
+ const brilligLocation = extractBrilligLocation(opcodeLocation);
79
+ if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
80
+ callstack_id = debug.brillig_locations[brilligFunctionId][brilligLocation];
81
+ if (callstack_id === undefined) {
82
+ return [];
83
+ }
84
+ }
85
+ if (callstack_id === undefined) {
86
+ return [];
87
+ }
88
+ const callStack = debug.location_tree.locations[callstack_id];
89
+ return getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
66
90
  }
67
91
  /**
68
92
  * Extracts a brillig location from an opcode location.
package/lib/debug.mjs CHANGED
@@ -29,22 +29,25 @@ export function extractCallStack(error, debug, files) {
29
29
  * Resolves the source code locations from an array of opcode locations
30
30
  */
31
31
  function resolveOpcodeLocations(opcodeLocations, debug, files, brilligFunctionId) {
32
- return opcodeLocations.flatMap((opcodeLocation) => getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId));
33
- }
34
- /**
35
- * Extracts the call stack from the location of a failing opcode and the debug metadata.
36
- * One opcode can point to multiple calls due to inlining.
37
- */
38
- function getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId) {
39
- let callStack = debug.locations[opcodeLocation] || [];
40
- if (callStack.length === 0) {
41
- const brilligLocation = extractBrilligLocation(opcodeLocation);
42
- if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
43
- callStack = debug.brillig_locations[brilligFunctionId][brilligLocation] || [];
32
+ let locations = opcodeLocations.flatMap((opcodeLocation) => getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId));
33
+ // Adds the acir call stack if the last location is a brillig opcode
34
+ if (locations.length > 0) {
35
+ const runtimeLocations = opcodeLocations[opcodeLocations.length - 1].split('.');
36
+ if (runtimeLocations.length === 2) {
37
+ const acirCallstackId = debug.acir_locations[runtimeLocations[0]];
38
+ if (acirCallstackId !== undefined) {
39
+ const callStack = debug.location_tree.locations[acirCallstackId];
40
+ const acirCallstack = getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
41
+ locations = locations.concat(acirCallstack);
42
+ }
44
43
  }
45
44
  }
46
- return callStack.map((call) => {
47
- const { file: fileId, span } = call;
45
+ return locations;
46
+ }
47
+ function getCallStackFromLocationNode(callStack, location_tree, files) {
48
+ const result = [];
49
+ while (callStack.parent !== null) {
50
+ const { file: fileId, span } = callStack.value;
48
51
  const { path, source } = files[fileId];
49
52
  const locationText = source.substring(span.start, span.end);
50
53
  const precedingText = source.substring(0, span.start);
@@ -52,13 +55,34 @@ function getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files,
52
55
  // Lines and columns in stacks are one indexed.
53
56
  const line = previousLines.length;
54
57
  const column = previousLines[previousLines.length - 1].length + 1;
55
- return {
58
+ result.push({
56
59
  filePath: path,
57
60
  line,
58
61
  column,
59
62
  locationText,
60
- };
61
- });
63
+ });
64
+ callStack = location_tree[callStack.parent];
65
+ }
66
+ return result;
67
+ }
68
+ /**
69
+ * Extracts the call stack from the location of a failing opcode and the debug metadata.
70
+ * One opcode can point to multiple calls due to inlining.
71
+ */
72
+ function getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId) {
73
+ let callstack_id = debug.acir_locations[opcodeLocation];
74
+ const brilligLocation = extractBrilligLocation(opcodeLocation);
75
+ if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
76
+ callstack_id = debug.brillig_locations[brilligFunctionId][brilligLocation];
77
+ if (callstack_id === undefined) {
78
+ return [];
79
+ }
80
+ }
81
+ if (callstack_id === undefined) {
82
+ return [];
83
+ }
84
+ const callStack = debug.location_tree.locations[callstack_id];
85
+ return getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
62
86
  }
63
87
  /**
64
88
  * Extracts a brillig location from an opcode location.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "contributors": [
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
- "version": "1.0.0-beta.4-17958e3.nightly",
6
+ "version": "1.0.0-beta.4-097b116.nightly",
7
7
  "packageManager": "yarn@4.5.2",
8
8
  "license": "(MIT OR Apache-2.0)",
9
9
  "type": "module",
@@ -17,9 +17,9 @@
17
17
  "url": "https://github.com/noir-lang/noir/issues"
18
18
  },
19
19
  "dependencies": {
20
- "@noir-lang/acvm_js": "1.0.0-beta.4-17958e3.nightly",
21
- "@noir-lang/noirc_abi": "1.0.0-beta.4-17958e3.nightly",
22
- "@noir-lang/types": "1.0.0-beta.4-17958e3.nightly",
20
+ "@noir-lang/acvm_js": "1.0.0-beta.4-097b116.nightly",
21
+ "@noir-lang/noirc_abi": "1.0.0-beta.4-097b116.nightly",
22
+ "@noir-lang/types": "1.0.0-beta.4-097b116.nightly",
23
23
  "pako": "^2.1.0"
24
24
  },
25
25
  "files": [