Reading, Writing and Relations Towards Extensional Semantics for Effect Analyses Andrew Kennedy Microsoft Research Cambridge (joint work with Nick Benton,

Slides:



Advertisements
Similar presentations
Equivalence Relations
Advertisements

Equivalence Relations
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
1 Turing Machines and Equivalent Models Section 13.2 The Church-Turing Thesis.
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
1 1 Regression Verification for Multi-Threaded Programs Sagar Chaki, SEI-Pittsburgh Arie Gurfinkel, SEI-Pittsburgh Ofer Strichman, Technion-Haifa Originally.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
C&O 355 Mathematical Programming Fall 2010 Lecture 20 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA A.
Time Bounds for General Function Pointers Robert Dockins and Aquinas Hobor (Princeton University) (NUS) TexPoint fonts used in EMF. Read the TexPoint manual.
Matrices: Inverse Matrix
CS 355 – Programming Languages
MATHEMATICAL FOUNDATIONS SUPPLEMENTAL MATERIAL – NOT ON EXAM.
Monads in Compilation Nick Benton Microsoft Research Cambridge.
Traced Premonoidal Categories Nick Benton Microsoft Research Martin Hyland University of Cambridge.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Conformance Simulation Relation ( ) Let and be two automata over the same alphabet simulates () if there exists a simulation relation such that Note that.
Correctness. Until now We’ve seen how to define dataflow analyses How do we know our analyses are correct? We could reason about each individual analysis.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Prof. Aiken CS 294 Lecture 21 Abstract Interpretation Part 2.
Tim Sheard Oregon Graduate Institute Lecture 11: A Reduction Semantics for MetaML CS510 Section FSC Winter 2005 Winter 2005.
Proof by Deduction. Deductions and Formal Proofs A deduction is a sequence of logic statements, each of which is known or assumed to be true A formal.
1/25 Pointer Logic Changki PSWLAB Pointer Logic Daniel Kroening and Ofer Strichman Decision Procedure.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
Hoare logic for higher order store using simple semantics Billiejoe (Nathaniel) Charlton University of Sussex WoLLIC 2011.
Solving fixpoint equations
Reading and Writing Mathematical Proofs
Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
CSC312 Automata Theory Lecture # 2 Languages.
Functional Programming With examples in F#. Pure Functional Programming Functional programming involves evaluating expressions rather than executing commands.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Albert Gatt LIN3021 Formal Semantics Lecture 4. In this lecture Compositionality in Natural Langauge revisited: The role of types The typed lambda calculus.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.
Mathematical Preliminaries
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
Copyright © Curt Hill Proofs An Introduction.
CPSC 536N Sparse Approximations Winter 2013 Lecture 1 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAAAAAAA.
1 First order theories (Chapter 1, Sections 1.4 – 1.5) From the slides for the book “Decision procedures” by D.Kroening and O.Strichman.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
CS104:Discrete Structures Chapter 2: Proof Techniques.
CMSC 330: Organization of Programming Languages Operational Semantics.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA.
Boolean Programs: A Model and Process For Software Analysis By Thomas Ball and Sriram K. Rajamani Microsoft technical paper MSR-TR Presented by.
Cs7120 (Prasad)L1-FP-HOF1 Functional Programming Basics Correctness > Clarity > Efficiency.
Cs776 (Prasad)L2HOF1 Higher-Order Functions. cs776 (Prasad)L2HOF2 Higher-Order Functions A function that takes a function as argument and/or returns a.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
Certifying and Synthesizing Membership Equational Proofs Patrick Lincoln (SRI) joint work with Steven Eker (SRI), Jose Meseguer (Urbana) and Grigore Rosu.
Operational Semantics of Scheme
Lecture 7: Constrained Conditional Models
SDN Network Updates Minimum updates within a single switch
Sparkle a functional theorem prover
On the Size of Pairing-based Non-interactive Arguments
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Complex Variables. Complex Variables Open Disks or Neighborhoods Definition. The set of all points z which satisfy the inequality |z – z0|
Proving Properties of Recursive List Functions
CS 154, Lecture 6: Communication Complexity
Logics for Data and Knowledge Representation
Programming Languages and Compilers (CS 421)
Equivalence Relations
Programming Languages and Compilers (CS 421)
Presentation transcript:

Reading, Writing and Relations Towards Extensional Semantics for Effect Analyses Andrew Kennedy Microsoft Research Cambridge (joint work with Nick Benton, Martin Hofmann & Lennart Beringer) Published in APLAS’06 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA A A AA A A A A A A A A AAAA A A A

Reading and writing When is this equivalence valid? C ; if B then C 1 else C 2  if B then { C;C 1 } else { C; C 2 } Answer: when B’s reads are disjoint from C’s writes. We’re interested in effect systems that can validate equations such as this. Specifically, we want to study their semantics.

Effect systems Effect systems (Gifford & Lucassen) associate to every term an approximation of its effect, such as ◦ Reading from a location in the store ◦ Writing to a location in the store ◦ Throwing an exception ◦ Performing I/O ◦ Allocating an object or ref cell ◦ Diverging Effect information can be used to justify transformations e.g. in optimizing compilers.

Syntactic approach to effect soundness Typically, effect systems are formalized in the style of a type system Usually, only a syntactic soundness result is shown. To do this, it is often necessary to instrument the standard semantics e.g. with traces of read/write operations. This “intensional” semantics is very close to the analysis, so it’s easy to prove a soundness result. But: ◦ It doesn’t capture what types mean – it’s purely syntactic ◦ It’s a cheat: the original semantics must be modified ◦ It confuses the inference system with the semantics of information that it produces ◦ It’s very hard to use it to prove equivalences

Intensional vs extensional effects Code Intensional effect Extensional (observable) effect x := x + 1; x := x – 1read x, write xnone if x=3 then y := x else y := 3read x, write ywrite y if x = 2 then y := y+1 else y := y-1; if x  2 then y := y+1 else y := y-1 read x, read y, write y none

Extensional interpretation of effects We prefer the extensional approach: what does it actually mean to “read” or “write”? Start simple: a store consisting of just 2 integer locations. Let f be the denotation of a command i.e. f 2 Z £ Z  Z £ Z. Suppose C does not write to the first location. Extensionally: there is some g : Z £ Z  Z such that f(x,y) = (x,g(x,y)) Suppose C does not read or write the first location. Extensionally: there is some g : Z  Z such that f(x,y) = (x,g(y)) Suppose C does not read from the first location. Extensionally: there is some h : Z  B, g 1,g 2 : Z  Z such that f(x,y) = (h(y) ? x : g 1 (y), g 2 (y))

Relations The “does not read” effect, in particular, was a little intricate to capture. But move to a relational interpretation, and we have a much slicker characterization of reading and writing.  = diagonal relation, £ and  usual constructions on relations f : R shorthand for (f,f) 2 R C does not write to the first location: 8 R µ . f : R £  R £ . C does not read or write the first location: 8 R. f : R £  R £ . C does not read from the first location: 8 R ¶ . f : R £  R £ .

Framework  ` M : A «  ` M : A ¬  ` M : X Base type system Refined type system (effect annotation, subtyping) «  ` M : X ¬ “erases to” Base semantics (sets and functions) Refined semantics (partial equivalence relations over base semantics)

Base language Types Terms Computation type Trivial computation Sequencing of computations Read from a global integer- valued location Write to a global location Value types Call by value

Selected typing rules

Base semantics Our language is simple: no recursion, no recursive types, global store of integer locations Obvious semantics in sets and functions:

Refined types and subtyping Subtyping Computation type is annotated with its effect Types An effect consists of a set of read and write effects to particular locations Set inclusion on effects induces a subtyping relation

Selected typing rules for refined types Effects are merged in let Trivial computations have no effect Reads have “read” effect Writes have “write” effect “Latent” effects are observed on function application

Erasure Define a map U from refined type to underlying base type. Easy results:

Embedding base into refined Define map G from base types to refined types that adds the “top” annotation to computation types: Easy result:

Goal Use the semantics to validate equivalences at particular types. E.g. effect-independent: E.g. effect-dependent:

Relational semantics of effects For a simple type A, the meaning « A ¬ was a set. For a refined type X, the meaning « X ¬ is a subset of the underlying set « U(X) ¬ together with a coarser notion of equality. That is: a partial equivalence relation on « U(X) ¬ (a symmetric, transitive relation). Roughly speaking: ◦ (x,x) in « X ¬ = “semantically, x behaves as type X” ◦ (x,y) in « X ¬ = “semantically, x is equivalent to y at type X”

Semantics of refined types, on one slide Values of base type are related just to themselves (diagonal relation) Functions are related in the usual “logical” fashion: related arguments  related results Computations are related if they preserve all state relations that respect the effect

Effect-respecting relations Computations are related if they produce related results and preserve all state relations R that respect .” We say R respects reads from l if We say R respects writes to l if We say R respects  if it respects each effect e in 

Results Soundness of subtyping: Fundamental theorem: Meaning of top effect: Equivalences ◦ Effect-independent: congruence rules, ,  rules, commuting conversions ◦ Effect-dependent: dead computation, duplicated computation, commuting computations, pure lambda hoist ◦ Reasoning is quite intricate, involving construction of specific effect-respecting relations. See paper!

Effect-dependent equivalences (1)

Effect-dependent equivalences (2)

Type isomorphisms This “currying” isomorphism follows from lambda-hoist and  -  rules. Interestingly, this does not hold in our model due to the presence of “snapback” functions. Here:

Other applications Our general approach – of defining semantics of refined types by relations over semantics of base types – transfers to other effects. ◦ “Semantics of an Effect Analysis for Exceptions”, Benton & Buchlovsky, TLDI’07. ◦ Here, the effect is directly observable and the definition of relations is obvious. Nevertheless, they’re necessary: a predicate-based semantics is unable to validate non-trivial equivalences.

Future directions Recursion ◦ Relations over domains instead of sets, unproblematic in absence of dynamic allocation Higher-typed store ◦ Much more challenging Dynamic allocation and regions ◦ Our current focus: runST-style encapsulation + its semantic analogue (e.g. purity of memoize function)