code_generation.txt 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. =========================
  2. Code generation with Rust
  3. =========================
  4. 50 tests currently passing (flag --rust):
  5. features/instate/test_instate.xml
  6. features/instate/test_instate_nested.xml
  7. features/action_lang/test_closure.xml
  8. features/action_lang/test_cond.xml
  9. features/action_lang/test_expressions.xml
  10. features/action_lang/test_functions2.xml
  11. features/action_lang/test_guard_action.xml
  12. features/action_lang/test_nested.xml
  13. features/history/test_composite_shallow.xml
  14. features/history/test_deep.xml
  15. features/history/test_default.xml
  16. features/history/test_parallel_deep.xml
  17. features/history/test_shallow.xml
  18. features/after/test_after.xml
  19. features/after/test_after_reentry.xml
  20. features/parallel/test_parallel.xml
  21. day_atlee/test_02_counter_takeone.xml
  22. day_atlee/test_03_trafficlight_single.xml
  23. day_atlee/test_04_counter_single.xml
  24. day_atlee/test_06_counter_lifeline.xml
  25. day_atlee/test_13_invar_rhs_smallstep.xml
  26. day_atlee/test_21_counter_combo.xml
  27. day_atlee/test_22_invar_combo_one.xml
  28. semantics/priority/test_explicit_flat.xml
  29. semantics/priority/test_explicit_ortho.xml
  30. semantics/priority/test_source_child.xml
  31. semantics/priority/test_source_parent.xml
  32. semantics/memory_protocol/test_gcsmall.xml
  33. semantics/event_lifeline/test_flat_nextss_takemany.xml
  34. semantics/event_lifeline/test_flat_nextss_takeone.xml
  35. semantics/event_lifeline/test_flat_queue_first.xml
  36. semantics/event_lifeline/test_flat_queue_whole_takemany.xml
  37. semantics/event_lifeline/test_flat_remainder.xml
  38. semantics/event_lifeline/test_ortho_nextcs_takemany.xml
  39. semantics/event_lifeline/test_ortho_nextcs_takeone.xml
  40. semantics/event_lifeline/test_ortho_nextss.xml
  41. semantics/event_lifeline/test_ortho_queue.xml
  42. semantics/big_step_maximality/test_cross_region1.xml
  43. semantics/big_step_maximality/test_cross_region2.xml
  44. semantics/big_step_maximality/test_flat_syntactic.xml
  45. semantics/big_step_maximality/test_flat_takemany.xml
  46. semantics/big_step_maximality/test_flat_takeone.xml
  47. semantics/big_step_maximality/test_ortho_syntactic.xml
  48. semantics/big_step_maximality/test_ortho_takemany.xml
  49. semantics/big_step_maximality/test_ortho_takeone.xml
  50. xml_syntax/stateref/test_flat_absolute.xml
  51. xml_syntax/stateref/test_flat_relative.xml
  52. xml_syntax/stateref/test_nested_absolute.xml
  53. xml_syntax/stateref/test_nested_relative.xml
  54. Roadmap
  55. -------
  56. (DONE) Milestone 1: Initial compilation to Rust
  57. - (DONE) entering and exiting states correctly
  58. - (DONE) incoming event triggers the right transition
  59. - (DONE) a port of the Controller class to Rust
  60. - (DONE) one implemented action: raise output event
  61. - (DONE) fixed semantics (YAKINDU-like)
  62. - "Take One" big step maximality
  63. - parent-first
  64. - (DONE) goal: subset of SCCD tests passes:
  65. semantics/big_step_maximality/test_flat_takeone.xml
  66. semantics/big_step_maximality/test_ortho_takeone.xml
  67. semantics/priority/test_source_parent.xml
  68. semantics/priority/test_explicit_flat.xml
  69. semantics/priority/test_explicit_ortho.xml
  70. - no history
  71. - no action language
  72. - guards evals and action stmts are just logged to console
  73. - guards always true, actions no effect
  74. - no event parameters
  75. (DONE) Milestone 2: Minimal support for semantic variability:
  76. - (DONE) Priority: Child-first
  77. - (DONE) Big-Step Maximality: Take Many
  78. - (DONE) goal: following tests should pass:
  79. semantics/priority/test_source_child.xml
  80. semantics/big_step_maximality/test_flat_takemany.xml
  81. semantics/big_step_maximality/test_ortho_takemany.xml
  82. (DONE) Milestone 3: Support history
  83. (DONE) Milestone 4: Timers (should be easy)
  84. (DONE) Milestone 5: Internal Events
  85. (DONE) Milestone 6: Action language
  86. (DONE) Milestone 7: INSTATE-function -> INSTATE-macro
  87. - INVARIANT: Action lang must never depend on statechart lang!
  88. - Evaluation of action lang expression can only read/write to the expression's scope (and parent scopes, if expression occurs in a function)
  89. -> Action lang expression evaluation cannot take mut ref to "state configuration"
  90. - Background: Currently implemented in interpreter as a function in "builtin"-scope:
  91. - Builtin-scope instantiated when statechart is instantiated
  92. - INSTATE-function is a value in "builtin" scope, a function partially bound to the statechart's execution state (which contains the "state configuration")
  93. - INSTATE-function takes an array of strings of absolutate paths to states. At runtime, these strings are used as keys in a dictionary to convert them to state IDs.
  94. -> Better to statically convert the absolute state paths to state IDs by introducing *macros*.
  95. - Better implementation:
  96. 1) Support macros in action lang:
  97. - From the type system's point of view, a macro call is just a function call (depending on the macro called, takes typed parameters and returns a typed value)
  98. - Macro body is executed statically, and during type check (= right after constructing AST).
  99. -> For INSTATE-macro, the macro body converts every state path to its correct state object.
  100. - Action lang parser constructor gets a dict of supported macros, their types, and their "bodies"
  101. 2) Based on the insight that INSTATE cannot occur everywhere (e.g. cannot occur in datamodel block), in fact it can only occur during a transition's guard eval or actions, treat these as follows:
  102. - Wrap guard eval or action code in an implicit function with as parameter the "state configuration".
  103. - Expansion of the INSTATE-macro then reads this parameter.
  104. Milestone n+1: "TODO"
  105. - Syntactic output events
  106. - Event parameters
  107. - Memory Protocol semantics
  108. - Concurrency semantics
  109. Insights
  110. --------
  111. - Rust compiler warnings are actually useful for the modeler:
  112. - e.g. An unexecutable transition is detected as an unreachable statement
  113. - e.g. An unused event is detected as an unused variable or never-constructed enum variant.
  114. - Rust's product ("struct") and sum ("enum") types map perfectly onto And- and Or-states
  115. Performance over time
  116. ---------------------
  117. for test semantics/big_step_maximality/test_ortho_takemany.xml
  118. commit ae8a94e186ee972c0d3e0b229b77901352137c64 - Dec 23, 2020 - implement additional event lifeline semantics, pass input event by reference instead of by value
  119. binary size, no opt: 800592 bytes
  120. binary size, opt-level=3: 422200 bytes
  121. instruction count (perf stat) (opt-level=3): 570.824 instructions:u
  122. commit 39fc866428c595c7ed909569d998981d1d350059 - Dec 22, 2020 - various fixes, support INSTATE
  123. binary size, no opt: 800544 bytes
  124. binary size, opt-level=3: 422200 bytes
  125. instruction count (perf stat) (opt-level=3): 570.776 instructions:u
  126. commit ec39dd73ea42a9ccee6f1edc8863b36625e0721a - Dec 20, 2020 - put reusable stuff in library
  127. binary size, opt-level=3: 422192 bytes
  128. instruction count (perf stat) (opt-level=3): 571.641 instructions:u
  129. commit 354576dd47587fd8e6277539a26a4743b2167565 - Dec 17, 2020 - action lang working
  130. binary size, no opt: 513760 bytes
  131. binary size, opt-level=3: 421056 bytes
  132. binary size, opt-level=3 inline-threshold=1000: 421056 bytes
  133. binary size, opt-level=z: 429200 bytes
  134. instruction count (perf stat) (opt-level=3): 575.539 instructions:u
  135. commit aa6a734f7d900479de9be99a8cdf68af0d561481 - Dec 2, 2020 - implemented big-step maximality
  136. binary size, no opt: 478976 bytes
  137. binary size, opt-level=3 inline-threshold=1000: 410880 bytes
  138. binary size, opt-level=z: 413576 bytes
  139. instruction count (perf stat) (opt-level=3): 580.701 instructions:u
  140. Performance insights
  141. - non-optimized binary size increased as features were added, optimized binary size stayed pretty much the same. this assures that Rust is able to inline and optimize away the many unused parameters of enter and exit functions.
  142. - the same conclusion can be drawn from binary size being slightly worse when setting a lower inline threshold (opt-level=z). this means that inlining is actually reducing the binaries' size, as we would expect (lots of unused parameters can be eliminated)
  143. - passing input event by reference instead of by value did not change the optimized binary size. probably evidence of Rust inlining or passing by value anyway.