You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🔴 Bug: Implicit parameter leaks into nested functions — If current_func is a nested function, a variable from an outer scope (e.g., a closure) will be added as a parameter of the inner function on first access. This breaks encapsulation and likely produces invalid DSL. Suggestion: Ensure _resolve only treats undiscovered names as parameters when they belong to the current function’s own scope, not to an outer one. Consider using a symbol table that tracks scopes before falling back to “create parameter”.
🟡 Potential duplicate parameter — If current_func.params is populated before this code runs (e.g., from an explicit function signature), the variable will not be re-added because _vars already contains it. But if the order is reversed, or if _vars is cleared between calls, the same variable could be appended to params multiple times. Suggestion: Add a guard: if v not in current_func.params before appending.
💭 Test coverage — This change alters the semantics of how function inputs are resolved. Ensure unit tests cover:
A variable used inside a function that is not declared in its signature becomes an implicit parameter.
Inside a nested function, outer variables are NOT added to the inner function’s parameters.
Variables used multiple times inside the same function are not added twice.
📁 scratchv/frontend/onnx_parser.py
🟡 Missing global registration for scalar initializers — The if arr.ndim != 0: branch now adds val to self.builder.program.global_values, but scalar initializers (ndim == 0) are not added. If scalars are also expected to be tracked globally, they should be added in the corresponding else branch. If they are intentionally excluded (e.g., because they are stored as constants elsewhere), add a comment to clarify the reasoning and avoid future confusion.
💭 help 文本可进一步明确 — 原描述“before and after optimization”改为“throughout the compiler pipeline”更准确,但若实际只在特定阶段运行,建议与实现同步。可考虑更精确的措辞,例如“Run IR verifier at key pipeline stages (pre-opt, post-opt, final)”。
📁 tests/test_ir_verifier.py
🔴 test_empty_block_falls_through_for_dominance — Line 299: creates a gap block with no terminator, then verifies. If the verifier requires every block to have a terminator (block-termination rule is ERROR level), verify_ir will return passed=False and the test fails. The test currently assumes empty blocks are allowed and fall through, but this is not guaranteed. Either add a BR target to gap, or explicitly expect a block-termination warning/error.
🟡 test_duplicate_block_labels_are_rejected — Line 338: directly creates BasicBlock("duplicate") objects and extends func.blocks without an entry block. This may cause an unrelated "entry-existence" error, which doesn't affect the label check but pollutes the test. Consider adding a real entry block first to keep the test focused.
🟡 Code duplication — make_warning_only_program() is defined at line 87 but never used. test_verify_ir_allows_warning_only_program (line 728) manually constructs the same program. Reuse the helper to reduce duplication.
💭 Fragile mock for ONNX — test_onnx_tensor_initializer_is_a_program_global (line 840) stubs sys.modules["onnx"] with a SimpleNamespace that only provides load and numpy_helper. If ONNXParser.parse internally references other attributes (e.g., onnx.TensorProto, onnx.GraphProto), the test will break. Consider using a more robust fixture (e.g., unittest.mock.patch with a real ONNX model string) or adding a note about the stubbed interface.
💭 Monkeypatching IRVerifier.verify — test_verifies_after_every_optimization_pass (line 790) patches IRVerifier.verify globally. This can interfere with other tests if they run in the same process (e.g., if tests are not isolated). While monkeypatch is fixture-scoped, it's worth noting that the patch is broad and could affect concurrent test runs. Consider using a more targeted approach (e.g., subclassing IRVerifier).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--verify-irintoCompilerConfigand verify after parsing, after every optimization pass, and before code generationVerification
python -m pytest tests/test_ir_verifier.py -q— 44 passedpython -m pytest tests -q --ignore=tests/test_simulator.py --deselect=tests/test_inst_counter.py::TestCompareFiles::test_compare_two_files— 364 passed, 4 skipped, 1 deselectedgit diff --checkNotes
NamedTemporaryFilehandle issue intest_compare_two_files; it is unrelated to this change.