@noir-lang/noir_js 1.0.0-beta.4-17958e3.nightly → 1.0.0-beta.4-3fb324e.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 +41 -17
- package/lib/debug.mjs +41 -17
- package/package.json +4 -4
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
47
|
-
|
|
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
|
-
|
|
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-
|
|
6
|
+
"version": "1.0.0-beta.4-3fb324e.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-
|
|
21
|
-
"@noir-lang/noirc_abi": "1.0.0-beta.4-
|
|
22
|
-
"@noir-lang/types": "1.0.0-beta.4-
|
|
20
|
+
"@noir-lang/acvm_js": "1.0.0-beta.4-3fb324e.nightly",
|
|
21
|
+
"@noir-lang/noirc_abi": "1.0.0-beta.4-3fb324e.nightly",
|
|
22
|
+
"@noir-lang/types": "1.0.0-beta.4-3fb324e.nightly",
|
|
23
23
|
"pako": "^2.1.0"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|