Skip to content
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

Add record name in the MLE_Record node #3161

Merged
merged 3 commits into from
Dec 13, 2023
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
2 changes: 1 addition & 1 deletion ocaml/fstar-lib/FStar_Extraction_ML_PrintML.ml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ let rec build_expr (e: mlexpr): expression =
| MLE_CTor args -> build_constructor_expr args
| MLE_Seq args -> build_seq args
| MLE_Tuple l -> Exp.tuple (map build_expr l)
| MLE_Record (path, l) ->
| MLE_Record (path, _, l) ->
let fields = map (fun (x,y) -> (path_to_ident(path, x), build_expr y)) l in
Exp.record fields None
| MLE_Proj (e, path) ->
Expand Down
22 changes: 11 additions & 11 deletions ocaml/fstar-lib/generated/FStar_Extraction_Krml.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions ocaml/fstar-lib/generated/FStar_Extraction_ML_Code.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion ocaml/fstar-lib/generated/FStar_Extraction_ML_RegEmb.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions ocaml/fstar-lib/generated/FStar_Extraction_ML_Syntax.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions ocaml/fstar-lib/generated/FStar_Extraction_ML_Term.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/extraction/FStar.Extraction.Krml.fst
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ and translate_expr' env e: expr =
| MLE_Coerce (e, t_from, t_to) ->
ECast (translate_expr env e, translate_type env t_to)

| MLE_Record (_, fields) ->
| MLE_Record (_, _, fields) ->
EFlat (assert_lid env e.mlty, List.map (fun (field, expr) ->
field, translate_expr env expr) fields)

Expand Down
2 changes: 1 addition & 1 deletion src/extraction/FStar.Extraction.ML.Code.fst
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ let rec doc_of_expr (currentModule : mlsymbol) (outer : level) (e : mlexpr) : do
| MLE_Name path ->
text (ptsym currentModule path)

| MLE_Record (path, fields) ->
| MLE_Record (path, _, fields) ->
let for1 (name, e) =
let doc = doc_of_expr currentModule (min_op_prec, NonAssoc) e in
reduce1 [text (ptsym currentModule (path, name)); text "="; doc] in
Expand Down
2 changes: 1 addition & 1 deletion src/extraction/FStar.Extraction.ML.RegEmb.fst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let ml_record : Ident.lid -> list (string & mlexpr) -> mlexpr =
fun l args ->
let s = Ident.path_of_lid l in
// [] -> assuming same module
mk (MLE_Record ([], args))
mk (MLE_Record ([], l |> Ident.ident_of_lid |> Ident.string_of_id, args))

let ml_lam nm e =
mk <| MLE_Fun ([(nm, MLTY_Top)], e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let rec elim_mlexpr' (env:env_t) (e:mlexpr') =
| MLE_CTor(l, es) -> MLE_CTor(l, List.map (elim_mlexpr env) es)
| MLE_Seq es -> MLE_Seq (List.map (elim_mlexpr env) es)
| MLE_Tuple es -> MLE_Tuple (List.map (elim_mlexpr env) es)
| MLE_Record(syms, fields) -> MLE_Record(syms, List.map (fun (s, e) -> s, elim_mlexpr env e) fields)
| MLE_Record(syms, nm, fields) -> MLE_Record(syms, nm, List.map (fun (s, e) -> s, elim_mlexpr env e) fields)
| MLE_Proj (e, p) -> MLE_Proj(elim_mlexpr env e, p)
| MLE_If(e, e1, e2_opt) -> MLE_If(elim_mlexpr env e, elim_mlexpr env e1, BU.map_opt e2_opt (elim_mlexpr env))
| MLE_Raise(p, es) -> MLE_Raise (p, List.map (elim_mlexpr env) es)
Expand Down
8 changes: 5 additions & 3 deletions src/extraction/FStar.Extraction.ML.Syntax.fst
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ type mlexpr' =
| MLE_CTor of mlpath * list mlexpr
| MLE_Seq of list mlexpr
| MLE_Tuple of list mlexpr
| MLE_Record of list mlsymbol * list (mlsymbol * mlexpr) // path of record type, and fields with values
| MLE_Record of list mlsymbol * mlsymbol * list (mlsymbol * mlexpr) // path of record type,
// name of record type,
// and fields with values
| MLE_Proj of mlexpr * mlpath
| MLE_If of mlexpr * mlexpr * option mlexpr
| MLE_Raise of mlpath * list mlexpr
Expand Down Expand Up @@ -314,8 +316,8 @@ let rec mlexpr_to_string (e:mlexpr) =
BU.format1 "(MLE_Seq [%s])" (String.concat "; " (List.map mlexpr_to_string es))
| MLE_Tuple es ->
BU.format1 "(MLE_Tuple [%s])" (String.concat "; " (List.map mlexpr_to_string es))
| MLE_Record (p, es) ->
BU.format2 "(MLE_Record (%s, [%s]))" (String.concat "; " p) (String.concat "; " (List.map (fun (x, e) -> BU.format2 "(%s, %s)" x (mlexpr_to_string e)) es))
| MLE_Record (p, n, es) ->
BU.format2 "(MLE_Record (%s, [%s]))" (String.concat "; " (p@[n])) (String.concat "; " (List.map (fun (x, e) -> BU.format2 "(%s, %s)" x (mlexpr_to_string e)) es))
| MLE_Proj (e, p) ->
BU.format2 "(MLE_Proj (%s, %s))" (mlexpr_to_string e) (mlpath_to_string p)
| MLE_If (e1, e2, None) ->
Expand Down
4 changes: 2 additions & 2 deletions src/extraction/FStar.Extraction.ML.Term.fst
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ let rec is_ml_value e =
| MLE_Fun _ -> true
| MLE_CTor (_, exps)
| MLE_Tuple exps -> BU.for_all is_ml_value exps
| MLE_Record (_, fields) -> BU.for_all (fun (_, e) -> is_ml_value e) fields
| MLE_Record (_, _, fields) -> BU.for_all (fun (_, e) -> is_ml_value e) fields
| MLE_TApp (h, _) -> is_ml_value h
| _ -> false

Expand Down Expand Up @@ -1149,7 +1149,7 @@ let maybe_eta_data_and_project_record (g:uenv) (qual : option fv_qual) (residual
let path = List.map string_of_id (ns_of_lid tyname) in
let fields = record_fields g tyname fields args in
let path = no_fstar_stubs_ns path in
with_ty e.mlty <| MLE_Record(path, fields)
with_ty e.mlty <| MLE_Record (path, tyname |> ident_of_lid |> string_of_id, fields)
| _ -> e
in
let resugar_and_maybe_eta qual e =
Expand Down