@@ -504,60 +504,57 @@ let prove_unique_tag_and_size env t
504
504
| None -> Unknown
505
505
| Some (tag , size ) -> Proved (tag, size)
506
506
507
- type variant_proof = {
508
- const_ctors : Target_imm.Set .t ;
507
+ type variant_like_proof = {
508
+ const_ctors : Target_imm.Set .t Or_unknown .t ;
509
509
non_const_ctors_with_sizes : Targetint.OCaml .t Tag.Scannable.Map .t ;
510
510
}
511
511
512
- let prove_variant env t : variant_proof proof_allowing_kind_mismatch =
512
+ let prove_variant_like env t : variant_like_proof proof_allowing_kind_mismatch =
513
513
(* Format.eprintf "prove_variant:@ %a\n%!" print t; *)
514
514
match expand_head t env with
515
- | Const (Tagged_immediate _ ) -> Unknown
515
+ | Const (Tagged_immediate imm ) ->
516
+ Proved {
517
+ const_ctors = Known (Target_imm.Set. singleton imm);
518
+ non_const_ctors_with_sizes = Tag.Scannable.Map. empty;
519
+ }
516
520
| Const _ -> Wrong_kind
517
521
| Value (Ok (Variant blocks_imms )) ->
518
- begin match blocks_imms.immediates with
522
+ begin match blocks_imms.blocks with
519
523
| Unknown -> Unknown
520
- | Known imms ->
521
- let const_ctors : _ Or_unknown.t =
522
- match prove_naked_immediates env imms with
523
- | Unknown -> Unknown
524
- | Invalid -> Known Target_imm.Set. empty
525
- | Proved const_ctors -> Known const_ctors
526
- in
527
- match const_ctors with
524
+ | Known blocks ->
525
+ match Row_like.For_blocks. all_tags_and_sizes blocks with
528
526
| Unknown -> Unknown
529
- | Known const_ctors ->
530
- let valid =
531
- Target_imm.Set. for_all Target_imm. is_non_negative const_ctors
527
+ | Known non_const_ctors_with_sizes ->
528
+ let non_const_ctors_with_sizes =
529
+ Tag.Map. fold
530
+ (fun tag size (result : _ Or_unknown.t ) : _ Or_unknown. t ->
531
+ match result with
532
+ | Unknown -> Unknown
533
+ | Known result ->
534
+ match Tag.Scannable. of_tag tag with
535
+ | None -> Unknown
536
+ | Some tag ->
537
+ Known (Tag.Scannable.Map. add tag size result))
538
+ non_const_ctors_with_sizes
539
+ (Or_unknown. Known Tag.Scannable.Map. empty)
532
540
in
533
- if not valid then Invalid
534
- else
535
- match blocks_imms.blocks with
536
- | Unknown -> Unknown
537
- | Known blocks ->
538
- match Row_like.For_blocks. all_tags_and_sizes blocks with
541
+ match non_const_ctors_with_sizes with
542
+ | Unknown -> Unknown
543
+ | Known non_const_ctors_with_sizes ->
544
+ let const_ctors : _ Or_unknown.t =
545
+ match blocks_imms.immediates with
539
546
| Unknown -> Unknown
540
- | Known non_const_ctors_with_sizes ->
541
- let non_const_ctors_with_sizes =
542
- Tag.Map. fold
543
- (fun tag size (result : _ Or_bottom.t ) : _ Or_bottom. t ->
544
- match result with
545
- | Bottom -> Bottom
546
- | Ok result ->
547
- match Tag.Scannable. of_tag tag with
548
- | None -> Bottom
549
- | Some tag ->
550
- Ok (Tag.Scannable.Map. add tag size result))
551
- non_const_ctors_with_sizes
552
- (Or_bottom. Ok Tag.Scannable.Map. empty)
553
- in
554
- match non_const_ctors_with_sizes with
555
- | Bottom -> Invalid
556
- | Ok non_const_ctors_with_sizes ->
557
- Proved {
558
- const_ctors;
559
- non_const_ctors_with_sizes;
560
- }
547
+ | Known imms ->
548
+ begin match prove_naked_immediates env imms with
549
+ | Unknown -> Unknown
550
+ | Invalid -> Known Target_imm.Set. empty
551
+ | Proved const_ctors -> Known const_ctors
552
+ end
553
+ in
554
+ Proved {
555
+ const_ctors;
556
+ non_const_ctors_with_sizes;
557
+ }
561
558
end
562
559
| Value (Ok _ ) -> Invalid
563
560
| Value Unknown -> Unknown
0 commit comments