150 likes | 261 Views
Towards a General Theory of Local Actions. Hongseok Yang Seoul National University Peter O’Hearn Queen Mary, University of London. Programming Language Semantics.
E N D
Towards a General Theory of Local Actions Hongseok Yang Seoul National University Peter O’Hearn Queen Mary, University of London
Programming Language Semantics “Semantics is a strange kind of applied mathematics; it seeks profound definitions rather than difficult theorems. The mathematical concepts which are relevant are immediately relevant. Without any long chains of reasoning, the application of such concepts directly reveals regularity in linguistic behavior, and strengthens and objectifies our intuitions of simplicity and uniformity.” John C. Reynolds (1980)
Modeling Locality • Two extreme views on commands: • Comm = States !p States • Comm = language-definable fns on States • Both definitions are bad; they do not reveal any regularity of programs. • In this talk, we define a semantics of Comm that models how commands use memory resources. • The execution of a command depends on what it accesses. • For each execution of a command, we can identify which locations are accessed. • The goal of this talk is to experience what it is like to do a research on semantics.
Overview • Partial Commutative Monoid • Safety Monotonicity • Frame Property • Miminum Resource Property • Finite Resource Property • Conclusion
Partial Commutative Monoid (PCM) • (M, *, e) is a PCM iff * is a partial binary operator on M such that • * is commutative: m*n = n*m; • * is associative: m*(n*p) = (m*n)*p; • e is the unit of *: m*e = e*m = m. • Intuition: • Each m in M denotes a resource. • * combines two compatible resources. • e means the empty resource. • States = (Nat!pNat,],{}) is a PCM.
Deterministic Action • A deterministic action t on (M,*,e) is a partial function from M to M. • The undefinedness of t indicates the “resource-shortage” error. • t(m) is not defined iff t(m) needs an unavailable resource during the execution. • (m,t) is called safe iff t(m) is defined. • Examples: • set10at2 = m. if (22dom(m)) (m[2!10]) undef • only2 = lm. if ({2}=dom(m)) m undef • have2or3 = lm. if (22dom(m) or 32dom(m)) m undef • reset = m. l. if (l2dom(m)) 0 undefNat • haveAllOdd = lm. if (OddNum µ dom(m)) m undef
Feasibility Question • Which of the following cannot be implemented? Why not? • set10at2 = m. if (22dom(m)) (m[2!10]) undef • only2 = lm. if ({2}=dom(m)) m undef • check2or3 = lm. if (22dom(m) or 32dom(m)) m undef • reset = m. l. if (l2dom(m)) 0 undefNat • haveAllOdd = lm. if (oddNumµdom(m)) m undef
Safety Monotonicity • Safety monotonicity: if (m,t) is safe and m#n, then (m*n,t) is also safe. • Intuition: If m has already all the resources that t accesses, the so does m*n. • Quiz: Which of the following violates this condition? (1) set10at2 (2) only2 (3) have2or3 (4) reset (5) haveAllOdd
Frame Property • Frame property: if (m,t) is safe and m#n, then t(m)*n = t(m*n). • Intuition: The behavior of t is determined by what t accesses. • Quiz: Which of the following does not satisfy frame property? (1) set10at2 (2)check2or3 (3)reset (4)haveAllOdd
Minimum Resource Property • Resource order: m v n iff there is some m’ such that m*m’ = n. • Minimum resource property: if (m,t) is safe, then there exists m0 such that • (m0,t) is safe, and m0vm; and • if (m1,t) is safe, and m1vm, then m0vm1. • Quiz: What does MRP mean? • Quiz: Which of the following violates the minimum resource property? (1) set2at10 (2) check2or3 (3) haveAllOdd
Finite Element • A resource m is finite iff for all chains {mi}i in M with resource order, if t{mi}i exists and t{mi}iwm, then there exists some mi such that miwm. • Quiz: Which elements in States are finite?
Finite Resource Property • Finite resource property: if (m,t) is safe, then there exists m0 such that • m0 is finite; • (m0,t) is safe; and • m0vm. • Quiz: What violates the finite resource property? (1) set2at10 (2) haveAllOdd
Semantics of Comm Comm = {t:States!pStates | t satisfies safety monotonicity, frame property, minimum resource property, finite resource property } • THEOREM: All the language-definable commands satisfy all four locality conditions, so that they are in Comm.
Frame Rule • THEOREM: A deterministic action t satisfies the frame rule iff it satisfies the frame property and the safety monotonicity. • The frame rule is not sound for reset and only2. {11}reset{10} {(11)*(21)}reset{(10)*(21)} {2 -}only2{true} {(2-)*(3-)}only2{true*(3-)}
Conclusion • We defined locality conditions that describe how language-definable functions use resources. • This new resource-oriented view on functions is crucial to have the frame rule, and its higher-order extensions. • Current research issues: • How to handle higher-order functions? • Can we explain locality conditions with existing notions in the domain theory? • Can we solve recursive “domain” equations that involve the “local” function space?