@tracecode/harness 0.5.1 → 0.6.1
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/CHANGELOG.md +29 -0
- package/README.md +30 -3
- package/dist/browser.cjs +974 -19
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +3 -2
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +974 -19
- package/dist/browser.js.map +1 -1
- package/dist/cli.cjs +24 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +24 -0
- package/dist/cli.js.map +1 -1
- package/dist/core.cjs +611 -4
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +20 -6
- package/dist/core.d.ts +20 -6
- package/dist/core.js +605 -4
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1004 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +998 -19
- package/dist/index.js.map +1 -1
- package/dist/internal/browser.cjs +211 -0
- package/dist/internal/browser.cjs.map +1 -1
- package/dist/internal/browser.d.cts +62 -6
- package/dist/internal/browser.d.ts +62 -6
- package/dist/internal/browser.js +210 -0
- package/dist/internal/browser.js.map +1 -1
- package/dist/javascript.d.cts +2 -2
- package/dist/javascript.d.ts +2 -2
- package/dist/{runtime-types-DtaaAhHL.d.ts → runtime-types-89nchXlY.d.cts} +8 -4
- package/dist/{runtime-types--lBQ6rYu.d.cts → runtime-types-CCQ-ZLc9.d.ts} +8 -4
- package/dist/{types-DwIYM3Ku.d.cts → types-zyvpJKCi.d.cts} +1 -0
- package/dist/{types-DwIYM3Ku.d.ts → types-zyvpJKCi.d.ts} +1 -0
- package/package.json +17 -5
- package/workers/java/.build/classes/harness/browser/JavaRewriteLibrary.class +0 -0
- package/workers/java/java-worker.js +712 -0
- package/workers/java/src/harness/browser/JavaRewriteLibrary.java +54 -0
- package/workers/javascript/javascript-worker.js +343 -63
- package/workers/python/generated-python-harness-snippets.js +3 -3
- package/workers/python/pyodide-worker.js +419 -68
- package/workers/python/runtime-core.js +52 -3
- package/workers/vendor/java-browser-spike-helper.jar +0 -0
- package/workers/vendor/java-practice-rewriter.jar +0 -0
- package/workers/vendor/java-rewrite-bridge.jar +0 -0
- package/workers/vendor/javaparser-core-3.25.10.jar +0 -0
- package/workers/vendor/jdk.compiler-17.jar +0 -0
|
@@ -16,6 +16,8 @@ function generateTracingCode(deps, userCode, functionName, inputs, executionStyl
|
|
|
16
16
|
|
|
17
17
|
// Configurable limits
|
|
18
18
|
const maxTraceSteps = options.maxTraceSteps || 2000;
|
|
19
|
+
const maxStoredEvents = options.maxStoredEvents || maxTraceSteps;
|
|
20
|
+
const effectiveMaxTraceSteps = Math.min(maxTraceSteps, maxStoredEvents);
|
|
19
21
|
const maxLineEvents = options.maxLineEvents || 10000;
|
|
20
22
|
const maxSingleLineHits = options.maxSingleLineHits || 500;
|
|
21
23
|
const minimalTrace = options.minimalTrace === true;
|
|
@@ -69,7 +71,7 @@ _call_stack = []
|
|
|
69
71
|
_pending_accesses = {}
|
|
70
72
|
_prev_hashmap_snapshots = {}
|
|
71
73
|
_TRACE_MUTATING_METHODS = {'append', 'appendleft', 'pop', 'popleft', 'extend', 'insert'}
|
|
72
|
-
_internal_funcs = {'_serialize', '_tracer', '_custom_print', '_dict_to_tree', '_dict_to_list', '_is_structural_constructor_frame', '_snapshot_call_stack', '_snapshot_locals', '_stable_token', '_looks_like_adjacency_list', '_looks_like_indexed_adjacency_list', '_extract_hashmap_snapshot', '_classify_runtime_object_kind', '_infer_hashmap_delta', '_clear_frame_hashmap_snapshots', '_build_runtime_visualization', '_resolve_inplace_result', '__tracecode_record_access', '__tracecode_flush_accesses', '__tracecode_normalize_indices', '__tracecode_make_access_event', '__tracecode_read_value', '__tracecode_write_value', '__tracecode_apply_augmented_value', '_tracecode_read_index', '_tracecode_write_index', '_tracecode_augassign_index', '_tracecode_mutating_call', '__tracecode_attach_parents', '_tracecode_extract_named_subscript', '__TracecodeAccessTransformer', '__tracecode_compile_user_code', '<listcomp>', '<dictcomp>', '<setcomp>', '<genexpr>'}
|
|
74
|
+
_internal_funcs = {'_serialize', '_tracer', '_custom_print', '_dict_to_tree', '_dict_to_list', '_is_structural_constructor_frame', '_snapshot_call_stack', '_snapshot_locals', '_stable_token', '_looks_like_adjacency_list', '_looks_like_indexed_adjacency_list', '_extract_hashmap_snapshot', '_classify_runtime_object_kind', '_infer_hashmap_delta', '_clear_frame_hashmap_snapshots', '_build_runtime_visualization', '_resolve_inplace_result', '__tracecode_record_access', '__tracecode_flush_accesses', '__tracecode_normalize_indices', '__tracecode_make_access_event', '__tracecode_read_value', '__tracecode_write_value', '__tracecode_apply_augmented_value', '_tracecode_read_index', '_tracecode_write_index', '_tracecode_augassign_index', '_tracecode_mutating_call', '_tracecode_is_pure_literal_scaffold', '_tracecode_collect_collapsed_literal_lines', '__tracecode_attach_parents', '_tracecode_extract_named_subscript', '__TracecodeAccessTransformer', '__tracecode_compile_user_code', '<listcomp>', '<dictcomp>', '<setcomp>', '<genexpr>'}
|
|
73
75
|
_internal_locals = {
|
|
74
76
|
'_trace_data', '_console_output', '_original_print', '_target_function',
|
|
75
77
|
'_MIRROR_PRINT_TO_WORKER_CONSOLE', '_MINIMAL_TRACE', '_SKIP_SENTINEL',
|
|
@@ -85,7 +87,8 @@ _internal_locals = {
|
|
|
85
87
|
'__tracecode_record_access', '__tracecode_flush_accesses', '__tracecode_normalize_indices',
|
|
86
88
|
'__tracecode_make_access_event', '__tracecode_read_value', '__tracecode_write_value',
|
|
87
89
|
'__tracecode_apply_augmented_value', '_tracecode_read_index', '_tracecode_write_index',
|
|
88
|
-
'_tracecode_augassign_index', '_tracecode_mutating_call', '
|
|
90
|
+
'_tracecode_augassign_index', '_tracecode_mutating_call', '_tracecode_collapsed_literal_lines',
|
|
91
|
+
'_tracecode_is_pure_literal_scaffold', '_tracecode_collect_collapsed_literal_lines', '__tracecode_attach_parents',
|
|
89
92
|
'_tracecode_extract_named_subscript', '__TracecodeAccessTransformer', '__tracecode_compile_user_code',
|
|
90
93
|
'_InfiniteLoopDetected', '_tb', '_result', '_exc_type', '_exc_msg', '_exc_tb',
|
|
91
94
|
'_error_line', '_solver', '_ops', '_args', '_cls', '_instance', '_out',
|
|
@@ -93,7 +96,7 @@ _internal_locals = {
|
|
|
93
96
|
'_globals_dict', '_k', '_preserve', '_real_globals', '_real_list',
|
|
94
97
|
'__tracecode_tree', '__tracecode_compiled'
|
|
95
98
|
}
|
|
96
|
-
_max_trace_steps = ${
|
|
99
|
+
_max_trace_steps = ${effectiveMaxTraceSteps}
|
|
97
100
|
_trace_limit_exceeded = False
|
|
98
101
|
_timeout_reason = None
|
|
99
102
|
_total_line_events = 0
|
|
@@ -630,6 +633,49 @@ def __tracecode_compile_user_code(source):
|
|
|
630
633
|
ast.fix_missing_locations(tree)
|
|
631
634
|
return compile(tree, '<user_code>', 'exec')
|
|
632
635
|
|
|
636
|
+
def _tracecode_is_pure_literal_scaffold(node):
|
|
637
|
+
if isinstance(node, (ast.Constant, ast.Name)):
|
|
638
|
+
return True
|
|
639
|
+
if isinstance(node, ast.UnaryOp):
|
|
640
|
+
return _tracecode_is_pure_literal_scaffold(node.operand)
|
|
641
|
+
if isinstance(node, ast.BinOp):
|
|
642
|
+
return _tracecode_is_pure_literal_scaffold(node.left) and _tracecode_is_pure_literal_scaffold(node.right)
|
|
643
|
+
if isinstance(node, (ast.List, ast.Tuple, ast.Set)):
|
|
644
|
+
return all(_tracecode_is_pure_literal_scaffold(elt) for elt in node.elts)
|
|
645
|
+
if isinstance(node, ast.Dict):
|
|
646
|
+
return all(
|
|
647
|
+
(key is None or _tracecode_is_pure_literal_scaffold(key)) and _tracecode_is_pure_literal_scaffold(value)
|
|
648
|
+
for key, value in zip(node.keys, node.values)
|
|
649
|
+
)
|
|
650
|
+
return False
|
|
651
|
+
|
|
652
|
+
def _tracecode_collect_collapsed_literal_lines(source):
|
|
653
|
+
try:
|
|
654
|
+
tree = ast.parse(source, filename='<user_code>', mode='exec')
|
|
655
|
+
except Exception:
|
|
656
|
+
return set()
|
|
657
|
+
|
|
658
|
+
collapsed_lines = set()
|
|
659
|
+
for node in ast.walk(tree):
|
|
660
|
+
statement_line = getattr(node, 'lineno', None)
|
|
661
|
+
value = None
|
|
662
|
+
if isinstance(node, ast.Assign):
|
|
663
|
+
value = node.value
|
|
664
|
+
elif isinstance(node, ast.AnnAssign):
|
|
665
|
+
value = node.value
|
|
666
|
+
elif isinstance(node, ast.Return):
|
|
667
|
+
value = node.value
|
|
668
|
+
if value is None or statement_line is None:
|
|
669
|
+
continue
|
|
670
|
+
end_line = getattr(value, 'end_lineno', None)
|
|
671
|
+
if end_line is None or end_line <= statement_line:
|
|
672
|
+
continue
|
|
673
|
+
if not _tracecode_is_pure_literal_scaffold(value):
|
|
674
|
+
continue
|
|
675
|
+
for line in range(statement_line + 1, end_line + 1):
|
|
676
|
+
collapsed_lines.add(line)
|
|
677
|
+
return collapsed_lines
|
|
678
|
+
|
|
633
679
|
def _stable_token(value):
|
|
634
680
|
try:
|
|
635
681
|
return json.dumps(value, sort_keys=True)
|
|
@@ -873,6 +919,8 @@ def _tracer(frame, event, arg):
|
|
|
873
919
|
|
|
874
920
|
# Fast counter for any loops
|
|
875
921
|
if event == 'line':
|
|
922
|
+
if frame.f_code.co_filename == '<user_code>' and frame.f_lineno in _tracecode_collapsed_literal_lines:
|
|
923
|
+
return _tracer
|
|
876
924
|
_total_line_events += 1
|
|
877
925
|
|
|
878
926
|
# Check total line events
|
|
@@ -1094,6 +1142,7 @@ print = _custom_print
|
|
|
1094
1142
|
`\n_user_code_str = """${escapedCode}"""`,
|
|
1095
1143
|
`import textwrap as _textwrap`,
|
|
1096
1144
|
`_user_code_str = _textwrap.dedent(_user_code_str.lstrip("\\n"))`,
|
|
1145
|
+
`_tracecode_collapsed_literal_lines = _tracecode_collect_collapsed_literal_lines(_user_code_str)`,
|
|
1097
1146
|
`__tracecode_compiled = __tracecode_compile_user_code(_user_code_str)`,
|
|
1098
1147
|
].join('\n');
|
|
1099
1148
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|