What s so hard about pointers? Reasoning about Pointer-based Data Structures. Traditional Alias Analysis. Language of Pointer Equalities

Similar documents
CS 573 Automata Theory and Formal Languages

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Petri Nets. Rebecca Albrecht. Seminar: Automata Theory Chair of Software Engeneering

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Nondeterministic Finite Automata

Regular languages refresher

Nondeterministic Automata vs Deterministic Automata

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

NON-DETERMINISTIC FSA

Finite State Automata and Determinisation

Minimal DFA. minimal DFA for L starting from any other

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Chapter 4 State-Space Planning

CSE 401 Compilers. Today s Agenda

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

CMSC 330: Organization of Programming Languages

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Abstraction of Nondeterministic Automata Rong Su

= state, a = reading and q j

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

Nondeterminism and Nodeterministic Automata

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CS 275 Automata and Formal Language Theory

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Prefix-Free Regular-Expression Matching

University of Sioux Falls. MAT204/205 Calculus I/II

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

State Complexity of Union and Intersection of Binary Suffix-Free Languages

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

1 Nondeterministic Finite Automata

Hybrid Systems Modeling, Analysis and Control

CS 330 Formal Methods and Models

Designing finite automata II

Revision Sheet. (a) Give a regular expression for each of the following languages:

Complementing Büchi Automata

Convert the NFA into DFA

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Deterministic Finite Automata

CS 267: Automated Verification. Lecture 8: Automata Theoretic Model Checking. Instructor: Tevfik Bultan

More on automata. Michael George. March 24 April 7, 2014

@#? Text Search ] { "!" Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Formal Methods for XML: Algorithms & Complexity

Let's start with an example:

CS375: Logic and Theory of Computing

Lecture 08: Feb. 08, 2019

Propositional models. Historical models of computation. Application: binary addition. Boolean functions. Implementation using switches.

CS 275 Automata and Formal Language Theory

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Bisimulation, Games & Hennessy Milner logic

Chapter 2 Finite Automata

CS241 Week 6 Tutorial Solutions

First Midterm Examination

Formal languages, automata, and theory of computation

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Lecture Notes No. 10

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Automatic Synthesis of New Behaviors from a Library of Available Behaviors

Model Reduction of Finite State Machines by Contraction

FABER Formal Languages, Automata and Models of Computation

Formal Languages and Automata

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Homework 3 Solutions

Algorithm Design and Analysis

First Midterm Examination

Lecture 09: Myhill-Nerode Theorem

Linear Inequalities. Work Sheet 1

On Determinisation of History-Deterministic Automata.

Formal Language and Automata Theory (CS21004)

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Foundations of XML Types: Tree Automata

12.4 Similarity in Right Triangles

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Gold s algorithm. Acknowledgements. Why would this be true? Gold's Algorithm. 1 Key ideas. Strings as states

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Lexical Analysis Finite Automate

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

The size of subsequence automaton

INTEGRATION. 1 Integrals of Complex Valued functions of a REAL variable

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Electromagnetism Notes, NYU Spring 2018

Compression of Palindromes and Regularity.

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

CHAPTER 1 Regular Languages. Contents

System Validation (IN4387) November 2, 2012, 14:00-17:00

CS 330 Formal Methods and Models

Algorithm Design and Analysis

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

6.5 Improper integrals

Transcription:

Wht s so hrd out pointers? Resoning out Pointer-sed Dt Strutures Sott MPek CS 294-3 1/21/4 1 Indiret ess egs lising question Consider xiom for memory: i j sel(upd(m, i, v), j) = sel(m, j) need to e le to onlude disequlity otherwise, every write invlidtes ll ious info i.e., strong updte 2 Trditionl Alis Anlysis Eh llotion site is n ojet Anlysis finds, for eh vrile, the set of ojets it might point to onservtive dtflow nlysis This is too impreise ells of dt struture re typilly onflted eh strut field is (usully) single vrile Lnguge of Pointer Equlities Clim: we n dequtely hrterize dt strutures with sets of xioms of the form p. pac = prst A,, et. re unry funtion symols pa mens A(p); think p->a or p.a ny # of symols on eh side (in priniple) 3 4 Exmple: Douly-linked List Exmple: Leled List p. p.. = p lel lel lel sys tht is injetive, s is its inverse p. p..lel = p.lel 5 the lel is trnsitively spred throughout the struture 6 1

Exmple: Grid Prolem: Undeidle Theories f f p. p..f = p.f. p. p..f = p.f. The lnguge inludes xiom sets with undeidle theories (onsequenes) Consider rule suh s p. pac = prst Cretes equivlene lsses of strings: xyzacijk f f f is n isomorphism xyzrstijk 7 8 Turing Mhine Enoding Use following funtion symols: A, tpe symols S i r/w hed lo, stte i E tpe end (expndle) C epting onsumer In stte 4, when reding, write A, move left, go to 7. p. pas 4 = ps 7 AA Exmple tpe, in stte i xaaas i AAE symol eing red In stte 6, when reding, ept. p. ps 6 = pc To Prove Theory Deidle Give mthing rules (i.e. when to instntite the xioms) Show mthing/ompletion termintes Show ll equlities mong given finite set of terms re disovered EDAG expnsion rgument Expnd tpe (dding A s) p. pe = pae Collpse to just C p. pca = pc 9 1 Exmple: Injetivity p. pa = p mth: pa Exmple: Trnsitivity mth: pa p. pa = p mth: pa nd p A x 11 A x A x 12 2

