a mystery esterel –small no type inference, subtyping, … no recursion, functions, … no...

38

Post on 22-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,
Page 2: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

A Mystery

• Esterel– small

• no type inference, subtyping, …• no recursion, functions, …• no pointers, malloc, GC, …• no complex data structures, libraries, …• …

– formal semantics [Berry&Cosserat84,Gonthier88]

) compiling Esterel is easy well… no!

Page 3: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Motivation

• Esterel– small kernel language + formal semantics– for embedded/real-time/safety-critical designs– compiled into C code, automata, digital circuits, VHDL…

• Mathematically certified compiler?– YES [Schneider04]

• for correct programs• for circuit synthesis• for non-optimized circuits

• let’s check correctness • let’s think generic• let’s aim at performance

)but:

Page 4: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Why Loops?

• Synchronous loops impact– correctness: instantaneous loops– performance: schizophrenia

• Specify code generation for loops

– check correctness– achieve performance – generic (independent from target language)– amenable to certification

Page 5: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

A Key to Many Improvements

• Compiler

• Semantics– better understanding of determinism + errors

• Language– new construct: higher expressivity + lower complexity

• Proofs– easier proofs + collection of proof techniques

Page 6: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Outline

• Esterel– Synchronous Reactive Language– Syntax and Formal Semantics

• Causality and Instantaneous Loops

• Schizophrenia

• Conclusion

Page 7: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Reactive Approach

• 0-delay abstraction ) reactions

• Clock-triggered ) instants

time

input input inputoutput output outputinput Event-driven

tick tick tick tick

time

inputs inputs inputs inputsoutputs outputs outputs outputs

Reactive

Page 8: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Synchronous Concurrency

• Parallel composition

• Master clock

• Instantaneous– broadcast of signals– reaction to presence and absence of signals

) deterministic concurrency

Asynchronous

Synchronous

Page 9: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Example

• pause • local signal declaration• signal emission• test• loop• parallel composition• sequence

Page 10: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Syntax

(in the document)

wait for the next tick

Page 11: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Non-Reactive Programs

• signals

• loops

INCORRECT

INCORRECT

Page 12: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Operational Semantics

Page 13: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Inputs and Outputs

Page 14: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Sequence and Concurrency

Page 15: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Deduction Trees

Page 16: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Loops and Local Signals

Page 17: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Example: Present Signal

Page 18: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Outline

• Esterel

• Causality and Instantaneous Loops– Deterministic Semantics– Instantaneous Loop Detection

• Schizophrenia

• Conclusion

Page 19: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Instantaneous Loops - Causality

Page 20: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Instantaneous Loops - Causality

Causality

Instantaneous Loop [Gonthier88]

Page 21: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Non-Determinism

INCORRECT

Page 22: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

22

A Deterministic Semantics

Deterministic

Semantics

Logical

Semantics

1

0

1

1

0

0

1

Constructive

Semantics

0

1

0

0

[Berry96]

Page 23: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Determinism + Explicit Errors

Page 24: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Determinism + Explicit Errors

Page 25: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Determinism + Explicit Errors

+ error propagation

A better semantics– correct programs: unchanged– incorrect programs: more easily handled– distinguishes causality errors and instantaneous loops

Page 26: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Instantaneous Loop Detection

Page 27: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Outline

• Esterel

• Causality and Instantaneous Loops

• Schizophrenia– Example and Definition– Diagnosis and Cure

• Conclusion

Page 28: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Schizophrenia

Are these programs equivalent? NO

How shall we define, diagnose, and cure schizophrenia?YES

[Berry92]

Page 29: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Defining Schizophrenia

1 2

*

*

*

Page 30: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Diagnosing Schizophrenia

Page 31: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Curing Schizophrenia

)

Recursively replicate loop bodies [Mignard94]

Page 32: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Curing Schizophrenia

)

Page 33: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Curing Schizophrenia

)

Unfolding using non-instantaneous gotopause

Page 34: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

And then…

• Extend Esterel with “gotopause”

• Specify the cure– proving it preserves the semantics– proving it cures schizophrenia

• Combine diagnosis and cure– to achieve performance

• Extend the algorithm to full Esterel

Page 35: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Implementation

initial size

(statements)

quadratic

rewriting

quasi-linear

rewriting

abro 14 18 14

P18 28 86 58

tcint 403 725 418

wristwatch 432 833 439

atds100 890 1372 990

cabine 7644 67680 8020

globalopt 10286 566585 16867

Page 36: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Conclusion

• Loops– Instantaneous Loop Detection– Schizophrenia

• generic + efficient

• Better Language– Deterministic Semantics– gotopause

• makes compiling Esterel much easier (because of schizophrenia)• makes compiling to Esterel much easier (ex: SyncCharts [And95])• makes optimizations much easier (source-to-source transformation)

(SAS’03)

(MEMOCODE’04)

(SOS’04)

(SLAP’04)

PROOFS IMPLEMENTATION

Page 37: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,

Future Work

• Mechanize proofs• Consider constructive causality• Apply gotopause to more optimizations…• Make gotopause available

• Dynamic well-formedness?• Semantics of signals?

Page 38: A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,