from system f to typed assembly language
play

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


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

  2. TYPED ASSEMBLY LANGUAGE

  3. TYPED ASSEMBLY LANGUAGE

  4. TYPED ASSEMBLY LANGUAGE

  5. TYPED ASSEMBLY LANGUAGE

  6. WHY DO WE WANT TAL?

  7. TYPE SYSTEMS ALL THE WAY!!

  8. TYPED INTERMEDIATE LANGUAGES ➤ T I L ➤ Throughout the 90’s (and today!) ➤ Benefits of Types (e ffi ciency + soundness) ➤ Target Language is Untyped ML … TIL x86 NO TYPES :( TYPES!

  9. HOW TO GUARANTEE SAFETY W/ UNTYPED AND UNTRUSTED CODE?

  10. PROOF-CARRYING CODE ➤ George Necula (POPL ’97) ➤ Compiler Produces: 1. Program 2. Proof ➤ First-Order Predicate Logic Based ➤ Di ffi cult to Build Compilers

  11. TYPED ASSEMBLY LANGUAGE ➤ Extend benefits of types all the way to the target ➤ Types as implementation of Proof-Carrying Code

  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

  13. SYSTEM F TO TAL ➤ Show that TAL is expressive

  14. SYSTEM F TO TAL ➤ CPS Conversion

  15. CPS TRANSLATION ➤ Continuation Passing Style ➤ Translate to near-linear series of let bindings & calls ➤ Removes function call stack Abstraction Translation Application Translation

  16. SYSTEM F TO λ K ➤ Continuation Passing Style ( fix f ( n : int ) : int . if 0 ( n ,1, n × f ( n − 1))) 6 λ F λ K ( fix f ( n : int , k : ( int ) → void ) . if 0( n , k (1), let x = n − 1 in f ( x , λ ( y : int ) . let z = n × y in k ( z )))) (6, λ ( n : int ) . halt [ int ] n )

  17. SYSTEM F TO TAL ➤ Closure Conversion

  18. 
 POLYMORPHIC CLOSURE CONVERSION ➤ Generate Explicit Closures ➤ Implements Encapsulation ➤ New Syntax ➤ Existential Types 
 τ , σ ::= . . . | ∃ α . τ ➤ Packing/Unpacking 
 u ::= . . . | v [ τ ] | pack [ τ 1 , v ] as τ 2 d ::= . . . | [ α , x ] = unpack v ➤ Uses Type Erasure* ➤ Function bodies type-check w/o environment type info ➤ Pack is a no-op at runtime

  19. TO λ C λ K ➤ Polymorphic Closure Conversion Function Type Translation Application Translation

  20. SYSTEM F TO TAL ➤ Hoisting

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

  22. TO λ C λ K ➤ Polymorphic Closure Conversion ➤ Factorial(6)

  23. SYSTEM F TO TAL ➤ Memory Allocation

  24. 
 ALLOCATION ➤ Assembly language doesn’t have Tuples! ➤ Need to allocate memory for tuples (and initialize!) 
 A [[ ⟨ τ 1 , . . . , τ n ⟩ ]] ≜ ⟨ A [[ τ 1 ]] 1 , . . . , A [[ τ n ]] 1 ⟩ ➤ x = (v 1 , v 2 )

  25. ALLOCATION λ H λ A

  26. SYSTEM F TO TAL ➤ Code Generation

  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

  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

  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)

  30. THANK YOU!

  31. POLYMORPHIC CC - TWICE EXAMPLE

  32. POLYMORPHIC CC - TWICE EXAMPLE

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend