Skip to content

Commit 3611e46

Browse files
committed
Various fixes
- Preserve some mapping locations better - Preserve documentation comments and attributes on scattered mappings and functions - Fix an issue with dead match branches when the eager_control_flow option was used in Jib compilation - Simplify Parse_ast representation of SD_mapping and SD_function - Re-order Ast.SD_function arguments to match surface syntax
1 parent bdc464f commit 3611e46

File tree

12 files changed

+102
-78
lines changed

12 files changed

+102
-78
lines changed

language/sail.ott

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ default_spec :: 'DT_' ::=
726726
scattered_def :: 'SD_' ::=
727727
{{ com scattered function and union type definitions }}
728728
{{ aux _ annot }} {{ auxparam 'a }}
729-
| scattered function rec_opt tannot_opt effect_opt id :: :: function
729+
| scattered function id : tannot_opt effect_opt :: :: function
730730
{{ texlong }} {{ com scattered function definition header }}
731731

732732
| function clause funcl :: :: funcl

src/lib/ast_util.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ and map_valspec_annot f = function VS_aux (vs_aux, annot) -> VS_aux (vs_aux, f a
991991
and map_scattered_annot f = function SD_aux (sd_aux, annot) -> SD_aux (map_scattered_annot_aux f sd_aux, f annot)
992992

993993
and map_scattered_annot_aux f = function
994-
| SD_function (rec_opt, tannot_opt, name) -> SD_function (map_recopt_annot f rec_opt, tannot_opt, name)
994+
| SD_function (name, tannot_opt) -> SD_function (name, tannot_opt)
995995
| SD_funcl fcl -> SD_funcl (map_funcl_annot f fcl)
996996
| SD_variant (id, typq) -> SD_variant (id, typq)
997997
| SD_unioncl (id, tu) -> SD_unioncl (id, tu)
@@ -1425,7 +1425,7 @@ let id_of_dec_spec (DEC_aux (DEC_reg (_, id, _), _)) = id
14251425

14261426
let id_of_scattered (SD_aux (sdef, _)) =
14271427
match sdef with
1428-
| SD_function (_, _, id)
1428+
| SD_function (id, _)
14291429
| SD_funcl (FCL_aux (FCL_funcl (id, _), _))
14301430
| SD_end id
14311431
| SD_variant (id, _)

src/lib/chunk_ast.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ let chunk_default_typing_spec comments chunks (DT_aux (DT_order (kind, typ), l))
11371137
chunk_atyp comments chunks typ;
11381138
Queue.push (Spacer (true, 1)) chunks
11391139

1140-
let chunk_fundef comments chunks (FD_aux (FD_function (rec_opt, tannot_opt, _, funcls), l)) =
1140+
let chunk_fundef comments chunks (FD_aux (FD_function (rec_opt, tannot_opt, funcls), l)) =
11411141
pop_comments comments chunks l;
11421142
let fn_id =
11431143
match funcls with
@@ -1276,7 +1276,7 @@ let chunk_scattered comments chunks (SD_aux (aux, l)) =
12761276
(Function { id; clause = true; rec_opt = None; typq_opt = None; return_typ_opt = None; funcls = [funcl_chunks] })
12771277
chunks
12781278
| SD_end id -> build_def chunks [chunk_keyword "end"; chunk_id id comments]
1279-
| SD_function (_, _, _, id) -> build_def chunks [chunk_keyword "scattered function"; chunk_id id comments]
1279+
| SD_function (id, _) -> build_def chunks [chunk_keyword "scattered function"; chunk_id id comments]
12801280
| _ -> Reporting.unreachable l __POS__ "unhandled scattered def"
12811281

12821282
let def_spacer (_, e) (s, _) = match (e, s) with Some l_e, Some l_s -> if l_s > l_e + 1 then 1 else 0 | _, _ -> 1

src/lib/initial_check.ml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,10 @@ module KindInference = struct
733733
let* case = infer_case ctx case in
734734
wrap (P.FCL_funcl (id, case))
735735

736-
let infer_fundef ctx (P.FD_aux (P.FD_function (rec_opt, tannot_opt, effects, funcls), l)) =
736+
let infer_fundef ctx (P.FD_aux (P.FD_function (rec_opt, tannot_opt, funcls), l)) =
737737
let* tannot_opt = infer_tannot_opt ctx tannot_opt in
738738
let* funcls = mapM (infer_funcl ctx) funcls in
739-
return (P.FD_aux (P.FD_function (rec_opt, tannot_opt, effects, funcls), l))
739+
return (P.FD_aux (P.FD_function (rec_opt, tannot_opt, funcls), l))
740740

741741
let rec infer_constructor ctx (P.Tu_aux (aux, l)) =
742742
let wrap aux = return (P.Tu_aux (aux, l)) in
@@ -1761,7 +1761,7 @@ let to_ast_impl_funcls ctx (P.FCL_aux (fcl, l) : P.funcl) : uannot funcl list =
17611761
| _ -> raise (Reporting.err_general l "Attributes or documentation comment not permitted here")
17621762

17631763
let to_ast_fundef ctx fdef =
1764-
let P.FD_aux (P.FD_function (rec_opt, tannot_opt, _, funcls), l), kenv =
1764+
let P.FD_aux (P.FD_function (rec_opt, tannot_opt, funcls), l), kenv =
17651765
KindInference.infer_fundef ctx fdef KindInference.initial_env
17661766
in
17671767
let tannot_opt, ctx = ConvertType.to_ast_tannot_opt kenv ctx tannot_opt in
@@ -1837,9 +1837,10 @@ let to_ast_dec ctx (P.DEC_aux (regdec, l)) =
18371837
let to_ast_scattered ctx (P.SD_aux (aux, l)) =
18381838
let extra_def, aux, ctx =
18391839
match aux with
1840-
| P.SD_function (rec_opt, tannot_opt, _, id) ->
1840+
| P.SD_function (id, tannot_opt) ->
1841+
let id = to_ast_id ctx id in
18411842
let tannot_opt, _ = to_ast_tannot_opt ctx tannot_opt in
1842-
(None, SD_function (to_ast_rec ctx rec_opt, tannot_opt, to_ast_id ctx id), ctx)
1843+
(None, SD_function (id, tannot_opt), ctx)
18431844
| P.SD_funcl funcl -> (None, SD_funcl (to_ast_funcl None [] ctx funcl), ctx)
18441845
| P.SD_variant (id, parse_typq) ->
18451846
let id = to_ast_id ctx id in
@@ -1904,15 +1905,6 @@ let to_ast_loop_measure ctx = function
19041905
| P.Loop (P.While, exp) -> (While, map_exp_annot (fun (l, _) -> (l, ())) @@ to_ast_exp ctx exp)
19051906
| P.Loop (P.Until, exp) -> (Until, map_exp_annot (fun (l, _) -> (l, ())) @@ to_ast_exp ctx exp)
19061907

1907-
(* Annotations on some scattered constructs will not be preserved after de-scattering, so warn about this *)
1908-
let check_annotation (DEF_aux (aux, def_annot)) =
1909-
if Option.is_some def_annot.doc_comment || not (Util.list_empty def_annot.attrs) then (
1910-
match aux with
1911-
| DEF_scattered (SD_aux ((SD_function _ | SD_mapping _ | SD_end _), _)) ->
1912-
Reporting.warn "" def_annot.loc "Documentation comments and attributes will not be preserved on this definition"
1913-
| _ -> ()
1914-
)
1915-
19161908
let pragma_arg_loc pragma arg_left_trim l =
19171909
let open Lexing in
19181910
Reporting.map_loc_range
@@ -2038,7 +2030,6 @@ let to_ast ctx (P.Defs files) =
20382030
List.fold_left
20392031
(fun (defs, ctx) def ->
20402032
let new_defs, ctx = to_ast_def None [] None ctx def in
2041-
List.iter check_annotation new_defs;
20422033
(new_defs @ defs, ctx)
20432034
)
20442035
([], ctx) defs

src/lib/jib_compile.ml

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -772,37 +772,42 @@ module Make (C : CONFIG) = struct
772772
let ctyp = ctyp_of_typ ctx typ in
773773
let aval_setup, cval, aval_cleanup = compile_aval l ctx aval in
774774
let compile_case case_match_id case_return_id (apat, guard, body) =
775-
let trivial_guard =
776-
match guard with
777-
| AE_aux (AE_val (AV_lit (L_aux (L_true, _), _)), _)
778-
| AE_aux (AE_val (AV_cval (V_lit (VL_bool true, CT_bool), _)), _) ->
779-
true
780-
| _ -> false
781-
in
782-
let pre_destructure, destructure, destructure_cleanup, ctx =
783-
compile_match ctx apat cval (fun l b -> icopy l (CL_id (case_match_id, CT_bool)) (V_call (Bnot, [b])))
784-
in
785-
let guard_setup, guard_call, guard_cleanup = compile_aexp ctx guard in
786-
let body_setup, body_call, body_cleanup = compile_aexp ctx body in
787-
[iinit l CT_bool case_match_id (V_lit (VL_bool true, CT_bool)); idecl l ctyp case_return_id]
788-
@ pre_destructure @ destructure
789-
@ ( if not trivial_guard then (
790-
let gs = ngensym () in
791-
guard_setup
792-
@ [idecl l CT_bool gs; guard_call (CL_id (gs, CT_bool))]
793-
@ guard_cleanup
794-
@ [
795-
iif l
796-
(V_call (Bnot, [V_id (gs, CT_bool)]))
797-
(destructure_cleanup @ [icopy l (CL_id (case_match_id, CT_bool)) (V_lit (VL_bool false, CT_bool))])
798-
[] CT_unit;
799-
]
775+
if is_dead_aexp body then []
776+
else (
777+
let trivial_guard =
778+
match guard with
779+
| AE_aux (AE_val (AV_lit (L_aux (L_true, _), _)), _)
780+
| AE_aux (AE_val (AV_cval (V_lit (VL_bool true, CT_bool), _)), _) ->
781+
true
782+
| _ -> false
783+
in
784+
let pre_destructure, destructure, destructure_cleanup, ctx =
785+
compile_match ctx apat cval (fun l b -> icopy l (CL_id (case_match_id, CT_bool)) (V_call (Bnot, [b])))
786+
in
787+
let guard_setup, guard_call, guard_cleanup = compile_aexp ctx guard in
788+
let body_setup, body_call, body_cleanup = compile_aexp ctx body in
789+
[iinit l CT_bool case_match_id (V_lit (VL_bool true, CT_bool)); idecl l ctyp case_return_id]
790+
@ pre_destructure @ destructure
791+
@ ( if not trivial_guard then (
792+
let gs = ngensym () in
793+
guard_setup
794+
@ [idecl l CT_bool gs; guard_call (CL_id (gs, CT_bool))]
795+
@ guard_cleanup
796+
@ [
797+
iif l
798+
(V_call (Bnot, [V_id (gs, CT_bool)]))
799+
(destructure_cleanup
800+
@ [icopy l (CL_id (case_match_id, CT_bool)) (V_lit (VL_bool false, CT_bool))]
801+
)
802+
[] CT_unit;
803+
]
804+
)
805+
else []
800806
)
801-
else []
802-
)
803-
@ body_setup
804-
@ [body_call (CL_id (case_return_id, ctyp))]
805-
@ body_cleanup @ destructure_cleanup
807+
@ body_setup
808+
@ [body_call (CL_id (case_return_id, ctyp))]
809+
@ body_cleanup @ destructure_cleanup
810+
)
806811
in
807812
let case_ids, cases =
808813
List.map

src/lib/parse_ast.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ type outcome_spec_aux = (* outcome declaration *)
375375
type outcome_spec = OV_aux of outcome_spec_aux * l
376376

377377
type fundef_aux = (* Function definition *)
378-
| FD_function of rec_opt * tannot_opt * effect_opt * funcl list
378+
| FD_function of rec_opt * tannot_opt * funcl list
379379

380380
type type_def_aux =
381381
(* Type definition body *)
@@ -395,7 +395,7 @@ type dec_spec_aux = (* Register declarations *)
395395
type scattered_def_aux =
396396
(* Function and type union definitions that can be spread across
397397
a file. Each one must end in $_$ *)
398-
| SD_function of rec_opt * tannot_opt * effect_opt * id (* scattered function definition header *)
398+
| SD_function of id * tannot_opt (* scattered function definition header *)
399399
| SD_funcl of funcl (* scattered function definition clause *)
400400
| SD_enum of id (* scattered enumeration definition header *)
401401
| SD_enumcl of id * id (* scattered enumeration member clause *)

src/lib/parser.mly

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ let mk_typqn = TypQ_aux (TypQ_no_forall, Unknown)
148148
149149
let mk_tannotn = Typ_annot_opt_aux (Typ_annot_opt_none, Unknown)
150150
let mk_tannot typq typ n m = Typ_annot_opt_aux (Typ_annot_opt_some (typq, typ), loc n m)
151-
let mk_eannotn = Effect_opt_aux (Effect_opt_none,Unknown)
152151
153152
let mk_typq kopts nc n m = TypQ_aux (TypQ_tq (List.map qi_id_of_kopt kopts @ nc), loc n m)
154153
@@ -1077,7 +1076,7 @@ rec_measure:
10771076

10781077
fun_def:
10791078
| Function_ rec_measure? funcls
1080-
{ let funcls, tannot = $3 in mk_fun (FD_function (default_opt mk_recn $2, tannot, mk_eannotn, funcls)) $startpos $endpos }
1079+
{ let funcls, tannot = $3 in mk_fun (FD_function (default_opt mk_recn $2, tannot, funcls)) $startpos $endpos }
10811080

10821081
fun_def_list:
10831082
| fun_def
@@ -1259,9 +1258,9 @@ scattered_def:
12591258
| Scattered Union id typaram
12601259
{ mk_sd (SD_variant($3, $4)) $startpos $endpos }
12611260
| Scattered Union id
1262-
{ mk_sd (SD_variant($3, mk_typqn)) $startpos $endpos }
1261+
{ mk_sd (SD_variant ($3, mk_typqn)) $startpos $endpos }
12631262
| Scattered Function_ id
1264-
{ mk_sd (SD_function(mk_recn, mk_tannotn, mk_eannotn, $3)) $startpos $endpos }
1263+
{ mk_sd (SD_function ($3, mk_tannotn)) $startpos $endpos }
12651264
| Scattered Mapping id
12661265
{ mk_sd (SD_mapping ($3, mk_tannotn)) $startpos $endpos }
12671266
| Scattered Mapping id Colon funcl_typ

src/lib/pretty_print_sail.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ module Printer (Config : PRINT_CONFIG) = struct
795795

796796
let doc_scattered (SD_aux (sd_aux, _)) =
797797
match sd_aux with
798-
| SD_function (_, _, id) -> string "scattered" ^^ space ^^ string "function" ^^ space ^^ doc_id id
798+
| SD_function (id, _) -> string "scattered" ^^ space ^^ string "function" ^^ space ^^ doc_id id
799799
| SD_funcl funcl -> string "function" ^^ space ^^ string "clause" ^^ space ^^ doc_funcl funcl
800800
| SD_end id -> string "end" ^^ space ^^ doc_id id
801801
| SD_variant (id, TypQ_aux (TypQ_no_forall, _)) ->

src/lib/scattered.ml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ let patch_funcl_loc def_annot (FCL_aux (aux, (_, tannot))) =
9595
let patch_mapcl_annot def_annot (MCL_aux (aux, (_, tannot))) =
9696
MCL_aux (aux, (Type_check.strip_def_annot def_annot, tannot))
9797

98-
let rec descatter' accumulator funcls mapcls = function
98+
let rec descatter' annots accumulator funcls mapcls = function
9999
(* For scattered functions we collect all the seperate function
100100
clauses until we find the last one, then we turn that function
101101
clause into a DEF_fundef containing all the clauses. *)
102+
| DEF_aux (DEF_scattered (SD_aux (SD_function (id, _), _)), def_annot) :: defs ->
103+
descatter' (Bindings.add id def_annot annots) accumulator funcls mapcls defs
102104
| DEF_aux (DEF_scattered (SD_aux (SD_funcl funcl, (l, tannot))), def_annot) :: defs
103105
when last_scattered_funcl (funcl_id funcl) defs ->
104106
let funcl = patch_funcl_loc def_annot funcl in
@@ -110,43 +112,46 @@ let rec descatter' accumulator funcls mapcls = function
110112
let clauses, update_attr =
111113
Type_check.(check_funcls_complete l (env_of_tannot tannot) clauses (typ_of_tannot tannot))
112114
in
115+
let def_annot =
116+
Option.value ~default:(mk_def_annot (gen_loc l) def_annot.env) (Bindings.find_opt (funcl_id funcl) annots)
117+
in
113118
let accumulator =
114119
DEF_aux
115120
( DEF_fundef (FD_aux (FD_function (fake_rec_opt l, no_tannot_opt l, clauses), (gen_loc l, tannot))),
116-
update_attr (mk_def_annot (gen_loc l) def_annot.env)
121+
update_attr def_annot
117122
)
118123
:: accumulator
119124
in
120-
descatter' accumulator funcls mapcls defs
125+
descatter' annots accumulator funcls mapcls defs
121126
| DEF_aux (DEF_scattered (SD_aux (SD_funcl funcl, _)), def_annot) :: defs ->
122127
let id = funcl_id funcl in
123128
let funcl = patch_funcl_loc def_annot funcl in
124129
begin
125130
match Bindings.find_opt id funcls with
126-
| Some clauses -> descatter' accumulator (Bindings.add id (funcl :: clauses) funcls) mapcls defs
127-
| None -> descatter' accumulator (Bindings.add id [funcl] funcls) mapcls defs
131+
| Some clauses -> descatter' annots accumulator (Bindings.add id (funcl :: clauses) funcls) mapcls defs
132+
| None -> descatter' annots accumulator (Bindings.add id [funcl] funcls) mapcls defs
128133
end
129134
(* Scattered mappings are handled the same way as scattered functions *)
135+
| DEF_aux (DEF_scattered (SD_aux (SD_mapping (id, _), _)), def_annot) :: defs ->
136+
descatter' (Bindings.add id def_annot annots) accumulator funcls mapcls defs
130137
| DEF_aux (DEF_scattered (SD_aux (SD_mapcl (id, mapcl), (l, tannot))), def_annot) :: defs
131138
when last_scattered_mapcl id defs ->
132139
let mapcl = patch_mapcl_annot def_annot mapcl in
133140
let clauses =
134141
match Bindings.find_opt id mapcls with Some clauses -> List.rev (mapcl :: clauses) | None -> [mapcl]
135142
in
143+
let def_annot = Option.value ~default:(mk_def_annot (gen_loc l) def_annot.env) (Bindings.find_opt id annots) in
136144
let accumulator =
137-
DEF_aux
138-
( DEF_mapdef (MD_aux (MD_mapping (id, no_tannot_opt l, clauses), (gen_loc l, tannot))),
139-
mk_def_annot (gen_loc l) def_annot.env
140-
)
145+
DEF_aux (DEF_mapdef (MD_aux (MD_mapping (id, no_tannot_opt l, clauses), (gen_loc l, tannot))), def_annot)
141146
:: accumulator
142147
in
143-
descatter' accumulator funcls mapcls defs
148+
descatter' annots accumulator funcls mapcls defs
144149
| DEF_aux (DEF_scattered (SD_aux (SD_mapcl (id, mapcl), _)), def_annot) :: defs ->
145150
let mapcl = patch_mapcl_annot def_annot mapcl in
146151
begin
147152
match Bindings.find_opt id mapcls with
148-
| Some clauses -> descatter' accumulator funcls (Bindings.add id (mapcl :: clauses) mapcls) defs
149-
| None -> descatter' accumulator funcls (Bindings.add id [mapcl] mapcls) defs
153+
| Some clauses -> descatter' annots accumulator funcls (Bindings.add id (mapcl :: clauses) mapcls) defs
154+
| None -> descatter' annots accumulator funcls (Bindings.add id [mapcl] mapcls) defs
150155
end
151156
(* For scattered unions, when we find a union declaration we
152157
immediately grab all the future clauses and turn it into a
@@ -164,7 +169,7 @@ let rec descatter' accumulator funcls mapcls = function
164169
:: records
165170
@ accumulator
166171
in
167-
descatter' accumulator funcls mapcls (filter_union_clauses id defs)
172+
descatter' annots accumulator funcls mapcls (filter_union_clauses id defs)
168173
end
169174
(* Therefore we should never see SD_unioncl... *)
170175
| DEF_aux (DEF_scattered (SD_aux (SD_unioncl _, (l, _))), _) :: _ ->
@@ -184,9 +189,9 @@ let rec descatter' accumulator funcls mapcls = function
184189
DEF_aux (DEF_type (TD_aux (TD_enum (id, members, false), (gen_loc l, Type_check.empty_tannot))), def_annot)
185190
:: accumulator
186191
in
187-
descatter' accumulator funcls mapcls (filter_enum_clauses id defs)
192+
descatter' annots accumulator funcls mapcls (filter_enum_clauses id defs)
188193
end
189-
| def :: defs -> descatter' (def :: accumulator) funcls mapcls defs
194+
| def :: defs -> descatter' annots (def :: accumulator) funcls mapcls defs
190195
| [] -> List.rev accumulator
191196

192-
let descatter ast = { ast with defs = descatter' [] Bindings.empty Bindings.empty ast.defs }
197+
let descatter ast = { ast with defs = descatter' Bindings.empty [] Bindings.empty Bindings.empty ast.defs }

src/lib/type_check.ml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,12 +2570,12 @@ and check_case env pat_typ pexp typ =
25702570
(* AA: Not sure if we still need this *)
25712571
| exception (Type_error _ as typ_exn) -> (
25722572
match pat with
2573-
| P_aux (P_lit lit, _) ->
2573+
| P_aux (P_lit lit, (l, _)) ->
25742574
let guard' = mk_exp (E_app_infix (mk_exp (E_id (mk_id "p#")), mk_id "==", mk_exp (E_lit lit))) in
25752575
let guard =
25762576
match guard with None -> guard' | Some guard -> mk_exp (E_app_infix (guard, mk_id "&", guard'))
25772577
in
2578-
check_case env pat_typ (Pat_aux (Pat_when (mk_pat (P_id (mk_id "p#")), guard, case), annot)) typ
2578+
check_case env pat_typ (Pat_aux (Pat_when (mk_pat ~loc:l (P_id (mk_id "p#")), guard, case), annot)) typ
25792579
| _ -> raise typ_exn
25802580
)
25812581

@@ -2868,7 +2868,7 @@ and bind_pat env (P_aux (pat_aux, (l, uannot)) as pat) typ =
28682868
let guard =
28692869
locate (fun _ -> l) (mk_exp (E_app_infix (mk_exp (E_id var), mk_id "==", mk_exp (E_lit lit))))
28702870
in
2871-
let typed_pat, env, guards = bind_pat env (mk_pat (P_id var)) typ in
2871+
let typed_pat, env, guards = bind_pat env (mk_pat ~loc:l (P_id var)) typ in
28722872
(typed_pat, env, guard :: guards)
28732873
| _ -> raise typ_exn
28742874
)
@@ -4248,7 +4248,7 @@ and infer_mpat allow_unknown other_env env (MP_aux (mpat_aux, (l, uannot)) as mp
42484248
| Local (Immutable, _) | Unbound _ -> begin
42494249
match Env.lookup_id v other_env with
42504250
| Local (Immutable, typ) ->
4251-
bind_mpat allow_unknown other_env env (mk_mpat (MP_typ (mk_mpat (MP_id v), typ))) typ
4251+
bind_mpat allow_unknown other_env env (mk_mpat ~loc:l (MP_typ (mk_mpat ~loc:l (MP_id v), typ))) typ
42524252
| Unbound _ ->
42534253
if allow_unknown then (annot_mpat (MP_id v) unknown_typ, env, [])
42544254
else
@@ -4934,7 +4934,14 @@ let rec check_typedef : Env.t -> env def_annot -> uannot type_def -> typed_def l
49344934
and check_scattered : Env.t -> env def_annot -> uannot scattered_def -> typed_def list * Env.t =
49354935
fun env def_annot (SD_aux (sdef, (l, uannot))) ->
49364936
match sdef with
4937-
| SD_function (_, _, id) | SD_mapping (id, _) -> ([], Env.add_scattered_id id env)
4937+
| SD_function (id, tannot_opt) ->
4938+
( [DEF_aux (DEF_scattered (SD_aux (SD_function (id, tannot_opt), (l, empty_tannot))), def_annot)],
4939+
Env.add_scattered_id id env
4940+
)
4941+
| SD_mapping (id, tannot_opt) ->
4942+
( [DEF_aux (DEF_scattered (SD_aux (SD_mapping (id, tannot_opt), (l, empty_tannot))), def_annot)],
4943+
Env.add_scattered_id id env
4944+
)
49384945
| SD_end id ->
49394946
if not (Env.is_scattered_id id env) then
49404947
typ_error l (string_of_id id ^ " is not a scattered definition, so it cannot be ended")

test/typecheck/fail/issue775.expect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Type error:
2+
fail/issue775.sail:12.49-51:
3+
12 |mapping clause encdec = UTYPE(imm, rd) <-> imm @ rd @ 0b0010111
4+
 | ^^
5+
 | Expected bitvector type, got regidx

test/typecheck/fail/issue775.sail

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
default Order dec
2+
$include <prelude.sail>
3+
4+
struct regidx = { regidx : bits(5) }
5+
6+
scattered union ast
7+
8+
val encdec : ast <-> bits(32)
9+
scattered mapping encdec
10+
11+
union clause ast = UTYPE : (bits(20), regidx)
12+
mapping clause encdec = UTYPE(imm, rd) <-> imm @ rd @ 0b0010111

0 commit comments

Comments
 (0)