CS162 Week 4 Kyle Dewey. Overview Reactive imperative programming in a nutshell Reactive imperative programming implementation details.

Slides:



Advertisements
Similar presentations
SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
Advertisements

School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
CS162 Week 9 Kyle Dewey. Overview What needs to be done Quirks with GC on miniJS Implementing GC on miniJS.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
Program Representations. Representing programs Goals.
ECE 103 Engineering Programming Chapter 11 One Minute Synopsis Herbert G. Mayer, PSU CS Status 7/1/2014.
CIS101 Introduction to Computing Week 12. Agenda Your questions Solutions to practice text Final HTML/JavaScript Project Copy and paste assignment JavaScript:
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
Catriel Beeri Pls/Winter 2004/5 environment1 1 The Environment Model  Introduction and overview  A look at the execution model  Dynamic scoping  Static.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Code Generation CS 480. Can be complex To do a good job of teaching about code generation I could easily spend ten weeks But, don’t have ten weeks, so.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
Reactive Programming
Imperative Programming
CONTROL FLOW IN C++ Satish Mishra PGT CS KV Trimulgherry.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
CS162 Week 8 Kyle Dewey. Overview Example online going over fail03.not (from the test suite) in depth A type system for secure information flow Implementing.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Python Programming Chapter 6: Iteration Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Code Optimization 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a.
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
CS101 Computer Programming I Chapter 4 Extra Examples.
Recap form last time How to do for loops map, filter, reduce Next up: dictionaries.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
CS162 Week 5 Kyle Dewey. Overview Announcements Reactive Imperative Programming Parallelism Software transactional memory.
RUBY by Ryan Chase.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
More on Loop Optimization Data Flow Analysis CS 480.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
CS162 Week 8 Kyle Dewey. Overview Example online going over fail03.not (from the test suite) in depth A type system for secure information flow Implementing.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
JavaScript and Ajax (Control Structures) Week 4 Web site:
CS162 Week 3 Kyle Dewey. Overview Grades posted for assignment 1 Secure information flow key implementation issues Reactive imperative programming.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
JavaScript, Sixth Edition
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Imperative Programming Statements and invariants.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
Operational Semantics of Scheme
User-Written Functions
Names and Attributes Names are a key programming language feature
REPETITION CONTROL STRUCTURE
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
Chapter 5 Conclusion CIS 61.
Env. Model Implementation
Loop Control Structure.
Repeating Instructions And Advance collection
The Metacircular Evaluator
CS190/295 Programming in Python for Life Sciences: Lecture 6
The Metacircular Evaluator
Controlling Program Flow
Presentation transcript:

CS162 Week 4 Kyle Dewey

Overview Reactive imperative programming in a nutshell Reactive imperative programming implementation details

Motivation An interesting language feature Another possible feature to add if designing a language, along with objects and higher-order functions

Citation Camil Demetrescu et al.: Reactive imperative programming with dataflow constraints - OOPSLA'11 Not an easy read, and it shouldn’t be necessary A few key details are ambiguous or missing

Reactive More familiar technology: spreadsheets The value of a cell can depend on the value in other cells If the value of a cell changes, all dependent cells are updated As in, all cells that somehow use the changed cell’s value

Imperative Can work with the imperative paradigm Roughly, with variable/field assignment When a variable/field changes, everything marked as dependent is updated Spreadsheets are a case of reactive functional programming

Marking as Dependent “When variable x changes, execute this given code” Explicitly associate x with code Why isn’t this a great idea?

Marking as Dependent Better alternative: “Here is some code that is reactive” Let the language figure out which variables/fields are involved Let the language worry about updating the right things The code is called a constraint

What would this look like?

newCons Operator Defines both code and what reacts to said code var a in a := 0; newCons { output a // `a` is reactive }; while (a < 10) { a := a + 1 // trigger `output` } Output:

More Interesting Example sanitize.not

Basic Semantics Execute code in what newCons delimits Mark addresses used inside what newCons delimits as reactive When these are changed outside of the same newCons, trigger the delimited code (a.k.a, the constraint)

Implementation From a high level, how might we implement this in the interpreter? var a in a := 0; newCons { output a // `a` is reactive }; while (a < 10) { a := a + 1 // trigger `output` } Output:

Questions Is this enough detail to implement newCons ? Is this enough detail to use newCons ?

Multiple Constraints #1 var a in a := 0; newCons { output a }; newCons { output a + 1 }; a := 10 Output:

Cyclical Constraints var a in a := 0; newCons { a := a + 1; output a }; a := 3 Output: 14

Multiple Constraints #2 var a in a := 3; newCons { output a }; newCons { a := a + 1 }; a := 5 Output: 3466

Nested Constraints var a, b in a := 4; b := ""; newCons { output a; newCons { output b }; b := b + "b" }; a := 5; b := "t" Output: 4 >b5bbb5ttbtb

newCons with Objects var obj in obj := {“foo”: 1, “bar”: 2}; newCons { output obj.foo }; obj.foo := 10; obj.bar := 20 What does this output? Output: 11010

Identical newCons Blocks var a in newCons { output a }; newCons { output a }; newCons { a := a + 1 }; a := 5 Assume programmers will not do this

Same newCons Multiple Times See deletedAddress.not

The Point There are a lot of different edge cases As the language designer, these should all be accounted for

atomic Blocks

Problem We need to update a variable multiple times during a loop The computation is not “done” until the last assignment We want to update only when the computation is done

Example var a in a := 0; newCons { output a }; while (a < 11) { a := a + 3 }; a := a + a // now `a` is ready Output:

Hacky Solution Add a flag isDone Set to false beforehand Set to true when a constraint is ready In the constraint, only process if isDone is true

Better Solution Let the language handle it Introduce a special atomic block Constraints are only updated once we leave the atomic block Instead of having multiple updates of the same constraint, only update the constraint once at the end

With atomic var a in a := 0; newCons { output a }; atomic { while (a < 11) { a := a + 3 }; a := a + a // now `a` is ready } Output: 024

Nesting atomic var a, b in newCons { output b }; newCons { output a }; atomic { a := 2; atomic { b := 4 }; a := 3 } Output: undefundef34

Implementation Details

Code Base Based on miniJS with objects Already have AST nodes for newCons and atomic Nothing in common with dynamic secure information flow

Evaluation Modes The interpreter can be in one of three modes: Normal mode (normal execution) Constraint mode Atomic Mode See domains.scala

Constraint Mode Whenever the body of a newCons block is executed First entrance of newCons When a reactive address is updated in normal mode or constraint mode When we exit all atomic blocks Stores which constraint is currently being executed (useful for preventing recursive constraints)

Atomic Mode Whenever we execute the body of an atomic block No constraints are triggered in this mode Store reactive addresses that were updated to trigger them once we leave atomic mode

Data Structures Dependencies Maps reactive addresses to sets of constraints See domains.scala constraintStack atomicStack

constraintStack For nested new constraints Records which constraint is currently active

atomicStack For nested atomic blocks Records which reactive addresses need constraint updates upon leaving the last atomic block

Tips Never execute a constraint when you are in atomic mode Self-recursive constraints should never trigger themselves Reactive addresses can be both added and removed via newCons, depending on what gets used in the newCons ’ body If a previously reactive address is not used when executing newCons, the address is no longer reactive