Counterexmple: Inj+Trns p. pa = p p. p = p p. pa = p A x 13 Exmple: Grid p. pa = pa Is it omplete? Exerise! Either: - find ounterexmple, or - onvine yourself it is omplete 14 Extension to Conditionls Usully, we need speil ses: p. pa pa = p Mthing with Conditionls In generl: NULL Clim: Mthing rule is intersetion of disjunt mthing rules Proof: If disjunt s rule is not stisfied, it ould e true ut irrelevnt 15 16 A Short Proof Exmple: inry Tree invrint premise gol instntite split ses (ontrdition) (ontrdition) 17 18 3

Exmple: Red-lk Tree Exmple: Linked Leves 19 2 Outline Resoning Aout Pointer-sed Dt Strutures (Prt 2) Sott MPek CS 294-3 1/26/24 First hlf: survey of pprohes Axiomtize trnsitive losure (Nelson) Use grph grmmrs (Shpe Types) Astrt interprettion (TVLA) Proving vi semnti trnsformtion (PALE) Seond hlf: How PALE works 21 22 Generl Themes Need lnguge to desrie dt strutures no info out hep lis nlysis wnt to e here onrete heps only Nelson s Rehility (POPL 83) Everything revolves round one predite: Need resoning engine for tht lnguge Key question: Wht is done with trnsitive losure? 23 u f f f n links... f v x 24 4

Derived Axioms u f(u) v x u v w x u v x u x y z x u y u x y z u f(u) v u v x p 25 Complete? Suffiient to verify Union-find, where equivlene lsses re irulr lists Otherwise, little is known My experiene: even if omplete, hrd to use utomtilly 26 Shpe Types [Frdet/Métyer 97] Exmple: Douly-linked List Hep is set of ojets, reltions unry reltions: progrm vriles inry reltions: pointers mong ojets hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } Grph grmmrs onstrin legl heps genertive rules for uilding heps 27 28 Exmple: Douly-linked List Exmple: Douly-linked List hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } Douly hed x, x, Expnd x Expnd x x y, y x, Expnd y Expnd x x Douly hed x, x, Expnd x Expnd x x y, y x, Expnd y Expnd x x 29 hed = { } = { } = { } Douly 3 5

Exmple: Douly-linked List Exmple: Douly-linked List hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } Douly hed x, x, Expnd x Expnd x x y, y x, Expnd y Expnd x x Douly hed x, x, Expnd x Expnd x x y, y x, Expnd y Expnd x x hed hed = { } = { } = { (,) } Expnd 31 hed hed = { } = { (,) } = { (,), (,) } Expnd 32 Exmple: Douly-linked List Exmple: Douly-linked List hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } Douly hed x, x, Expnd x Expnd x x y, y x, Expnd y Expnd x x Douly hed x, x, Expnd x Expnd x x y, y x, Expnd y Expnd x x hed hed = { } = { (,), (,) } = { (,), (,), (,) } Expnd 33 hed hed = { } = { (,), (,), (,) } = { (,), (,), (,) } 34 Exmple: Til-linked List hed til Exmple: inry Tree root left right left right left right TilList hed x, til x z, Expnd x z Expnd x z x y, til y z, Expnd y z Expnd x z x z, til z z 35 intree root x, Expnd x Expnd x left x y, right x z, Expnd y, Expnd z Expnd x left x, right x 36 6

Deision Prolem TVLA [Sgiv et l. 2] Assuming the hep onformed to given grph grmmr, nd hnge is pplied to tht hep, does the new hep lso onform? Undeidle in generl Authors suggest restriting the grmmrs to otin deidility Their lim: restritions ok in prtie 37 As in Shpe Types, hep is ojets/reltions Sets of heps denoted y letting inry reltions hve vlue 1/2, unknown Formuls simply evluted (onservtively) Shpe hrterized y dditionl instrumenttion predites Evolution ross updtes still n issue 38 PALE [Møller/Shwrtzh 1] Dt strutures desried vi grph types Certin fields for kone tree Other fields vlues determined y the kone, with routing expressions Grph types trnslted into WSkS, wek seond-order logi of k suessors WSkS formuls deided y redution to Grph Types kone tree simply identify the fields nd roots involved; it is impliit tht they must form tree Routing expressions onstrin non-tree pointers y (in essene) writing little nvigtion progrm tul nottion resemles regulr expressions utomt 39 4 Exmple: Til-linked List Exmple: Tree w/ Linked Leves hed til Tree fields: hed, Routing expression onstrint for til: p. p < *. [λx. x.=null] > p.til 41 ^ = [λx. isroot(x)] $ = [λx. islef(x)] p. p < right *. ( left right ^ ). left *. $ > p. 42 7

