## "expression validity" in WP

I propose updating the weakest precondition with a predicate over expressions,
mainly for the purpose of establishing a notion of `well formed`

expressions.

General idea: The idea is that some expressions might be outright invalid in the absence of certain properties on the state. A predicate on expression, that are preserved under step reduction, could be used to differentiate such expressions. Furthermore, being able to derive certain properties about expressions when opening the weakest precondition might allow for some automation in regards to "pure" reductions that depend on the state while not changing it.

Specific Case:
My Iris instantation is a "language" over processes, where `pstate := gmap pid (state)`

and `pexpr := pid * expr`

, where `pid`

is a process identifier.
For modularity I have separate reduction layers, with the top-layer looking up the state of the process in the state map `step ((p,e), <[p := σh]>σp) -> ((p,e'), <[p := σh']>σp), efs)`

.

This means that every single reduction requires the process id of the expression to be in the map, even if it does not change (in case the underlying reduction is pure).

The presence of the necessary mapping is then expressed as a logical fragment, which is required by every single of my weakest precondition rules. Furthermore, I cannot do "Pure" reductions, as conceptualised with the existing `PureExec`

class.

Proposed Solution:
Update the language instantiation to include a predicate over expressions (here named `well_formed`

), and use it in the weakest precondition.
The predicate should uphold certain properties, such as being preserved under step reduction and contexts.

```
Definition wp_pre `{irisG Λ Σ} (s : stuckness)
(wp : coPset -c> expr Λ -c> (val Λ -c> iProp Σ) -c> iProp Σ) :
coPset -c> expr Λ -c> (val Λ -c> iProp Σ) -c> iProp Σ := λ E e1 Φ,
match to_val e1 with
| Some v => |={E}=> Φ v
| None => ∀ σ1 κ κs n,
state_interp σ1 (κ ++ κs) n ∗ well_formed e1 ={E,∅}=∗
⌜if s is NotStuck then reducible e1 σ1 else True⌝ ∗
∀ e2 σ2 efs, ⌜prim_step e1 σ1 κ e2 σ2 efs⌝ ={∅,∅,E}▷=∗
state_interp σ2 κs (length efs + n) ∗
well_formed e2 ∗
wp E e2 Φ ∗
[∗ list] i ↦ ef ∈ efs, well_formed ef ∗ wp ⊤ ef fork_post
end%I.
```

Define a lifted `PureExecState`

, which defines expressions that are reducible and "pure" assuming that the state interpretation and well-formedness predicates hold:

```
Record pure_step_state (e1 e2 : expr Λ) := {
pure_exec_val_state : to_val e1 = None;
pure_step_safe_state σ1 κ n : state_interp σ1 κ n -∗ well_formed e1 -∗ ⌜reducible_no_obs e1 σ1⌝;
pure_step_det_state σ1 κ κs e2' σ2 efs n :
state_interp σ1 (κ++κs) n -∗ well_formed e1 -∗ ⌜prim_step e1 σ1 κ e2' σ2 efs⌝ → ⌜κ = [] ∧ σ2 = σ1 ∧ e2' = e2 ∧ efs = []⌝
}.
```

An important property of the proposed change is that original Iris instances remain unchanged when given `True`

as the well_formed predicate.

Points of discussion:

- It has earlier been suggested to introduce closedness of expression in a similar manner. Note however that the closedness condition on expressions has been phased out of the current iteration of Iris.
- The change would mean that any WP holds trivially true for invalid expressions, which must then suddenly be considered in many places.