| 1 | module scheme |
| 2 | |
| 3 | // This is a backend admission probe. The semantic cases are separate and must |
| 4 | // pass on the unchanged baseline; this assertion is expected to fail there. |
| 5 | fn test_native_private_wind_admission_runs_complete_private_loop() { |
| 6 | mut vm := new_with_options(Options{max_steps: 0, max_frames: 0})! |
| 7 | vm.eval('(define (work n) (let ((sum 0)) (let loop ((i 0)) |
| 8 | (if (= i n) sum (begin |
| 9 | (dynamic-wind (lambda () (set! sum (+ sum 1))) |
| 10 | (lambda () (set! sum (+ sum 2))) |
| 11 | (lambda () (set! sum (+ sum 4)))) |
| 12 | (loop (+ i 1)))))))')! |
| 13 | vm.with_native_execution(fn (mut vm VM) !Value { |
| 14 | assert vm.call(vm.lookup('work')!, [integer(17)])!.whole() == 119 |
| 15 | scope := unsafe { &NativeScope(vm.native_execution_scope) } |
| 16 | root := vm.lookup('work')!.procedure_pointer().function |
| 17 | assert scope.plans.any(voidptr(it.root) == voidptr(root) && !it.disabled) |
| 18 | assert scope.hits == 1 && scope.deopts == 0 |
| 19 | return unspecified() |
| 20 | })! |
| 21 | } |
| 22 | |
| 23 | fn test_native_private_wind_admission_keeps_callback_internal_loop() { |
| 24 | mut vm := new_with_options(Options{max_steps: 0, max_frames: 0})! |
| 25 | vm.eval('(define (work n) (let ((state 0)) |
| 26 | (let ((answer (dynamic-wind |
| 27 | (lambda () (set! state 1)) |
| 28 | (lambda () (let loop ((i n) (total 0)) |
| 29 | (if (= i 0) total (loop (- i 1) (+ total i))))) |
| 30 | (lambda () (set! state 4))))) (+ (* answer 10) state))))')! |
| 31 | vm.with_native_execution(fn (mut vm VM) !Value { |
| 32 | assert vm.call(vm.lookup('work')!, [integer(10)])!.whole() == 554 |
| 33 | scope := unsafe { &NativeScope(vm.native_execution_scope) } |
| 34 | root := vm.lookup('work')!.procedure_pointer().function |
| 35 | assert scope.plans.any(voidptr(it.root) == voidptr(root) && !it.disabled) |
| 36 | assert scope.hits == 1 && scope.deopts == 0 |
| 37 | return unspecified() |
| 38 | })! |
| 39 | } |
| 40 | |