ensō - university of texas at austinwcook/presentations/2011-11-enso-viewpointsb2.pdfgoals •...

49
Ensō William Cook, UT Austin Tijs van der Storm, CWI

Upload: others

Post on 21-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Ensō William Cook, UT Austin Tijs van der Storm, CWI

Page 2: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Goals

•  Eliminate boilerplate –  100x or more reduction

• Don't Design Programs –  Program the design: "run the design"

•  Integrated External DSLs –  Interpreted with partial evaluation

•  Consistent, self-hosted system –  Top half of desktop/server stack

Page 3: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Languages

Data definition Grammars

Stencils (Diagram/GUIs) Web UI Security Workflow

Page 4: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Strategy

External DSL not "embedded"

Interpreters Aspect = Interpreter Composition

Partial Evaluation interpreter compiler

Generic Operations Difference, parsing, etc

Page 5: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

"Smalltalk of Modeling"

Self-Describing Extreme Reuse Extreme Malleability Ruby runtime

DSL/MDD is the new paradigm Built on top of Objects … but it is not objects

Page 6: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Next Steps •  Theory

–  Why? How does it fit in PL? –  Enso details –  Partial Evaluation –  Better RPC (loosely related work)

• Demonstrations –  Diagram Editor –  Web Applications/Security –  Distributed Synchronization –  Read the code :-)

Page 7: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Why DSLs?

Page 8: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Spectrum of Programming

How implementation

What Specification

Page 9: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

How implementation

What Specification

C asm

B CASL

Page 10: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

How What

C asm

Java Haskell

Smalltalk

B CASL

Page 11: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Verification

How What

Programming Languages

B CASL

Page 12: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Verification

How What

Programming Languages

B CASL

Synthesis

Page 13: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Verification Lite

How What

B CASL

Types

Programming Languages

Synthesis

Page 14: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

How What

B CASL ???? Behavior

Synthesis Lite

Page 15: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

How What

B CASL DSL Behavior

Synthesis Lite

Page 16: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

How What

B CASL DSL Behavior

Synthesis Lite

Verification Lite

Types

Page 17: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

DSLs

Strategy + Specifics New dimension of modularity

Page 18: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Ensō Data

Page 19: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Managed Data

• Data –  Don't just program data types/structures –  Code up your data structuring mechanism –  In other words, override "dot" in o.f

•  Control over data architecture –  Persistence, access control –  Bi-directional Relationships –  Invariants, constraints, derived data

Page 20: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Managed Data

Data Manager

Data Description

Page 21: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Ensō Data

• Graphs with a spanning tree –  Spanning tree defined by subset of edge

labels

•  Properties –  Holistic view of data graphs –  Bidirectional edges

•  Seeking –  Easy to work with in PL –  Easy mapping to RDBMS

21

Page 22: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Point Schema

•  A point has x and y integer components

•  A schema describes the structure of data

Instance Schema

(3, 4) class Point x: integer y: integer

22

Page 23: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Description of Schemas

•  A class has a name and a list of fields, each of which ha a name and a type

Individual Schema

class Point x: integer y: integer

class Class name: string fields: Field* class Field name: string type: ??? Not explained

Not explained

23

Page 24: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Schema of Schemas Individual Schema

class Point x: int y: int

class Schema types: Type* class Type name: string class Primitive < Type class Class < Type fields: Field* super: Type? class Field name: string type: Type many: bool

Not explained

24

Page 25: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

class  Schema          types:  Type*  class  Type          name:  string  class  Primi4ve  <  Type    class  Class  <  Type          fields:  Field*          super:  Type?  

class  Field            name:  string            type:  Type            many:  bool            op4onal:  bool  primi*ve  string  primi*ve  bool  

Schema Schema

25

Page 26: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Adding More Metadata

•  Inverse fields –  parent/child, instructor/course, etc –  automatically maintained

•  Field properties –  key: ensures uniqueness in context –  traversal: ensures reachability –  ordering: ordered/unordered collections

•  Invariants –  field.type = field.inverse.owner

•  More… – Computed fields, etc 26

Page 27: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Factories

•  Factories –  Manages data described by a schema

•  Points factory = Factory.new(PointSchema)

pnt = factory.Point(3, 5) print pnt.x

•  Interpreted –  Virtual object has fields specified by schema –  Ensures data is valid with respect to schema

27

Page 28: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Grammars

•  A point is written as (x, y)

• Notes: –  Direct reading, no abstract syntax tree –  Bidirectional: can parse and pretty-print

Individual Grammar

(3, 4) start P P::= [Point] "(" x:int "," y:int ")"

28

Page 29: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

start  S  S  ::=  [Schema]  types:(P|  C)*    P  ::=  [Primi4ve]  "primi4ve"  name:sym  C  ::=  [Class]  "class"  name:sym  ("<"  super:Class^)?                                                        fields:F*    F::=  [Field]  name:sym  ":"  type:Type^                                      (many:"*”  |  op4onal:"?”)?  

Schema Grammar

29

primi4ve  int  class  Class  <  Type          fields:  Field*          super:  Type?  

Page 30: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Bidirectional

•  Parsing: matches tokens, generates instances •  Printing: matches instances, generates tokens

primi4ve  int  class  Class  <  Type          fields:  Field*          super:  Type?  

P  ::=  [Primi4ve]  "primi4ve"  name:sym  C  ::=  [Class]  "class"  name:sym  ("<"  super:Class^)?                                                        fields:F*  

