@@ -45,7 +45,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
45
45
46
46
let get_slot_ty (slot :Ast.slot ) : Ast.ty =
47
47
match slot.Ast. slot_ty with
48
- Some ty -> ty
48
+ Some ty -> ty
49
49
| None -> Common. bug () " get_slot_ty: no type in slot"
50
50
in
51
51
@@ -62,7 +62,11 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
62
62
in
63
63
64
64
let maybe_mutable (mutability :Ast.mutability ) (ty :Ast.ty ) : Ast.ty =
65
- if mutability = Ast. MUT_mutable then Ast. TY_mutable ty else ty
65
+ let res =
66
+ if mutability = Ast. MUT_mutable then Ast. TY_mutable ty else ty
67
+ in
68
+ log cx " maybe_mutable: %a -> %a" Ast. sprintf_ty ty Ast. sprintf_ty res;
69
+ res
66
70
in
67
71
68
72
(*
@@ -229,7 +233,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
229
233
()
230
234
" internal_check_slot: supplied defn wasn't a slot at all"
231
235
in
232
- match infer, slot.Ast. slot_ty with
236
+ match infer, slot.Ast. slot_ty with
233
237
Some expected , Some actual ->
234
238
demand expected actual;
235
239
actual
@@ -301,6 +305,10 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
301
305
| `Module items -> Ast. sprintf_mod_items chan items
302
306
in
303
307
308
+ let _ = log cx " base lval %a, base type %a"
309
+ Ast. sprintf_lval base sprintf_itype ()
310
+ in
311
+
304
312
let rec typecheck base_ity =
305
313
match base_ity, comp with
306
314
`Type (Ast. TY_rec ty_rec ), Ast. COMP_named (Ast. COMP_ident id ) ->
@@ -455,14 +463,14 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
455
463
: (Ast.ty * int) =
456
464
let yield_ty ty =
457
465
let (ty, n_boxes) = if deref then unbox ty else (ty, 0 ) in
458
- (maybe_mutable mut ty, n_boxes)
466
+ (maybe_mutable mut ty, n_boxes)
459
467
in
460
468
match infer, internal_check_lval infer lval with
461
469
| None , LTYPE_mono ty -> yield_ty ty
462
470
| Some expected , LTYPE_mono actual ->
463
471
demand expected actual;
464
472
yield_ty actual
465
- | None , (LTYPE_poly _ as lty ) ->
473
+ | None , (LTYPE_poly _ as lty ) ->
466
474
Common. err
467
475
None
468
476
" not enough context to automatically instantiate the polymorphic \
@@ -487,9 +495,21 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
487
495
* Get the real one. *)
488
496
let lval_id = Semant. lval_base_id lval in
489
497
let lval = Hashtbl. find cx.Semant. ctxt_all_lvals lval_id in
498
+ let _ = log cx " generic_check_lval %a mut=%s deref=%s infer=%s"
499
+ Ast. sprintf_lval lval
500
+ (if mut = Ast. MUT_mutable then " mutable" else " immutable" )
501
+ (if deref then " true" else " false" )
502
+ (match infer with
503
+ None -> " <none>"
504
+ | Some t -> Fmt. fmt_to_str Ast. fmt_ty t)
505
+ in
490
506
let (lval_ty, n_boxes) =
491
507
internal_check_outer_lval ~mut: mut ~deref: deref infer lval
492
508
in
509
+ let _ = log cx " checked lval %a with type %a"
510
+ Ast. sprintf_lval lval
511
+ Ast. sprintf_ty lval_ty
512
+ in
493
513
494
514
if Hashtbl. mem cx.Semant. ctxt_all_lval_types lval_id then
495
515
assert ((Hashtbl. find cx.Semant. ctxt_all_lval_types lval_id) = lval_ty)
@@ -514,8 +534,8 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
514
534
implemented; please add explicit dereference operators" ;
515
535
Hashtbl. replace cx.Semant. ctxt_auto_deref_lval lval_id (n_boxes > 0 );
516
536
517
- (* Before demoting the lval to a value, strip off mutability. *)
518
- fundamental_ty lval_ty
537
+ (* Before demoting the lval to a value, strip off mutability. *)
538
+ fundamental_ty lval_ty
519
539
520
540
(* Note that this function should be avoided when possible, because it
521
541
* cannot perform type inference. In general you should prefer
@@ -538,11 +558,12 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
538
558
in
539
559
540
560
let infer_lval
541
- ?mut :(mut = Ast. MUT_mutable )
561
+ ?mut :(mut = Ast. MUT_immutable )
542
562
(ty:Ast.ty )
543
563
(lval:Ast.lval )
544
564
: unit =
545
- ignore (generic_check_lval ?mut:mut ~deref:false (Some ty ) lval)
565
+ ignore (generic_check_lval ?mut:mut ~deref: false
566
+ (Some (Ast. TY_mutable ty)) lval)
546
567
in
547
568
548
569
(*
@@ -574,7 +595,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
574
595
| Ast. EXPR_binary (binop , lhs , rhs ) ->
575
596
let operand_ty = check_atom ~deref: true lhs in
576
597
demand operand_ty (check_atom ~deref: true rhs);
577
- check_binop binop operand_ty
598
+ check_binop binop operand_ty
578
599
| Ast. EXPR_unary (Ast. UNOP_not, atom ) ->
579
600
demand Ast. TY_bool (check_atom ~deref: true atom);
580
601
Ast. TY_bool
@@ -596,7 +617,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
596
617
let check_fn (callee :Ast.lval ) (args :Ast.atom array ) : Ast.ty =
597
618
let arg_tys = Array. map check_atom args in
598
619
let callee_ty = check_lval callee in
599
- demand_fn (Array. map (fun ty -> Some ty) arg_tys) callee_ty
620
+ demand_fn (Array. map (fun ty -> Some ty) arg_tys) callee_ty
600
621
in
601
622
602
623
let rec check_pat (expected :Ast.ty ) (pat :Ast.pat ) : unit =
0 commit comments