COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION Reiner Hhnle - - PowerPoint PPT Presentation

combining partial evaluation and symbolic execution
SMART_READER_LITE
LIVE PREVIEW

COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION Reiner Hhnle - - PowerPoint PPT Presentation

COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION Reiner Hhnle & Richard Bubel Chalmers University Symposium09 Speyer CONTROL CIRCUIT y = 80; threshold = 100; if (y > threshold) { decrease = true; } else { decrease = false;


slide-1
SLIDE 1

COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION

Reiner Hähnle & Richard Bubel

Chalmers University

Symposium’09

Speyer

slide-2
SLIDE 2

CONTROL CIRCUIT

y = 80; threshold = 100; if (y > threshold) { decrease = true; } else { decrease = false; } while (|y-threshold| > eps) { y = decrease ? y-1 : y+1; }

slide-3
SLIDE 3

y = 80; threshold = 100; if (y > threshold) { decrease = true; } else { decrease = false; } while (|y-threshold| > eps) { y = decrease ? y-1 : y+1; }

decrease ?

CONTROL-FLOW GRAPH

|y-threshold| > eps ?

threshold=100 decrease = true; y=y+1; decrease = false; y=y-1; y = 80 y>threshold ?

slide-4
SLIDE 4

PARTIAL EVALUATION

|y-100| > eps ? |y-threshold| > eps ?

false decrease ? y>threshold ? 80>100 ? threshold=100 decrease = true; y=y+1; decrease = false; y=y-1; y = 80

  • constant propagation
  • constant expression

evaluation

  • dead-code elimination
  • other: type coercion,

safe dereferencing etc.

false

Evaluator Evaluator y 80 threshold 100 decrease false Evaluator Evaluator y

  • threshold

100 decrease false

Static information propagated along CFG

slide-5
SLIDE 5

decrease ?

PARTIAL EVALUATION

A Bit More Realistic

|y-threshold| > eps ?

y>threshold ? threshold=100 decrease = true; y=y+1; decrease = false; y=y-1; y = 80 decrease ?

|y-100| > eps ?

y>100 ? threshold=100 decrease = true; y=y+1; decrease = false; y=y-1;

slide-6
SLIDE 6

decrease ?

|y-threshold| > eps ?

y>threshold ? threshold=100 decrease = true; y=y+1; decrease = false; y=y-1;

SYMBOLIC EXECUTION

slide-7
SLIDE 7

decrease ?

|y-threshold| > eps ?

y>threshold ? threshold=100 decrease = true; y=y+1; decrease = false; y=y-1;

SYMBOLIC EXECUTION

threshold=100 y>threshold ? decrease = true; decrease=false;

|y-threshold| > eps ? |y-threshold| > eps ?

decrease ? decrease ? y=y-1; y=y+1; y=y-1; y=y+1;

|y-threshold| > eps ?

decrease ? y=y-1; y=y+1; |y-threshold| > eps ? decrease ? y=y-1; y=y+1;

|y-threshold| > eps ?

decrease ? y=y-1; y=y+1;

|y-threshold| > eps ?

decrease ? y=y-1; y=y+1;

slide-8
SLIDE 8

OPTIMIZING SYMBOLIC EXECUTION

Symbolic Execution

  • unfolds control-flow graph into tree
  • unfeasible paths must be closed by first-order proof search

interleave partial evaluation and symbolic execution

slide-9
SLIDE 9 |y-threshold| > eps ? |y-100| > eps ?

|y-100| > eps ? |y-100| > eps ?

|y-100| > eps ? |y-100| > eps ? |y-100| > eps ? |y-threshold| > eps ? |y-threshold| > eps ? |y-threshold| > eps ? decrease ? |y-threshold| > eps ? y>threshold ? threshold=100 decrease = true; y=y+1; decrease = false; y=y-1;

|y-threshold| > eps ? |y-threshold| > eps ?

y>threshold ?

decrease ?

true

decrease ?

decrease ?

decrease ? decrease ?

decrease ?

false false true

false

true

y>100 ?

INTERLEAVING

threshold=100 decrease=true; decrease=false; y=y-1; y=y+1; y=y-1; y=y+1;

y=y-1; y=y+1; y=y-1; y=y+1; y=y-1; y=y+1; y=y-1; y=y+1;

slide-10
SLIDE 10 |y-100| > eps ? |y-100| > eps ?

|y-100| > eps ? |y-100| > eps ?

decrease ? |y-threshold| > eps ? y>threshold ? threshold=100 decrease = true; y=y+1; decrease = false; y=y-1;

true false

false

true

INTERLEAVING

threshold=100 decrease=true; decrease=false; y=y-1; y=y+1;

y=y-1; y=y+1;

y>100 ?

slide-11
SLIDE 11

Simple OO-Programming Language

  • single inheritance
  • dereferencing null, division by zero etc. cause non-

termination

  • dynamic method binding
  • no nested expressions

PROGRAM LOGIC

Programming Language

slide-12
SLIDE 12

PROGRAM LOGIC

Syntax

p ↓ ( U , ϕ ) denotes a program equivalent to if is executed in a state s satisfying and coinciding on ϕ U p p

Dynamic Logic with Updates:

↓: PrgEl × Upd × For → PrgEl

PrgEl = Statement ˙ ∪ Expression

where Specialisation operator (as usual) Examples:

  • (x = o.a + 3)↓(o.a := 10, o!= null)

x =(y)↓(y := 3, true)+3;

slide-13
SLIDE 13

PROGRAM LOGIC

Notions Program variables and attributes are modelled as non-rigid constants and unary function symbols Signature Σ: States : s ∈ S interpretes program variables and attributes

  • Domain : sorted universe (interpretes sorts)
  • Interpretation : interpretes rigid function and

predicate symbols

I

D First-order structure(D, I):

slide-14
SLIDE 14

PROGRAM LOGIC

Signature Extension

p ↓Σ′⊇Σ (U, ϕ)

where

(D, I)Σ′ ⊇ (D, I)Σ sΣ′ ⊇ sΣ βΣ′ ⊇ βΣ and and Partial Evaluation may extend the signature (temporary variables, anonymous updates )

slide-15
SLIDE 15

PROGRAM LOGIC

Soundness Condition on the Specialisation Operator

p ↓Σ′⊇Σ (U, ϕ)

p↓(U, ϕ)ψ →

  • {U}(ϕ → pψ)
  • (D, I)Σ′ , sΣ′ , βΣ′ |

=

ψ For all formulas

  • verΣ for all (D, I)Σ′, sΣ′, βΣ′

, :

slide-16
SLIDE 16

if(b){p}else{q}↓(U, ϕ)

  • p↓(U, ϕ)

U(ϕ → b . = true)

  • .a↓(U, ϕ)

@(o.a)↓(U, ϕ)

  • U(ϕ →!(o .

= null))

  • (p; q)↓(U, ϕ)

p↓(U, ϕ); q↓(U′, ϕ′)

⊢ respModStrong(p, mod)

U′ := UVmod

(D, I) | = {U}{Vmod}ϕ′ ⇒ (D, I) | = {U}pϕ

Rewrite Action Correctness Requirement Dead-Code Elimination Safe Field Access Partial Evaluator Propagation

PROGRAM LOGIC

Partial Evaluation Rules

slide-17
SLIDE 17

Γ ⊢ U!(o . = null), ∆ Γ ⊢ U{o.a := t}q ↓ (o.a := t, !o . = null)φ, ∆ Γ ⊢ Uo.a = t; qφ, ∆

PROGRAM LOGIC

Partial Evaluator Introduction Rules and several others

slide-18
SLIDE 18

PROGRAM LOGIC

Type Inference Rules res = o.m(a1, . . . , an)↓(ϕ, U)

  • ′ = o↓(ϕ, U)

⊢ U(ϕ → o! . = null & C :: instance(o)) res = @((C)o′).m(a1 ↓(ϕ, U), . . . , an ↓(ϕ, U))

slide-19
SLIDE 19

PROGRAM LOGIC

Type Inference Rules

equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj) equals(Obj)

A

A a = ...; boolean eq = a.equals(c);

C

a is an instance of C

B

Evaluator ...

slide-20
SLIDE 20

DEMO

slide-21
SLIDE 21

FUTURE WORK

  • Simplification of specifications
  • Partial evaluation of contracts and loop invariants
  • Applicable to JavaCardDL / JML / OCL
  • Investigate applicability to application engineering
slide-22
SLIDE 22

FUTURE WORK

Application Engineering

Model Driven Architecture

Platform Independent Model Platform Specific Model Platform Definition Model

Application Engineering

Feature Configuration Application Productline Artefacts

Partial Evaluation

Program

p ↓ ( U , ϕ )

(U, ϕ) p

slide-23
SLIDE 23

CONCLUSION

(for the moment)

replaced proof search by computation

⊢ ↓

y = 80; threshold = 100; if (y > threshold) { decrease = true; } else { decrease = false; } while (y-threshold > eps) { y = decrease ? y-1 : y+1; }

computation linear in number of locs

β

partial eval. as generalisation of β-reduction in Hoare/VCG