Commit e2794c9
authored
Aiur: support non-tail match on a non-variable scrutinee (#435)
The match compiler hoists a non-variable match scrutinee into a fresh
let (MatchCompiler.switch), so `let x = match foo(bar) {..}` simplified
to `let x = (let w = foo(bar); match w {..})`. That buried the match one
let deep, where Lower's non-tail-match detector — which only fires when a
match is the immediate letVar/letWild RHS — couldn't see it, and lowering
threw "Non-tail match in arbitrary position (not supported)".
Fix in the Simple stage: mkLetFloating floats leading lets out of a
let-RHS (`let x = (let w = e; rest); b` -> `let w = e; let x = rest; b`),
restoring the invariant that a non-tail match sits directly in its
letVar/letWild RHS. The hoisted w's are fresh match-compiler locals, so
widening their scope cannot capture anything.
Tests: ntm_match_on_call exercises a function-call scrutinee, folded into
the non_tail_match aggregate in both the aiur and aiur-cross suites.1 parent 3fe83fe commit e2794c9
3 files changed
Lines changed: 47 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
30 | 48 | | |
31 | 49 | | |
32 | 50 | | |
| |||
38 | 56 | | |
39 | 57 | | |
40 | 58 | | |
41 | | - | |
| 59 | + | |
42 | 60 | | |
43 | 61 | | |
44 | 62 | | |
45 | | - | |
| 63 | + | |
46 | 64 | | |
47 | 65 | | |
48 | 66 | | |
| |||
52 | 70 | | |
53 | 71 | | |
54 | 72 | | |
55 | | - | |
| 73 | + | |
56 | 74 | | |
57 | 75 | | |
58 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
555 | 564 | | |
556 | 565 | | |
557 | 566 | | |
| |||
777 | 786 | | |
778 | 787 | | |
779 | 788 | | |
| 789 | + | |
| 790 | + | |
780 | 791 | | |
781 | | - | |
| 792 | + | |
782 | 793 | | |
783 | 794 | | |
784 | 795 | | |
| |||
935 | 946 | | |
936 | 947 | | |
937 | 948 | | |
938 | | - | |
939 | | - | |
| 949 | + | |
| 950 | + | |
940 | 951 | | |
941 | 952 | | |
942 | 953 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
544 | 553 | | |
545 | 554 | | |
546 | 555 | | |
| |||
1058 | 1067 | | |
1059 | 1068 | | |
1060 | 1069 | | |
| 1070 | + | |
| 1071 | + | |
1061 | 1072 | | |
1062 | | - | |
| 1073 | + | |
1063 | 1074 | | |
1064 | 1075 | | |
1065 | 1076 | | |
| |||
0 commit comments