Skip to content

Commit bee2185

Browse files
Jonathan D.A. Jewellclaude
andcommitted
fix: resolve OCaml 5.x build errors and warnings
- Rename `effect` type to `eff` (reserved keyword in OCaml 5.x) - types.ml, typecheck.ml, unify.ml updated throughout - Remove deprecated menhir --explain flag from lib/dune - Fix parser.mly impl_trait_ref double Option wrapping - Fix resolve.ml comment prematurely closed by `use *)` - Add missing let* operator to unify.ml - Remove [@@deriving show] from scope_kind (Hashtbl.pp unbound) - Fix borrow.ml missing begin/end block for nested match - Fix test_parser.ml incomplete record patterns and dead code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ced9a71 commit bee2185

File tree

9 files changed

+69
-62
lines changed

9 files changed

+69
-62
lines changed

lib/borrow.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ let rec check_expr (state : state) (symbols : Symbol.t) (expr : expr) : unit res
262262

263263
| ExprLet lb ->
264264
let* () = check_expr state symbols lb.el_value in
265-
match lb.el_body with
266-
| Some body -> check_expr state symbols body
267-
| None -> Ok ()
265+
begin match lb.el_body with
266+
| Some body -> check_expr state symbols body
267+
| None -> Ok ()
268+
end
268269

269270
| ExprIf ei ->
270271
let* () = check_expr state symbols ei.ei_cond in

lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
(menhir
99
(modules parser)
10-
(flags --explain --table))
10+
(flags --table))

lib/parser.mly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ effect_term:
321321
trait_decl:
322322
| vis = visibility? TRAIT name = ident type_params = type_params?
323323
super = supertraits?
324-
where_clause = where_clause?
324+
_where_clause = where_clause?
325325
LBRACE items = list(trait_item) RBRACE
326326
{ { trd_vis = Option.value vis ~default:Private;
327327
trd_name = name;
@@ -368,9 +368,9 @@ impl_block:
368368
ib_items = items } }
369369

370370
impl_trait_ref:
371-
| name = ident FOR { Some { tr_name = name; tr_args = [] } }
371+
| name = ident FOR { { tr_name = name; tr_args = [] } }
372372
| name = ident LBRACKET args = separated_list(COMMA, type_arg) RBRACKET FOR
373-
{ Some { tr_name = name; tr_args = args } }
373+
{ { tr_name = name; tr_args = args } }
374374

375375
impl_item:
376376
| f = fn_decl { ImplFn f }

lib/resolve.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ let resolve_program (program : program) : (context, resolve_error * Span.t) Resu
401401

