Skip to content

Commit c6d1841

Browse files
nikswamyCopilot
andcommitted
Add explicit ML effect annotations for --MLish removal
With the removal of --MLish from F*, functions that call effectful operations must now have explicit ML return type annotations. The --MLish flag previously made ML the default effect for all unannotated top-level let bindings; without it, the default is Tot. Changes by file: src/syntax_extension/PulseSyntaxExtension.Sugar.fst: - Added 'open FStarC.Effect' and 'open FStarC.Class.Deq' - eq_ident, eq_lident: added ': ML bool' (=? operator is ML) - forall2: changed parameter type to 'f:'a -> 'a -> ML bool' - eq_opt, eq_slprop, eq_while_invariant1: added ': ML bool' - Entire eq_decl mutual recursion block (eq_decl, eq_fn_decl, eq_fn_defn, eq_slprop_defn, eq_ascription, eq_computation_type, eq_annot, eq_body, eq_stmt, eq_stmt', eq_let_init, eq_array_init, eq_hint_type, eq_ensures_slprop, eq_lambda): added ': ML bool' - stmt_to_string, branch_to_string: added ': ML string' src/syntax_extension/PulseSyntaxExtension.Err.fst: - err type: nat -> ML (...) instead of nat -> Tot (...) - bind_err, map_err_opt: added ML annotations src/syntax_extension/PulseSyntaxExtension.Desugar.fst: - All desugar_* functions: added ': ML (err ...)' annotations - as_qual: added ML annotation - desugar_decl: moved out of mutual recursion group (it calls but is not called by the other mutually recursive functions) - Helper functions (close_st_term_bvs, close_comp_bvs, fold_right1, sugar_app, sugar_var, etc.): added ML annotations src/syntax_extension/PulseSyntaxExtension.ASTBuilder.fst: - Functions calling mk/mk_term/show: added ML annotations src/syntax_extension/PulseSyntaxExtension.Env.fst: - Functions using refs and show: added ML annotations src/syntax_extension/PulseSyntaxExtension.Printing.fst: - Printing functions using show: added ML annotations src/extraction/ExtractPulse.fst: - lookup_goto: added ': ML' (dereferences goto_env ref) src/extraction/ExtractPulseC.fst: - char_of_typechar, string_of_typestring, go: added ML annotations - Functions calling FStarC.String operations: added ML annotations src/extraction/ExtractPulseOCaml.fst: - hua, tr_typ: added ': ML' annotations Build verified: clean build passes with no errors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0abf8e8 commit c6d1841

10 files changed

+156
-151
lines changed

src/extraction/ExtractPulse.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ let with_goto_env_update #a (f: goto_env_t -> goto_env_t) (k: unit -> ML a) : ML
7474
let with_goto_env_elem #a (id: mlident) (e: goto_env_elem) (k: unit -> ML a) : ML a =
7575
with_goto_env_update (Cons (id, e)) k
7676

77-
let lookup_goto (id: mlident) : option goto_env_elem =
77+
let lookup_goto (id: mlident) : ML (option goto_env_elem) =
7878
let rec go (env: goto_env_t) =
7979
match env with
8080
| [] -> None

src/extraction/ExtractPulseC.fst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ open FStarC.Extraction.Krml
1414
module BU = FStarC.Util
1515

1616
(* JL: TODO: in stdlib somewhere? *)
17-
let opt_bind (m: option 'a) (k: 'a -> option 'b): option 'b =
17+
let opt_bind (m: option 'a) (k: 'a -> ML (option 'b)): ML (option 'b) =
1818
match m with Some x -> k x | None -> None
1919

20-
let char_of_typechar (t: mlty): option char =
20+
let char_of_typechar (t: mlty): ML (option char) =
2121
match t with
2222
| MLTY_Named ([], p) ->
2323
let p = Syntax.string_of_mlpath p in
@@ -30,8 +30,8 @@ let char_of_typechar (t: mlty): option char =
3030
3131
| _ -> None
3232
33-
let string_of_typestring (t: mlty): option string =
34-
let rec go t: option (list string) =
33+
let string_of_typestring (t: mlty): ML (option string) =
34+
let rec go t: ML (option (list string)) =
3535
match t with
3636
| MLTY_Named ([], p)
3737
when Syntax.string_of_mlpath p = "Pulse.C.Typestring.string_nil"
@@ -49,9 +49,9 @@ let string_of_typestring (t: mlty): option string =
4949
in
5050
opt_bind (go t) (fun ss -> Some (FStar.String.concat "" ss))
5151
52-
let lident_of_string (s: string): option lident =
52+
let lident_of_string (s: string): ML (option lident) =
5353
let path = FStar.String.split ['.'] s in
54-
let rec go p =
54+
let rec go p : ML (option lident) =
5555
match p with
5656
| [] -> None
5757
| [s] -> Some ([], s)
@@ -60,11 +60,11 @@ let lident_of_string (s: string): option lident =
6060
Some (s :: names, name))
6161
in go path
6262
63-
let lident_of_typestring (t: mlty): option lident =
63+
let lident_of_typestring (t: mlty): ML (option lident) =
6464
opt_bind (string_of_typestring t) lident_of_string
6565
66-
let int_of_typenat (t: mlty): option int =
67-
let rec go t =
66+
let int_of_typenat (t: mlty): ML (option int) =
67+
let rec go t : ML (option int) =
6868
match t with
6969
| MLTY_Named ([], p)
7070
when Syntax.string_of_mlpath p = "Pulse.C.Typenat.z"
@@ -81,7 +81,7 @@ let int_of_typenat (t: mlty): option int =
8181
in
8282
go t
8383
84-
let my_types_without_decay () =
84+
let my_types_without_decay () : ML unit =
8585
register_pre_translate_type_without_decay begin fun env t ->
8686
match t with
8787
@@ -124,7 +124,7 @@ let my_types_without_decay () =
124124
| _ -> raise NotSupportedByKrmlExtension
125125
end
126126
127-
let my_types () = register_pre_translate_type begin fun env t ->
127+
let my_types () : ML unit = register_pre_translate_type begin fun env t ->
128128
match t with
129129
| MLTY_Named ([t; _; _], p)
130130
when false
@@ -135,7 +135,7 @@ let my_types () = register_pre_translate_type begin fun env t ->
135135
| _ -> raise NotSupportedByKrmlExtension
136136
end
137137
138-
let my_exprs () = register_pre_translate_expr begin fun env e ->
138+
let my_exprs () : ML unit = register_pre_translate_expr begin fun env e ->
139139
match e.expr with
140140
| MLE_App ({ expr = MLE_TApp({ expr = MLE_Name p }, _) }, [ _ (* typedef *) ])
141141
when (
@@ -302,8 +302,8 @@ let my_exprs () = register_pre_translate_expr begin fun env e ->
302302
| _ -> raise NotSupportedByKrmlExtension
303303
end
304304
305-
let parse_steel_c_fields env (fields: mlty): option (list _) =
306-
let rec go fields =
305+
let parse_steel_c_fields env (fields: mlty): ML (option (list _)) =
306+
let rec go fields : ML _ =
307307
match fields with
308308
| MLTY_Named ([], p)
309309
when false
@@ -347,6 +347,7 @@ let parse_steel_c_fields env (fields: mlty): option (list _) =
347347
348348
let define_struct_gen
349349
env p args fields
350+
: ML (option _)
350351
=
351352
let env = List.fold_left (fun env name -> extend_t env name) env args in
352353
let fields = Option.must (parse_steel_c_fields env fields) in
@@ -355,6 +356,7 @@ let define_struct_gen
355356
356357
let define_struct
357358
env tag fields
359+
: ML (option _)
358360
=
359361
(* JL: TODO remove/improve these print commands *)
360362
print_endline "Parsing struct definition.";
@@ -368,13 +370,15 @@ let define_struct
368370
369371
let define_union_gen
370372
env p args fields
373+
: ML (option _)
371374
=
372375
let env = List.fold_left (fun env name -> extend_t env name) env args in
373376
let fields = Option.must (parse_steel_c_fields env fields) in
374377
Some (DUntaggedUnion (p, [], List.length args, fields))
375378
376379
let define_union
377380
env tag fields
381+
: ML (option _)
378382
=
379383
(* JL: TODO remove/improve these print commands *)
380384
print_endline "Parsing union definition.";
@@ -386,7 +390,7 @@ let define_union
386390
| Some p ->
387391
define_union_gen env p [] fields
388392
389-
let my_type_decls () = register_pre_translate_type_decl begin fun env ty ->
393+
let my_type_decls () : ML unit = register_pre_translate_type_decl begin fun env ty ->
390394
match ty with
391395
| {tydecl_defn=Some (MLTD_Abbrev (MLTY_Named ([tag; fields; _; _], p)))}
392396
when Syntax.string_of_mlpath p = "Pulse.C.Types.Struct.define_struct0"

src/extraction/ExtractPulseOCaml.fst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Ident = FStarC.Ident
3232

3333
let dbg = Debug.get_toggle "extraction"
3434

35-
let hua (t:term) : option (S.fv & list S.universe & S.args) =
35+
let hua (t:term) : ML (option (S.fv & list S.universe & S.args)) =
3636
let t = U.unmeta t in
3737
let hd, args = U.head_and_args_full t in
3838
let hd = U.unmeta hd in
@@ -41,7 +41,7 @@ let hua (t:term) : option (S.fv & list S.universe & S.args) =
4141
| Tm_uinst ({ n = Tm_fvar fv }, us) -> Some (fv, us, args)
4242
| _ -> None
4343

44-
let tr_typ (g:uenv) (t:term) : mlty =
44+
let tr_typ (g:uenv) (t:term) : ML mlty =
4545
(* Only enabled with an extension flag *)
4646
if Options.Ext.get "pulse:extract_ocaml_bare" = "" then
4747
raise NotSupportedByExtension;
@@ -74,7 +74,7 @@ let tr_typ (g:uenv) (t:term) : mlty =
7474
| _ ->
7575
raise NotSupportedByExtension
7676

77-
let tr_expr (g:uenv) (t:term) : mlexpr & e_tag & mlty =
77+
let tr_expr (g:uenv) (t:term) : ML (mlexpr & e_tag & mlty) =
7878
(* Only enabled with an extension flag *)
7979
if Options.Ext.get "pulse:extract_ocaml_bare" = "" then
8080
raise NotSupportedByExtension;

src/syntax_extension/PulseSyntaxExtension.ASTBuilder.fst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let tm t r = { tm=t; range=r; level=Un}
3838
let parse_decl_name
3939
: contents:string ->
4040
FStarC.Range.range ->
41-
either AU.error_message FStarC.Ident.ident
41+
ML (either AU.error_message FStarC.Ident.ident)
4242
= fun contents r ->
4343
match Parser.parse_peek_id contents r with
4444
| Inl s -> Inr (Ident.id_of_text s)
@@ -49,12 +49,12 @@ let parse_decl_name
4949

5050
let i s r = tm (Const (Const_int(string_of_int s, None))) r
5151
let str s r = tm (Const (Const_string (s, r))) r
52-
let lid_as_term ns r = str (Ident.string_of_lid ns) r
52+
let lid_as_term ns r : ML _ = str (Ident.string_of_lid ns) r
5353

5454
let encode_open_namespaces_and_abbreviations
5555
(ctx:open_namespaces_and_abbreviations)
5656
(r:FStarC.Range.range)
57-
: term & term
57+
: ML (term & term)
5858
= let tm t = tm t r in
5959
let str s = str s r in
6060
let lid_as_term ns = lid_as_term ns r in
@@ -72,7 +72,7 @@ let encode_open_namespaces_and_abbreviations
7272
namespaces, abbrevs
7373

7474
let encode_range (r:FStarC.Range.range)
75-
: term & term & term
75+
: ML (term & term & term)
7676
= let open FStarC.Range in
7777
let line = line_of_pos (start_of_range r) in
7878
let col = col_of_pos (start_of_range r) in
@@ -82,7 +82,7 @@ let parse_decl
8282
: open_namespaces_and_abbreviations ->
8383
contents:string ->
8484
FStarC.Range.range ->
85-
either AU.error_message decl
85+
ML (either AU.error_message decl)
8686
= fun ctx contents r ->
8787
let tm t = tm t r in
8888
let str s = str s r in
@@ -110,7 +110,7 @@ let parse_decl
110110
let d = { d; drange = r; quals = [ Irreducible ]; attrs = [str "uninterpreted_by_smt"]; interleaved = false } in
111111
Inr d
112112

113-
let maybe_report_error first_error decls =
113+
let maybe_report_error first_error decls : ML _ =
114114
match first_error with
115115
| None -> Inr decls
116116
| Some (raw_error, msg, r) ->
@@ -135,7 +135,7 @@ let maybe_report_error first_error decls =
135135
)
136136
open FStarC.Class.Show
137137
let parse_extension_lang (contents:string) (r:FStarC.Range.range)
138-
: either AU.error_message (list decl)
138+
: ML (either AU.error_message (list decl))
139139
= match Parser.parse_lang contents r with
140140
| Inr None ->
141141
Inl { message = [Errors.text "#lang-pulse: Parsing failed"]; range = r }
@@ -160,7 +160,7 @@ let parse_extension_lang (contents:string) (r:FStarC.Range.range)
160160
in
161161
let splice_decl
162162
(d:PulseSyntaxExtension.Sugar.decl)
163-
: decl
163+
: ML decl
164164
= let id, r = id_and_range_of_decl d in
165165
let id_txt = Ident.string_of_id id in
166166
let decors =
@@ -218,7 +218,7 @@ let desugar_pulse (env:TcEnv.env)
218218
(namespaces:list string)
219219
(module_abbrevs:list (string & string))
220220
(sugar:sugar_decl)
221-
: either PulseSyntaxExtension.SyntaxWrapper.decl (option (list Pprint.document & R.range))
221+
: ML (either PulseSyntaxExtension.SyntaxWrapper.decl (option (list Pprint.document & R.range)))
222222
= let namespaces = L.map Ident.path_of_text namespaces in
223223
let module_abbrevs = L.map (fun (x, l) -> x, Ident.path_of_text l) module_abbrevs in
224224
let env = D.reinitialize_env env.dsenv (TcEnv.current_module env) namespaces module_abbrevs in
@@ -230,7 +230,7 @@ let desugar_pulse_decl_callback
230230
(blob:FStarC.Dyn.dyn)
231231
(lids:list lident)
232232
(rng:R.range)
233-
: list FStarC.Syntax.Syntax.sigelt'
233+
: ML (list FStarC.Syntax.Syntax.sigelt')
234234
= let d = D.desugar_decl (D.mk_env env) (FStarC.Dyn.undyn blob) 0 in
235235
match fst d with
236236
| Inr None ->
@@ -259,7 +259,7 @@ let parse_pulse (env:TcEnv.env)
259259
(content:string)
260260
(file_name:string)
261261
(line col:int)
262-
: either PulseSyntaxExtension.SyntaxWrapper.decl (option (list Pprint.document & R.range))
262+
: ML (either PulseSyntaxExtension.SyntaxWrapper.decl (option (list Pprint.document & R.range)))
263263
= let range =
264264
let p = R.mk_pos line col in
265265
R.mk_range file_name p p

0 commit comments

Comments
 (0)