Edwin Westbrook, Mathias Ricken, Jun Inoue, Yilong Yao, Tamer Abdlatif, Walid Taha.

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

CPSC 388 – Compiler Design and Construction
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint Edwin Westbrook, Mathias Ricken, and Walid Taha.
Mint: A Multi-stage Extension of Java COMP 600 Mathias Ricken Rice University February 8, 2010.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
The Type System1. 2.NET Type System The type system is the part of the CLR that defines all the types that programmers can use, and allows developers.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
Paper Analysis Implementing Multi-stage Languages Using ASTs, Gensym, and Reflection by Calcagno, Taha, Huang, and Leroy.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Compilation 2007 Scopes and Environments Michael I. Schwartzbach BRICS, University of Aarhus.
1 A Short Introduction to (Object-Oriented) Type Systems Kris De Volder.
CS0007: Introduction to Computer Programming Introduction to Arrays.
A Framework for Smart Proxies and Interceptors in RMI Nuno Santos P. Marques, L. Silva CISUC, University of Coimbra, Portugal
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint Edwin Westbrook, Mathias Ricken, and Walid Taha.
Computer Science Detecting Memory Access Errors via Illegal Write Monitoring Ongoing Research by Emre Can Sezer.
CSC 212 Stacks & Queues. Announcement Many programs not compiled before submission  Several could not be compiled  Several others not tested with javadoc.
Core Java: Essential Features 08/05/2015 Kien Tran.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Mint: A Multi-stage Extension of Java Purdue University - Computer Science Colloquia Mathias Ricken Rice University March 15, 2010.
C++ Memory Overview 4 major memory segments Key differences from Java
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
Types in programming languages1 What are types, and why do we need them?
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Object-Oriented Programming Chapter Chapter
CSE 413 Languages & Implementation Hal Perkins Autumn 2012 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint Edwin Westbrook, Mathias Ricken, and Walid Taha.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
Java Annotations for Types and Expressions Mathias Ricken October 24, 2008 COMP 617 Seminar.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
CIS 200 Test 01 Review. Built-In Types Properties  Exposed “Variables” or accessible values of an object  Can have access controlled via scope modifiers.
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
Chapter 5 Names, Bindings, Type Checking CSCE 343.
Heath Carroll Bill Hanczaryk Rich Porter.  A Theory of Type Polymorphism in Programming ◦ Robin Milner (1977)  Milner credited with introducing the.
Names and Attributes Names are a key programming language feature
Type Checking, and Scopes
CIS 200 Test 01 Review.
CS 326 Programming Languages, Concepts and Implementation
Review: Chapter 5: Syntax directed translation
Generics, Lambdas, Reflections
Scope of Variables.
Java Programming Language
Subprograms In Text: Chapter 9.
Binding Times Binding is an association between two things Examples:
자바 언어를 위한 정적 분석 (Static Analyses for Java) ‘99 한국정보과학회 가을학술발표회 튜토리얼
Tonga Institute of Higher Education
COMPILERS Semantic Analysis
Lecture 10 Concepts of Programming Languages
Subtype Substitution Principle
Types and Related Issues
SPL – PS2 C++ Memory Handling.
Presentation transcript:

Edwin Westbrook, Mathias Ricken, Jun Inoue, Yilong Yao, Tamer Abdlatif, Walid Taha

Abstractions are Expensive 2 power(2,17) : 41 nspower17(2) : 9 ns public static int power (int x, int n){ if (n == 1) return x; else return x * power(x, n-1); } public static int power17(int x){ return x * … * x; }

Bringing MSP to the Mainstream Want Multi-stage programming in Java Difficulty: MSP + side effects [Kameyama et al., 09],[Aktemur 09], [Kameyama et al., 08],[Kim et al. 06],[Calcagno et al., 00] Existing solutions are complex type systems Hard for mainstream programmers to use Do not allow “the Java way” of programming Our solution: weak separability MSP that fits with Java programming 3

Outline Multi-stage programming in Java Mint Multi-stage reflection library MSP + effects problem: scope extrusion Our solution: weak separability A type system for weak separability Performance 4

MSP in Mint Code has type Code Code built with brackets Code spliced with escapes `e Code compiled and run with run() method Code x = ; Code y = ; Integer z = y.run(); // returns 6 5

Staged power in Mint 6 public static Code spower (Code x, Integer n) { if (n == 1) { return x; } else { return ; } spower (, 17) Example:

Staged Reflection in Mint 7 Class ClassCode Field FieldCode Standard primitivesStaged primitives Field[] Class.getFields() FieldCode [] Class.getFields() Object Field.get(Object) B FieldCode.get(A)

Simple Staged Serializer 8 public static Code sserialize (ClassCode t, Code o) { // handle base types if (t.getCodeClass () == Integer.class) return )o)); } |>; // handle defined classes Code result = ; for (FieldCode fc: t.getFields ()) { result = <| { `result; `(serializeField (fc, o)); } |>; } return result; }

The Scope Extrusion Problem 9 Code x = ; Code c = <| { Integer y = foo(); Integer z = `(x = ); } |>

