2. Semantics or Intent
Semantics Vs. Intent
Intent is often a limiting factor in reasoning about programs.
▶ optimizations
▶ useful error messages
▶ static & dynamic analysis
▶ declarative languages
3. Semantics or Intent
Sources of Both
Many resources for how programs behave, few for intended
behavior.
▶ program syntax
▶ inferred types & annotations
▶ concrete & symbolic execution
▶ tests, specs, contracts
4. Semantics or Intent
Constrained View
Reasoning about programs is most often done from a standing
start.
▶ single snapshot
▶ programs evolve
▶ state evolves
5. Semantics for Diffs
At a High Level
The idea is to assign meaning to patches in a way that
augments the runtime’s understanding of the programmers
intent.
▶ SQL DDL
▶ System Configuration (Chef)
▶ Dynamic Software Update (DSU)
6. SQL DLL
Declarative
SQL’s data definition language starts with a descriptive
approach to objects in a schema.
Example
-- not idempotent
create table foo (
bar int,
baz varchar(10)
);
7. SQL DLL
Declarativish
Degenerates quickly and reasoning about the schema is tough.
Example
-- idempotent
create table if not exists foo (
bar int,
baz varchar(10)
);
alter table foo add column bak varchar(10);
alter table foo drop column bak;
alter table foo add column baks varchar(20);
8. SQL DLL
Diff View
Looking at a diff of the table declaration suggests intent.
Bi-directional.
Example
create table foo (
bar int,
- baz varchar(10)
+ baz varchar(10),
+ bak varchar(10)
);
create table foo (
bar int,
baz varchar(10),
- bak varchar(10)
+ baks varchar(20)
);
9. DDL Wrappers
Hack Solutions
Database migrations are well established in industry. Captures
the idea but poorly.
Example
class AddBaksToFoo < ActiveRecord::Migration
def up
drop_column :foo, :bak
add_column :foo, :baks, varchar(20)
end
def down
add_column :foo, :bak, varchar(10)
remove_column :foo, :baks
end
end
10. DDL Semantics
Traditional Grammar
Program ::= Declaration;
Declaration ::= Declaration; Declaration | Create | Alter | Drop
Create ::= create table Identifier ( Column )
Drop ::= drop table Identifier
Column ::= Column, Column | Identifier Type
Alter ::= alter table Identifier add Identifier Type
| alter table Identifier drop Identifier
Type := int | varchar(10)
11. DDL Semantics
Denotational Semantics
S : Declaration → Schema → Schema
S [[D;]] s = S [[D]] s
S [[D1; D2]] s = S [[D2]] (S [[D1]] s)
S [[create table I ( C )]] s = schemaChg I (T [[C]] table) s
S [[drop table I]] s = schemaChg I ⊥s
S [[alter table I1 add I2 Ty]] s = schemaChg I1 (T [[I2 Ty]] (s I1)) s
S [[alter table I1 drop I2]] s = schemaChg I1 (tableChg I2 ⊥ (s I1)) s
T : Declaration → Table → Table
T [[C1, C2]] t = T [[C2]] (T [[C1]] t)
T [[I Ty]] t = tableChg I Ty t
12. DDL Semantics
Reduced Grammar
Program := Declaration;
Declaration := Declaration; Declaration | Create | Alter | Drop
Create := create table Identifier ( Column )
Column := Column, Column | Identifier Type
Type := int | varchar(10)
13. DDL Semantics
Denotational Semantics
δ ∈ {−, +, η}
S : Differential → Schema → Schema
S [[D;]]δ
s = T [[D]]δ
s
S [[D1; D2]]δ
s = T [[D2]]δ
(T [[D1]]δ
s)
S [[create table I ( C )]]−
s = schemaChg I ⊥ s
S [[create table I ( C )]]+
s = schemaChg I (T [[C]] table) s
S [[create table I ( C )]]η
s = schemaChg I (T [[C]] (s I))
T : Differential → Table → Table
T [[C1, C2]]δ
t = T [[C2]]δ
(T [[C1]]δ
t)
T [[I Ty]]−
t = tableChg I ⊥ t
T [[I Ty]]+
t = tableChg I Ty t
T [[I Ty]]η
t = t
14. System Configuration
System Configuration
The “DevOps” movement and server configuration as testable,
repeatable code.
▶ Millions in start-up funding
▶ Chef (63MM), Puppet(13.5MM), Ansible, Salt Stack
▶ Vagrant, Packer, Docker
▶ Predominantly declarative
15. System Configuration
System Configuration
Configuring things like package installation starts declarative.
Example
# clear/declarative
package "memcached"
# oops! artifacts
package "memcached" do
action :remove
end
16. Dynamic Software Update
Update In-Flight
Concerned with the process, implications, timing and
semantics of software updates.
▶ Security
▶ Uptime (server & PC)
▶ Chrome, Firefox
17. Dynamic Software Update
Type mismatch
Depending on the timing of an update an adapter may be
required.
Example
# old version
# (Int, Int) -> String
def op(n, m):
return str(sqrt(n, m))
# new version
# (Int, Int) -> Int
def op(n, m):
return sqrt(n, m)
18. Dynamic Software Update
Type mismatch
The diff suggests str as the adapter.
Example
def op(n, m):
- return str(sqrt(n, m))
+ return sqrt(n, m)