-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is @tuplegen
broken?
#13
Comments
I am the original author of this package, but I stopped maintaining it many years ago. This package is difficult to maintain because it relies on the undocumented aspects of internal representations of expressions, which can change from one release of the compiler to the next. If you would like to try to fix the problem yourself, please feel free to submit a PR. To get started, you can use the
|
Thanks for the pointer! Do you remember what the last version that worked was? The output appears the same as far back as |
It appears that I last worked on the code around 2015, when Julia was at about v. 0.5. |
Okay, it looks to me that 0.5 broke this by making a comprehension wrap a generator. 0.4.7 (2016)I believe this is the last one that would have worked
0.5.2 (2017)Added generator (this is what most likely broke it)
0.7.0 (2018)Changed a little bit again (see very end)
1.10.2 (2024)Same as 0.7.0, so it's been stable for six years. It looks like this can be fixed by replacing |
Glad you figured this out! If you want to submit a PR to fix it, I'll be happy to approve. |
Unfortunately this is the best I can do. macro tuplegen(expr)
if expr.head != :comprehension || length(expr.args[1].args) != 2 ||
expr.args[1].args[2].head != :(=) ||
typeof(expr.args[1].args[2].args[1]) != Symbol
error("Expression following tuplegen macro must be a comprehension as described in the documentation")
end
varname = expr.args[1].args[2].args[1]
ret = Expr(:tuple)
for k in Core.eval(__module__, expr.args[1].args[2].args[2])
e2 = copy_and_substitute_tree(expr.args[1].args[1], varname, k, __module__)
push!(ret.args,e2)
end
esc(ret)
end |
Does this seem to fix the problem? Why did you use the word "unfortunately" in your previous post? |
"Unfortuantely" was simply in regard to having to give you a code snippet instead of a proper PR. Also, as I learn more about Julia marcos, I believe the following would work as well. macro tuplegen(expr)
Expr(:tuple, :($expr...))
end
|
I think the macro in your previous posting will simply emit |
You're right, that allocates. This doesn't seem to: macro tuplegen(expr)
Expr(:tuple, eval(expr)...)
end |
The code in your previous posting evaluates the code entirely at macro-expansion time. This will work only if the tuple does not involve any program variables other than the loop index. For example, the macro in your previous post would not work in the following example:
because the value of a is not known at macro-expansion time. |
With a little digging I was able to confirm that
length(expr.args) == 1
instead of 2 which is what triggers the error. I'm not familiar enough with macros to dig deeper than that. Maybe I'm using it wrong, but I've been able to get@unroll
working just fine.The text was updated successfully, but these errors were encountered: