1 / 23

Generating Heap-bounded Programs

Generating Heap-bounded Programs. Walid Taha , Stephan Ellner (Rice University) Hongwei Xi (Boston University). Why do languages matter?. The need for well thought-out languages (or “models”) will only increase in the future Applications are constantly growing in complexity

shino
Download Presentation

Generating Heap-bounded Programs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Generating Heap-bounded Programs Walid Taha, Stephan Ellner (Rice University) Hongwei Xi (Boston University)

  2. Why do languages matter? The need for well thought-out languages (or “models”) will only increase in the future • Applications are constantly growing in complexity • The need for simplicity is constant • Can we think outside our languages? • Using old languages means making old mistakes Carefully designed languages allow us to • Ensure strong safety properties • Preserve desirable reasoning principles • Ultimately: Reduce developer/owner cost

  3. FORTRAN C Assembly/C C/C++ Embedded systems:An area of growing demand

  4. Trouble with High-level Languages High-level languages deprive programmer of control over basic resources Programming embedded systems requires attention to various kinds of resources: • Concrete resources: • Abstract resources: • Critical sections, capabilities, power, bandwidth, availability, security, freedom of race conditions… Resource-bounded languages provide guarantees But they limit expressivity Can we combine the best of both worlds?

  5. I2 I2 I2 I1 P O Traditional Programming I P O LFPL [Hofmann, ’99/00] I1 I1 P1 P1 P2 P2 O O Multi-Stage Programming (MSP) [Taha, Sheard ’97] Multi-Stage Programming (MSP) [Taha, Sheard ’97] I2 I1 P1 P2 O Resource Aware Programming [EMSOFT ’03]

  6. Insertion sort This can be resource-bounded program: let rec insert(a,l) = case l of nil -> cons(a, nil) | cons(b,t) -> if a < b then cons(a, cons(b, t)) else cons(b, insert(a, t)) let rec sort(l) = case l of nil -> nil | cons(a,t) -> insert(a, sort(t))

  7. I2 I2 I2 I1 P O Traditional Programming I P O LFPL [Hofmann, ’99/00] I1 I1 P1 P1 P2 P2 O O Multi-Stage Programming (MSP) [Taha, Sheard ’97] Multi-Stage Programming (MSP) [Taha, Sheard ’97] I2 I1 P1 P2 O Resource Aware Programming [EMSOFT ’03]

  8. Hoffman’s (RB) LFPL • Allows heap-bounded manipulation of dynamic data structures • Can be translated into imperative C programs that have competitive performance (without optimizations) • How does it work: • You want to avoid duplicating structures • Linear types. Default: Variables used only once

  9. Insertion sort in LFPL This is a resource-bounded program [Hoffman’99/00] let rec insert(d,a,l) = case l of nil -> cons(a, nil) at d | cons(b,t) at e -> if a < b then cons(a, cons(b, t) at e) at d else cons(b, insert(e,a, t)) at d let rec sort(l) = case l of nil -> nil | cons(a,t) at d -> insert(d, a, sort(t))

  10. I2 I2 I2 I1 P O Traditional Programming I P O LFPL [Hofmann, ’99/00] I1 I1 P1 P1 P2 P2 O O Multi-Stage Programming (MSP) [Taha, Sheard ’97] Multi-Stage Programming (MSP) [Taha, Sheard ’97] I2 I1 P1 P2 O Resource Aware Programming [EMSOFT ’03]

  11. Multi-stage programming (MSP) • Provide abstraction mechanisms like: polymorphism, higher-order functions, exceptions, … • “Abstractions without guilt” through prg. generation • Without damaging the static typing discipline

  12. Multi-stage programming (MSP) Three staging annotations: Simplified typing rules:

  13. x P n xn Small example: Exponentiation Single stage: let rec exp(n:int, x:real):real = if n = 0 then 1.0 else if even (n) then sqr (exp(n div 2,x)) else x * (exp(n - 1,x));;

  14. x P1 P2 xn n Small example: Exponentiation Two stage: let rec exp(n:int, x:<real>):<real>= if n = 0 then <1.0> else if even (n) then <sqr~(exp(n div 2,x))> else <~x*~(exp(n - 1,x))>;; Only things in gold are left for second stage

  15. Small example: Exponentiation To use the staged exp we simply write: <f(x) =~(exp(5,<x>))>;; The result for the second stage is: <f(x)= x*(sqr(sqr(x*1.0)))> No recursion Just 4 ops!

  16. I2 I2 I2 I1 P O Traditional Programming I P O LFPL [Hofmann, ’99/00] I1 I1 P1 P1 P2 P2 O O Multi-Stage Programming (MSP) [Taha, Sheard ’97] Multi-Stage Programming (MSP) [Taha, Sheard ’97] I2 I1 P1 P2 O Resource Aware Programming [EMSOFT ’03]

  17. Why RAP (= MSP + RB) is hard Two key points: • Want to guarantee RB before generation • Must somehow isolate expressive features, even when used in same language. Naïve combination doesn’t work. For LFPL: • Can just combine non-linear and linear environments • Some first-stage values must be linear • Some second-stage values can be non-linear

  18. RAP language for LFPL • GeHB: A language for “Generating Heap-Bounded programs” • Intuitively: Program/configure on PC, execute on embedded/real-time platform • All done in one language that integrates the two platforms very closely • Static analysis (type system) guarantees that • The two platforms never get confused • Before any programs are generated, we know that all generated programs will be resource bounded.

  19. Type System

  20. Summary of Results • Evaluation (generation) preserves types • Standard type preservation • Code values are easily turned into LFPL code • Requires a form of let-floating • Can only be done for well-typed terms • Generated LFPL code is well-typed • And Hofmann shows how to translate to C • No lost expressivity (GeHB is strictly more expressive)

  21. Safe, fast, and generic insert. sort let rec sort_gen(myLess,list) = let [less] = myLess in (* Co-monadic co-bind *) <let rec insert(d,a,l) = case l of nil -> cons(a, nil) at d | cons(b,t) at d' -> if ~ (less(<a> ,<b> )) then cons(a, cons(b, t) at d') at d else cons(b, insert(a, d', t)) at d in let rec sort(l) = case l of nil -> nil | cons(a,t) at d -> insert(d, a, sort(t)) in sort(~list)>

  22. Summary • GP languages give us expressivity • But no guarantees about resources • RB languages give us resource bound • But limit expressivity • MSP allows us to express staging • Carefully designed RAP languages give the programmer more control without becoming too low-level or unsafe. Claim: Underlying idea is general & tractable.

  23. Future work on RAP Success requires targeting three areas: • Design an theory • Lots of basic PL research needed here • In RB languages, MSP, and how to combine • Applications • Currently: device drivers and n.w. interface cards • Implementation and engineering aspects • Multiple target platforms • Essential for technology transition

More Related