30

Page 31: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

G ::= [Grammar] "start" \start:Rule^ rules:R* R ::= [Rule] name:sym "::=" arg:A A ::= [Alt] alts:{C "|"}+ C ::= [Create] "[" name:sym "]" arg:S | S S ::= [Sequence] elements:F* F ::= [Field] name:sym ":" arg:P | P P ::= [Value] kind:("int" | "str" | "real" | "sym") | [Call] rule:Rule^ | [Ref] name:sym "^" | [Lit] value:str | [Regular] arg:P "*" @"many = true" | [Regular] arg:Pattern "?" @"optional = true" | [Code] "@" code:str | "(" A ")"

Grammar Grammar

31

Page 32: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

class Grammar start: Rule; /rules: Rule* class Exp end class Rule < Exp: #name: str; /arg: Exp class Alt < Exp: /alts: Exp+ class Sequence < Exp: /items: Exp* class Create < Exp; name: str; /arg: Exp class Field < Exp; name: str; /arg: Exp class Code < Exp: code: str class Value < Exp: kind: str class Ref < Exp: name: str class Lit < Exp: value: str class Call < Exp: rule: Rule class Regular < Exp /arg: Exp; optional: bool; many: bool; sep: str?

Grammar Schema

32

Page 33: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Quad Model

33

Page 34: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Stencils

Page 35: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Stencil

data

Presentation

adsf

Page 36: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

(Traditional) Data Binding

data

Presentation

adsf

edits

Page 37: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Collection Binding

Data collection

add remove

Presentation

adsf

x

abs

Page 38: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Web/Security

Page 39: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

EnsōWeb def index {! html("Todos") {! form {! datatable(root->todos) {! column("Todo") { textedit(row->todo); } ! column("Done") { checkbox(row->done); }! column("Delete") { delete_checkbox(row); }! }! submit("Submit", index());! navigate("New", new_todo(root->todos, new(Todo)));! }! }!}!def new_todo(todos, todo) {! html("New Todo") {! form {! "Todo: " textedit(todo->todo);!

! submit("Submit", index());! }! }}!

class Todos! todos: Todo*!end!

class Todo! owner: Todos / ! Todos.todos! todo: str! done: bool!end!

Page 40: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Todo App

Page 41: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

41

Authorization & Access Control •  Authorization

–  Ensure that subjects only perform authorized actions –  Also: authentication, non-interference, signatures, etc.

•  Access Control –  Subjects are only granted authorized access to objects –  Matrix: extensional definition of access at point in time

•  Role-Based Access Control –  Specify access for groups of subjects and objects

objects

Read +Update +Delete su

bjec

ts

Page 42: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

EnsōWeb Interpreter

Factory : ∀S:Schema → DataS

Web : pages → DataS → HTTP → HTML

factory = Factory(schema) response = Web(pages, factory, request)

42

Page 43: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Interpreter Wrapping: SQL

Factory : ∀S:Schema → DataS DB : DataS → String → DataS Web : pages → DataS → HTTP → HTML

factory = Factory(schema) db = DB(factory, "connection…") response = Web(pages, db, request)

43

Page 44: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Wrapping: Security

Factory : ∀S:Schema → DataS DB : DataS → String → DataS

Secure : DataS → Policy → User → DataS Web : pages → DataS → HTTP → HTML

factory = Factory(schema) db = DB(factory, "connection…") sec = Secure(db, security, user) response = Web(pages, sec, request) 44

Page 45: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Multiple Interpretations

Factory : ∀S:Schema → DataS Extract: pages → HTTP → Query FastDB: DataS → String → Query → DataS

Web : pages → DataS → HTTP → HTML

factory = Factory(schema) sql = FastDB(factory, "connection…") query = Extract(pages, request) response = Web(pages, sql(query), request) 45

Page 46: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

EnsōWeb Concepts

•  Composition by wrapping • Wrappers implement same interface as

wrappee •  Clients needn’t know extensions •  Partial evaluation to weave dynamic

delegation overhead into code –  Experiments in last version of Ensō,

but not in current version yet

46

Page 47: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Generic Differences

Δ : Schema ➞ Schema The delta function takes a data type S and creates

a data type for representing "changes to S"

diff: ∀S:Schema ➞ (S, S) ➞ ΔS patch: ∀S:Schema ➞ S × ΔS ➞ S conflicts: ∀S:Schema ➞ (ΔS, ΔS) ➞ [(ΔS, ΔS)] merge: ∀S:Schema ➞ (ΔS, ΔS, [(ΔS, ΔS)]) ➞ ΔS

47

Page 48: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

EnsōSync (a mini-Unison) def sync(base, s1, s2) d1 = diff(base, s1) d2 = diff(base, s2) confs = conflict(d1, d2)

r = resolve!(confs) -- possibly human intervention d = merge(d1, d2, r) new_base = patch(base, d) update1 = diff(s1, new_base) update2 = diff(s2, new_base)

apply(update1) -- write to disk apply(update2) end

48

Page 49: Ensō - University of Texas at Austinwcook/presentations/2011-11-Enso-ViewpointsB2.pdfGoals • Eliminate boilerplate – 100x or more reduction • Don't Design Programs – Program

Conclusion

•  Executable Specifications •  Interpreters and Composition •  Partial Evaluation

•  Collaborate?