FROM SYSTEM F TO TYPED ASSEMBLY LANGUAGE Greg Morrisett, David - - PowerPoint PPT Presentation

from system f to typed assembly language
SMART_READER_LITE
LIVE PREVIEW

FROM SYSTEM F TO TYPED ASSEMBLY LANGUAGE Greg Morrisett, David - - PowerPoint PPT Presentation

FROM SYSTEM F TO TYPED ASSEMBLY LANGUAGE Greg Morrisett, David Walker, Karl Crary & Neal Glew TOPLAS 1999 Presentation by: Drew Zagieboylo/Matthew Milano TYPED ASSEMBLY LANGUAGE TYPED ASSEMBLY LANGUAGE TYPED ASSEMBLY LANGUAGE TYPED


slide-1
SLIDE 1

FROM SYSTEM F TO TYPED ASSEMBLY LANGUAGE

Greg Morrisett, David Walker, Karl Crary & Neal Glew TOPLAS 1999

Presentation by: 
 Drew Zagieboylo/Matthew Milano

slide-2
SLIDE 2

TYPED ASSEMBLY LANGUAGE

slide-3
SLIDE 3

TYPED ASSEMBLY LANGUAGE

slide-4
SLIDE 4

TYPED ASSEMBLY LANGUAGE

slide-5
SLIDE 5

TYPED ASSEMBLY LANGUAGE

slide-6
SLIDE 6

WHY DO WE WANT TAL?

slide-7
SLIDE 7

TYPE SYSTEMS ALL THE WAY!!

slide-8
SLIDE 8

x86

NO TYPES :(

TYPED INTERMEDIATE LANGUAGES

➤ TIL ➤ Throughout the 90’s (and today!) ➤ Benefits of Types (efficiency + soundness) ➤ Target Language is Untyped ML TIL …

TYPES!

slide-9
SLIDE 9

HOW TO GUARANTEE SAFETY W/ UNTYPED AND UNTRUSTED CODE?

slide-10
SLIDE 10

PROOF-CARRYING CODE

➤ George Necula (POPL ’97) ➤ Compiler Produces:

  • 1. Program
  • 2. Proof

➤ First-Order Predicate

Logic Based

➤ Difficult to Build

Compilers

slide-11
SLIDE 11

TYPED ASSEMBLY LANGUAGE

➤ Extend benefits of types all the way to the target ➤ Types as implementation of Proof-Carrying Code

slide-12
SLIDE 12

TYPED ASSEMBLY LANGUAGE - FEATURES

➤ RISC-style language ➤ Types: ➤ Code types ➤ Pointer Types ➤ Existential Type Constructor ➤ Security: ➤ No pointer forging! ➤ Control Flow Integrity ➤ Other: ➤ Memory Allocation

slide-13
SLIDE 13

SYSTEM F TO TAL

➤ Show that TAL is expressive

slide-14
SLIDE 14

SYSTEM F TO TAL

➤ CPS Conversion

slide-15
SLIDE 15

CPS TRANSLATION

➤ Continuation Passing Style ➤ Translate to near-linear series of let bindings & calls ➤ Removes function call stack

Abstraction Translation Application Translation

slide-16
SLIDE 16

SYSTEM F TO

➤ Continuation Passing Style

λK (fix f(n : int) : int . if0 (n,1,n × f(n − 1))) 6 λF (fix f(n : int, k : (int) → void) . λK if0(n, k(1), (6,λ(n : int) . halt[int]n) f(x, λ(y : int) . let z = n × y in k(z)))) let x = n − 1in

slide-17
SLIDE 17

SYSTEM F TO TAL

➤ Closure Conversion

slide-18
SLIDE 18

POLYMORPHIC CLOSURE CONVERSION

➤ Generate Explicit Closures ➤ Implements Encapsulation ➤ New Syntax ➤ Existential Types
 ➤ Packing/Unpacking


➤ Uses Type Erasure* ➤ Function bodies type-check w/o environment type info ➤ Pack is a no-op at runtime

τ, σ ::= . . . |∃α . τ u ::= . . . |v[τ]| pack[τ1, v] as τ2 d ::= . . . |[α, x] = unpack v

slide-19
SLIDE 19

TO

➤ Polymorphic Closure Conversion

λK λC

Function Type Translation Application Translation

slide-20
SLIDE 20

SYSTEM F TO TAL

➤ Hoisting

slide-21
SLIDE 21

HOISTING

➤ Separating Code Definition & Program ➤ Much like real memory layout ➤ Closures make this easy! ➤ Bind fix statements to variables, pointing to code

slide-22
SLIDE 22

TO

➤ Polymorphic Closure Conversion ➤ Factorial(6)

λK λC

slide-23
SLIDE 23

SYSTEM F TO TAL

➤ Memory Allocation

slide-24
SLIDE 24

ALLOCATION

➤ Assembly language doesn’t have Tuples! ➤ Need to allocate memory for tuples (and initialize!)


➤ x = (v1, v2)

A[[⟨τ1, . . . , τn⟩]] ≜ ⟨A[[τ1]]1, . . . , A[[τn]]1⟩

slide-25
SLIDE 25

ALLOCATION

λH λA

slide-26
SLIDE 26

SYSTEM F TO TAL

➤ Code Generation

slide-27
SLIDE 27

SYSTEM F TO TAL

➤ Code Generation ➤ Mostly direct translation to assembly ➤ Function types annotate registers


➤ unpack is just a mov instruction w/ type erasure ➤ malloc is abstract

slide-28
SLIDE 28

TAL IMPLEMENTATION

➤ TALx86 : IA32 ISA ➤ Variation from Paper: ➤ Other data types (arrays, floats, etc.) ➤ Not CPS -> Uses Explicit Stack ➤ Implements malloc and unpack instructions ➤ Modules with Type Interfaces ➤ Some optimizations ➤ Register-sized objects vs. “large objects” ➤ Cross-module optimization

slide-29
SLIDE 29

CONCLUSIONS

➤ System F -> TAL ➤ We can have security and expressivity ➤ Utilizes many PL techniques ➤ Type-directed Compilation ➤ Formalism omits many optimizations (other work) ➤ Future Work & Impact ➤ Cyclone (low level, typed language) ➤ (and then Rust)

slide-30
SLIDE 30

THANK YOU!

slide-31
SLIDE 31

POLYMORPHIC CC - TWICE EXAMPLE

slide-32
SLIDE 32

POLYMORPHIC CC - TWICE EXAMPLE