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

Safety-checker: support for SLH primitives #814

Merged
merged 1 commit into from
Jun 3, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
The compilation of these is proven to preserve functional semantics.
We also provide a speculative CCT checker, via the `jazzct` flag `--sct`.
([PR #447](https://github.com/jasmin-lang/jasmin/pull/447),
[PR #723](https://github.com/jasmin-lang/jasmin/pull/723)).
[PR #723](https://github.com/jasmin-lang/jasmin/pull/723),
[PR #814](https://github.com/jasmin-lang/jasmin/pull/814))

- Register arrays and sub-arrays can appear as arguments and return values of
local functions;
Expand Down
20 changes: 20 additions & 0 deletions compiler/safety/success/slh.jazz
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export
fn deref(reg u64 x) -> reg u64 {
reg u64[2] msf;

msf[1] = #init_msf();
msf[0] = #mov_msf(msf[1]);

reg bool b;
b = x < 10;
if b {
msf[1] = #update_msf(b, msf[0]);
} else {
msf[1] = #update_msf(!b, msf[0]);
}

x = [x];
x = #protect(x, msf[1]);

return x;
}
13 changes: 13 additions & 0 deletions compiler/safetylib/safetyInterpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,19 @@ end = struct
let e = Papp1 (E.Olnot ws, e1) in
[Some e]

| Sopn.Oslh op ->
begin match op with
| SLHinit -> [ Some (pcast U64 (Pconst (Z.of_int 0))) ]
| SLHupdate ->
let b, msf = as_seq2 es in
let msf = Pif (Bty (U U64), b, msf, pcast U64 (Pconst (Z.of_int (-1)))) in
[ Some msf ]
| SLHmove -> let msf = as_seq1 es in [ Some msf ]
| SLHprotect _ | SLHprotect_ptr _ ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is suspicious, what about protect(x, -1)? I think you assume that the program is well typed for SCT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the semantics of #protect?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I forgot that the semantic of protect is the identity at source level.
Sorry for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This program is well-typed and has a well-defined semantics (the identity). However, it cannot be compiled.

export
fn p(reg u64 x) -> reg u64 {
reg u64 y msf;
msf = 42;
y = #protect(x, msf);
return y;
}

let x, _msf = as_seq2 es in
[ Some x ]
| SLHprotect_ptr_fail _ -> assert false
end
| _ ->
debug (fun () ->
Format.eprintf "Warning: unknown opn %a, default to ⊤.@."
Expand Down