backstage java
play

Backstage Java Making a Difference in Metaprogramming Zachary - PowerPoint PPT Presentation

Backstage Java Making a Difference in Metaprogramming Zachary Palmer and Scott F. Smith The Johns Hopkins University October 27, 2011 Difference-Based Metaprogramming Introduction to Metaprogramming Difference-Based Metaprogramming


  1. Backstage Java How about some of this? ❅❅●❡♥❡r❛t❡❈♦♥str✉❝t♦r❋r♦♠Pr♦♣❡rt✐❡s ♣✉❜❧✐❝ ❝❧❛ss Location { ❅❅Pr♦♣❡rt② ♣r✐✈❛t❡ ✐♥t x; ❅❅Pr♦♣❡rt② ♣r✐✈❛t❡ ✐♥t y; ♣✉❜❧✐❝ String toString() { r❡t✉r♥ "("+ t❤✐s .x+","+ t❤✐s .y+")"; } }

  2. Backstage Java How about some of this? ❅❅●❡♥❡r❛t❡❈♦♥str✉❝t♦r❋r♦♠Pr♦♣❡rt✐❡s ♣✉❜❧✐❝ ❝❧❛ss Location { ❅❅Pr♦♣❡rt② ♣r✐✈❛t❡ ✐♥t x; ❅❅Pr♦♣❡rt② ♣r✐✈❛t❡ ✐♥t y; ♣✉❜❧✐❝ String toString() { r❡t✉r♥ "("+ t❤✐s .x+","+ t❤✐s .y+")"; } } Harder than it looks...

  3. Traditional Metaprogramming

  4. Traditional Metaprogramming • Metaprograms are a series of program transformations

  5. Traditional Metaprogramming • Metaprograms are a series of program transformations • Each available transformation occurs exactly once

  6. Traditional Metaprogramming • Metaprograms are a series of program transformations • Each available transformation occurs exactly once • True even for embedded syntax

  7. Embedded Metaprogram Semantics

  8. Embedded Metaprogram Semantics

  9. Embedded Metaprogram Semantics φ 1 φ 2

  10. Embedded Metaprogram Semantics � � �� φ 1 φ 2

  11. Embedded Metaprogram Semantics � � �� φ 2 φ 1

  12. Embedded Metaprogram Semantics � � �� φ 2 φ 1 How do we pick?

  13. Ambiguity in Metaprogramming Assuming three transformations φ 1 , φ 2 , φ 3 ... ? ? ? ? ? ? ρ

  14. Ambiguity in Metaprogramming Assuming three transformations φ 1 , φ 2 , φ 3 ... ? ? ? ? ? ? ρ OpenJava, Groovy

  15. Total Ordering Solution Declaring φ 2 before φ 1 , which is before φ 3 . ρ ′ ρ

  16. Total Ordering Solution Declaring φ 2 before φ 1 , which is before φ 3 . ρ ′ ρ ROSE

  17. Necessary Commutation Solution Requiring that φ i ◦ φ j = φ j ◦ φ i for all i and j ρ ′ ρ

  18. Necessary Commutation Solution Requiring that φ i ◦ φ j = φ j ◦ φ i for all i and j ρ ′ ρ Template Haskell, MetaOCaml, LISP, ...

  19. Hybrid Solution ρ

  20. Hybrid Solution Suppose that φ 1 and φ 2 commute. ρ

  21. Hybrid Solution Suppose that φ 1 and φ 2 commute. ◦ ◦ ρ

  22. Hybrid Solution Suppose that φ 1 and φ 2 commute. Suppose that φ 3 must occur after them. ◦ ◦ ρ

  23. Hybrid Solution Suppose that φ 1 and φ 2 commute. Suppose that φ 3 must occur after them. ◦ ◦ ρ

  24. Hybrid Solution Suppose that φ 1 and φ 2 commute. Suppose that φ 3 must occur after them. ◦ ◦ ρ

  25. Hybrid Solution Suppose that φ 1 and φ 2 commute. Suppose that φ 3 must occur after them. ◦ ◦ ρ

  26. Hybrid Solution Suppose that φ 1 and φ 2 commute. Suppose that φ 3 must occur after them. ◦ ◦ ρ Backstage Java*

  27. Commuting Transformations How do we tell if φ 1 and φ 2 commute?

  28. Commuting Transformations How do we tell if φ 1 and φ 2 commute? ◦ ?

  29. Commuting Transformations How do we tell if φ 1 and φ 2 commute? ◦ ? Determining whether or not two arbitrary transformations commute is undecidable!

  30. Difference-Based Metaprogramming

  31. Difference-Based Metaprogramming Treat metaprograms as transformation generators :

  32. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ

  33. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′

  34. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ • Language of ¯ δ is not Turing-complete

  35. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ • Language of ¯ δ is not Turing-complete • Each ¯ δ is generated on a case-by-case basis

  36. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ • Language of ¯ δ is not Turing-complete • Each ¯ δ is generated on a case-by-case basis • No practically significant loss of expressiveness

  37. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ ¯ δ can express: • Creation of a node

  38. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ ¯ δ can express: • Creation of a node • Assignment to a node property

  39. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ ¯ δ can express: • Creation of a node • Assignment to a node property • Additions before or after an element in a list

  40. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ ¯ δ can express: • Creation of a node • Assignment to a node property • Additions before or after an element in a list • Removal of an element from a list

  41. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ Now, prove commutation over pairs of � ¯ δ � .

  42. Difference-Based Metaprogramming Treat metaprograms as transformation generators : = ¯ φ ( ρ ) δ � ¯ δ � ( ρ ) = ρ ′ Now, prove commutation over pairs of � ¯ δ � . � ¯ � ¯ δ 2 � δ 1 � ◦ � ¯ � ¯ δ 1 � δ 2 �

  43. A Simple BSJ Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❬✿ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡ ❧✐st ❂ ❝♦♥t❡①t✳❣❡t❆♥❝❤♦r✭✮✳ ❣❡t◆❡❛r❡st❆♥❝❡st♦r❖❢❚②♣❡✭ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡✳❝❧❛ss✮❀ ❧✐st✳❛❞❞❋✐rst✭ ❁✿❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀✿❃✮❀ ✿❪ ❬✿ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡ ❧✐st ❂ ❝♦♥t❡①t✳❣❡t❆♥❝❤♦r✭✮✳ ❣❡t◆❡❛r❡st❆♥❝❡st♦r❖❢❚②♣❡✭ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡✳❝❧❛ss✮❀ ❧✐st✳❛❞❞▲❛st✭ ❁✿❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀✿❃✮❀ ✿❪ } }

  44. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors

  45. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes

  46. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first)

  47. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last)

  48. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute.

  49. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute. • Execute ¯ δ 1 and ¯ δ 2 in some order.

  50. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute. • Execute ¯ δ 1 and ¯ δ 2 in some order.

  51. A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ M 1 M 2 ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute. • Execute ¯ δ 1 and ¯ δ 2 in some order.

  52. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute. • Execute ¯ δ 1 and ¯ δ 2 in some order.

  53. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute. • Execute ¯ δ 1 and ¯ δ 2 in some order.

  54. A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ M 1 M 2 ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute. • Execute ¯ δ 1 and ¯ δ 2 in some order.

  55. A Simple Example ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ; ; ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” last) • Prove that ¯ δ 1 and ¯ δ 2 commute. • Execute ¯ δ 1 and ¯ δ 2 in some order.

  56. An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❬✿ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡ ❧✐st ❂ ❝♦♥t❡①t✳❣❡t❆♥❝❤♦r✭✮✳ ❣❡t◆❡❛r❡st❆♥❝❡st♦r❖❢❚②♣❡✭ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡✳❝❧❛ss✮❀ ❧✐st✳❛❞❞❋✐rst✭ ❁✿❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀✿❃✮❀ ✿❪ ❬✿ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡ ❧✐st ❂ ❝♦♥t❡①t✳❣❡t❆♥❝❤♦r✭✮✳ ❣❡t◆❡❛r❡st❆♥❝❡st♦r❖❢❚②♣❡✭ ❇❧♦❝❦❙t❛t❡♠❡♥t▲✐st◆♦❞❡✳❝❧❛ss✮❀ ❧✐st✳ ❛❞❞❋✐rst ✭ ❁✿❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀✿❃✮❀ ✿❪ } }

  57. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first )

  58. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute!

  59. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute!

  60. An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute!

  61. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute!

  62. ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute!

  63. An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ M 1 M 2 } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute!

  64. An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ; ; } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute!

  65. An Example of Conflict ♣✉❜❧✐❝ ❝❧❛ss Example { ♣✉❜❧✐❝ st❛t✐❝ ✈♦✐❞ main(String[] arg) { ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍♦✇ ❛r❡ ②♦✉❄✧✮❀ ❙②st❡♠✳♦✉t✳♣r✐♥t❧♥✭✧❍❡❧❧♦✱ ✇♦r❧❞✦✧✮❀ ; ; } } • Replace metaprograms with anchors • Run each metaprogram to collect its changes • φ 1 ( ρ ) = ¯ δ 1 (“Hello, world!” first) • φ 2 ( ρ ) = ¯ δ 2 (“How are you?” first ) • Now, ¯ δ 1 and ¯ δ 2 do not commute! • But we can detect this!

  66. Conflict Detection Record Node Creation Rule List Remove Rule v } � ⇒ ρ ′ η �→ ˆ v / ∈ ρ ρ � η �→ { l �→ ˆ η 1 �→ L ∈ ρ ◦ R η ( l = ˆ v )) ρ ⇒ ρ ′ η 2 = ( η 2 , M ′ , S ) = Σ( η 2 , M , L ) (+ L = [ ◦ η ′ , ◦ η 2 , ◦ η ′′ ] List Node Creation Rule L ′ = [ ◦ η ′ , ( η 2 , M ′ , S ∪ {M} ) , ◦ η ′′ ] η �→ ˆ v / ∈ ρ ρ � η 1 �→ L ′ � ⇒ ρ ′ ρ � η �→ [( ⊲, M , ∅ ) , ( ⊳, M , ∅ )] � ⇒ ρ ′ ( M � η 1 : ↓ η 2 ) ρ ⇒ ρ ′ L η ) ρ ⇒ ρ ′ ( M � + Recursive Application Rule Record Assignment Rule δ ′ e ⇒ ρ δ ρ ⇒ ρ ′ Value Rule v �� ⇒ ρ ′ η �→ R ∈ ρ ρ � η �→ R � l �→ ˆ δ ( δ ′ e ) ⇒ ρ ′ v ⇒ ˆ v ) ρ ⇒ ρ ′ ˆ v ( η. l ← ˆ Record Assignment Conflict Rule List Add Before Rule v ′ △ ˆ v � = ˆ η 3 � = ⊲ η 1 �→ L ∈ ρ ◦ L = [ ◦ η ′ , ◦ η 3 , ◦ v ′ η 3 = Σ( △ η ′′ ] η. l ← ˆ v � η. l ← ˆ η 3 , M , L ) L ′ = [ ◦ η ′ , ( η 2 , M , ∅ ) , ◦ η 3 , ◦ η ′′ ] Add Before Conflict Rule ω ( η ′ ρ � η 1 �→ L ′ � ⇒ ρ ′ ω ( η 2 ) 2 ) η 1 : η 2 � △ η 3 � η 1 : η ′ 2 � △ ( M � η 1 : η 2 � △ η 3 ) ρ ⇒ ρ ′ η 3 Add After Conflict Rule List Add After Rule ω ( η ′ ω ( η 2 ) 2 ) △ η 3 � = ⊳ η 1 �→ L ∈ ρ η 1 : △ η 3 � η 2 � η 1 : △ η 3 � η ′ ◦ L = [ ◦ η ′ , ◦ η 3 , ◦ η 3 = Σ( △ η ′′ ] 2 η 3 , M , L ) L ′ = [ ◦ η ′ , ◦ η 3 , ( η 2 , M , ∅ ) , ◦ η ′′ ] Unordered Creation Conflict Rule R η ( l �→ ˆ ρ � η 1 �→ L ′ � ⇒ ρ ′ L η η ∈ δ ′ δ = + v ) ∨ δ = + ( M � η 1 : △ η 3 � η 2 ) ρ ⇒ ρ ′ δ � δ ′

  67. Conflict Detection Record Node Creation Rule List Remove Rule v } � ⇒ ρ ′ η �→ ˆ v / ∈ ρ ρ � η �→ { l �→ ˆ η 1 �→ L ∈ ρ ◦ R η ( l = ˆ v )) ρ ⇒ ρ ′ η 2 = ( η 2 , M ′ , S ) = Σ( η 2 , M , L ) (+ L = [ ◦ η ′ , ◦ η 2 , ◦ η ′′ ] List Node Creation Rule L ′ = [ ◦ η ′ , ( η 2 , M ′ , S ∪ {M} ) , ◦ η ′′ ] η �→ ˆ v / ∈ ρ ρ � η 1 �→ L ′ � ⇒ ρ ′ ρ � η �→ [( ⊲, M , ∅ ) , ( ⊳, M , ∅ )] � ⇒ ρ ′ ( M � η 1 : ↓ η 2 ) ρ ⇒ ρ ′ L η ) ρ ⇒ ρ ′ ( M � + Recursive Application Rule Record Assignment Rule δ ′ e ⇒ ρ δ ρ ⇒ ρ ′ Value Rule v �� ⇒ ρ ′ η �→ R ∈ ρ ρ � η �→ R � l �→ ˆ δ ( δ ′ e ) ⇒ ρ ′ v ⇒ ˆ v ) ρ ⇒ ρ ′ ˆ v ( η. l ← ˆ Record Assignment Conflict Rule List Add Before Rule v ′ △ ˆ v � = ˆ η 3 � = ⊲ η 1 �→ L ∈ ρ ◦ L = [ ◦ η ′ , ◦ η 3 , ◦ v ′ η 3 = Σ( △ η ′′ ] η. l ← ˆ v � η. l ← ˆ η 3 , M , L ) L ′ = [ ◦ η ′ , ( η 2 , M , ∅ ) , ◦ η 3 , ◦ η ′′ ] Add Before Conflict Rule ω ( η ′ ρ � η 1 �→ L ′ � ⇒ ρ ′ ω ( η 2 ) 2 ) η 1 : η 2 � △ η 3 � η 1 : η ′ 2 � △ ( M � η 1 : η 2 � △ η 3 ) ρ ⇒ ρ ′ η 3 Add After Conflict Rule List Add After Rule ω ( η ′ ω ( η 2 ) 2 ) △ η 3 � = ⊳ η 1 �→ L ∈ ρ η 1 : △ η 3 � η 2 � η 1 : △ η 3 � η ′ ◦ L = [ ◦ η ′ , ◦ η 3 , ◦ η 3 = Σ( △ η ′′ ] 2 η 3 , M , L ) L ′ = [ ◦ η ′ , ◦ η 3 , ( η 2 , M , ∅ ) , ◦ η ′′ ] Unordered Creation Conflict Rule R η ( l �→ ˆ ρ � η 1 �→ L ′ � ⇒ ρ ′ L η η ∈ δ ′ δ = + v ) ∨ δ = + ( M � η 1 : △ η 3 � η 2 ) ρ ⇒ ρ ′ δ � δ ′

  68. Huzzah! • Metaprogram conflicts are detected at compile time

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend