
Hello, On Sat, 06 Feb 2021 12:35:09 +1300 Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 5/02/21 8:51 pm, Paul Sokolovsky wrote:
a = 0 while a < 5: a += 1 ----
becomes:
---- a0 = 0 while (a1 := phi(a0, a2)) < 5: a2 = a1 + 1
SSA seems to be something intended for compilers to use as an intermediate representation, not something to actually write code in. So I'm puzzled as to why you would want to do this.
Let's summarize what I've written so far: 1. I draw attention to the case that "=" can do parallel assignments, while ":=". If I would stop here, there would be immediate questions: "But where/how you would use that?". So I at once presented: 2. A usecase, and even not a manual once-off usecase, but a usecase which would affect every "while", again, and again. Now you definitely can question *the usecase*, but please keep in mind that my point was to show a gap in walrus functionality, and just show an example for that. But back to the specific SSA usecase: 1. Before compilers can "use it as an intermediate representation", humans should code up those compilers. For that, they would need to learn how SSA looks and play with it. And I for example was very excited at the perspective that Python is *the* language which would allow to express pure SSA form on the high-level language level (without additional patchings, not related to SSA per se). 2. Even after compilers produce SSA as IR, humans still need to have insight into it and verify it. Again, ability to do *just SSA* and not "munge code and do SSA" is a benefit. Note that "but how that will work on a millions lines of generated code" is not infrequent question when discussing various Python proposals, so please don't dismiss the SSA case just because it's supposed to be "auto-generated IR". It's still need to be legible and debuggable for humans.
Also, what definition do you have in mind for phi? It doesn't seem to be something you can implement as a real function.
With the above notes, I guess discussing the SSA encoding case in more detail specifically on python-dev doesn't make much sense. But you're absolutely right, I simplified snippets for the presentation here. Real "executable SSA" code requires more arguments to phi, and is available in this repo: https://github.com/pfalcon/python-ssa/blob/master/example_while1_ssa.py (As you can see, I exactly was doing "conversion to the infinite loop" transformation, as also suggested by Terry Reedy. But I'd like to use the SSA usecase to try to address accidental gap in the walrus operator functionality, that's the point).
-- Greg
[] -- Best regards, Paul mailto:pmiscml@gmail.com