Formal Models for Programming Languages

Slides:



Advertisements
Similar presentations
Transposing F to C Transposing F to C Andrew Kennedy & Don Syme Microsoft Research Cambridge, U.K.
Advertisements

Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Programming Languages and Paradigms
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
ISBN Chapter 9 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Introduction Two fundamental abstraction facilities.
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
1 Java Grande Introduction  Grande Application: a GA is any application, scientific or industrial, that requires a large number of computing resources(CPUs,
Feather-Weight Java COS 441 Princeton University Fall 2004.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
Comparison of OO Programming Languages © Jason Voegele, 2003.
CS 355 – Programming Languages
Imperative Programming
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Type Equivalence Rules Ada –Strict name equivalence except for almost everything Unique array constructors give rise to unique types Subtypes can create.
Gary MarsdenSlide 1University of Cape Town Principles of programming language design Gary Marsden Semester 2 – 2001.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Featherweight Generic Ownership Alex Potanin, James Noble Victoria University of Wellington Dave Clarke CWI, Netherlands Robert Biddle Carlton University.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich
Introduction to OOP CPS235: Introduction.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
CS 100Lecture 231 Announcements Check your grades on the door of 5141 Upson More review tomorrow Review session Sunday night w/Alan FINAL EXAM: Tuesday.
Language Paradigms CS655.
Heath Carroll Bill Hanczaryk Rich Porter.  A Theory of Type Polymorphism in Programming ◦ Robin Milner (1977)  Milner credited with introducing the.
Functional Programming
Functional Programming
Type Checking and Type Inference
Programming Languages and Compilers (CS 421)
CSE341: Programming Languages Lecture 11 Type Inference
Visit for more Learning Resources
CSE-321 Programming Languages Simply Typed -Calculus
Semantic Analysis Type Checking
PROGRAMMING LANGUAGES
Compiler Construction (CS-636)
Class 22: Inheritance CS150: Computer Science University of Virginia
CS 326 Programming Languages, Concepts and Implementation
Programming Languages and Compilers (CS 421)
1.1 Reasons to study concepts of PLs
Generics, Lambdas, Reflections
CS 3304 Comparative Languages Fall 2011
Names, Binding, and Scope
Foundations of Programming Languages – Course Overview
Java Programming Language
Foundations of Programming Languages – Course Overview
Objects and Aspects: What we’ve seen so far
CSE341: Programming Languages Lecture 11 Type Inference
Generic programming in Java
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
More Object-Oriented Programming
Programming Languages 2nd edition Tucker and Noonan
CSE341: Programming Languages Lecture 11 Type Inference
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
CSE341: Programming Languages Lecture 11 Type Inference
Reasons To Study Programming Languages
CSE341: Programming Languages Lecture 11 Type Inference
Group 4: Song Li, Ying Lu, Hexin Wang, and Michael Walker May 1, 2000
CSE341: Programming Languages Lecture 11 Type Inference
SPL – PS3 C++ Classes.
Presentation transcript:

Formal Models for Programming Languages FJ and FGJ Alexandra Stefan 11/26/2018

Topics of Discussion Programming Languages (PLs) and Formal Models Case study: Java - Featherweight Java (FJ) Extension: Generic Java (1.5 beta) – Featherweight Generic Java (FGJ) Some properties: compositionality ... Related work 11/26/2018

PLs & formal models First was the computer … and then the programs … and then the programs to write programs … Numerous programming languages: imperative: Ada, Pascal, Perl, Java, all of the Cs … functional: Scheme, SML, Prolog, Haskel, OCaml … How to choose one? What makes one better than the other? expressive power? No. friendliness? (readability/ modifiability/ debugging) Yes. 11/26/2018

PLs & formal models Then questions and needs were raised about languages: How safe is it? It passed compilation: what next? Can I trust it to run well? Will it stab me on the back? Can it be extended? Improved efficiency: generic classes Increased expressivity: XML syntax How would I design a new language? 11/26/2018

PLs & formal models Here we come, the PL people! How do we do this? check their properties (e.g. type preservation, progress, …) try to capture the invariants with a type system How do we do this? using a formal model 11/26/2018

Formal model Design choice: completeness or compactness? more complex is more unwieldy too parsimonious is useless trade-off 11/26/2018

Formal model Examples: Lambda calculus Java: FJ, FGJ, Javas (Javase), Javalight, ClassicJava, … C: C 11/26/2018

Topics of Discussion Programming Languages (PLs) and Formal Models Case study: Java - Featherweight Java (FJ) Extension: Generic Java (1.5 beta) – Featherweight Generic Java (FGJ) Some properties: compositionality ... Related work 11/26/2018

Topics of Discussion Programming Languages (PLs) and Formal Models Case study: Java - Featherweight Java (FJ) 11/26/2018

Case study: Featherweight Java (FJ) Proposed by Igarashi, Pierce, and Wadler in 1999. Models Java’s type system. Minimal core calculus “Favors compactness over completeness almost obsessively” (It hardly resembles Java!) no assignment -> functional captures the core features of Java typing. How close is it to Java? FJ ~ purely functional core of Java. (every FJ program is ‘literally’ an executable Java program) 11/26/2018

FJ: What can be done with it? It allows easy proofs for type safety for FJ FJ’s main application is to model extensions of Java FGJ Featherweight Open Java Inner classes 11/26/2018

FJ What does it include? What does it not include? Object creation (*) Field access (*) Method invocation (*) Cast (*) Variables (*) Mutually recursive class definitions Method override Method recursion – this Assignment (final) Null pointers Base types Messages to super Field shadowing Method overloading Access control (public, private, …) Interfaces Exceptions 11/26/2018

FJ How does an FJ program look like? Sanity conditions for classes Pair: (class table, expression) The class table - fixed Sanity conditions for classes ‘Object’ - not part of the class table All necessary classes are defined No cycles in the subtyping relation induced by the class table 11/26/2018

FJ: class declaration examples 11/26/2018

FJ: expression examples 11/26/2018

FJ: syntax & subtyping rules 11/26/2018

FJ: auxiliary functions 11/26/2018

FJ: expression typing 11/26/2018

FJ: expression typing 11/26/2018

FJ: evaluation rules 11/26/2018

FJ: results 11/26/2018

Topics of Discussion Programming Languages (PLs) and Formal Models Case study: Java - Featherweight Java (FJ) Extension: Generic Java (1.5 beta) – Featherweight Generic Java (FGJ) Some properties: compositionality ... Related work 11/26/2018

Compositional compilation “Polymorphic Bytecode: Compositional Compilation for Java-like Languages” D. Anacona S. Drossopoulou F. Damiani E. Zucca 11/26/2018

Separate compilation: motivation Why do we want these properties? modularity safety 11/26/2018

Separate compilation compile link compile compile fragment Used fragments fragment compile link Used fragments fragment compile fragment compile fragment 11/26/2018

Java-like languages ‘clash of philosophy’ Separate compilation -> byte-code reflects compilation environment Dynamic linking -> byte-code does not reflect compilation environment no: (compilation ~ execution) environment no: (final ~ globally) compiled application type-safety through runtime verification Example: E m(B x){ return x.f1.f2} CEnv1 = … B {… C f1; …} … C {… E f2 …} -> mdB1 = E m(B x){ return x[B.f1 C][C.f2 E]} CEnv2 = … B {… D f1; …} … D {… F f2 …} -> -> mdB2 = E m(B x){ return x[B.f1 D][D.f2 F]} 11/26/2018

Compositionality Compositional analysis: Compositional compilation: analyze source code fragments separately put them together finish analysis of the whole without reanalyzing the fragments Compositional compilation: typecheck source code fragments separately -> generate corresponding binaries link together fragments whose mutual constraints are satisfied, without reinspecting the code 11/26/2018

Compositional compilation: IDEA Compile fragments separately Generate bytecode with type variables constraints –> relate the type variables Put the constraints together (particular order) Solve the constraints –> substitution Put the bytecode together Apply the substitution Done! 11/26/2018

Compositional compilation How good is it? We are not sure yet, but it looks promising. My work: Try to apply it for FGJ. 11/26/2018

Topics of Discussion Programming Languages (PLs) and Formal Models Case study: Java - Featherweight Java (FJ) Extension: Generic Java (1.5 beta) – Featherweight Generic Java (FGJ) Some properties: compositionality ... Related work 11/26/2018

Generic Java Version: 1.5 beta Parametric polymorphism Uses the standard JVM Backward & Forward compatibility with old code. 11/26/2018

FGJ: class declaration examples 11/26/2018

FGJ: term examples 11/26/2018

Homogeneous vs Heterogeneous polymorphism Description One piece of code: handles all instances of a generic class Stack<T> ---> Stack Object < ---> T problem: raw types The template: rewritten as specialized code for each unique set of parameters Examples Generic Java, ML C++ (templates) Byte code size Small Large: linear in size of parameter combinations Type semantics Clear Blurred: the complier does not know the classes derive from the same template generic class can not be rewritten Speed Slow: runtime cast Fast: no additional casts 11/26/2018

Generic Java (GJ) No explicit type arguments to a generic method: parsing problem “e.m<A,B>(e’)”  “e.m<A”, “B>(e’)” Performs parameter inference: has a least type 11/26/2018

Featherweight Generic Java (FGJ) FJ extended with generic classes Not a subset of GJ: requires type arguments to generic methods Not concerned with parameter inference 11/26/2018

FGJ: syntax & subtyping rules 11/26/2018

FGJ: auxiliary functions 11/26/2018

FGJ 11/26/2018

FGJ 11/26/2018

FGJ: expression typing 11/26/2018

FGJ: expression typing 11/26/2018

FGJ: evaluation rules 11/26/2018

FGJ: results 11/26/2018

Topics of Discussion Programming Languages (PLs) and Formal Models Case study: Java - Featherweight Java (FJ) Extension: Generic Java (1.5 beta) – Featherweight Generic Java (FGJ) Some properties: compositionality ... Related work 11/26/2018

Related work “Types and Programming Languages” by B.C.Pierce “Featherweight Java – A Minimal Core Calculus for Java and GJ” by Atsushi Igarashi, Benjamin C. Pierce, Philip Wadler “GJ Specification” by Gilad Bracha, Martin Odersky, David Stoutamire, Philid Wadler “Bringing Genericity to Java” by David W. Dunham “Polymorphic Bytecode: Compositional Compilation for Java-like Languages” by D. Anacona, S. Drossopoulou, F. Damiani, E. Zucca 11/26/2018