Skip to content

Commit

Permalink
update to fix cases of no discriminants
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWhiting committed Jul 12, 2024
1 parent f8d000e commit 7a4b5ee
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Core/MatchMerge.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ splitBranchConstructors' b@(Branch ps _) branches =
-- ++ show (vcat (text (show accP) : map (text . show) ps'))
-- ++ "\nis\n" ++ show (vcat (map (text . show) patNews))
-- ++ "\nwith new discriminators" ++ show newVars ++ "\n") $ return ()
if all isSimpleMatch patNews then
if all isSimpleMatch patNews || all null newVars then -- If there are no discriminators we assume they don't match because the guard distinguishes
-- Didn't match the current branch (i.e. returned a trivial common superstructure - just wildcards / vars), keep the old pattern
-- Add the new branch to the list of branches that don't match any subpattern
return (bs', b':bs2', matchAnys, discriminators, accP)
Expand Down
2 changes: 1 addition & 1 deletion test/parc/parc15.kk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fun test(xs:list<int>, y:int) {
match(xs) {
Cons(x as 0) ->
Cons(x) ->
/* dup x; drop y */
match(xs) {
Cons -> /* drop xs */ x
Expand Down
19 changes: 8 additions & 11 deletions test/parc/parc15.kk.out
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import std/core = std/core = "";
pub fun test : (xs : list<int>, y : int) -> int
= fn(xs: list<int>, y: int){
match (xs) {
(std/core/types/Cons(((@skip std/core/types/@Box((@case40: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
(std/core/types/Cons(((@skip std/core/types/@Box((x: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
-> val _ : int
= std/core/types/@dup(@case40);
= std/core/types/@dup(x);
val _ : ()
= std/core/types/@drop(y);
(match (@case40) {
0
-> (match (xs) {
(match (xs) {
(std/core/types/Cons(((@skip std/core/types/@Box((@pat@xxx: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
-> val _ : ()
= (match ((std/core/types/@is-unique(xs))) {
Expand All @@ -47,14 +45,16 @@ pub fun test : (xs : list<int>, y : int) -> int
= std/core/types/@dec-ref(xs);
std/core/types/Unit;
});
@case40;
x;
(@skip std/core/types/Nil() : (list<int>) )
-> val _ : ()
= std/core/types/@drop(@case40);
= std/core/types/@drop(x);
2;
});
_
(std/core/types/Cons(((@skip std/core/types/@Box((@pat@xxx: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
-> val _ : ()
= std/core/types/@drop(y);
val _ : ()
= (match ((std/core/types/@is-unique(xs))) {
(std/core/types/True() : bool )
-> val _ : ()
Expand All @@ -71,10 +71,7 @@ pub fun test : (xs : list<int>, y : int) -> int
= std/core/types/@dec-ref(xs);
std/core/types/Unit;
});
val _ : ()
= std/core/types/@drop(@case40);
2;
});
(@skip std/core/types/Nil() : (list<int>) )
-> y;
};
Expand Down
2 changes: 1 addition & 1 deletion test/parc/parc16.kk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fun test(xs:list<int>, y:int, z:int) {
// drop z
match(xs) {
Cons(x as 0) ->
Cons(x) ->
// dup x; drop y
match(xs) {
Cons -> /* drop xs */ x
Expand Down
19 changes: 8 additions & 11 deletions test/parc/parc16.kk.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ pub fun test : (xs : list<int>, y : int, z : int) -> int
val _ : ()
= std/core/types/@drop(z);
match (xs) {
(std/core/types/Cons(((@skip std/core/types/@Box((@case40: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
(std/core/types/Cons(((@skip std/core/types/@Box((x: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
-> val _ : int
= std/core/types/@dup(@case40);
= std/core/types/@dup(x);
val _ : ()
= std/core/types/@drop(y);
(match (@case40) {
0
-> (match (xs) {
(match (xs) {
(std/core/types/Cons(((@skip std/core/types/@Box((@pat@xxx: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
-> val _ : ()
= (match ((std/core/types/@is-unique(xs))) {
Expand All @@ -49,14 +47,16 @@ pub fun test : (xs : list<int>, y : int, z : int) -> int
= std/core/types/@dec-ref(xs);
std/core/types/Unit;
});
@case40;
x;
(@skip std/core/types/Nil() : (list<int>) )
-> val _ : ()
= std/core/types/@drop(@case40);
= std/core/types/@drop(x);
2;
});
_
(std/core/types/Cons(((@skip std/core/types/@Box((@pat@xxx: int)) : @Box ) as @box-xxx: @Box), (@pat@xxx: list<int>)) : list<int> )
-> val _ : ()
= std/core/types/@drop(y);
val _ : ()
= (match ((std/core/types/@is-unique(xs))) {
(std/core/types/True() : bool )
-> val _ : ()
Expand All @@ -73,10 +73,7 @@ pub fun test : (xs : list<int>, y : int, z : int) -> int
= std/core/types/@dec-ref(xs);
std/core/types/Unit;
});
val _ : ()
= std/core/types/@drop(@case40);
2;
});
(@skip std/core/types/Nil() : (list<int>) )
-> y;
};
Expand Down

0 comments on commit 7a4b5ee

Please sign in to comment.