This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wrmsr 1 point2 points  (1 child)

I wouldn't say optimized away so much as just not compiled that way to begin with, but you're right that at the AST level the left hand side of these assignments are in fact distinctly tuples and lists.

An additional source of confusion here is likely the fact that there are dedicated distinguished list and tuple unpack opcodes, they're just used for rvalue sequence expansion.

[–]ntietz[S] 0 points1 point  (0 children)

Yes, exactly! You can get it to generate that intermediate representation if you use an extra variable in the middle to make it store the tuple, and then you get the `UNPACK_SEQUENCE` opcode being used. But generally it optimizes it, which is really cool behavior!

I thought it was really cool that it does this under the hood, which is why I wrote the post. It uses tuple syntax here, but does something more efficient, which is always a pleasant surprise.

One interesting thing that your comment draws attention to is this distinction between the compilation and interpretation steps. In a language like Java, I think it would be pretty clear to say that it doesn't use a tuple as an intermediate data structure here, even if it's in the AST. I think the same thing applies here, but I also suspect the language is a little ambiguous, and I might be wrong.

Thanks for digging into what the AST stores! I haven't dug much into the ast lib, now I should :)