Scope Extrusion via Exceptions 10 Code meth (Code c) { throw new CodeContainerException (c); } Code c = )); } |>; CodeContainerException ( )

Scope Extrusion via Cross-Stage Persistence See paper! 11

Solution: Weak Separability No effects containing code be seen outside of escapes 12 ` e e2e2 effect (1, 3) effect (, 7)

Weak Separability part 1: Type T is Code-Free iff: T not a subtype of Code for some T’ All field types of T are code-free All method return types of T are code-free T is final 13 Not code-free: class C { Code c; Object x; Code foo () { … } } Not final Field not code-free Return not code-free

Weak Separability part 2: Term t is Weakly Separable iff: All assignments are either: At code-free types, OR To variables bound in term t Each throw new C(e 1, …, e n ); has code-free e i Cross-stage persistence for final code-free variables 14

Expressivity of Weak Separability Build code with accumulators: <| `(for (i = 0; i < n; ++i) accum = ;) |> Throw exceptions out of code generators: <| `(if (malformed (data)) throw new BadData (data); …) |> Update global counters Generated code can contain effects 15

Typing for Weak Separability 16 <| { Integer y = foo(); return `(e); } |> e can see heap values with Should not see outside

Consider a Small-Step Trace 17 <| { Integer y = foo(); return `(e 1 ); } |> <| { Integer y = foo(); return e 2 ; } |> e1e1 * heap: l 1 = 0 l 2 = l 3 = B(f=l 1 ) heap: l 1 = 0 l 2 = l 3 = B(f=l 1 ) heap: l 1 = 0 l 2 = l 3 = B(f=l 1 ) heap: l 1 = 0 l 2 = l 3 = B(f=l 1 ) heap: l 1 = 2 l 2 = l 3 = B(f=l 4 ) l 4 = 7 l 5 = heap: l 1 = 2 l 2 = l 3 = B(f=l 4 ) l 4 = 7 l 5 = heap: l 1 = 2 l 2 = l 3 = B(f=l 4 ) l 4 = 7 l 5 = heap: l 1 = 2 l 2 = l 3 = B(f=l 4 ) l 4 = 7 l 5 = Bad!

Solution: Stack of Heap Typings 18 <| { Integer y = foo(); return `(e 1 ); } |> <| { Integer y = foo(); return e 2 ; } |> e1e1 * typing: l 1 : Integer l 2 : Code l 3 : B typing: l 1 : Integer l 2 : Code l 3 : B typing: l 1 : Integer l 2 : Code l 3 : B typing: l 1 : Integer l 2 : Code l 3 : B typing: l 1 : Integer l 2 = Code l 3 : B typing: l 1 : Integer l 2 = Code l 3 : B typing: l 1 : Integer l 2 : Code l 3 : B l 4 : Integer typing: l 1 : Integer l 2 : Code l 3 : B l 4 : Integer typing: l 4 : Integer l 5 : Code l 4 : Integer l 5 : Code Smashing Lemma

Typing in Symbols 19  1 ; …;  n ;  |- (H, e) : T Type heaps and expressions together One heap typing for each dynamic binding

Typing in Symbols 20 <| { Integer y = foo(); return `(e); } |>  1 ; …;  n ;  |- (H,  1 ; …;  n ;  ; , y:Integer |- e : Integer )  1 ; …;  n ;  ; , |- H H typed with Γ H constrains Σ

Smashing Lemma (approx) If:  1 ; …;  n ;  |- H 1  1 ; …;  n ;  ;  |- H 2 H 1 | L = H 2 | L for L = dom(  i  i ) - dom(cf(  i  i )) Then:  1 ; …;  n-1 ;  n  cf(  );  |- H 2 21

Performance Results 22

Conclusion: Mint = Java + MSP MSP reduces the cost of abstractions Mint brings MSP to the mainstream Key insight: weak separability Only code-free effects can be seen outside of escapes Can do MSP with common Java idioms: Build code with an accumulator Throw exceptions out of generators 23

Future Work: Faster Compilation Currently we call full compiler at runtime: SLOW Maybe we could generate code snippets? 24 public static Code spower (Code x, Integer n) { if (n == 1) { return x; } else { return <| `x * `(spower (x, n-1)) |>; } interface I$$1 { Integer getValue (); } class C$$1 implements I$$1 { Helper$$1 x, rec_call; Integer getValue () { return x.getValue() * rec_call.getValue(); }

25 QUESTIONS?

Running Generators 26 interface class PowerFun{ public Integer call (Integer x); } PowerFun f = <| new PowerFun () { public Integer run (Integer x) { `(spower(, 17)); } } |>.run ();

Scope Extrusion via Cross-Stage Persistence 27 Code > doCSP (Thunk t) { return ; } Code c = <| { Integer y = foo(); Code d = `(doCSP(new Thunk() { Code call () { return ; })) } |>;