Towards a Module System for K Mark Hills and Grigore Ro su { - - PowerPoint PPT Presentation

towards a module system for k
SMART_READER_LITE
LIVE PREVIEW

Towards a Module System for K Mark Hills and Grigore Ro su { - - PowerPoint PPT Presentation

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Towards a Module System for K Mark Hills and Grigore Ro su { mhills, grosu } @cs.uiuc.edu Department of Computer


slide-1
SLIDE 1

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work

Towards a Module System for K

Mark Hills and Grigore Ro¸ su {mhills, grosu}@cs.uiuc.edu

Department of Computer Science University of Illinois at Urbana-Champaign

WADT’08, 14 June 2008

Hills and Ro¸ su WADT’08: Towards a Module System for K 1 / 29

slide-2
SLIDE 2

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work

1

Motivation

2

K

3

Context Transformers

4

Variable Patterns and Sort Inference

5

The K Module System

6

Related and Future Work

Hills and Ro¸ su WADT’08: Towards a Module System for K 2 / 29

slide-3
SLIDE 3

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work

Motivation

Formal semantics of programming languages not used widely

  • utside of research community

We strongly believe that one important way to increase use of formal semantics is to make semantic definitions more broadly usable and useful This work focuses on two aspects of this goal:

Enable improved reuse of definitions through definitional modularity Provide tool support for working with language definitions

Hills and Ro¸ su WADT’08: Towards a Module System for K 3 / 29

slide-4
SLIDE 4

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

K: High Level View

K provides a rewrite-based method to formally define computation Focus here: formal definitions of programming languages Definitions should be flexible and modular: use, and reuse, for language documentation, program execution, analysis, proof

Hills and Ro¸ su WADT’08: Towards a Module System for K 4 / 29

slide-5
SLIDE 5

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

K Basics: Computations

K based around concepts from Rewriting Logic Semantics, with some intuitions from Chemical Abstract Machines and Reduction Semantics Abstract computational structures contain context needed to produce a future computation (like continuations) Context can consist of lists or multisets, generally representing sequential or concurrent computation potential Context includes special component, k, made up of list of computational tasks separated by , like t1 t2 ... tn From here on, computational structures called computations

Hills and Ro¸ su WADT’08: Towards a Module System for K 5 / 29

slide-6
SLIDE 6

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

K Basics: Computations, Continued

Intuition from CHAMs: language constructs can heat (break apart into pieces for evaluation) and cool (form back together) Represented using ⇋, like a1 + a2 ⇋ a1 + a2 Operators containing called freezers Heating/cooling pair can be seen as an equation Intuition from RS: can be seen as similar to evaluation contexts, marking the location where evaluation can occur

Hills and Ro¸ su WADT’08: Towards a Module System for K 6 / 29

slide-7
SLIDE 7

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

K Basics: Cells

Computations take place in context of a configuration Configurations hierarchical (like in RLS), made up of K cells Each cell holds specific piece of information: computation, environment, store, etc Two regularly used cells:

⊤ (top), representing entire configuration k, representing current computation

Cells can be repeated (e.g., multiple computations in a concurrent language)

Hills and Ro¸ su WADT’08: Towards a Module System for K 7 / 29

slide-8
SLIDE 8

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

Example: K Configuration

Hills and Ro¸ su WADT’08: Towards a Module System for K 8 / 29

slide-9
SLIDE 9

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

K Basics: Equations and Rules

Computations defined used equations and rules Heating/Cooling Rules (Structural Equations): manipulate term structure, non-computational, reversible, can think of as just equations Rules: computational, not reversible, may be concurrent

Hills and Ro¸ su WADT’08: Towards a Module System for K 9 / 29

slide-10
SLIDE 10

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

Example: Equations

a1 + a2 ⇋ a1 + a2 a1 + a2 ⇋ a2 a1 + if b then s1 else s2 = b if then s1 else s2

Reminder: is not an evaluation context, but a freezer. Also,

  • perations with freezers are boring to write, so we can mark
  • perations strict(natlist), with a freezer generated for each

position in the list. To do so for all operands, just use strict. _+_ : AExp AExp -> AExp [strict]

Hills and Ro¸ su WADT’08: Towards a Module System for K 10 / 29

slide-11
SLIDE 11

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

Example: Rules

i1 + i2 → i, where i is the sum of i1 and i2 if true then s1 else s2 → s1 if false then s1 else s2 → s2 x := v · | k |(x, l)| env |(l, v | store

Hills and Ro¸ su WADT’08: Towards a Module System for K 11 / 29

slide-12
SLIDE 12

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work K Overview Language Semantics in K For More Information

For More Information

For more information on K: “A Rewriting Logic Approach to Type Inference” (earlier talk) K website: http://fsl.cs.uiuc.edu/k

Includes tech reports and other papers related to K

Hills and Ro¸ su WADT’08: Towards a Module System for K 12 / 29

slide-13
SLIDE 13

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Overview Example Problem Context Transformers

The Need for Context Transformers

Rewriting logic semantics equations/rules (just rules from here, unless distinction matters) match across configuration items Configuration items provide context to where rule can apply

Hills and Ro¸ su WADT’08: Towards a Module System for K 13 / 29

slide-14
SLIDE 14

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Overview Example Problem Context Transformers

The Need for Context Transformers

Rewriting logic semantics equations/rules (just rules from here, unless distinction matters) match across configuration items Configuration items provide context to where rule can apply Problem: change in configuration structure can change context, break existing rules

Hills and Ro¸ su WADT’08: Towards a Module System for K 13 / 29

slide-15
SLIDE 15

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Overview Example Problem Context Transformers

Example

x := v · | k |(x, l)| env |(l, v | store

Hills and Ro¸ su WADT’08: Towards a Module System for K 14 / 29

slide-16
SLIDE 16

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Overview Example Problem Context Transformers

Example, After Configuration Change

x := v · | k |(x, l)| envt |(l, v | store

Hills and Ro¸ su WADT’08: Towards a Module System for K 15 / 29

slide-17
SLIDE 17

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Overview Example Problem Context Transformers

Context Transformers

Context transformers solve problem by transforming context of rule to match configuration Handles almost all common cases using simple restrictions

Top level configuration items should have distinct names Matching items are those closest together in graph

Ambiguous matches will be flagged by tool User can explicitly specify context to handle unusual cases

Hills and Ro¸ su WADT’08: Towards a Module System for K 16 / 29

slide-18
SLIDE 18

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Variable Patterns Sort Inference

Variable Patterns

Provide way to define sorts of variables based on regular expressions for variable names Similar concepts found in other formalisms (e.g., ASF+SDF) Patterns visible throughout specification, not just in declaration module Example: var Var[0-9] for variables Var0, Var1, ..., Var9

Hills and Ro¸ su WADT’08: Towards a Module System for K 17 / 29

slide-19
SLIDE 19

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Variable Patterns Sort Inference

Sort Inference

In some specifications, variable declarations can make up half

  • f spec

Patterns help reduce this; sort inference can reduce even more Sorts of variables inferred based on definitions of ops Variables can always be explicitly declared or tagged with sorts if needed

x := v · | k |(x, l)| env |(l, v | store

Hills and Ro¸ su WADT’08: Towards a Module System for K 18 / 29

slide-20
SLIDE 20

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Module Formats

Modules use similar syntax to Maude modules Module formats provided on top of standard module syntax to improve conciseness, allow defaults, enable special tool support Currently defined module formats: abstract syntax, language feature/semantics, configuration item, utility (similar to generic), language K provides built-ins (sets, maps, lists, etc); additional can be defined using standard algebraic techniques Note: Meta-information can be associated with all items in modules; not shown below to reduce clutter

Hills and Ro¸ su WADT’08: Towards a Module System for K 19 / 29

slide-21
SLIDE 21

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Generic Modules

1 module Path/Name 2

imports /Some/Mod, /Other/Mod with { attribs } .

3

exports SImp, SImp’, _op_ : SImp SImp’ -> SImp’ .

4

requires Val, SReq, _ : SReq -> SReq .

5 6

sort Loc .

7

sortalias Store = FiniteMap(Loc,Val) .

8

subsort SSub < SSup .

9 10

var V : Val . var Store[0-9’]* : Store .

11 12

  • p _someop_ : SomeSort SomeSort -> SomeSort .

13

eq [OptEqName] T = T’ [ where optional side-conditions ] .

14

rl [OptRlName] T2 => T3 [ where optional side-conditions ] .

15 end module Hills and Ro¸ su WADT’08: Towards a Module System for K 20 / 29

slide-22
SLIDE 22

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Example: Abstract Syntax

1 module Exp/AExp is 2

imports Exp with { sort Exp renamed AExp } .

3

var AE[0-9’a-zA-Z]* : AExp .

4 end module

Undecorated module names are syntax modules Imports allow sort renaming Variable pattern declarations usable in other modules that (directly or indirectly) import this module Non-pattern variable declarations considered local

Hills and Ro¸ su WADT’08: Towards a Module System for K 21 / 29

slide-23
SLIDE 23

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Example: Abstract Syntax

1 module Exp/AExp/Plus is 2

imports Exp/AExp .

3

_+_ : AExp AExp -> AExp .

4 end module

Syntax defined using mixfix notation Any K attributes (strict, etc) defined directly on syntax considered defaults

Hills and Ro¸ su WADT’08: Towards a Module System for K 22 / 29

slide-24
SLIDE 24

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Example: Semantics

1 module Exp/AExp/Plus[Dynamic] is 2

imports Exp/AExp/Plus

3

with { op _+_ now strict, extends + [Int * Int -> Int] } .

4 end module

Type of dynamics given after path in [brackets] Any K attributes on syntax can be overridden on import Strictness auto-generates structural equalities for heating/cooling Extends uses predefined operations to give semantics to common constructs

Hills and Ro¸ su WADT’08: Towards a Module System for K 23 / 29

slide-25
SLIDE 25

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Example: Semantics

1 module Dynamic/Exp/BExp/And[Dynamic] is 2

imports Exp/BExp/And with { op _and_ now strict(1) } .

3

rl true and B => B .

4

rl false and B => false .

5 end module

Strictness can be enforced on individual arguments; here only first strict for short-circuit evaluation Combination of rules and strictness assign meaning to language construct

Hills and Ro¸ su WADT’08: Towards a Module System for K 24 / 29

slide-26
SLIDE 26

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Example: Semantics

1 module Exp/BExp/And[Static] is 2

imports Exp/BExp/And with { op _and_ now strict } .

3

rl bool and bool => bool .

4

rl T1 and T2 => fail [ where T1 =/= bool or T2 =/= bool ] .

5 end module

Strictness can be different for static or dynamic semantics Side condition added to distinguish fail case

Hills and Ro¸ su WADT’08: Towards a Module System for K 25 / 29

slide-27
SLIDE 27

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Example: Language

1 module Imp[Language] is 2

imports type=Config Top, K, Env, Store .

3

config = top(store(Store) env(Env) k(K) nextLoc(Nat)) .

4 5

imports type=Dynamic

6

Val/Int, Val/Bool, Exp/AExp/Name, Exp/AExp/Plus,

7

Exp/BExp/LEq, Exp/BExp/Not, Exp/BExp/And, Stmt/Seq,

8

Stmt/Assign, Stmt/IfThenElse, Stmt/While, Stmt/Halt, Pgm .

9 end module

Language modules set up configuration, bring in semantics On import, type=tag syntactic sugar for Module[tag] config used to define state configuration

Hills and Ro¸ su WADT’08: Towards a Module System for K 26 / 29

slide-28
SLIDE 28

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules

Config Example

config = top(store(Store) t*(env(Env) k(K)) nextLoc(Nat)) .

Hills and Ro¸ su WADT’08: Towards a Module System for K 27 / 29

slide-29
SLIDE 29

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Related Work Future Work

Related Work, Briefly

Modular Semantics: MSOS, Action Semantics, Monads, Modular ASMs (Montages) Rewriting Logic Semantics: work on modularity (Braga and Meseguer) Tool Support: Action Semantics, Montages, many others

Hills and Ro¸ su WADT’08: Towards a Module System for K 28 / 29

slide-30
SLIDE 30

Outline Motivation K Context Transformers Variable Patterns and Sort Inference The K Module System Related and Future Work Related Work Future Work

Future Work

Continue development of tools (Eclipse plugin, translation to Maude/K) Continue moving over language modules Online module database with links into tool: build languages through module sharing and reuse

Hills and Ro¸ su WADT’08: Towards a Module System for K 29 / 29