+
Skip to content

Conversation

nomeata
Copy link

@nomeata nomeata commented Apr 21, 2023

This pass can go before the sideconditions pass #9, to do something more clever with option projection. Here is an example:

   ;; 3-typing.watsup:238.1-240.23
-  rule extend {C : context, n : n, nt : numtype}:
+  rule extend {C : context, n : n, nt : numtype, o0 : nat}:
     `%|-%:%`(C, EXTEND_instr(nt, n), `%->%`([(nt <: valtype)], [(nt <: valtype)]))
-    -- if ($size(nt <: valtype) =/= ?())
-    -- if (n <= !($size(nt <: valtype)))
+    -- if ($size(nt <: valtype) = ?(o0))
+    -- if (n <= o0)

Before it would introduce != null constraints and leave !(e) in place, which is correct, but typically hard to work with in a formalization. With this pass before, it introduces a fresh variable o0 and asserts that the partial expression is = ?o0.

This is a separate pass because maybe only some backends will prefer this (and because it’s slightly complicated).

nomeata added 7 commits April 8, 2023 21:56
This transformation make explicit the following implicit side conditions
of terms in premises and conclusions:

 * Array access          a[i]         i < |a|
 * Joint iteration       e*{v1,v2}    |v1*| = |v2*|
 * Option projection     !(e)         e =!= null

Depends upon #6 and #5.
@nomeata
Copy link
Author

nomeata commented Apr 21, 2023

I did some mildly nasty things to Validation.mli to be able to infer the types of expressions. This probably needs some cleanup there first (immutable validate_bind for example), or change validation to add type annotations altogether, or so.

@nomeata
Copy link
Author

nomeata commented Apr 21, 2023

CI is only red because github is stupid and tries to merge before running CI, instead of testing the latest commit. This can be fixed in the github workflow file, maybe I should open a PR for that later.

Will merge later (need to handle the HintD declaration).

@rossberg
Copy link
Collaborator

Should we just annotate every node in the IL AST with its type?

@nomeata
Copy link
Author

nomeata commented Apr 26, 2023

Yes, probably. As a Source.note as in Motoko?

Maybe make it a type option, so that IL passes don't have to worry about annotating nodes they generate, and one has to run the validator to reannotate?

@rossberg
Copy link
Collaborator

Yes, that's what I was thinking. And then we can remove all type annotations inside exp constructors. Not sure about making it optional, is there indication that it might be difficult in places?

@nomeata
Copy link
Author

nomeata commented Apr 26, 2023

Not yet, we can try without option and I'll complain if it's hard somewhere.

@nomeata
Copy link
Author

nomeata commented Apr 26, 2023

Or we could do what GHC does: only annotate enough leafs (variables and functions, I assume) so that one can infer the type for all expressions without context. A bit less bookkeeping, and performance is not super critical here.

@rossberg
Copy link
Collaborator

rossberg commented Apr 27, 2023

Okay, I implemented this (i.e., types in all expression nodes). Also removed the now redundant annotations on DotE, CaseE, and DotP again.

It was slightly painful to construct the types in the sideconditions phase, because that required a variable environment. We can make them optional if that turns out to be too dreadful in the future.

@nomeata
Copy link
Author

nomeata commented Apr 27, 2023

Cool, will update this pass accordingly in a few days (unless someone beats me to it)

@nomeata
Copy link
Author

nomeata commented May 2, 2023

Updated to use the type information in the AST annotations.

@nomeata nomeata merged commit 9b2121f into main May 9, 2023
@nomeata nomeata deleted the the-elimination branch May 9, 2023 09:34
let rec t_exp n e : eqns * exp =
(* Descend first using t_exp2, and then see if we have to pull out the current expression *)
let eqns, e' = t_exp2 n e in
match e.it with

Choose a reason for hiding this comment

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

@nomeata - Was this supposed to be e'.it instead of e.it?

Copy link
Author

Choose a reason for hiding this comment

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

Oh, quite likely. We probably don’t have nested the so far. Thanks for spotting!

Alan-Liang pushed a commit to Alan-Liang/spectec that referenced this pull request Sep 1, 2024
Merge with WebAssembly/spec and WebAssembly/gc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载