For loop over inhomogeneous tuples #12
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From ndscan/scan_runner.py:
This is one of the reason that requires code generation for ndscan. Maybe we can support for loops over inhomogeneous tuples by unrolling the loop and then do the type checking.
Sounds good.
Related: inhomogeneous kernel lists #519
D works this way (
AliasSeq!()
constructs a built-in tuple):The loop body is effectively unrolled for this style of "static foreach", which worked out quite well, and I found quite easy to grasp/teach.
Perhaps the cleanest way would be to allow some sort of
unroll
loop annotation for integer-ranged loops that works unchanged in host Python, but leads to the loop variable being a compile-time constant in @kernel.This could then be coupled with allowing compile-time constants as tuple indices.
OK. It seems that python decorators (
@something
) cannot be used here, maybe we should use a comment? What about#artiq:unroll
or something similar?Put it on the iterator or test?
That being said, if we start doing pseudocomments for this sort of thing (e.g. #9 (comment)) then we probably want to consistently use pseudocomments.
It should be
# nac3:unroll
. nac3core should be usable outside ARTIQ.Do we have to support while loops? Also, I wonder if it would be complicated to write it as a function, as we could have cases like this:
I think a pseudocomment would be simpler, and we could raise an error in case the loop cannot be unrolled statically, instead of throwing type errors.
Ok, pseudocomment it is then.
Not necessarily, but it shouldn't be very complicated to support them I believe.
For example:
This is just an example. I don't think we can fully unroll this kind of loops, and it would be hard to explain if the code is a bit more complicated or involves multiple variables. We can unroll for loops as long as the list is constant size or the iterator is known statically, which we should, and we could just raise an error if it isn't (with a clear error message that which iterator cannot be unrolled statically).
Sure. I would only support the most simple cases, if anything. By "simple case" I mean a few arithmetic operations on the loop variable and maybe support related variables and tests. Anyway that is not important.