diff options
-rw-r--r-- | bytecomp/lambda.ml | 2 | ||||
-rw-r--r-- | bytecomp/matching.ml | 6 | ||||
-rw-r--r-- | testsuite/tests/basic/patmatch.ml | 12 | ||||
-rw-r--r-- | testsuite/tests/basic/patmatch.reference | 1 |
4 files changed, 20 insertions, 1 deletions
diff --git a/bytecomp/lambda.ml b/bytecomp/lambda.ml index aa56c31fa..1c82898c6 100644 --- a/bytecomp/lambda.ml +++ b/bytecomp/lambda.ml @@ -204,6 +204,8 @@ let rec same l1 l2 = match (l1, l2) with | Lvar v1, Lvar v2 -> Ident.same v1 v2 + | Lconst (Const_base (Const_string _)), _ -> + false (* do not share strings *) | Lconst c1, Lconst c2 -> c1 = c2 | Lapply(a1, bl1, _), Lapply(a2, bl2, _) -> diff --git a/bytecomp/matching.ml b/bytecomp/matching.ml index b6ba0ac86..5e01d4f4b 100644 --- a/bytecomp/matching.ml +++ b/bytecomp/matching.ml @@ -443,7 +443,9 @@ let pretty_precompiled_res first nexts = -(* A slight attempt to identify semantically equivalent lambda-expressions *) +(* A slight attempt to identify semantically equivalent lambda-expressions, + We could have used Lambda.same, but our goal here is also to + find alpha-equivalent (simple) terms *) exception Not_simple let rec raw_rec env : lambda -> lambda = function @@ -454,6 +456,8 @@ let rec raw_rec env : lambda -> lambda = function end | Lprim (Pfield i,args) -> Lprim (Pfield i, List.map (raw_rec env) args) + | Lconst (Const_base (Const_string _)) -> + raise Not_simple (* do not share strings *) | Lconst _ as l -> l | Lstaticraise (i,args) -> Lstaticraise (i, List.map (raw_rec env) args) diff --git a/testsuite/tests/basic/patmatch.ml b/testsuite/tests/basic/patmatch.ml index 476d23755..e3f1453c0 100644 --- a/testsuite/tests/basic/patmatch.ml +++ b/testsuite/tests/basic/patmatch.ml @@ -155,3 +155,15 @@ let test e b = let () = let r = test Foo false in if r = 0 then printf "PR#5788=Ok\n" + + +(* No string sharing PR#6322 *) +let test x = match x with + | true -> "a" + | false -> "a" + +let () = + let s1 = test true in + let s2 = test false in + s1.[0] <- 'p'; + if s1 <> s2 then printf "PR#6322=Ok\n%!" diff --git a/testsuite/tests/basic/patmatch.reference b/testsuite/tests/basic/patmatch.reference index 069400b10..fbe0167c9 100644 --- a/testsuite/tests/basic/patmatch.reference +++ b/testsuite/tests/basic/patmatch.reference @@ -69,3 +69,4 @@ l([|4;5;6|]) = 15 PR#5992=Ok PR#5788=Ok PR#5788=Ok +PR#6322=Ok |