Add Op::PushCsgWrap: eliminate union/difference/intersection's native reentry - #67
Merged
Conversation
… reentry A recursive call wrapped in union()/difference()/intersection() still fell to Op::NativeStatement, costing one real native C++ frame per level and capping recursion at kMaxDriveVmNativeDepth=40 -- the same Windows-crash risk Op::PushBuiltinWrap already closed for translate/rotate/scale/mirror/ multmatrix/resize/color/#/%/! and Op::CallChildren closed for children(). These three were left out because resolveCsg needs per-top-level-child "group_sizes" bookkeeping that a single flat bracket can't represent. Op::PushCsgWrap/CsgGroupStart/CsgGroupEnd/PopCsgWrap replicate resolveCsg's own two-pass shape (every assignment evaluated first, then one group per geometry statement) as inline compiled bytecode, so a wrapped recursive call now compiles straight to Op::CallModule -- zero native stack cost, bounded only by the heap-sized kMaxVmCallStackDepth.
This was referenced Aug 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
union()/difference()/intersection()were the last construct still falling toOp::NativeStatementwhen they wrap a recursive call, capping recursion atkMaxDriveVmNativeDepth=40(the same Windows native-reentry riskOp::PushBuiltinWrap(Close the NativeStatement gap for translate/color/modifier-wrapped recursion #63) andOp::CallChildren(Add Op::CallChildren: eliminate children()'s native reentry #66) already closed for every other builtin-with-children).Op::PushBuiltinWrapbecauseresolveCsgneeds per-top-level-child "group_sizes" bookkeeping a single flat bracket can't represent (e.g.difference(){ A; B; C; }= A − (B∪C), even whenAitself expands to more than one body).Op::PushCsgWrap/CsgGroupStart/CsgGroupEnd/PopCsgWrapreplicateresolveCsg's own two-pass shape (all assignments first, then one group per geometry statement) as inline compiled bytecode. A wrapped recursive call now compiles straight toOp::CallModule— zero native stack cost, bounded only by the heap-sizedkMaxVmCallStackDepth(1,000,000) instead of 40.Test plan
OSCAD_BYTECODE_VMon (default) and off (OSCAD_BYTECODE_VM=0), up from 721 (6 new tests).kMaxCsgTreeDepth=2000still errors cleanly (now via the correct, orthogonal guard);$-named-arg propagation into a compiled CSG wrap's children; assignment-before-geometry-statement ordering preserved; group_sizes/multi-body-operand grouping correctness inside a compiled module body.examples/fractal_tree.scad(deepattach()/attachable()recursion, exercising union/difference through BOSL2's own internals) renders cleanly via the VM path.🤖 Generated with Claude Code