Compiler Generation for Substructural Operational Semantics Anand - - PowerPoint PPT Presentation

compiler generation for substructural operational
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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 Pfenning, Chair ▸ Iliano Cervesato, Carnegie Mellon Qatar

slide-2
SLIDE 2

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.
slide-3
SLIDE 3

Compiler Generation for Substructural Operational Semantics Introduction

Specification Synthesis

slide-4
SLIDE 4

Compiler Generation for Substructural Operational Semantics Introduction

Compiling and Executing a Program

slide-5
SLIDE 5

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

slide-6
SLIDE 6

Compiler Generation for Substructural Operational Semantics Introduction

SSOS

▸ SSOS specifies semantics of programming languages using

state-transition rules encoded in a substructural logic.

slide-7
SLIDE 7

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.

slide-8
SLIDE 8

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 ↝ ...

slide-9
SLIDE 9

Compiler Generation for Substructural Operational Semantics Introduction

Transition Rules in CLF

▸ CLF is a logical framework based on intuitionistic lax linear

logic.

slide-10
SLIDE 10

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.

slide-11
SLIDE 11

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

slide-12
SLIDE 12

Compiler Generation for Substructural Operational Semantics Introduction

SSOS Transition Rule Schema

▸ Active rule:

active ↝ r1,r2,...,rn

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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.

slide-15
SLIDE 15

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.

slide-16
SLIDE 16

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.
slide-17
SLIDE 17

Compiler Generation for Substructural Operational Semantics Introduction

Example

⟨exp⟩ ::= ⟨numeric-constant⟩ | ⟨exp⟩ ⟨op⟩ ⟨exp⟩ ⟨op⟩ ::= + | x | ...

slide-18
SLIDE 18

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.
slide-19
SLIDE 19

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 }.
slide-20
SLIDE 20

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 }.
slide-21
SLIDE 21

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 }.
slide-22
SLIDE 22

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 + + + - -.

slide-23
SLIDE 23

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

slide-24
SLIDE 24

Compiler Generation for Substructural Operational Semantics Introduction

Returning a canonical value

ev/num : eval (exp/num N) W

  • o { ret (exp/num N) W }.
slide-25
SLIDE 25

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

slide-26
SLIDE 26

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.

slide-27
SLIDE 27

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.

slide-28
SLIDE 28

Compiler Generation for Substructural Operational Semantics Thesis Part 1

In pictures

..., ret (exp/num V1) X1, cont X1 (f/op1 op/+ ...)

W1,...

slide-29
SLIDE 29

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,...

slide-30
SLIDE 30

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,...

slide-31
SLIDE 31

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,...

slide-32
SLIDE 32

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

slide-33
SLIDE 33

Compiler Generation for Substructural Operational Semantics Thesis Part 1

Contributions

▸ Separable SSOS (S3OS) ▸ Semicompositional S3OS (S4OS) ▸ Techniques to transform SSOS to S3OS and S4OS.

slide-34
SLIDE 34

Compiler Generation for Substructural Operational Semantics Thesis Part 1

Big Picture

slide-35
SLIDE 35

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

slide-36
SLIDE 36

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 }.
slide-37
SLIDE 37

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 }.
slide-38
SLIDE 38

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 }.
slide-39
SLIDE 39

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 }.
slide-40
SLIDE 40

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 }.
slide-41
SLIDE 41

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 }.
slide-42
SLIDE 42

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 }.
slide-43
SLIDE 43

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

slide-44
SLIDE 44

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 }.
slide-45
SLIDE 45

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 }.
slide-46
SLIDE 46

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 }.
slide-47
SLIDE 47

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.

slide-48
SLIDE 48

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

slide-49
SLIDE 49

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.

slide-50
SLIDE 50

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.

slide-51
SLIDE 51

Compiler Generation for Substructural Operational Semantics Thesis Part 2

Contributions

Logical approximations for compiler generation

▸ Skolemization using constructed destinations ▸ Mode-driven erasure

slide-52
SLIDE 52

Compiler Generation for Substructural Operational Semantics Thesis Part 2

Big Picture

slide-53
SLIDE 53

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

slide-54
SLIDE 54

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 }.

slide-55
SLIDE 55

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!

slide-56
SLIDE 56

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 }.

slide-57
SLIDE 57

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 }.

slide-58
SLIDE 58

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 }.

slide-59
SLIDE 59

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 }.

slide-60
SLIDE 60

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 }.

slide-61
SLIDE 61

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 }.

slide-62
SLIDE 62

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.

slide-63
SLIDE 63

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.

slide-64
SLIDE 64

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.

slide-65
SLIDE 65

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

slide-66
SLIDE 66

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 }.
slide-67
SLIDE 67

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 }.
slide-68
SLIDE 68

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 }.
slide-69
SLIDE 69

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 }.
slide-70
SLIDE 70

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 }.
slide-71
SLIDE 71

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

slide-72
SLIDE 72

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 }.
slide-73
SLIDE 73

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

slide-74
SLIDE 74

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.

slide-75
SLIDE 75

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.

slide-76
SLIDE 76

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

slide-77
SLIDE 77

Compiler Generation for Substructural Operational Semantics Thesis Part 3 (Optional)

Big Picture

slide-78
SLIDE 78

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

slide-79
SLIDE 79

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 }.

slide-80
SLIDE 80

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 }.

slide-81
SLIDE 81

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

slide-82
SLIDE 82

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 }.

slide-83
SLIDE 83

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

slide-84
SLIDE 84

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) }.
slide-85
SLIDE 85

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.

slide-86
SLIDE 86

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) }.
slide-87
SLIDE 87

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) }.
slide-88
SLIDE 88

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.

slide-89
SLIDE 89

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 }.
slide-90
SLIDE 90

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 }.
slide-91
SLIDE 91

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.

slide-92
SLIDE 92

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.

slide-93
SLIDE 93

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

slide-94
SLIDE 94

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.

slide-95
SLIDE 95

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.

slide-96
SLIDE 96

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.

slide-97
SLIDE 97

Compiler Generation for Substructural Operational Semantics Conclusion Questions

Questions?

Thank you for attending.