@@ -130,12 +130,34 @@ control flow with the
130
130
[ Relooper] ( https://github.com/kripken/emscripten/raw/master/docs/paper.pdf )
131
131
[ algorithm] ( http://dl.acm.org/citation.cfm?id=2048224&CFID=670868333&CFTOKEN=46181900 ) ,
132
132
with guaranteed low code size overhead, and typically minimal throughput
133
- overhead (except for pathological cases of irreducible control
133
+ overhead (due to using a label threading variable for irreducible control
134
134
flow). Alternative approaches can generate reducible control flow via node
135
135
splitting, which can reduce throughput overhead, at the cost of increasing
136
136
code size (potentially very significantly in pathological cases).
137
- Also,
138
- [ more expressive control flow constructs] ( FutureFeatures.md#more-expressive-control-flow )
137
+
138
+ More specifically, control flow in WebAssembly has the same restrictions as in
139
+ high-level languages such as Java and JavaScript, which do not have arbitrary
140
+ ` goto ` s, but do have labeled ` break ` : WebAssembly's ` br ` control flow construct is
141
+ in fact
142
+ [ functionally equivalent to a labeled ` break ` ] ( AstSemantics.md#branches-and-nesting ) .
143
+ The main limitation that such control flow has over completely arbitrary control
144
+ flow is that it is not possible to
145
+ [ jump into the middle of loops] ( https://en.wikipedia.org/wiki/Duff's_device )
146
+ (unless you introduce a label threading variable, of course, which allows any
147
+ CFG to be represented, as in the Relooper algorithm). And the relationship
148
+ is bidirectional, as it is in fact possible to represent any control flow having
149
+ that limitation by using just ` block ` s, ` loop ` s, and labeled ` break ` s: create a
150
+ ` loop ` s where necessary, and then you are left with sections in which control
151
+ flow can only branch forward, in which you can sort and create nested ` blocks ` .
152
+ Branches forward are then simply labeled ` break ` s, which can go as forward as
153
+ necessary in that section.
154
+
155
+ In summary, we know that structured control flow can be represented in the
156
+ WebAssembly AST in a guaranteed manner. Arbitrary control flow can also be
157
+ represented there, with overhead that experience has shown is acceptable
158
+ especially given the rarity of irreducible control flow.
159
+
160
+ [ More expressive control flow constructs] ( FutureFeatures.md#more-expressive-control-flow )
139
161
may be added in the future.
140
162
141
163
0 commit comments