⏺ All 867 tests pass (294 in compiler, up from 293 with the new regre… #339
No reviewers
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq!339
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "i-338"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
…ssion test).
https://github.com/navicore/patch-seq/issues/338
Summary: Bug #338 Fix
Root Cause: In codegen_word_call (statements.rs), when a user-defined word with a specialized version (like edit-done returning i64) was called in tail
position within an if-then branch:
The Fix: Added a check in codegen_word_call (lines 22-35 in statements.rs) to determine if we would be in a tail call position for a user-defined word
before trying specialized dispatch. If so, skip specialized dispatch and use the normal tail call path which properly emits musttail + ret.
// Check if this would be a tail call position for a user-defined word.
// If so, skip specialized dispatch - we need the tail call path to emit
// musttail + ret for proper TCO. (Issue #338)
let is_seq_word = !BUILTIN_SYMBOLS.contains_key(name) ...;
let would_tail_call = position == TailPosition::Tail && is_seq_word && ...;
if !would_tail_call {
if let Some(result) = self.try_specialized_dispatch(...) { ... }
}
Files Changed:
Code Review for PR #339
Summary
This PR fixes issue #338 where invalid LLVM IR was generated when a specialized function was called in tail position within an if-then branch. The fix correctly prioritizes tail call optimization over specialized dispatch.
✅ Code Quality & Best Practices
Strong Points:
would_tail_callclearly expresses intent and mirrors the existingcan_tail_callpattern used later in the functionwould_tail_callmirror those incan_tail_call(lines 81-85), maintaining consistencyCode Structure:
codegen_word_callin statements.rs:28-47✅ Bug Fix Validation
The Fix is Correct:
The logic correctly identifies when specialized dispatch should be skipped:
This matches the exact conditions needed for tail calls (statements.rs:81-85), ensuring that when
codegen_branchexpects a terminator (musttail + ret), it will actually be emitted.Why This Works:
will_emit_tail_call(words.rs:431-468) returnstruefor user-defined words in tail positioncodegen_branch(words.rs:389) sees this and expects the branch to emit its own terminatortry_specialized_dispatchwould intercept and emit onlycall i64 @func()without a terminatormusttail call + ret✅ Test Coverage
Excellent Regression Test:
The test at mod.rs:1158-1269 is comprehensive:
@seq_get_value_i64)musttail call tailcc ptr @seq_get_value)Test Quality:
✅ Performance Considerations
No Performance Regression:
would_tail_callcheck) are cheap boolean checksTrade-off is Correct:
✅ Security Considerations
No Security Issues:
🔍 Minor Observations
1. Code Duplication (Not Blocking):
The conditions for
would_tail_call(lines 36-40) andcan_tail_call(lines 81-85) are identical. Consider extracting to a helper method to reduce duplication and ensure they stay in sync:Then use:
However, this is a minor style point - the current duplication is clear and the conditions are simple enough.
2. Edge Case Coverage:
The test covers the if-then scenario. Consider if similar issues could occur with:
codegen_branchpath, so likely covered)The existing test suite (867 tests passing) likely covers these, but worth noting.
✅ Final Assessment
Verdict: LGTM ✅
This is a high-quality bug fix:
Recommendation: Approve and merge. The minor duplication point is not worth blocking for - it can be addressed in a future refactoring if desired.
Great work on the thorough root cause analysis and surgical fix! The detailed commit message and test documentation will help future maintainers understand this subtle interaction between specialized dispatch and tail call optimization.
Code Review for PR #339: Fix for Issue #338
Summary
This PR fixes a critical compiler bug where specialized function calls in tail position within if-then branches resulted in invalid LLVM IR due to missing terminator instructions. The fix is well-targeted and includes a comprehensive regression test.
✅ Strengths
Root Cause Analysis: The PR description provides excellent documentation of the problem:
will_emit_tail_callandtry_specialized_dispatchMinimal, Surgical Fix: The change in
statements.rs:28-44is precisely scoped:Comprehensive Test Coverage: The test in
mod.rs:1157-1267is exemplary:get-value) in tail position in an if-then branchCode Quality:
would_tail_call,is_seq_word)🔍 Observations & Questions
Logic Duplication: The
would_tail_callcheck (lines 36-40) duplicates the logic fromcan_tail_call(lines 79-83). This is:Suggestion: Consider extracting to a helper method like
fn can_emit_tail_call(&self, is_seq_word: bool) -> boolto keep the logic DRY. However, this is a minor refactoring opportunity, not a blocker.Test Assertion Precision: The test verifies the presence of
musttail call tailcc ptr @seq_get_value(line 1265), which is excellent. However:@seq_get_value_i64) in the then-branch to more explicitly verify the fix?Edge Case Coverage: The fix handles user-defined words in tail position. Are there similar issues with:
Note: The current code already calls
spill_virtual_stackbefore control flow (control_flow.rs:22, 150), so this may already be handled. Just worth confirming.🔒 Security & Performance
📋 Minor Nits
Line 33: The check
!self.external_builtins.contains_key(name)appears in bothis_seq_worddefinitions (line 33-35 and 66-74). Consider extracting this to a helper method for clarity.Test naming:
test_issue_338_specialized_call_in_if_branch_has_terminatoris descriptive but long. The name accurately describes the test, though.✅ Verdict
LGTM with minor suggestions for future refactoring.
This is a high-quality fix:
The duplicate logic for tail call detection is a minor code smell but doesn't affect correctness. The fix appropriately prioritizes correctness (musttail + ret) over optimization (specialized dispatch) in the specific case where they conflict.
Recommended: Approve and merge. Consider the refactoring suggestions in a follow-up PR if desired.
📝 Test Results Referenced
From PR description: "All 867 tests pass (294 in compiler, up from 293 with the new regression test)"
Excellent - the new test increases coverage without breaking existing functionality.