Skip to content

Commit 4333a8d

Browse files
authored
Effects typechecking fixes (#1216)
* Fixed a type error generation * Also conditionally remove linearity tracking for do operations in the parser * Forgot one more linear operation
1 parent 5156ea3 commit 4333a8d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

core/parser.mly

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ unary_expression:
709709
| OPERATOR unary_expression { unary_appl ~ppos:$loc (UnaryOp.Name $1) $2 }
710710
| postfix_expression | constructor_expression { $1 }
711711
| DOOP CONSTRUCTOR loption(arg_spec) { with_pos $loc (DoOperation (with_pos $loc($2) (Operation $2), $3, None, DeclaredLinearity.Unl)) }
712-
| LINDOOP CONSTRUCTOR loption(arg_spec) { with_pos $loc (DoOperation (with_pos $loc($2) (Operation $2), $3, None, DeclaredLinearity.Lin)) }
712+
| LINDOOP CONSTRUCTOR loption(arg_spec) { with_pos $loc (DoOperation (with_pos $loc($2) (Operation $2), $3, None,
713+
if lincont_enabled then DeclaredLinearity.Lin else DeclaredLinearity.Unl)) }
713714

714715
infix_appl:
715716
| unary_expression { $1 }
@@ -1399,7 +1400,8 @@ resumable_operation_pattern:
13991400
| operation_pattern FATRARROW pattern
14001401
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3, DeclaredLinearity.Unl)) }
14011402
| operation_pattern FATLOLLI pattern
1402-
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3, DeclaredLinearity.Lin)) }
1403+
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3,
1404+
if lincont_enabled then DeclaredLinearity.Lin else DeclaredLinearity.Unl)) }
14031405
| operation_pattern RARROW pattern
14041406
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3, DeclaredLinearity.Unl)) }
14051407
| operation_pattern

core/typeSugar.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -683,16 +683,16 @@ end
683683
"while the computation can perform effects" ^ nl() ^
684684
tab() ^ code (show_type rt))
685685

686-
let do_operation ~pos ~t1:(_,lt) ~t2:(rexpr,rt) ~error:_ =
686+
let do_operation ~pos ~t1:(resume,lt) ~t2:(_,rt) ~error:_ =
687687
build_tyvar_names [lt;rt];
688-
let dropDoPrefix = Str.substitute_first (Str.regexp "do ") (fun _ -> "") in
689-
let operation = dropDoPrefix (code rexpr) in
690-
die pos ("Invocation of the operation " ^ nl() ^
691-
tab() ^ operation ^ nl() ^
692-
"requires an effect context " ^ nl() ^
693-
tab() ^ code (show_effectrow (TypeUtils.extract_row rt)) ^ nl() ^
694-
"but, the currently allowed effects are" ^ nl()
695-
^ tab() ^ code ( show_effectrow (TypeUtils.extract_row lt)))
688+
let dropDoPrefix = Str.substitute_first (Str.regexp {|^\(lin\)?do |}) (fun _ -> "") in
689+
let operation = code (dropDoPrefix resume) in
690+
die pos ("Invocation of the operation" ^ nli() ^
691+
operation ^ nl() ^
692+
"requires an effect context" ^ nli() ^
693+
code (show_type lt) ^ nl() ^
694+
"but, the currently allowed effect is" ^ nli()
695+
^ code (show_type rt))
696696

697697
let try_effect ~pos ~t1:(_,lt) ~t2:(_,rt) ~error:_ =
698698
build_tyvar_names [lt;rt];
@@ -4592,7 +4592,7 @@ let rec type_check : context -> phrase -> phrase * Types.datatype * Usage.t =
45924592
unify ~handle:Gripers.do_operation
45934593
(term, infer_opt) ;
45944594
unify ~handle:Gripers.do_operation
4595-
(no_pos (T.Effect context.effect_row), (p, T.Effect row))
4595+
((p, T.Effect row), no_pos (T.Effect context.effect_row))
45964596
in
45974597
(* postponed *)
45984598
(* let () = if is_lindo then () *)

0 commit comments

Comments
 (0)