Files
RustAst/examples/destructuring.myc
T
Michael Schimmel 2e8d5284c2 Feat: Enable nested destructuring optimization
This commit introduces optimizations for nested destructuring, allowing
tuples and records to be flattened and matched directly against function
arguments. This significantly improves performance by enabling more
constant folding and reducing intermediate allocations.

The changes include:
- Modifying the `Binder` to correctly count nested parameters.
- Enhancing `flatten_tuple` in the `Optimizer` to handle records and NOP
  nodes.
- Updating `map_params_to_args` to recursively destructure nested
  compound arguments.
- Adding integration tests to verify the correctness of tuple-to-tuple
  and record-to-tuple destructuring optimizations.
2026-02-22 16:34:40 +01:00

28 lines
692 B
Plaintext

;; Benchmark: 969ns
;; Benchmark-Repeat: 2078
;; Comprehensive Destructuring Test
;; Covers: Nested tuples, mixed params, dynamic passing
(do
;; 1. Deeply nested
(def deep (fn [[a [[b c] d]]] (+ a (+ b (+ c d)))))
;; 2. Mixed: Tuple and Single
(def mixed (fn [[x y] z] (+ (+ x y) z)))
;; 3. Dynamic: Passing a list variable
(def call-dynamic (fn [f data] (f data)))
(def data [10 [20 30]])
;; Validation
(if (= (deep [1 [[2 3] 4]]) 10)
(if (= (mixed [1 2] 3) 6)
(if (= (call-dynamic (fn [[a [b c]]] (+ a (+ b c))) data) 60)
"PASS"
"FAIL-DYNAMIC")
"FAIL-MIXED")
"FAIL-DEEP"))
;; Output: "PASS"