402402
(* TODO: Phase 1 implementation
403403
- [ ] Module qualified lookups
404-
- [ ] Import resolution (use, use as, use *)
404+
- [ ] Import resolution (use, use as, use * )
405405
- [ ] Visibility checking
406406
- [ ] Forward references in mutual recursion
407407
- [ ] Type alias expansion during resolution

lib/symbol.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ and scope_kind =
5252
| ScopeBlock
5353
| ScopeMatch
5454
| ScopeHandler
55-
[@@deriving show]
5655

5756
(** The symbol table *)
5857
type t = {

lib/typecheck.ml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type context = {
4141
var_types : (Symbol.symbol_id, scheme) Hashtbl.t;
4242

4343
(** Current effect context *)
44-
current_effect : effect;
44+
current_effect : eff;
4545
}
4646

4747
(* Result bind - define before use *)
@@ -214,8 +214,8 @@ and ast_to_ty_arg (ctx : context) (arg : type_arg) : ty =
214214
| TyArg ty -> ast_to_ty ctx ty
215215
| NatArg _ -> TNat (NLit 0) (* TODO: Convert nat expr *)
216216

217-
and ast_to_eff (ctx : context) (eff : effect_expr) : effect =
218-
match eff with
217+
and ast_to_eff (ctx : context) (e : effect_expr) : eff =
218+
match e with
219219
| EffCon (id, _) -> ESingleton id.name
220220
| EffVar _id -> fresh_effvar ctx.level
221221
| EffUnion (e1, e2) -> EUnion [ast_to_eff ctx e1; ast_to_eff ctx e2]
@@ -298,7 +298,7 @@ and pattern_span (pat : pattern) : Span.t =
298298
| PatAs (id, _) -> id.span
299299

300300
(** Synthesize (infer) the type of an expression *)
301-
let rec synth (ctx : context) (expr : expr) : (ty * effect) result =
301+
let rec synth (ctx : context) (expr : expr) : (ty * eff) result =
302302
match expr with
303303
| ExprVar id ->
304304
let* ty = lookup_var ctx id in
@@ -502,8 +502,8 @@ let rec synth (ctx : context) (expr : expr) : (ty * effect) result =
502502
| ExprSpan (e, _span) ->
503503
synth ctx e
504504

505-
and synth_app (ctx : context) (func_ty : ty) (func_eff : effect)
506-
(args : expr list) (span : Span.t) : (ty * effect) result =
505+
and synth_app (ctx : context) (func_ty : ty) (func_eff : eff)
506+
(args : expr list) (span : Span.t) : (ty * eff) result =
507507
match args with
508508
| [] -> Ok (func_ty, func_eff)
509509
| arg :: rest ->
@@ -527,7 +527,7 @@ and synth_app (ctx : context) (func_ty : ty) (func_eff : effect)
527527
end
528528

529529
(** Check an expression against an expected type *)
530-
and check (ctx : context) (expr : expr) (expected : ty) : effect result =
530+
and check (ctx : context) (expr : expr) (expected : ty) : eff result =
531531
match (expr, repr expected) with
532532
(* Lambda checking *)
533533
| (ExprLambda lam, TArrow (param_ty, ret_ty, arr_eff)) ->
@@ -584,13 +584,13 @@ and check (ctx : context) (expr : expr) (expected : ty) : effect result =
584584
| _ ->
585585
check_subsumption ctx expr expected
586586

587-
and check_subsumption (ctx : context) (expr : expr) (expected : ty) : effect result =
587+
and check_subsumption (ctx : context) (expr : expr) (expected : ty) : eff result =
588588
let* (actual, eff) = synth ctx expr in
589589
match Unify.unify actual expected with
590590
| Ok () -> Ok eff
591591
| Error e -> Error (UnificationFailed (e, expr_span expr))
592592

593-
and synth_list (ctx : context) (exprs : expr list) : ((ty * effect) list) result =
593+
and synth_list (ctx : context) (exprs : expr list) : ((ty * eff) list) result =
594594
List.fold_right (fun expr acc ->
595595
match acc with
596596
| Error e -> Error e
@@ -600,7 +600,7 @@ and synth_list (ctx : context) (exprs : expr list) : ((ty * effect) list) result
600600
| Ok result -> Ok (result :: results)
601601
) exprs (Ok [])
602602

603-
and check_list (ctx : context) (exprs : expr list) (tys : ty list) : (effect list) result =
603+
and check_list (ctx : context) (exprs : expr list) (tys : ty list) : (eff list) result =
604604
List.fold_right2 (fun expr ty acc ->
605605
match acc with
606606
| Error e -> Error e
@@ -611,7 +611,7 @@ and check_list (ctx : context) (exprs : expr list) (tys : ty list) : (effect lis
611611
) exprs tys (Ok [])
612612

613613
and synth_record_fields (ctx : context) (fields : (ident * expr option) list)
614-
: ((string * ty * effect) list) result =
614+
: ((string * ty * eff) list) result =
615615
List.fold_right (fun (id, expr_opt) acc ->
616616
match acc with
617617
| Error e -> Error e
@@ -630,7 +630,7 @@ and synth_record_fields (ctx : context) (fields : (ident * expr option) list)
630630
end
631631
) fields (Ok [])
632632

633-
and synth_block (ctx : context) (blk : block) : (ty * effect) result =
633+
and synth_block (ctx : context) (blk : block) : (ty * eff) result =
634634
let* effs = List.fold_left (fun acc stmt ->
635635
let* effs = acc in
636636
let* eff = synth_stmt ctx stmt in
@@ -643,7 +643,7 @@ and synth_block (ctx : context) (blk : block) : (ty * effect) result =
643643
| None ->
644644
Ok (ty_unit, union_eff effs)
645645

646-
and check_block (ctx : context) (blk : block) (expected : ty) : effect result =
646+
and check_block (ctx : context) (blk : block) (expected : ty) : eff result =
647647
let* effs = List.fold_left (fun acc stmt ->
648648
let* effs = acc in
649649
let* eff = synth_stmt ctx stmt in
@@ -659,7 +659,7 @@ and check_block (ctx : context) (blk : block) (expected : ty) : effect result =
659659
| Error e -> Error (UnificationFailed (e, Span.dummy))
660660
end
661661

662-
and synth_stmt (ctx : context) (stmt : stmt) : effect result =
662+
and synth_stmt (ctx : context) (stmt : stmt) : eff result =
663663
match stmt with
664664
| StmtLet sl ->
665665
let ctx' = enter_level ctx in
@@ -688,7 +688,7 @@ and synth_stmt (ctx : context) (stmt : stmt) : effect result =
688688
Ok (union_eff [iter_eff; body_eff])
689689

690690
and synth_binop (ctx : context) (left : expr) (op : binary_op) (right : expr)
691-
(span : Span.t) : (ty * effect) result =
691+
(span : Span.t) : (ty * eff) result =
692692
let* (left_ty, left_eff) = synth ctx left in
693693
let* (right_ty, right_eff) = synth ctx right in
694694
let eff = union_eff [left_eff; right_eff] in
@@ -714,7 +714,7 @@ and synth_binop (ctx : context) (left : expr) (op : binary_op) (right : expr)
714714
| Error e, _ | _, Error e -> Error (UnificationFailed (e, span))
715715
end
716716

717-
and synth_unary (ctx : context) (op : unary_op) (operand : expr) : (ty * effect) result =
717+
and synth_unary (ctx : context) (op : unary_op) (operand : expr) : (ty * eff) result =
718718
let* (operand_ty, operand_eff) = synth ctx operand in
719719
match op with
720720
| OpNeg ->
@@ -822,7 +822,7 @@ and find_field (name : string) (row : row) : ty option =
822822
else find_field name rest
823823
| RVar _ -> None
824824

825-
and union_eff (effs : effect list) : effect =
825+
and union_eff (effs : eff list) : eff =
826826
let effs = List.filter (fun e -> e <> EPure) effs in
827827
match effs with
828828
| [] -> EPure

lib/types.ml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ type ty =
4242
| TVar of tyvar_state ref (** Type variable (mutable for unification) *)
4343
| TCon of string (** Type constructor (Int, Bool, etc.) *)
4444
| TApp of ty * ty list (** Type application *)
45-
| TArrow of ty * ty * effect (** Function type with effect *)
46-
| TDepArrow of string * ty * ty * effect (** Dependent function type *)
45+
| TArrow of ty * ty * eff (** Function type with effect *)
46+
| TDepArrow of string * ty * ty * eff (** Dependent function type *)
4747
| TTuple of ty list (** Tuple type *)
4848
| TRecord of row (** Record type *)
4949
| TVariant of row (** Variant type *)
@@ -75,16 +75,16 @@ and rowvar_state =
7575
[@@deriving show]
7676

7777
(** Effect type *)
78-
and effect =
78+
and eff =
7979
| EPure (** No effects *)
8080
| EVar of effvar_state ref (** Effect variable *)
8181
| ESingleton of string (** Single effect *)
82-
| EUnion of effect list (** Union of effects *)
82+
| EUnion of eff list (** Union of effects *)
8383
[@@deriving show]
8484

8585
and effvar_state =
8686
| EUnbound of effvar * int
87-
| ELink of effect
87+
| ELink of eff
8888
[@@deriving show]
8989

9090
(** Type-level natural expression *)
@@ -136,7 +136,7 @@ let fresh_rowvar (level : int) : row =
136136
next_rowvar := id + 1;
137137
RVar (ref (RUnbound (id, level)))
138138

139-
let fresh_effvar (level : int) : effect =
139+
let fresh_effvar (level : int) : eff =
140140
let id = !next_effvar in
141141
next_effvar := id + 1;
142142
EVar (ref (EUnbound (id, level)))
@@ -191,17 +191,17 @@ let rec repr_row (row : row) : row =
191191
| _ -> row
192192

193193
(** Follow links in an effect *)
194-
let rec repr_eff (eff : effect) : effect =
195-
match eff with
194+
let rec repr_eff (e : eff) : eff =
195+
match e with
196196
| EVar r ->
197197
begin match !r with
198-
| ELink eff' ->
199-
let eff'' = repr_eff eff' in
200-
r := ELink eff'';
201-
eff''
202-
| EUnbound _ -> eff
198+
| ELink e' ->
199+
let e'' = repr_eff e' in
200+
r := ELink e'';
201+
e''
202+
| EUnbound _ -> e
203203
end
204-
| _ -> eff
204+
| _ -> e
205205

206206
(* TODO: Phase 1 implementation
207207
- [ ] Pretty printing for types

lib/unify.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ type unify_error =
1515
| OccursCheck of tyvar * ty
1616
| RowMismatch of row * row
1717
| RowOccursCheck of rowvar * row
18-
| EffectMismatch of effect * effect
19-
| EffectOccursCheck of effvar * effect
18+
| EffectMismatch of eff * eff
19+
| EffectOccursCheck of effvar * eff
2020
| KindMismatch of kind * kind
2121
| LabelNotFound of string * row
2222
[@@deriving show]
2323

2424
type 'a result = ('a, unify_error) Result.t
2525

26+
(* Result bind operator *)
27+
let ( let* ) = Result.bind
28+
2629
(** Check if a type variable occurs in a type (occurs check) *)
2730
let rec occurs_in_ty (var : tyvar) (ty : ty) : bool =
2831
match repr ty with
@@ -57,8 +60,8 @@ and occurs_in_row (var : tyvar) (row : row) : bool =
5760
occurs_in_ty var ty || occurs_in_row var rest
5861
| RVar _ -> false
5962

60-
and occurs_in_eff (var : tyvar) (eff : effect) : bool =
61-
match repr_eff eff with
63+
and occurs_in_eff (var : tyvar) (e : eff) : bool =
64+
match repr_eff e with
6265
| EPure -> false
6366
| EVar _ -> false
6467
| ESingleton _ -> false
@@ -76,8 +79,8 @@ let rec rowvar_occurs_in_row (var : rowvar) (row : row) : bool =
7679
end
7780

7881
(** Check if an effect variable occurs in an effect *)
79-
let rec effvar_occurs_in_eff (var : effvar) (eff : effect) : bool =
80-
match repr_eff eff with
82+
let rec effvar_occurs_in_eff (var : effvar) (e : eff) : bool =
83+
match repr_eff e with
8184
| EPure -> false
8285
| ESingleton _ -> false
8386
| EVar r ->
@@ -158,7 +161,7 @@ let rec unify (t1 : ty) (t2 : ty) : unit result =
158161
unify_row r1 r2
159162

160163
(* Forall types *)
161-
| (TForall (v1, k1, body1), TForall (v2, k2, body2)) ->
164+
| (TForall (_v1, k1, body1), TForall (_v2, k2, body2)) ->
162165
if k1 <> k2 then
163166
Error (KindMismatch (k1, k2))
164167
else
@@ -250,7 +253,7 @@ and unify_row (r1 : row) (r2 : row) : unit result =
250253
Error (LabelNotFound (l, r2))
251254

252255
(** Unify two effects *)
253-
and unify_eff (e1 : effect) (e2 : effect) : unit result =
256+
and unify_eff (e1 : eff) (e2 : eff) : unit result =
254257
let e1 = repr_eff e1 in
255258
let e2 = repr_eff e2 in
256259
match (e1, e2) with

test/test_parser.ml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ let test_literal_string () =
4848
| _ -> Alcotest.fail "Expected string literal"
4949

5050
let test_literal_bool () =
51-
let expr = parse_expr "true" in
52-
match expr with
53-
| Ast.ExprLit (Ast.LitBool (true, _)) -> ()
54-
| _ -> Alcotest.fail "Expected bool literal";
55-
let expr = parse_expr "false" in
56-
match expr with
57-
| Ast.ExprLit (Ast.LitBool (false, _)) -> ()
58-
| _ -> Alcotest.fail "Expected bool literal"
51+
begin
52+
let expr = parse_expr "true" in
53+
match expr with
54+
| Ast.ExprLit (Ast.LitBool (true, _)) -> ()
55+
| _ -> Alcotest.fail "Expected true literal"
56+
end;
57+
begin
58+
let expr = parse_expr "false" in
59+
match expr with
60+
| Ast.ExprLit (Ast.LitBool (false, _)) -> ()
61+
| _ -> Alcotest.fail "Expected false literal"
62+
end
5963

6064
let test_literal_unit () =
6165
let expr = parse_expr "()" in
@@ -200,7 +204,7 @@ let test_match_expr () =
200204
let test_lambda () =
201205
let expr = parse_expr "|x| x + 1" in
202206
match expr with
203-
| Ast.ExprLambda { elam_params = [_]; elam_body = _ } -> ()
207+
| Ast.ExprLambda { elam_params = [_]; elam_body = _; _ } -> ()
204208
| _ -> Alcotest.fail "Expected lambda"
205209

206210
let test_block () =
@@ -279,14 +283,14 @@ let test_struct_decl () =
279283
let prog = parse "struct Point { x: Int, y: Int }" in
280284
match prog.prog_decls with
281285
| [Ast.TopType { td_name = { name = "Point"; _ };
282-
td_body = Ast.TyStruct [_; _] }] -> ()
286+
td_body = Ast.TyStruct [_; _]; _ }] -> ()
283287
| _ -> Alcotest.fail "Expected struct declaration"
284288

285289
let test_enum_decl () =
286290
let prog = parse "enum Option[T] { Some(T), None }" in
287291
match prog.prog_decls with
288292
| [Ast.TopType { td_name = { name = "Option"; _ };
289-
td_body = Ast.TyEnum [_; _] }] -> ()
293+
td_body = Ast.TyEnum [_; _]; _ }] -> ()
290294
| _ -> Alcotest.fail "Expected enum declaration"
291295

292296
let test_type_alias () =
@@ -298,13 +302,13 @@ let test_type_alias () =
298302
let test_trait_decl () =
299303
let prog = parse "trait Eq { fn eq(self: ref Self, other: ref Self) -> Bool; }" in
300304
match prog.prog_decls with
301-
| [Ast.TopTrait { trd_name = { name = "Eq"; _ }; trd_items = [_] }] -> ()
305+
| [Ast.TopTrait { trd_name = { name = "Eq"; _ }; trd_items = [_]; _ }] -> ()
302306
| _ -> Alcotest.fail "Expected trait declaration"
303307

304308
let test_impl_block () =
305309
let prog = parse "impl Point { fn new(x: Int, y: Int) -> Point { Point { x: x, y: y } } }" in
306310
match prog.prog_decls with
307-
| [Ast.TopImpl { ib_self_ty = _; ib_items = [_] }] -> ()
311+
| [Ast.TopImpl { ib_self_ty = _; ib_items = [_]; _ }] -> ()
308312
| _ -> Alcotest.fail "Expected impl block"
309313

310314
let test_impl_trait () =
@@ -316,7 +320,7 @@ let test_impl_trait () =
316320
let test_effect_decl () =
317321
let prog = parse "effect Console { fn print(msg: String) -> (); fn read() -> String; }" in
318322
match prog.prog_decls with
319-
| [Ast.TopEffect { ed_name = { name = "Console"; _ }; ed_ops = [_; _] }] -> ()
323+
| [Ast.TopEffect { ed_name = { name = "Console"; _ }; ed_ops = [_; _]; _ }] -> ()
320324
| _ -> Alcotest.fail "Expected effect declaration"
321325

322326
(* ========== Type Expression Tests ========== *)

0 commit comments

Comments
 (0)