Skip to content

Commit e86eae6

Browse files
authored
flambda2-types: Do not lose array information if a field is unknown (#3839)
1 parent 6a0e91e commit e86eae6

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

middle_end/flambda2/types/meet_and_join.ml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,17 +1807,14 @@ and join_array_contents env (array_contents1 : TG.array_contents Or_unknown.t)
18071807
else
18081808
match joined_element_kind with
18091809
| Bottom | Unknown -> Unknown
1810-
| Ok _ -> (
1811-
let exception Unknown_result in
1812-
try
1813-
let fields =
1814-
Array.init (Array.length fields1) (fun idx ->
1815-
match join env fields1.(idx) fields2.(idx) with
1816-
| Unknown -> raise Unknown_result
1817-
| Known ty -> ty)
1818-
in
1819-
Known (TG.Immutable { fields })
1820-
with Unknown_result -> Unknown)))
1810+
| Ok _ ->
1811+
let fields =
1812+
Array.init (Array.length fields1) (fun idx ->
1813+
match join env fields1.(idx) fields2.(idx) with
1814+
| Unknown -> MTC.unknown_like fields1.(idx)
1815+
| Known ty -> ty)
1816+
in
1817+
Known (TG.Immutable { fields })))
18211818
env array_contents1 array_contents2
18221819

18231820
and join_variant env ~(blocks1 : TG.Row_like_for_blocks.t Or_unknown.t)

middle_end/flambda2/types/meet_and_n_way_join.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,18 +2088,19 @@ and n_way_join_array_contents env
20882088
| Bottom | Unknown -> Unknown, env
20892089
| Ok _ -> (
20902090
let exception Unknown_result in
2091-
try
2092-
let other_fields =
2093-
List.fold_left
2094-
(fun acc (id, array_content) ->
2095-
match (array_content : TG.array_contents) with
2096-
| Mutable -> raise Unknown_result
2097-
| Immutable { fields = other_fields } ->
2098-
if Array.length other_fields <> Array.length first_fields
2099-
then raise Unknown_result
2100-
else (id, other_fields) :: acc)
2101-
[] array_contents
2102-
in
2091+
match
2092+
List.fold_left
2093+
(fun acc (id, array_content) ->
2094+
match (array_content : TG.array_contents) with
2095+
| Mutable -> raise Unknown_result
2096+
| Immutable { fields = other_fields } ->
2097+
if Array.length other_fields <> Array.length first_fields
2098+
then raise Unknown_result
2099+
else (id, other_fields) :: acc)
2100+
[] array_contents
2101+
with
2102+
| exception Unknown_result -> Unknown, env
2103+
| other_fields ->
21032104
let env_ref = ref env in
21042105
let fields =
21052106
Array.init (Array.length first_fields) (fun idx ->
@@ -2111,13 +2112,12 @@ and n_way_join_array_contents env
21112112
other_id, other_fields.(idx))
21122113
other_fields)
21132114
with
2114-
| Unknown, _ -> raise Unknown_result
2115+
| Unknown, _ -> MTC.unknown_like first_fields.(idx)
21152116
| Known ty, env ->
21162117
env_ref := env;
21172118
ty)
21182119
in
2119-
Known (TG.Immutable { fields }), !env_ref
2120-
with Unknown_result -> Unknown, env)))
2120+
Known (TG.Immutable { fields }), !env_ref)))
21212121
env array_contents
21222122

21232123
and n_way_join_variant env

0 commit comments

Comments
 (0)