Pretty-big-step semantics



Similar documents

Functional programming languages

Variations of Batteric V, Part 1

Bi-inductive Structural Semantics

The countdown problem

Peter V. Homeier and David F. Martin. and

Regression Verification: Status Report

Coinductive Big-Step Semantics for Concurrency

1 Operational Semantics for While

ML for the Working Programmer

Extraction of certified programs with effects from proofs with monadic types in Coq

COMPUTER SCIENCE TRIPOS

POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful

The CompCert verified C compiler

[Refer Slide Time: 05:10]

MAT Program Verication: Exercises

PROGRAM LOGICS FOR CERTIFIED COMPILERS

The previous chapter provided a definition of the semantics of a programming

Observational Program Calculi and the Correctness of Translations

A Systematic Approach. to Parallel Program Verication. Tadao TAKAOKA. Department of Computer Science. Ibaraki University. Hitachi, Ibaraki 316, JAPAN

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Compiler Construction

Resources, process calculi and Godel-Dummett logics

Language. Johann Eder. Universitat Klagenfurt. Institut fur Informatik. Universiatsstr. 65. A-9020 Klagenfurt / AUSTRIA

Ensuring Consistency in Long Running Transactions

Introduction to formal semantics -

Lecture 11: Tail Recursion; Continuations

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Rigorous Software Development CSCI-GA

Programming Languages

Chapter 7: Functional Programming Languages

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Static Program Transformations for Efficient Software Model Checking

Anatomy of Programming Languages. William R. Cook

Programming Language Pragmatics

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Automata and Formal Languages

Investigating a File Transfer Protocol Using CSP and B

The Halting Problem is Undecidable

CHAPTER 18 Programming Your App to Make Decisions: Conditional Blocks

CHAPTER 7 GENERAL PROOF SYSTEMS

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

Compiler I: Syntax Analysis Human Thought

GENERIC and GIMPLE: A New Tree Representation for Entire Functions

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Origin Tracking in Attribute Grammars

Chapter 6: Programming Languages

XSLT - A Beginner's Glossary

CS 111 Classes I 1. Software Organization View to this point:

WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT?

Boolean Algebra Part 1

CSE 880. Advanced Database Systems. Active Database Design Issues

Algebraic Properties and Proofs

Introducing Formal Methods. Software Engineering and Formal Methods

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Computer Programming I

Chapter 15 Functional Programming Languages

AP Computer Science Java Subset

Vocabulary. Term Page Definition Clarifying Example. biconditional statement. conclusion. conditional statement. conjecture.

Indiana State Core Curriculum Standards updated 2009 Algebra I

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Chapter 13: Query Processing. Basic Steps in Query Processing

Simple Loop Patterns and Rich Loop Invariants

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

LAKE ELSINORE UNIFIED SCHOOL DISTRICT

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala

A Propositional Dynamic Logic for CCS Programs

Termination Checking: Comparing Structural Recursion and Sized Types by Examples

Finite Automata. Reading: Chapter 2

OAMulator. Online One Address Machine emulator and OAMPL compiler.

Introduction to Python

Data Structures Fibonacci Heaps, Amortized Analysis

AURA: A language with authorization and audit

A SOUND TYPE SYSTEM FOR SECURE FLOW ANALYSIS

Informatica e Sistemi in Tempo Reale

Chapter 2: Elements of Java

2.1. Inductive Reasoning EXAMPLE A

Foundational Proof Certificates

Outline Basic concepts of Python language

Introduction to type systems

InvGen: An Efficient Invariant Generator

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

The Classes P and NP

The Bakery Algorithm: Yet Another. Specication and Verication. Dean Rosenzweig z. Abstract. In a meeting at Schloss Dagstuhl in June 1993, Uri Abraham

Structure Definitions. Inconsistent Data Structure. Repaired Data Structure. attributelist

Full and Complete Binary Trees

CSCE-608 Database Systems COURSE PROJECT #2

How To Write A Test Engine For A Microsoft Microsoft Web Browser (Php) For A Web Browser For A Non-Procedural Reason)

CA Compiler Construction

