summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Campbell2018-05-22 18:38:07 +0100
committerBrian Campbell2018-05-22 18:52:21 +0100
commit0c583ea8feec9bc2aed441a976449974ff9350cc (patch)
treefec1daf2298bf61359291e8507d868ebaa22d9f5
parentf87597747784a838f5373132e78c3b3c0c13f320 (diff)
Fix one part of cast introduction, leave another for later
-rw-r--r--src/monomorphise.ml12
-rw-r--r--test/mono/castreq.sail7
2 files changed, 13 insertions, 6 deletions
diff --git a/src/monomorphise.ml b/src/monomorphise.ml
index 4f257712..98ef5034 100644
--- a/src/monomorphise.ml
+++ b/src/monomorphise.ml
@@ -3975,6 +3975,9 @@ let add_bitvector_casts (Defs defs) =
end
| E_return e' ->
E_aux (E_return (make_bitvector_cast_exp top_env quant_kids (fill_in_type (env_of e') (typ_of e')) ret_typ e'),ann)
+ (* TODO: (env_of_annot ann) isn't suitable, because it contains
+ constraints revealing the case splits involved; needs a more
+ subtle approach *)
| E_assign (LEXP_aux (lexp,lexp_annot),e') ->
E_aux (E_assign (LEXP_aux (lexp,lexp_annot),
make_bitvector_cast_exp (env_of_annot ann) quant_kids (fill_in_type (env_of e') (typ_of e'))
@@ -3987,7 +3990,8 @@ let add_bitvector_casts (Defs defs) =
e_aux = rewrite_aux } exp
in
let rewrite_funcl (FCL_aux (FCL_Funcl (id,pexp),fcl_ann)) =
- let (tq,typ) = Env.get_val_spec_orig id (env_of_annot fcl_ann) in
+ let fcl_env = env_of_annot fcl_ann in
+ let (tq,typ) = Env.get_val_spec_orig id fcl_env in
let quant_kids = List.map kopt_kid (quant_kopts tq) in
let ret_typ =
match typ with
@@ -3998,11 +4002,11 @@ let add_bitvector_casts (Defs defs) =
" is not a function type"))
in
let pat,guard,body,annot = destruct_pexp pexp in
- let env = env_of body in
- let body = rewrite_body id quant_kids env ret_typ body in
+ let body_env = env_of body in
+ let body = rewrite_body id quant_kids body_env ret_typ body in
(* Also add a cast around the entire function clause body, if necessary *)
let body =
- make_bitvector_cast_exp env quant_kids (fill_in_type (env_of body) (typ_of body)) ret_typ body
+ make_bitvector_cast_exp fcl_env quant_kids (fill_in_type body_env (typ_of body)) ret_typ body
in
let pexp = construct_pexp (pat,guard,body,annot) in
FCL_aux (FCL_Funcl (id,pexp),fcl_ann)
diff --git a/test/mono/castreq.sail b/test/mono/castreq.sail
index 67a7fc8e..3400d650 100644
--- a/test/mono/castreq.sail
+++ b/test/mono/castreq.sail
@@ -51,6 +51,8 @@ function ret(x) =
64 => let z = y@y@y@y in { dfsf = 4; return z; undefined }
}
+/* TODO: Assignments need more plumbing
+
val assign : forall 'm 'n, 'm in {8,16} & 'n in {32,64}. bits('m) -> bits('n) effect {undef}
function assign(x) = {
@@ -62,6 +64,7 @@ function assign(x) = {
};
r
}
+*/
/* Adding casts for top-level pattern matches */
@@ -102,10 +105,10 @@ function run () = {
assert((ret(0x34) : bits(64)) == 0x0034003400340034);
assert((ret(0x3456) : bits(32)) == 0x34563456);
assert((ret(0x3456) : bits(64)) == 0x3456345634563456);
- assert((assign(0x12) : bits(32)) == 0x00120012);
+/* assert((assign(0x12) : bits(32)) == 0x00120012);
assert((assign(0x1234) : bits(32)) == 0x12341234);
assert((assign(0x12) : bits(64)) == 0x0012001200120012);
- assert((assign(0x1234) : bits(64)) == 0x1234123412341234);
+ assert((assign(0x1234) : bits(64)) == 0x1234123412341234);*/
assert(foo2(32,0x12) == 0x00120012);
assert(foo2(64,0x12) == 0x0012001200120012);
assert(foo3(4,0x12) == 0x00120012);