Compiler Generation for Substructural Operational Semantics
Compiler Generation for Substructural Operational Semantics Anand - - PowerPoint PPT Presentation
Compiler Generation for Substructural Operational Semantics Anand - - PowerPoint PPT Presentation
Compiler Generation for Substructural Operational Semantics Masters Thesis Presentation Compiler Generation for Substructural Operational Semantics Anand Subramanian <asubrama@andrew.cmu.edu> 2012-12-18 Thesis Committee: Frank
Compiler Generation for Substructural Operational Semantics Introduction
Introduction
This thesis explores the synthesis of compilers and virtual machines from semantic specification of programming languages in SSOS. Our methodology has been tested on an encoding of the semantics
- f C0 in CLF.
Compiler Generation for Substructural Operational Semantics Introduction
Specification Synthesis
Compiler Generation for Substructural Operational Semantics Introduction
Compiling and Executing a Program
Compiler Generation for Substructural Operational Semantics Introduction
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Introduction
SSOS
▸ SSOS specifies semantics of programming languages using
state-transition rules encoded in a substructural logic.
Compiler Generation for Substructural Operational Semantics Introduction
SSOS
▸ SSOS specifies semantics of programming languages using
state-transition rules encoded in a substructural logic.
▸
∆ ↝ ∆′ ∆ and ∆′ are states, represented as multisets of resources.
Compiler Generation for Substructural Operational Semantics Introduction
SSOS
▸ SSOS specifies semantics of programming languages using
state-transition rules encoded in a substructural logic.
▸
∆ ↝ ∆′ ∆ and ∆′ are states, represented as multisets of resources.
▸ A program’s execution is simulated by setting up the initial
state ∆0 with the program and its environment, and repeatedly applying SSOS rules. ∆0 ↝ ∆1 ↝ ∆2 ↝ ...
Compiler Generation for Substructural Operational Semantics Introduction
Transition Rules in CLF
▸ CLF is a logical framework based on intuitionistic lax linear
logic.
Compiler Generation for Substructural Operational Semantics Introduction
Transition Rules in CLF
▸ CLF is a logical framework based on intuitionistic lax linear
logic.
▸ Transitions are encoded using linear implication in the forward
chaining fragment.
Compiler Generation for Substructural Operational Semantics Introduction
Transition Rules in CLF
▸ CLF is a logical framework based on intuitionistic lax linear
logic.
▸ Transitions are encoded using linear implication in the forward
chaining fragment.
▸ Transitions rules only mention the resources that are being
rewritten, i.e.: ∆,a1,a2...am ↝ ∆,c1,c2...cn can be encoded as: a1,a2...am ↝ c1,c2...cn
Compiler Generation for Substructural Operational Semantics Introduction
SSOS Transition Rule Schema
▸ Active rule:
active ↝ r1,r2,...,rn
Compiler Generation for Substructural Operational Semantics Introduction
SSOS Transition Rule Schema
▸ Active rule:
active ↝ r1,r2,...,rn
▸ Latent rule:
passive1,passive2,...,passivem,latent ↝ r1,r2,...,rn
Compiler Generation for Substructural Operational Semantics Introduction
SSOS Transition Rule Schema
▸ Active rule:
active ↝ r1,r2,...,rn
▸ Latent rule:
passive1,passive2,...,passivem,latent ↝ r1,r2,...,rn
▸ Resources must be strictly classified as active, latent or
passive.
Compiler Generation for Substructural Operational Semantics Introduction
SSOS Transition Rule Schema
▸ Active rule:
active ↝ r1,r2,...,rn
▸ Latent rule:
passive1,passive2,...,passivem,latent ↝ r1,r2,...,rn
▸ Resources must be strictly classified as active, latent or
passive.
Compiler Generation for Substructural Operational Semantics Introduction
SSOS Resources in CLF
exp : type. dest : type. eval : exp -> dest -> type. ret : exp -> dest -> type. frame : type. cont : frame
- > dest -> dest -> type.
Compiler Generation for Substructural Operational Semantics Introduction
Example
⟨exp⟩ ::= ⟨numeric-constant⟩ | ⟨exp⟩ ⟨op⟩ ⟨exp⟩ ⟨op⟩ ::= + | x | ...
Compiler Generation for Substructural Operational Semantics Introduction
Example
⟨exp⟩ ::= ⟨numeric-constant⟩ | ⟨exp⟩ ⟨op⟩ ⟨exp⟩ ⟨op⟩ ::= + | x | ...
bin : type.
- p
: type.
- p/+ : op.
- p/x : op.
exp/num : bin -> exp. exp/op : exp -> op -> e x p
- > exp.
Compiler Generation for Substructural Operational Semantics Introduction
Specification of Binary Operations
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x. eval E2 x *
cont (f/op2 V1 B) x W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Introduction
Specification of Binary Operations
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x. eval E2 x *
cont (f/op2 V1 B) x W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Introduction
Specification of Binary Operations
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x. eval E2 x *
cont (f/op2 V1 B) x W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Introduction
Ripple Carry Adder
bit : type. bin : type. bin/add : bin -> bin -> bit -> bin -> bit -> type. #mode bin/add + + + - -.
Compiler Generation for Substructural Operational Semantics Introduction
Ripple Carry Adder
bit : type. bin : type. bin/add : bin -> bin -> bit -> bin -> bit -> type. #mode bin/add + + + - -.
Implemented using backward chaining
Compiler Generation for Substructural Operational Semantics Introduction
Returning a canonical value
ev/num : eval (exp/num N) W
- o { ret (exp/num N) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 1
Thesis Statement 1
The substructural operational semantics of a programming language can be stated in such a way that the latent resources are of static provenance, and passive resources are dynamic values.
Compiler Generation for Substructural Operational Semantics Thesis Part 1
Thesis Statement 1
The substructural operational semantics of a programming language can be stated in such a way that the latent resources are of static provenance, and passive resources are dynamic values. In such a form, the latent resources correspond to instructions synthesized from the program, and passive resources correspond to operands to these instructions.
Compiler Generation for Substructural Operational Semantics Thesis Part 1
In pictures
..., ret (exp/num V1) X1, cont X1 (f/op1 op/+ ...)
W1,...
Compiler Generation for Substructural Operational Semantics Thesis Part 1
In pictures
..., ret (exp/num V1) X1, cont X1 (f/op1 op/+ ...)
W1,...
tr/op1 ..., ret (exp/num V2) X2, cont X2 (f/op1 op/x ...)
W2,...
Compiler Generation for Substructural Operational Semantics Thesis Part 1
In pictures
..., ret (exp/num V1) X1, cont X1 (f/op1 op/+ ...)
W1,...
tr/op1 ..., ret (exp/num V2) X2, cont X2 (f/op1 op/x ...)
W2,...
tr/op1 ..., ret (exp/num V3) X3, cont X3 (f/op2 op/x ...)
W3,...
Compiler Generation for Substructural Operational Semantics Thesis Part 1
In pictures
..., ret (exp/num V1) X1, cont X1 (f/op1 op/+ ...)
W1,...
tr/op1 ..., ret (exp/num V2) X2, cont X2 (f/op1 op/x ...)
W2,...
tr/op1 ..., ret (exp/num V3) X3, cont X3 (f/op2 op/x ...)
W3,...
tr/op2/mul ..., ret (exp/num V4) X4, cont X4 (f/op2 op/+ ...)
W4,...
Compiler Generation for Substructural Operational Semantics Thesis Part 1
In pictures
..., ret (exp/num V1) X1, cont X1 (f/op1 op/+ ...)
W1,...
tr/op1 ..., ret (exp/num V2) X2, cont X2 (f/op1 op/x ...)
W2,...
tr/op1 ..., ret (exp/num V3) X3, cont X3 (f/op2 op/x ...)
W3,...
tr/op2/mul ..., ret (exp/num V4) X4, cont X4 (f/op2 op/+ ...)
W4,...
tr/op2/add
Compiler Generation for Substructural Operational Semantics Thesis Part 1
Contributions
▸ Separable SSOS (S3OS) ▸ Semicompositional S3OS (S4OS) ▸ Techniques to transform SSOS to S3OS and S4OS.
Compiler Generation for Substructural Operational Semantics Thesis Part 1
Big Picture
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Need to separate values from continuations
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x. eval E2 x *
cont (f/op2 V1 B) x W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Need to separate values from continuations
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x. eval E2 x *
cont (f/op2 V1 B) x W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Separate values using DPS
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o {
Exists x. eval E2 x * cont (f/op2 V1 B) x W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Separate values using DPS
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x1. ret V1 x1 *
Exists x2. eval E2 x2 * cont1 x1 (f/op2 B) x2 W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Separate values using DPS
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x1. ret V1 x1 *
Exists x2. eval E2 x2 * cont1 x1 (f/op2 B) x2 W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Separate values using DPS
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x1. ret V1 x1 *
Exists x2. eval E2 x2 * cont1 x1 (f/op2 B) x2 W }. tr/op2/add : ret (exp/num N2) X * cont (f/op2 (exp/num N1) op/+) X W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Separation using DPS in S3OS
Separate values using DPS
ev/op : eval (exp/op E1 B E2) W
- o { Exists x. eval E1 x *
cont (f/op1 B E2) x W }. tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { Exists x1. ret V1 x1 *
Exists x2. eval E2 x2 * cont1 x1 (f/op2 B) x2 W }. tr/op2/add : ret (exp/num N1) X1 * ret (exp/num N2) X2 * cont1 X1 (f/op2 op/+) X2 W * !bin/add N1 N2 b0 N3 _
- o { ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Active Transitions in S3OS
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Active Transitions in S3OS
What about active transitions in S3OS?
ev/num : eval (exp/num N) W
- o { ret (exp/num N) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Active Transitions in S3OS
Transform them to pass through a latent transition!
ev/num : eval (exp/num N) W
- o { ret (exp/num N) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Active Transitions in S3OS
Active Transitions in S3OS
ev/num : eval (exp/num N) Wdummy
- o { Exists x. ret dummy x *
cont (f/num N) x W }. tr/num : ret dummy X * cont (f/num N) X W
- o { ret (exp/num N) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 1 Active Transitions in S3OS
The instruction set
f/num : bin -> frame. f/op1 : op -> exp -> frame. f/op2 : op -> frame.
Compiler Generation for Substructural Operational Semantics Thesis Part 2
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 2
Thesis Statement
Given a separable SSOS specification for a programming language, the latent resources/instructions for a program can be computed without referring to the program’s inputs or dynamic values.
Compiler Generation for Substructural Operational Semantics Thesis Part 2
Thesis Statement
Given a separable SSOS specification for a programming language, the latent resources/instructions for a program can be computed without referring to the program’s inputs or dynamic values. We can do so by approximating the behavior of the specification.
Compiler Generation for Substructural Operational Semantics Thesis Part 2
Contributions
Logical approximations for compiler generation
▸ Skolemization using constructed destinations ▸ Mode-driven erasure
Compiler Generation for Substructural Operational Semantics Thesis Part 2
Big Picture
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Compile by collecting all resources
ev/num : !eval (exp/num N) W
- o { Exists x.
!ret dummy x * !cont (f/num N) x W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Compile by collecting all resources
ev/num : !eval (exp/num N) W
- o { Exists x.
!ret dummy x * !cont (f/num N) x W }.
Will not saturate!
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Solution: use a skolem function instead
d/1 : dest -> dest. ev/num : eval (exp/num N) W
- o { Exists x.
ret dummy x * cont (f/num N) x W }. d/2 : dest -> dest. ev/op : eval (exp/op E1 B E2) W
- o { Exists x.
eval E1 x * cont (f/op1 B E2) x W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Skolemize using source labels
d/1 : dest -> dest. ev/num : eval (exp/num L N) W
- o { Exists x = (dest/label L).
ret dummy x * cont (f/num N) x W }. d/2 : dest -> dest. ev/op : eval (exp/op E1 B E2) W
- o { Exists x.
eval E1 x * cont (f/op1 B E2) x W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Skolemize using destination constructor
d/1 : dest -> dest. ev/num : eval (exp/num N) W
- o { Exists x = (d/1 W).
ret dummy x * cont (f/num N) x W }. d/2 : dest -> dest. ev/op : eval (exp/op E1 B E2) W
- o { Exists x.
eval E1 x * cont (f/op1 B E2) x W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Skolemize using destination constructor
d/1 : dest -> dest. ev/num : eval (exp/num N) W
- o { Exists x = (d/1 W).
ret dummy x * cont (f/num N) x W }. d/2 : dest -> dest. ev/op : eval (exp/op E1 B E2) W
- o { Exists x.
eval E1 x * cont (f/op1 B E2) x W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Skolemize using destination constructor
d/1 : dest -> dest. ev/num : eval (exp/num N) W
- o { Exists x = (d/1 W).
ret dummy x * cont (f/num N) x W }. d/2 : dest -> dest. ev/op : eval (exp/op E1 B E2) W
- o { Exists x = (d/2 W).
eval E1 x * cont (f/op1 B E2) x W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
Skolemize using destination constructor
d/1 : dest -> dest. ev/num : eval (exp/num N) W
- o {
ret dummy (d/1 W) * cont (f/num N) (d/1 W) W }. d/2 : dest -> dest. ev/op : eval (exp/op E1 B E2) W
- o {
eval E1 (d/2 W) * cont (f/op1 B E2) (d/2 W) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
S3OS-sko correctness is tricky!
▸ Need to ensure that we generate only finitely many
destinations.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
S3OS-sko correctness is tricky!
▸ Need to ensure that we generate only finitely many
destinations.
▸ Skolemization should not related resources that were
previously unrelated by destinations.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-sko: Skolemized Destinations
S3OS-sko correctness is tricky!
▸ Need to ensure that we generate only finitely many
destinations.
▸ Skolemization should not related resources that were
previously unrelated by destinations.
▸ S3OS-sko requires a few more changes. See Chapter 3 for
details.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Compile by collecting resources
tr/op1 : !ret V1 X * !cont (f/op1 B E2) X W
- o { !ret V1 (d/3 W) *
!eval E2 (d/4 W) * !cont1 (d/3 W) (f/op2 B) (d/4 W) W }. tr/op2/add : !ret (exp/num N1) X1 * !ret (exp/num N2) X2 * !cont1 X1 (f/op2 op/+) X2 W * !bin/add N1 N2 b0 N3 _
- o { !ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Try erasing dynamic content
tr/op1 : !ret V1 X * !cont (f/op1 B E2) X W
- o { !ret V1 (d/3 W) *
!eval E2 (d/4 W) * !cont1 (d/3 W) (f/op2 B) (d/4 W) W }. tr/op2/add : !ret (exp/num N1) X1 * !ret (exp/num N2) X2 * !cont1 X1 (f/op2 op/+) X2 W * !bin/add N1 N2 b0 N3 _
- o { !ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Try erasing dynamic content
tr/op1 : !ret X * !cont (f/op1 B E2) X W
- o { !ret (d/3 W) *
!eval E2 (d/4 W) * !cont1 (d/3 W) (f/op2 B) (d/4 W) W }. tr/op2/add : !ret (exp/num N1) X1 * !ret (exp/num N2) X2 * !cont1 X1 (f/op2 op/+) X2 W * !bin/add N1 N2 b0 N3 _
- o { !ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Try erasing dynamic content
tr/op1 : !ret X * !cont (f/op1 B E2) X W
- o { !ret (d/3 W) *
!eval E2 (d/4 W) * !cont1 (d/3 W) (f/op2 B) (d/4 W) W }. tr/op2/add : !ret (exp/num N1) X1 * !ret (exp/num N2) X2 * !cont1 X1 (f/op2 op/+) X2 W * !bin/add N1 N2 b0 N3 _
- o { !ret (exp/num N3) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Try erasing dynamic content
tr/op1 : !ret X * !cont (f/op1 B E2) X W
- o { !ret (d/3 W) *
!eval E2 (d/4 W) * !cont1 (d/3 W) (f/op2 B) (d/4 W) W }. tr/op2/add : !ret X1 * !ret X2 * !cont1 X1 (f/op2 op/+) X2 W * !bin/add N1 N2 b0 N3 _
- o { !ret W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Try erasing dynamic content
tr/op1 : !ret X * !cont (f/op1 B E2) X W
- o { !ret (d/3 W) *
!eval E2 (d/4 W) * !cont1 (d/3 W) (f/op2 B) (d/4 W) W }. tr/op2/add : !ret X1 * !ret X2 * !cont1 X1 (f/op2 op/+) X2 W * !bin/add N1 N2 b0 N3 _
- o { !ret W }.
bin/add is not well-moded
Compiler Generation for Substructural Operational Semantics Thesis Part 2 S3OS-comp: Mode-driven Erasure
Erase ill-moded resources
tr/op1 : !ret X * !cont (f/op1 B E2) X W
- o { !ret (d/3 W) *
!eval E2 (d/4 W) * !cont1 (d/3 W) (f/op2 B) (d/4 W) W }. tr/op2/add : !ret X1 * !ret X2 * !cont1 X1 (f/op2 op/+) X2 W *
- o { !ret W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional)
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional)
Thesis Statement
A separable SSOS specification can be used to synthesize a virtual machine that executes the virtual instruction set characteristic of the specification.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional)
Thesis Statement
A separable SSOS specification can be used to synthesize a virtual machine that executes the virtual instruction set characteristic of the specification. The virtual machine serves as a specification of the instruction set, and it does not refer to the original program text.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional)
Contributions
▸ Approximations that preserve sufficient information for code
execution
▸ A family of virtual instruction sets that is target-independent ▸ Techniques to erase program text
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional)
Big Picture
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) S3OS-VM
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) S3OS-VM
S3OS-JIT
ev/num : eval (exp/num N) W
- o { ret dummy (d/1 W) *
!cont (f/num N) (d/1 W) W }. ev/op : eval (exp/op E1 B E2) W
- o { eval E1 (d/2 W) *
!cont (f/op1 B E2) (d/2 W) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) S3OS-VM
S3OS-VM – stop producing continuations
ev/num : eval (exp/num N) W
- o { ret dummy (d/1 W) *
!cont (f/num N) (d/1 W) W }. ev/op : eval (exp/op E1 B E2) W
- o { eval E1 (d/2 W) *
!cont (f/op1 B E2) (d/2 W) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Erasing Program Text
ev/num : eval (exp/num N) W
- o { ret dummy (d/1 W)
!cont (f/num N) (d/1 W) W }. ev/op : eval (exp/op E1 B E2) W
- o { eval E1 (d/2 W)
!cont (f/op1 B E2) (d/2 W) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Erasing Program Text
ev/num : eval W
- o { ret dummy (d/1 W) }.
!cont (f/num N) (d/1 W) W ev/op : eval W
- o { eval (d/2 W) }.
!cont (f/op1 B E2) (d/2 W) W
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Disambiguate Active Rules
ev/num : eval W * !cont (f/num N) (d/1 W) W
- o { ret dummy (d/1 W) }.
ev/op : eval W * !cont (f/op1 B E2) (d/2 W) W
- o { eval (d/2 W) }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Disambiguate Active Rules
ev/num : eval W * !cont (f/num N) (d/1 W) W
- o { ret dummy (d/1 W) }.
ev/op : eval W * !cont (f/op1 B E2) (d/2 W) W
- o { eval (d/2 W) }.
Requires inversion property.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Simplify Frames
ev/op : eval W * !cont (f/op1 B E2) (d/2 W) W
- o { eval (d/2 W) }.
tr/op1 : ret V1 X * cont (f/op1 B E2) X W
- o { ret V1 (d/3 W) * eval (d/4 W) }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Simplify Frames
ev/op : eval W * !cont (f/op1 _ _) (d/2 W) W
- o { eval (d/2 W) }.
tr/op1 : ret V1 X * cont (f/op1 _ _) X W
- o { ret V1 (d/3 W) * eval (d/4 W) }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Simplify Frames
ev/op : eval W * !cont (f/op1 _ _) (d/2 W) W
- o { eval (d/2 W) }.
tr/op1 : ret V1 X * cont (f/op1 _ _) X W
- o { ret V1 (d/3 W) * eval (d/4 W) }.
B and E2 are unnecessary.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Simplify Frames
ev/num : eval W * !cont (f/num N) (d/1 W) W
- o { ret dummy (d/1 W) }.
tr/num : ret dummy X * !cont (f/num N) X W
- o { ret (exp/num N) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Simplify Frames
ev/num : eval W * !cont (f/num _) (d/1 W) W
- o { ret dummy (d/1 W) }.
tr/num : ret dummy X * !cont (f/num N) X W
- o { ret (exp/num N) W }.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
Simplify Frames
ev/num : eval W * !cont (f/num _) (d/1 W) W
- o { ret dummy (d/1 W) }.
tr/num : ret dummy X * !cont (f/num N) X W
- o { ret (exp/num N) W }.
N is needed in second rule.
Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional) Erasing Program Text
The simplified instruction set
f/num : bin -> frame. f/op1 : frame. f/op2 : op -> frame.
Compiler Generation for Substructural Operational Semantics Conclusion
Outline
Introduction Thesis Part 1 Separation using DPS in S3OS Active Transitions in S3OS Thesis Part 2 S3OS-sko: Skolemized Destinations S3OS-comp: Mode-driven Erasure Thesis Part 3 (Optional) S3OS-VM Erasing Program Text Conclusion
Compiler Generation for Substructural Operational Semantics Conclusion S4OS
S4OS
▸ Requires strict conformity to semicompositionality. ▸ Sufficiently expressive for loops, procedures, and mutable
state.
▸ Can express higher order language features with explicit
closures (No HOAS).
▸ Specification synthesis has same structure as S3OS.
Compiler Generation for Substructural Operational Semantics Conclusion Proving and Testing
Proving and Testing
▸ Correctness stated using a semi-formal bisimulation for
transformed specifications. To be mechanized.
▸ Implemented C0 in S4OS ▸ S4OS-VM instruction set for C0 similar to reference C0VM. ▸ Implemented call-by-name λ-calculus and futures with explicit
closures.
Compiler Generation for Substructural Operational Semantics Conclusion The Virtual Instruction Set
The Virtual Instruction Set
▸ Target independent. Reflects the modularity of the source
language.
▸ Similar source languages have similar SSOS. Therefore, the
components to compile one instruction set can potentially be reused to compile features from another language to the same target.
▸ Not an intermediate representation like LLVM. Similar to
ML-RISC.
Compiler Generation for Substructural Operational Semantics Conclusion Questions