EMSCRIPTEN - COMPILING LLVM BITCODE TO JAVASCRIPT (?!)

3515ICT Theory of Computation Turing Machines

Programming Your App to Make Decisions: Conditional Blocks

CSCI 3136 Principles of Programming Languages

How To Verify Stack Space Bounds In C Programs In Coq

Algorithms and Data Structures

Unit 6. Loop statements

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

Transcription:

Pretty-big-step semantics Arthur Charguéraud INRIA October 2012 1 / 34

Motivation Formalization of JavaScript with Sergio Maeis, Daniele Filaretti, Alan Schmitt, Martin Bodin. Previous work: Semi-formal small-step semantics for the entire language (jssec.net) Informal big-step semantics for the core language (POPL'12) Current work: Formal big-step semantics for the entire language Interpreter proved correct w.r.t. the semantics 2 / 34

Motivation for big-step Big-step semantics: more faithful to the reference manual easier than small-step for proving an interpreter easier than small-step for proving a program logic Small-step semantics considered better-suited for: machine-code semantics not the case of JS type soundness proofs no types in JS concurrent languages no concurrency in JS 3 / 34

Big-step semantics for loops Semantics of a C-style loop for ( ; t 1 ; t 2 ) { t 3 }, written for t 1 t 2 t 3, in terms of the evaluation judgment t /m v /m. t 1/m1 false /m2 for t 1 t 2 t 3/m1 tt /m2 t 1/m1 true /m2 t 3/m2 tt /m3 t 2/m3 tt /m4 for t 1 t 2 t 3/m4 tt /m5 for t 1 t 2 t 3/m1 tt /m5 4 / 34

Big-step semantics for loops: exceptions Exceptions in terms of the judgment t /m exn /m. t 1/m1 exn /m 2 for t 1 t 2 t 3/m1 exn /m 2 t 1/m1 true /m2 t 3/m2 exn /m 3 for t 1 t 2 t 3/m1 exn /m 3 t 1/m1 true /m2 t 3/m2 tt /m3 t 2/m3 exn /m 4 for t 1 t 2 t 3/m1 exn /m 4 t 1/m1 true /m2 t 3/m2 tt /m3 t 2/m3 tt /m4 for t 1 t 2 t 3/m4 exn /m 5 for t 1 t 2 t 3/m1 exn /m 5 5 / 34

Big-step semantics for loops: divergence Divergence in terms of the coinductive judgment t /m (Leroy 2006). t 1/m1 for t 1 t 2 t 3/m1 t 1/m1 true /m2 t 3/m2 for t 1 t 2 t 3/m1 t 1/m1 true /m2 t 3/m2 tt /m3 t 2/m3 for t 1 t 2 t 3/m1 t 1/m1 true /m2 t 3/m2 tt /m3 t 2/m3 tt /m4 for t 1 t 2 t 3/m4 for t 1 t 2 t 3/m1 6 / 34

Big-step semantics for loops: summary t 1/m1 false /m 2 for t 1 t 2 t 3/m1 tt /m2 t 1/m1 true /m 2 t 3/m2 tt /m3 t 2/m3 tt /m4 for t 1 t 2 t 3/m4 tt /m5 for t 1 t 2 t 3/m1 tt /m5 t 1/m1 exn /m 2 for t 1 t 2 t 3/m1 exn /m 2 t 1/m1 true /m t 2 3/m2 exn /m 3 for t 1 t 2 t 3/m1 exn /m 3 t 1/m1 for t 1 t 2 t 3/m1 t 1/m1 true /m t 2 3/m2 for t 1 t 2 t 3/m1 t 1/m1 true /m 2 t 3/m2 tt /m3 t 2/m3 exn /m 4 for t 1 t 2 t 3/m1 exn /m 4 t 1/m1 true /m 2 t 3/m2 tt /m3 t 2/m3 for t 1 t 2 t 3/m1 t 1/m1 true /m 2 t 3/m2 tt /m3 t 2/m3 tt /m4 for t 1 t 2 t 3/m4 exn /m 5 for t 1 t 2 t 3/m1 exn /m 5 t 1/m1 true /m 2 t 3/m2 tt /m3 t 2/m3 tt /m4 for t 1 t 2 t 3/m4 for t 1 t 2 t 3/m1 Even with factorization: 9 rules, 21 premises. With pretty-big-step: 6 rules, 7 premises. 7 / 34

In this talk Pretty-big-step semantics: construction extension to traces application to core-caml type soundness proofs 8 / 34

Pretty-big-step 9 / 34

Big-step semantics Grammar of λ-terms v := int n abs x t t := val v var x app t t Call-by-value big-step semantics (t v) v v t 1 abs x t t 2 v [x v] t v app t 1 t 2 v 10 / 34

A rst attempt Big-step rule for applications: t 1 abs x t t 2 v [x v] t v app t 1 t 2 v A rst attempt at pretty-big-step rules: t 1 v 1 app v 1 t 2 v app t 1 t 2 v t 2 v 2 app v 1 v 2 v app v 1 t 2 v [x v] t v app (abs x t) v v Similar idea in Cousot and Cousot's bi-inductive semantics (2007) 11 / 34

Intermediate terms To prevent overlap between the rules, we use intermediate terms. e := trm t app1 v t app2 v v Denition of the judgment e v, with trm implicit v v t 1 v 1 app1 v 1 t 2 v app t 1 t 2 v t 2 v 2 app2 v 1 v 2 v app1 v 1 t 2 v [x v] t v app2 (abs x t) v v 12 / 34

Adding exceptions Value-carrying exceptions and exception handlers t :=... raise t try t t Two behaviors: return a value or throw an exception. e b b := ret v exn v 13 / 34

Generalization of intermediate terms Need to generalize intermediate terms t 1 b 1 app1 b 1 t 2 b app t 1 t 2 b app1 (exn v) t 2 exn v t 2 b 2 app2 v 1 b 2 b app1 (ret v 1 ) t 2 b New grammar of intermediate terms e := trm t app1 b t app2 v b raise1 b try1 b t 14 / 34

Pretty-big-step rules for exceptions v v t 1 b 1 app1 b 1 t 2 b app t 1 t 2 b app1 (exn v) t exn v t 2 b 2 app2 v 1 b 2 b app1 v 1 t 2 b app2 v (exn v) exn v [x v] t b app2 (abs x t) v b t 1 b 1 try1 b 1 t 2 b try t 1 t 2 b try1 v t v app t v b try1 (exn v) t b t b 1 raise1 b 1 b raise t b raise1 v exn v raise1 (exn v) exn v 15 / 34

Adding divergence Outcome of an evaluation: termination or divergence o := ter b div New grammar of intermediate terms e := trm t app1 o t app2 v o raise1 o try1 o t Evaluation rules t 1 o 1 app1 o 1 t 2 b app t 1 t 2 b app1 div t div 16 / 34

The abort predicate We want to factorize pairs of similar rules, such as: app1 (exn v) t (exn v) app1 div t div Solution: abort o app1 o t o where abort characterizes exceptions (exn v) and divergence (div). 17 / 34

Summary: grammars and judgments Grammars: b := ret v exn v o := ter b div e := trm t app1 o t app2 v o raise1 o try1 o t Judgments: abort o e o e co o Theorem (equivalence with big-step) t ter b t b t co div t 18 / 34

Summary: rules v v t 1 o 1 app1 o 1 t 2 o app t 1 t 2 o abort o app1 o t o t 2 o 2 app2 v 1 o 2 o app1 v 1 t 2 o t o 1 raise1 o 1 o raise t o t 1 o 1 try1 o 1 t 2 o try t 1 t 2 o abort o app2 v o o abort o raise1 o o try1 v t v [x v] t o app2 (abs x t) v o raise1 v exn v app t v o try1 (exn v) t o try1 div t div 19 / 34

Traces 20 / 34

Denition of traces A trace records I/O interactions and ɛ-transitions. A terminating program has a nite trace. A diverging program has an innite trace. α := ɛ in n out n τ := list α σ := stream α o := ter τ b div σ We are not using possibly-innite traces (coinductive lists) like Nakata and Uustalu (2009) and Danielsson (2012). 21 / 34

Operation on traces Concatenation of a nite trace τ to the front τ τ τ σ τ o Equivalence of two traces up to nite consecutive insertions of ɛ-transitions o o ɛ n [α] o ɛ m [α] o 22 / 34

Trace semantics in pretty-big-step Every rule appends an ɛ-transtion in order to be productive. v ter [ɛ] v t 1 o 1 app1 o 1 t 2 o app t 1 t 2 [ɛ] o abort o app1 o t o t 2 o 2 app2 v 1 o 2 o app1 (ter τ v 1 ) t 2 τ o abort o app2 v o o [x v] t o app2 (abs x t) (ter τ v) τ o 23 / 34

Trace semantics in pretty-big-step, cont. I/O operations are recorded in the trace. t o 1 write1 o 1 o write t [ɛ] o write1 (ter τ n) ter τ [out n] tt t o 1 read1 o 1 o read t [ɛ] o read1 (ter τ tt) ter τ [in n] n abort o read1 o o abort o write1 o o 24 / 34

Benets of trace semantics Theorem (nite traces can only be produced by nite derivations) e co ter τ v e ter τ v So, we do not need the inductive judgment: the coinductive one suces. Theorem (equivalence with big-step) t co ter τ b t b/τ t co div σ t /σ 25 / 34

Proofs with trace semantics: problems A typical simulation theorem e co o o. o o e co o Coinductive proof? No luck! 1. is not coinductive 2. is not coinductive 3. o is not coinductive Yet, coinductive reasoning is morally correct. 26 / 34

Pretty-big-step: scaling up 27 / 34

Scaling up to real languages What's next: the generic abort rule semantics of side-eects semantics of loops formalization of core-caml 28 / 34

Abort rules Many similar abort rules: can we factorize them? abort o app1 o t o abort o app2 v o o abort o raise1 o o 29 / 34

The generic abort rule The auxiliary function getout getout (app1 o t) Some o getout (app2 v o) Some o getout (raise1 o) Some o getout (trm t) None getout (try1 o t) None The generic abort rule, which replaces the rules from the previous slide getout e = Some o e o abort o 30 / 34

Side-eects Generalization of terminating outcomes to carry a memory store: o := ter m b div Evaluation judgment in the form e /m o. Example rules: t 1 /m o 1 app1 o 1 t 2 /m o app t 1 t 2 /m o t 2 /m o 2 app2 v 1 o 2 /m o app1 (ter m v 1 ) t 2 /m o 31 / 34

Pretty-big-step semantics for loops A single intermediate term for i o t 1 t 2 t 3, where i {1, 2, 3}. Evaluation rules, with the judgment e /m o. t 1 /m o 1 for 1 o 1 t 1 t 2 t 3 /m o for t 1 t 2 t 3 /m o for 1 (ret m false) t 1 t 2 t 3 /m ret m tt t 3 /m o 3 for 2 o 3 t 1 t 2 t 3 /m o for 1 (ret m true) t 1 t 2 t 3 /m o t 2 /m o 2 for 3 o 2 t 1 t 2 t 3 /m o for 2 (ret m tt) t 1 t 2 t 3 /m o for t 1 t 2 t 3 /m o for 3 (ret m tt) t 1 t 2 t 3 /m o abort o for i o t 1 t 2 t 3 /m o 32 / 34

Pretty-big-step semantics for core-caml Formalization of core-caml: booleans, integers, tuples, algebraic data types, mutable records, boolean operators (lazy and, lazy or, negation), integer operators (negation, addition, subtraction, multiplication, division), comparison operator, functions, recursive functions, applications, sequences, let-bindings, conditionals (with optional else branch), for loops and while loops, pattern matching (with nested patterns, as patterns, or patterns, and when clauses), raise construct, try-with construct with pattern matching, and assertions. rules premises tokens Big-step without divergence 71 83 1540 Big-step with divergence 113 143 2263 Pretty-big-step 70 60 1361 Pretty-big-step reduces the size of the denition by 40%. Pretty-big-step reduces the number of premises by more than a factor 2. 33 / 34

Thanks! 34 / 34