← Back to context

Comment by nickcw

11 hours ago

This looks like a very interesting approach bringing comptime to a static version of python. This version of comptime can then be used to define new types in the same way Zig does it.

I absolutely hate the terminology though red/blue redshifting etc. Why do blue functions disappear when redshifting? If you red shift blue then it goes down in frequency so you might get green or red. Perhaps my physics brain is just over thinking it!

> The other fundamental concept in SPy is redshifting.

> Each expression is given a color:

> blue expressions are those which can safely be evaluated ahead of time, because they don't have side effects and all operands are statically known.

> red expressions are those which needs to be evaluated at runtime.

> During redshifting we eagerly evaluate all the blue parts of the code: it's a form of partial evaluation. This process plays very well with the freezing that we discussed above, because a lot of operations on frozen data become automatically blue: for example, if we statically know the type of an object, the logic to look up a method inside the frozen class hierarchy is a blue operation and it's optimized away, leaving just a direct call as a result.

Please just rename it comptime then at least people who have learnt Zig will know what it means immediately.

In FORTH these would have been called IMMEDIATE words. Namely functions which run at "compile" time rather than run time.

hello, spy author here.

> Why do blue functions disappear when redshifting? If you red shift blue then it goes down in frequency so you might get green or red. Perhaps my physics brain is just over thinking it!

yes I think you are overthinking :). It's not meant to be accurate physics of course.

The usage of colors to distinguish comptime vs runtim code comes from PyPy: in that context, we used "green" and "red", and initial versions of SPy used the same convention.

Then someone pointed out that green/red is not colorblind friendly and so I changed it to blue.

Having actual colors for the two phases is VERY useful for visualization: e.g. we already have a "spy --colorize" command which shows you which parts are blue and which are red.

As for "redshifting": the AST "before" has a mixture of blue and red colors, while the AST "after" has only red nodes, thus the final AST is "more red" than the first one, that's why I chose that name.