Conversation
Phase 2c: Effect-based tracking
Added a compile-time check that quotations with Yield effect cannot be called directly with call - they must be wrapped with strand.weave.
Changes made:
1. crates/compiler/src/typechecker.rs:
- Added check_call_yield_effect() method (~20 lines)
- Integrated check into infer_word_call() for call
- Added 3 new tests:
- test_call_yield_quotation_error - calling yield quotation fails
- test_strand_weave_yield_quotation_ok - strand.weave on yield quotation succeeds
- test_call_pure_quotation_ok - calling pure quotation succeeds
Error message:
Cannot call quotation with Yield effect directly.
Quotations that yield values must be wrapped with `strand.weave`.
Example: `[ yielding-code ] strand.weave` instead of `[ yielding-code ] call`
Issue #142 is now substantially complete:
- ✅ Phase 2a: Single-word data flow analysis
- ✅ Phase 2b: Cross-word analysis
- ✅ Phase 2c: Effect-based tracking (Yield → strand.weave requirement)
All 224 Rust tests and 123 integration tests pass.
PR Review: Phase 2c Effect-based TrackingSummaryThis PR adds a compile-time check that prevents calling quotations with Yield effects directly with ✅ Strengths1. Clean, Minimal ImplementationThe core logic in
2. Excellent Test CoverageThree well-designed tests cover the key scenarios:
Each test includes clear comments explaining the scenario and expected behavior. 3. User-Friendly Error MessagesThe error message at line 976-979 is exemplary:
4. Proper Integration
🔍 Observations & Questions1. Stack Cloning (Line 968)if let Some((_rest, top_type)) = stack.clone().pop() {Minor performance consideration: The 2. Consistency with Other Call-like OperationsThe check is applied specifically to
Question: Is the intent that:
If #1, this is correct. If #2, we might need additional checks. Based on issue #142's goals, restricting just 3. Potential Edge CasesWhat happens in these scenarios? Case A: Indirect call through closure Case B: Yield quotation stored and called later I suspect Case B might not be caught since the Yield effect may not propagate through the returned quotation type from 4. Error Reporting LocationThe error doesn't reference a 🎯 Suggestions (Optional Enhancements)1. Add Documentation CommentConsider expanding the doc comment on /// Check if `call` is being applied to a quotation with Yield effects.
///
/// Quotations with Yield must be wrapped in strand.weave to handle the yields.
/// This prevents runtime errors where yielding code is executed in a non-strand context.
///
/// # Rationale
/// Direct calls to yielding quotations would attempt to yield outside of a strand,
/// which is undefined behavior. strand.weave sets up the necessary runtime context.
2. Consider Additional Test CasesTo ensure robustness: // Test: Closure with Yield (not just Quotation)
#[test]
fn test_call_yield_closure_error() {
// Verify that Closures with Yield effects are also caught
}
// Test: Empty stack case
#[test]
fn test_call_empty_stack() {
// Ensure graceful handling when call is used with empty stack
// (Should fail with type error, not panic)
}3. Integration TestAdd a 🔒 Security & Safety✅ No security concerns identified 🚀 Performance✅ Compile-time check only—zero runtime overhead 📝 Code Quality
Final Verdict✅ APPROVE - This PR successfully implements Phase 2c as specified in issue #142. The code is clean, well-tested, and integrates smoothly with the existing type system. The suggested enhancements are minor improvements, not blockers. Recommendation: Merge after considering whether the edge cases in observation #3 need to be addressed (they may be out of scope for this phase). Great work completing Phase 2c! The progression from pattern-based linting to effect-based compile-time checking is a significant improvement in safety guarantees. 🎉 |
Phase 2c: Effect-based tracking
Added a compile-time check that quotations with Yield effect cannot be called directly with call - they must be wrapped with strand.weave.
Changes made:
- Added check_call_yield_effect() method (~20 lines)
- Integrated check into infer_word_call() for call
- Added 3 new tests:
Error message:
Cannot call quotation with Yield effect directly.
Quotations that yield values must be wrapped with
strand.weave.Example:
[ yielding-code ] strand.weaveinstead of[ yielding-code ] callIssue #142 is now substantially complete:
All 224 Rust tests and 123 integration tests pass.