More closure types allowed in capture and better error messages for t…#33
More closure types allowed in capture and better error messages for t…#33
Conversation
…he ones we do not support Variant capture: Error: Variant captures are not yet supported. Capturing Variants in closures requires additional implementation. Supported capture types: Int, Bool, Float, String, Quotation. Closure capture (nested closures): Error: Closure captures are not yet supported. Closures capturing other closures require additional implementation. Supported capture types: Int, Bool, Float, String, Quotation. Summary of closure capture work completed: | Type | Status | Notes | |-----------|---------------|----------------------------------| | Int | ✅ Supported | env_get_int returns i64 | | Bool | ✅ Supported | env_get_bool returns i64 (0/1) | | Float | ✅ Supported | env_get_float returns f64 | | String | ✅ Supported | env_get_string returns SeqString | | Quotation | ✅ Supported | env_get_quotation returns fn ptr | | Variant | ❌ Clear error | Compound type, deferred | | Closure | ❌ Clear error | Nested closures, deferred |
Pull Request Review: Closure Capture Type ExpansionSummaryThis PR extends closure capture support from just Int and String to include Bool, Float, and Quotation types. The implementation is well-structured with matching changes across the compiler's codegen and runtime layers, plus comprehensive test coverage. ✅ StrengthsCode Quality
Architecture
Testing
Documentation
🔍 Issues & Concerns1. Potential Type Mismatch Issue (Minor)Location: The Bool capture handler retrieves a bool as i64 but then pushes it using Type::Bool => {
// Bool is stored as i64 (0 or 1)
let bool_var = self.fresh_temp();
writeln!(
&mut self.output,
" %{} = call i64 @patch_seq_env_get_bool(ptr %env_data, i64 %env_len, i32 {})",
bool_var, index
)
.unwrap();
let new_stack_var = self.fresh_temp();
writeln!(
&mut self.output,
" %{} = call ptr @patch_seq_push_int(ptr %{}, i64 %{})", // ⚠️ push_int for Bool
new_stack_var, stack_var, bool_var
)
.unwrap();
stack_var = new_stack_var;
}Concern: This pushes the bool value as an
Recommendation: Either:
2. Missing Quotation Push Function Declaration (Potential Bug)Location: The codegen declares the new getter functions: writeln!(&mut ir, "declare i64 @patch_seq_env_get_bool(ptr, i64, i32)").unwrap();
writeln!(&mut ir, "declare double @patch_seq_env_get_float(ptr, i64, i32)").unwrap();
writeln!(&mut ir, "declare i64 @patch_seq_env_get_quotation(ptr, i64, i32)").unwrap();But at line 496, the code calls: writeln!(
&mut self.output,
" %{} = call ptr @patch_seq_push_quotation(ptr %{}, i64 %{})",
new_stack_var, stack_var, fn_ptr_var
)Concern: I don't see Recommendation: Verify that writeln!(&mut ir, "declare ptr @patch_seq_push_quotation(ptr, i64)").unwrap();3. Redundant
|
Issue 1: Bool push as Int ✅ Intentional - Line 632-637 shows BoolLiteral also uses push_int with 0/1 - This is a consistent design decision - bools are represented as integers at runtime - No change needed Issue 2: push_quotation declaration ✅ Already declared - Line 238: declare ptr @patch_seq_push_quotation(ptr, i64) exists - No issue here Issue 3: #[unsafe(no_mangle)] syntax ✅ Correct for Rust 2024 - This is the modern syntax requiring explicit unsafe marking on attributes - Used consistently throughout the codebase - Compiles fine - no change needed Issue 4: Integration test automation ✅ Already covered - just ci compiles all examples including test-closure-captures.seq - Visible in CI output: Compiling examples/test-closure-captures.seq... Issue 5: Float epsilon ✅ Already fixed - Changed from pi/e approximations to 1.234/5.678 Issue 6: Variant detection via string prefix⚠️ Valid but acceptable - The reviewer is right that starts_with("Variant") is fragile - However, Variant isn't a direct Type enum variant - it's represented as Type::Var("Variant$N") - This is a known limitation that could be improved later Verdict: The PR is ready to merge. All critical issues from the review are either already addressed or are intentional design decisions.
PR Review: Closure Capture Type SupportSummaryThis PR adds support for capturing Bool, Float, and Quotation types in closures, significantly expanding closure functionality. The implementation is well-structured and follows existing patterns consistently. ✅ StrengthsCode Quality
Design Decisions
|
…he ones we do not support
Variant capture:
Error: Variant captures are not yet supported. Capturing Variants in closures requires additional implementation. Supported capture types: Int, Bool, Float, String, Quotation.
Closure capture (nested closures):
Error: Closure captures are not yet supported. Closures capturing other closures require additional implementation. Supported capture types: Int, Bool, Float, String, Quotation.
Summary of closure capture work completed: