SpaceLang

$v$::= $() \;\;|\;\; n \in \mathbb{N} \;\;|\;\; l \in L \;\;|\;\; \mu_{ptr} f. \lambda \overrightarrow{x}. t$
$b$::= $\overrightarrow{v} \;\;|\;\; \emptyset $
$\odot$::= $+\;\;|\;\;-\;\;|\;\;\times$
$t$::= $v \;\;|\;\; x \;\;|\;\; t \odot x \;\;|\;\; (t\;\overrightarrow{u})_{ptr}$
$\text{alloc}\;t\;\;|\;\;t[t]\;\;|\;\;t[t]\gets t\;|$
$\text{let}\;x=t\;\text{in}\;t$
$\text{if}\;t\;\text{then}\;t\;\text{else}\;t$

      let x = alloc 2 in
      x[0] ← 5
      x[1] ← 15
      ...
      let y = alloc 1 in
      y[0] ← x[0] + x[1]
      ... // x is not used again

Can we free x?


      let x = alloc 2 in
      x[0] ← 5
      x[1] ← 15
      ...
      let y = alloc 1 in
      y[0] ← x[0] + x[1]
      ...
    
$ \{x \mapsto [5,15] \}$
y[0] ← x[0] + x[1]
$ \{\lambda\_.\,y \mapsto 20 \} $

$x \gets l$



      let x = alloc 2 in
      x[0] ← 5
      x[1] ← 15
      ...
      let y = alloc 1 in
      y[0] ← x[0] + x[1]
      ...
    
$ \{x \mapsto [5,15]\,\ast\, x \gets \emptyset\}$
y[0] ← x[0] + x[1]
$ \{\lambda\_.\,y \mapsto 20\,\ast\,\color{red}{??}\} $

$ \diamond\,n\,\ast\,\dagger\!\!\dagger\!\!\{x\}$


$ \{x \mapsto [5,15]\,\ast\, x \gets \emptyset\}$
y[0] ← x[0] + x[1]
$ \{\lambda\_.\,y \mapsto 20\,\ast\,\diamond\,2\,\ast\,\dagger\!\!\dagger\!\!\{x\}\} $

$x \mapsto [5,15]\;\ast\;x \gets \emptyset$

$\implies{}_{\!\!\!\!I}$

$\diamond\,2\,\ast\,\dagger\!\!\dagger\!\!\{x\}$

What about the stack?

$\text{Stackable}_p\;x$


$x \mapsto [5,15]\;\ast\;x \gets \emptyset\;$

$\ast\;\text{Stackable}_p\;x\;\ast\;x \notin V$

$\implies{}_{\!\!\!\!I}$

$\diamond\,2\,\ast\,\dagger\!\!\dagger\!\!\{x\}$