200 likes | 216 Views
From State- to Delta-Based Bidirectional Model Tranformation. Zinovy Diskin, Yingfei Xiong, Krzysztof Czarnecki Generative Software Development Lab The University of Waterloo Canada. Waterloo Model Synchronization Project: Get model sync right! ( :-). Model sync is hard because:
E N D
From State- to Delta-Based Bidirectional Model Tranformation Zinovy Diskin,Yingfei Xiong, Krzysztof Czarnecki Generative Software Development Lab The University of Waterloo Canada
Waterloo Model Synchronization Project: Get model sync right! ( :-) Model sync is hard because: • Models are complex & heterog. data struct. • Rel-ships are also complexs and heterog. • .. and often implicit! • Semantics is not clear • Network of model inter-connection is non-trivial (cycles are possible) Space of heterogeneous models and their relationships
This paper addresses a very simple case: • Number of model is extremely simple: n=2 • The relationship is simple: one model is a view to the other A -----> B • Semantics is crystal clear • The corresponding algebraic framework Lenses & Co Ltd. is simple and widely spread. • Nothing to do? ICMT-2010, Malaga
Content of the talk • View update propagation and lenses • State-based BX. Three problems • Deltas do matter • Algebra for update-based BX: u-lenses • Fixing the problems • Conclusions ICMT-2010, Malaga
Deltas (update mappings) do matter Source model: State A View model: State B • One case • = { p1 p1’ p2 p2’ } • Another case • = { p2p2’ } Source model: State A’ View model: State B bDate=1965-01-01 ICMT-2010, Malaga
Mo-dels Up-dates B1 B0 Update propagation with lenses(Harmony Group; POPL, PODS, ICFP) l A0 B0 :get B A B :dif :put A’ B’ B’ Roughly, put = dif;put In detail, put(B’,A) = put(,A) = put(dif(A.get, B’)
Problems of state-based (alignment is hidden) frameworks • Automatic alignment may be wrong but tools’ interfaces does not allow the user to control alignment • Sequential composition of state-based BXs may be wrong • Interaction of state-based BX and update composition is difficult to specify (if at all possible) ICMT-2010, Malaga
Problem 1. Automatic alignment may be wrong There are no absolutely reliable keys Homonymy of identification: Key = {fstName, lastName} {fstName, lastName, bDate} {fstName, lastName, bDate, pets, hobby…} SSN! But fixing a typo creates Synonymy Thus, dif is almost but still not an algebraic operation. User’s input may be needed but it’s not assumed by the interfaces of sync tool. ICMT-2010, Malaga
Problem 2. What’s wrong with sequential composition of state-based BX k l A0 B0 C0 :k.get :l.get A B C k l :l.put :k.put A’ B’ C’ k.dif(B,B’) l.dif(B,B’) ICMT-2010, Malaga
PutPut law: How update propagation interacts with update composition l A0 B0 :get A B :put A’ B’ :put :put A’’ B’’ ICMT-2010, Malaga
1;2={p2p2’’}Id What’s wrong with PutPut Source model: State A View model: State B 1 1 = {p2p2’} Source model: State A’ View model: State B 2 2 = {p2’ p2’’} Source model: State A’’ View model: State B’’ 1965-01-01
(A1 A0) (B0 B1) Delta-based update propagation l A, B are categories, i.e., graphs with composable arrows :get0 B:B0 A:A0 :put b:B1 a:A1 :get1 A’:A0 B’:B0 :get0 ICMT-2010, Malaga
Laws of delta-based upd.prpg :get0 :get0 A B A B :put b1 :put b1;b2 Id Id :get1 A’ B’ :get0 A’ :put b2 B’ :get0 A’’ B’’ put(IdB,A) = IdA (where B=A.get0) put(b1;b2, A) = put(b1, A); put(b2, A’) (where A’=target(put(b1,A)) The same for get The same for get
Summary of laws • Idle updates (identity deltas) are preserved in both directions (GetIdl, PutIdl) • Composition is preserved in both directions (GetGet, PutPut) • Correctness: get of put is the same view updat(PutGet) Definition. An u-lens is given by the following data: -- two categories A, B: nodes are states, arrows are deltas -- functions get0, get1, and put satisfying some or all of the laws. U-lens is well-behavedif (1,3) hold. U-lens is very well-behaved if (2) holds as well. ICMT-2010, Malaga
Problem 1. Solution 3:put 2:user’s input 1:dif B B A 3 1 2 A’ B’ B’
Problem 2. Solution k l A0 B0 C0 :k.get :l.get C A B k k k :l.uput :k.uput A’ B’ C’ No diff in-between k and l ! ICMT-2010, Malaga
Problem 3. Solution: U-lenses with alignment Definition 1.Operation dif: B0xB0-->B1 (DifId) dif(B,B)=1B (DifDif) dif(B, B’,B’’)=dif(B,B’) ; dif(B’,B’’) Def.2.U-lens with alignment (ua-lens) is a pair L=(u,dif) with u a lens A-->B and dif an alignment on B. L is called very wb if u is very wb. L is called very-very wb if dif is also very wb. Theorem 1. Any ua-lens L gives rise to an ordinary s-lens L0. Moreover, if L is very-very wb then L0 is very wb. ICMT-2010, Malaga
Conclusions • Practical: • Alignment and propagation are different problems to be separated & addressed differently • Deltas should be explicit in interfaces of BX tools • Theoretical • Adequate algebraic models of model sync are graph-based • Category theory is inevitable. Particularly, with the same formalism, we can interpret arrows structurally or operationally • Arrow (mapping-based) thinking is fruitful for model sync ICMT-2010, Malaga
Questions/Comments? ICMT-2010, Malaga
Why algebraic models of update propagation are useful • For tool builders: Support a classical rule: First specify then implement • For tool users: Predictability is important for version management • For both: Interfaces are based on adequate specifications ICMT-2010, Malaga