Stack effect calculus with typed wildcards, polymorphism and inheritance. Abstract

Similar documents
Let us dene the basic notation and list some results. We will consider that stack eects (type signatures) form a polycyclic monoid (introduced in [NiP

A stack eect (type signature) is a pair of input parameter types and output parameter types. We also consider the type clash as a stack eect. The set

JOURNAL OF OBJECT TECHNOLOGY

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Modeling Systems Using Design Patterns

Operational Semantics. One-Slide Summary. Lecture Outline

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

type classes & locales

Names, Scopes, and Bindings II. Hwansoo Han

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Flight Systems are Cyber-Physical Systems

Records. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Chapter 9. Subprograms

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Principles of Programming Languages

Efficient Separate Compilation of Object-Oriented Languages

Compilation 2012 The What and Why of Compilers

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Intermediate Code Generation Part II

Relational Algebra. Lecture 4A Kathleen Durant Northeastern University

Why Types Matter. Zheng Gao CREST, UCL

Transforming The Code: More Than Meets The Eye

Polymorphism. Arizona State University 1

22c:111 Programming Language Concepts. Fall Types I

Lecture 12: Data Types (and Some Leftover ML)

The Imperative Paradigm

An Approach to the Generation of High-Assurance Java Card Applets

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

The design of a programming language for provably correct programs: success and failure

An Introduction to Subtyping

Partial Metrics and Quantale-valued Sets (Preprint)

CIS-331 Fall 2014 Exam 1 Name: Total of 109 Points Version 1

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

In the previous chapter we saw how representing the Forth stack as a sequence of untyped

COMPOSABILITY, PROVABILITY, REUSABILITY (CPR) FOR SURVIVABILITY

Note 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University

Programming Languages FILS Andrei Vasilateanu

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Technical Aspects of Intrusion Detection Techniques

A FRAMEWORK FOR DATA STRUCTURES IN A TYPED FORTH

The type system of Axiom

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Lecture 10: Boolean Expressions

TYPES, VALUES AND DECLARATIONS

Lecture 13: Expression Evaluation

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Extracting the Range of cps from Affine Typing

Resolving of Intersection Types in Java

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

Global Namin-g in Distributed systems

Syllabi of the Comprehensive Examination in Computer Science

OASIS: Architecture, Model and Management of Policy

International Journal of Software and Web Sciences (IJSWS) EVALUATING TESTABILITY OF OBJECT ORIENTED SYSTEM

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

Contents. Chapter 1 SPECIFYING SYNTAX 1

Scientific Computing

Advances in Programming Languages

In this chapter you ll learn:

Programming Languages Third Edition

The Power of Abstraction. Barbara Liskov November 2009

Today s lecture. CS 314 fall 01 C++ 1, page 1

Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Impact of Dependency Graph in Software Testing

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

Software Project Seminar VII: Tools of the Craft. 23 march 2006 Jevgeni Kabanov

Static Safety Analysis of UML Action Semantics for Critical Systems Development

Chapter 9. Subprograms

C++ (Non for C Programmer) (BT307) 40 Hours

STEPHEN WOLFRAM MATHEMATICADO. Fourth Edition WOLFRAM MEDIA CAMBRIDGE UNIVERSITY PRESS

Rule Formats for Nominal Modal Transition Systems

XRay Views: Understanding the Internals of Classes

40 Behaviour Compatibility

ABriefOverviewofAgda A Functional Language with Dependent Types

Website Redevelopment Content Information Session. Presentation by

Efficient Separate Compilation of Object-Oriented Languages

The P ower Power o f of A bstraction Abstraction Barbara Liskov October 2009

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

Chapter 1 Getting Started

An introduction to C++ template programming

Arithmetic and Bitwise Operations on Binary Data

Soot A Java Bytecode Optimization Framework. Sable Research Group School of Computer Science McGill University

1 A question of semantics

CS 671, Automated Reasoning

Semantic Subtyping. Alain Frisch (ENS Paris) Giuseppe Castagna (ENS Paris) Véronique Benzaken (LRI U Paris Sud)

Java byte code verification

GREENWOOD PUBLIC SCHOOL DISTRICT AP Calculus AB Pacing Guide FIRST NINE WEEKS

THE USE OF PROLOG FOR THE STUDY OF ALGEBRAIC STRUCTURES AND COMPLEX OPERATIONS

TIME-BASED CONSTRAINTS IN THE OBJECT CONSTRAINT LANGUAGE OCL

Thesis book. Extension of strongly typed object-oriented systems using metaprograms István Zólyomi

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Static type safety guarantees for the operators of a relational database querying system. Cédric Lavanchy

An Introduction to Software Engineering. David Greenstein Monta Vista High School

Handout 10: Imperative programs and the Lambda Calculus

Transcription:

Stack effect calculus with typed wildcards, polymorphism and inheritance Jaanus Pöial University of Tartu, Estonia Abstract In early 1990s author introduced a formal stack effect calculus for verification of compilers that translated high level languages (Fortran, Modula) into Forth, see [PST90], [P90a], [P90h]. The calculus was partially applicable to static type checking of Forth programs, but this was not the primary goal these days. Stack effects (formal specifications of input and output parameters for stack operations) were defined using flat type space where different types were considered incompatible and no subtyping or inheritance was allowed. The so called wildcard types were introduced by sets of stack effects, see [P91]. This framework does not suite well with abstract stack machines that use principles of object orientation (see, for example, [AG98] about type checking in Java Virtual Machine). Peter Knaggs and Bill Stoddart improved the type signature algebra and introduced a lot of useful things (type variables, subtyping, reference types, wildcards, etc.), see [SK93], [K93]. In this presentation a modified framework for type checking is proposed to support typed wildcards and inheritance. Now it is possible to perform little more exact type calculations and express polymorphic operations. Every type symbol has its place in the type hierarchy and, at the same time, it may be treated as a wildcard symbol. Earlier approaches matched wildcards to concrete symbols (resulting in this concrete symbol) or to other wildcards (resulting in a new wildcard); this approach is more general allowing stepwise refinement of types. Not only the type checking is target here, but also the (static) choice of the right version for polymorphic operations (known as method overloading in object oriented languages). Given a type hierarchy, formal specifications for operations and a program we can refine the type signatures in the program according to the context where an operation appears. Experimental implementation of this framework is in progress. References [PST90] Tombak M., Soo V., Pöial J. A Forth-Oriented Compiler Compiler and its Applications. FORTH Dimensions (ISSN 0884-0822), Vol XVI No 5, Jan-Feb 1995, Forth Interest Group, Oakland, USA, 21-22. [P90a] Pöial J. Algebraic Specification of Stack Effects. FORTH Dimensions (ISSN 0884-0822), Vol XVI No 4, Nov-Dec 1994, Forth Interest Group, Oakland, USA, 18-20. [P90h] [P91] [SK93] [K93] [AG98] Pöial J. A Bit of History. FORTH Dimensions (ISSN 0884-0822), Vol XVI No 4, Nov-Dec 1994, Forth Interest Group, Oakland, USA, p. 17, 20. Pöial J. Multiple Stack-effects of Forth Programs. 1991 FORML Conf. Proceedings, euroforml'91 Conference, Oct 11-13, 1991, Marianske Lazne, Czechoslovakia, Forth Interest Group, Oakland, USA, 1992, 400-406. Bill Stoddart, Peter J. Knaggs. Type Interference in Stack Based Languages. Formal Aspects of Computing 5(4): 289-298 (1993). Peter J. Knaggs. Practical and Theoretical Aspects of Forth Software Development. PhD thesis, School of Computing and Mathematics, University of Teesside, Middlesbrough, Cleveland, UK, March 1993. Allen Goldberg. A Specification of Java Loading and Bytecode Verification. In Proc. 5th ACM Conference on Computer and Communications Security (CCS'98), pages 49-58, October 1998. This work was supported by Estonian Science Foundation grant No. 5279

Stack effect calculus with typed wildcards, polymorphism and inheritance Jaanus Pöial Institute of Computer Science University of Tartu, Estonia jaanus@cs.ut.ee Supported by Estonian Science Foundation grant No 5279

Goal 1: early checking for possible problems when using stack machines and stack based languages Type checking in stack based languages Postfix is hard to read and maintain by human programmer => programming tools, intelligent editors, Validation of code generation tools (e.g. compilers)

Goal 2: formal manipulations on stack programs optimisation transformation to different execution architectures parallelisation

History 1990 compiler compiler project: Mati Tombak, Viljo Soo, Jaanus Pöial Compilers for Modula 2 and Fortran Formal stack effect calculus introduced for rough checking of translators (whether all possible generated Forth-programs are type correct ) Type checking of Forth programs was not interesting at the beginning 1990-1994 type inference theory, mainly targeted to type checking: Bill Stoddart, Peter Knaggs, Jaanus Pöial

Stack effects Informal description OPERATION STACK EFFECT DESCRIPTION e.g. + ( a b -- a+b ) add two topmost elements top b a a+b before after

Stack effect calculus, the first approach T - operand types ( char, flag, addr,...) T * - type lists (last type on the top) Ø - type clash symbol (stack error) The set of stack effects: S = ( T * x T * ) U { Ø } ( a : b) input parameters (types) output parameters (types)

Composition (multiplication) For all s in S: s Ø = Ø s = Ø For all a, b, c, d, e, f in T * : (a : b) (eb : d) = (ea : d) (a : fc) (c : d) = (a : fd) Ø, otherwise Ø is zero 1 = ( : ) is unity for this operation S is polycyclic monoid

Drawbacks Type system was too simple ( flat ) Wildcards as sets, control structures implemented using sets (J.Pöial, 1991) Type signatures with wildcards, type variables, subtyping, reference types,... (B.Stoddart, P.Knaggs, 1991-93) Support for object oriented features was not developed enough: e.g. polymorphism, overloading,

Second approach Type hierarchy ( more exact type wins ) Wildcards are typed and numbered uniquely in scope of analysis Composition is defined by rules (like in Stoddart-Knaggs approach) that affect the whole scope of analysis Polymorphism is supported by replacing the concept of wildcard from the same element to the element of the same type : Example. Let flag<x and n<x, where flag O n plus ( x[1] x[1] : x[1] ) canberefinedto (flag[1] flag[1] : flag[1]) or (n[1] n[1] : n[1])

Notation t, u, - types (just symbols) t u t is subtype of u (t is more exact) or equal to u (subtype relation is transitive) t O u - t and u are incompatible types t i - type symbols with wildcard index (index is unique for thesametype ) a, b, c, d, - type lists (top right) that represent the stack state

Notation (cont.) s = (a : b) stack effect (a stack state before the operation, b after) -typeclash(zeroeffect) (a : b) (c : d) - composition of stack effects (a : b) and (c : d) defined by rules x, y sequences of stack effects y, where u j := t k substitution: all occurances of u j in all type lists of sequence y are replased by t k, where k is unique index over y

Rules x x ( a b)( d ) x ( a bd ) x x ( a )( c d ) x ( ca d ) x ( a bt )( cu d ), where t u

Rules (cont.) ( )( ) ( )( ) k j k i j i t u and t t d c b a x u t d cu bt a x = = : : where, where, ( )( ) ( )( ) k j k i j i u u and u t d c b a x t u d cu bt a x = = : :,where where,

Example (small subset) Type system: a-addr < c-addr < addr < x flag < x char < n < x

Example (cont.) Words and specifications: DUP ( x[1] -- x[1] x[1] ) DROP ( x -- ) SWAP ( x[2] x[1] -- x[1] x[2] ) ROT ( x[3] x[2] x[1] -- x[2] x[1] x[3] ) OVER ( x[2] x[1] -- x[2] x[1] x[2] ) PLUS ( x[1] x[1] -- x[1] ) same type + ( x x -- x ) @ ( a-addr -- x )! ( x a-addr -- ) C@ ( c-addr -- char ) C! ( char c-addr -- ) DP ( -- a-addr ) 0= ( n -- flag )

Example (cont.) Programs (should be live demo) Simple one: SWAP SWAP Conflict: C@! More exact analysis: 0= + 0= 0= PLUS 0= Information moving backwards: OVER OVER + ROT ROT + C! OVER OVER PLUS ROT ROT PLUS C! OVER OVER PLUS ROT ROT PLUS OVER OVER + ROT ROT PLUS C! OVER OVER PLUS ROT ROT + C!

Results Rules for composition of stack effects are modified to support subtyping (partially this was done in [StK93]). This is prerequisite for handling inheritance and operation overloading. Wildcards are interpreted in more general sense that allows to (statically) introduce polymorphic words (e.g. PLUS might be + for numbers and AND for Boolean flags). Composition is context sensitive: it affects the whole scope of analysis and it is possible to calculate exact signatures for polymorphic operations. Experimental implementation is in progress.