
On Wed, Jul 8, 2020 at 6:17 PM Inada Naoki <songofacandy@gmail.com> wrote:
Since this is very new system, can we have some restriction to allow aggressive optimization than regular Python code?
# Class Pattern
Example:
match val: case Point(0, y): ... case Point(x, 0): ... case Point(x, y): ...
* Can VM cache the "Point" at first execution, and never lookup in next time? (e.g. function executed many times)
I'd prefer not - that seems very confusing.
# Constant value pattern
Example:
match val: case Sides.SPAM: ... case Sides.EGGS: ...
* Can VM cache the value of "Sides.SPAM" and "Sides.EGGS" for next execution?
Similar, but with the additional consideration that you can create a "pre-baked pattern" by using a dict, so if you're worried about performance, use the slightly uglier notation (assuming that Sides.SPAM and Sides.EGGS are both hashable - and if they're not, the risk of prebaking is way too high).
* Can VM lookup "Point" only once per executing `match`, instead three times? * Can VM lookup "Sides" only once, instead of two?
These two I would be less averse to, but the trouble is that they make the semantics a bit harder to explain. "Dotted names are looked up if not already looked up, otherwise they use the same object from the previous lookup". If you have (say) "case socket.AddressFamily.AF_INET", does it cache "socket", "socket.AddressFamily", or both? ChrisA