Skip to content

Effects typechecking fixes #1216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ unary_expression:
| OPERATOR unary_expression { unary_appl ~ppos:$loc (UnaryOp.Name $1) $2 }
| postfix_expression | constructor_expression { $1 }
| DOOP CONSTRUCTOR loption(arg_spec) { with_pos $loc (DoOperation (with_pos $loc($2) (Operation $2), $3, None, DeclaredLinearity.Unl)) }
| LINDOOP CONSTRUCTOR loption(arg_spec) { with_pos $loc (DoOperation (with_pos $loc($2) (Operation $2), $3, None, DeclaredLinearity.Lin)) }
| LINDOOP CONSTRUCTOR loption(arg_spec) { with_pos $loc (DoOperation (with_pos $loc($2) (Operation $2), $3, None,
if lincont_enabled then DeclaredLinearity.Lin else DeclaredLinearity.Unl)) }

infix_appl:
| unary_expression { $1 }
Expand Down Expand Up @@ -1399,7 +1400,8 @@ resumable_operation_pattern:
| operation_pattern FATRARROW pattern
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3, DeclaredLinearity.Unl)) }
| operation_pattern FATLOLLI pattern
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3, DeclaredLinearity.Lin)) }
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3,
if lincont_enabled then DeclaredLinearity.Lin else DeclaredLinearity.Unl)) }
| operation_pattern RARROW pattern
{ with_pos $loc (Pattern.Operation (fst $1, snd $1, $3, DeclaredLinearity.Unl)) }
| operation_pattern
Expand Down
20 changes: 10 additions & 10 deletions core/typeSugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,16 @@ end
"while the computation can perform effects" ^ nl() ^
tab() ^ code (show_type rt))

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

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