WS1S Wek mondi seond order logi of one suessor rek 43 44 WS1S Wek mondi seond order theory of one suessor Definle Conepts in WS1S isempty(x) Y. X Y isequl(x,y) X Y Y X issingleton(x) X Y. Y X Y=X Y= iszero(x) issingleton(x) Y. X = Y+1 45 46 Interprettion Enoding Ide: Use it strings to enode finite sets e.g. 111 = { 1, 3, 4 } Enode severl sets with it vetor strings e.g. mens X 1 = { 1, 3 } nd X 2 = { 2, 3} Evlute Using Automt Given formul φ, wnt to rete n utomton M(φ) s.t. Ψφ M(φ) reognizes Ψ string X 1 X 2 : Note: Not nonil enoding (triling s) 47 48 8

X 1 = X 2 \ X 3 X 2 = X 1 + 1 exmple input: expet expet in X 2 1 in X 2 49 5 φ = θ Propositionl Connetives Let M e utomton for θ Mke sure M is omplete, deterministi Simply invert epting/non-epting sttes φ = φ 1 φ 2 Construt produt utomton Aept wherever oth do 51 X i. φ Let M e utomton for φ Chnge ll ith vetor omponents to * i.e. remove sensitivity to X i result is nondeterministi utomton Let stte s e epting if it n reh n epting stte vi trnsitions 52 X 2. X 2 = X 1 + 1 X 2. X 2 = X 1 + 1 Originl: X 2 = X 1 + 1 Chnge referenes to X 2 to * 53 54 9

X 2. X 2 = X 1 + 1 Automton-Logi Connetion Aept if n reh epting vi trnsitions Conversion to utomt give effetive proedure for deiding formuls: Convert formul to utomton φ is vlid iff M(φ) n only reh epting sttes φ is stisfile iff M(φ) hs rehle epting stte 55 56 Is this mgi? Complexity Originl semntis Not oviously deidle---so how did the utomton do it? Automton is mesure of formul Consider formul:... φ Eh use of quntifier introdues nondeterminism Eh use of negtion requires determiniztion (powerset onstrution) omplexity; ompre to ounting +1 s Cost: O( ), = M(φ) 57 58 2 2 2...2 n n WS2S Interprettion Enoding (WS2S) Two suessor funtions insted of one 59 Ide: represent sets of strings using trees N X 1 = { LLR, LRL, RRR, R } L R N Y L R L R N N N N L R L R L R L R N Y Y N N N N Y 6 1

Evlute With Tree Automt ottom-up tree utomton: Finite set of sttes Q Aepting set of sttes Q F Q Trnsition reltion, elements of form f(q 1, q 2,..., q n ) q where f is tree onstrutor of rity n Exmple: nil 1 N(1,1) 1 Y(1,1) 2 N(1,2) 3 (ept) N(2,2) 3 (ept) else 4 N * Y 61 nil 1 (1,1) 1 (1,1) 1 (1,1) 1 X 1 X 2 (WS2S) (epting) (_,_) 2 (2,_) 2 (_,2) 2 (rejeting) rell the WS1S version: 62 Remining Cses Grph Types WSkS Negtion: determinize, invert Conjuntion: produt, intersetion Set differene: esy, like suset Suessor pplition: esy, like +1 Existentil Nondeterminize the quntified trk Any stte rehle vi prefix is initil 63 kone: p.left orresponds to {p}.l Routing expressions: X is p.left * iff p X y X y y.left X Y....(ove)..Y.. X Y (the ove is tully just guess) ontins left * smllest suh 64 Integrtion into Nelson-Oppen? Conlusion Cn test for unstisfiility? Yes. Cn emit implied equlities? Only(?) y mking seprte queries H x = y Non-onvex theory; n emit se splits? I do not see how. Deision lgorithm is powerful ut opque 65 Dt struture desription lnguge: powerful for uxilliries; hs trnsitive losure wek for kone: must e tree Deision lgorithm: entirely sed on semntis (no proof system) lever use of utomt potentilly very d performne unler how to integrte to shre results 66 11

Referenes Referenes (prt 2) Nelson Rehility Greg Nelson Verifying rehility invrints of linked strutures POPL 83 Shpe Types Psl Frdet, Dniel Le Métyer Shpe Types POPL 97 TVLA Shmuel Sgiv, Thoms W. Reps, Reinhrd Wilhelm Prmetri shpe nlysis vi 3-vlued logi TOPLAS 22 67 PALE Anders Møller, Mihel Shwrtzh The Pointer Assertion Logi Engine PLDI 1 Nils Klrlund, Mihel Shwrtzh Grph Types POPL 93 Nils Klrlund, Anders Møller, Mihel Shwrtzh MONA Implementtion Serets IJFCS (I got my WSkS mteril from here) Nils Klrlund Mon nd Fido: The Logi-Automton Connetion in Prtie CSL 97 (Another WSkS tretment, little less ler) 68 12