-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix macro hygiene when calling the macro in the same module. #15850
Conversation
Also, the |
The NULL check might be left over from a case that used to happen during bootstrap. |
a8284df
to
5be65b9
Compare
OK, I comment out that code (replaced it with an |
No, it should apply normal hygiene rules, but this is going to require some further fixes. For example in 0.4:
This is correct, but gets a
I can see why this regression was not caught, since the code doesn't work either way. Your change to ast.c is fine, but changing the test should not have been necessary. We'd need the macro expansion to return a more permissive kind of module reference that lets you define a new function using the syntax
which would include any module that uses macros to define its own functions. This might be too breaking. |
What do you think is the best solution for this? Allowing assign to |
Maybe we should just go ahead and allow |
I'm also thinking maybe we can avoid replacing |
I think we will still need to return |
Currently if a macro returns |
a9ed484
to
3f08f8e
Compare
This PR should be ready now. Before someone restarted AppVeyor there was a timeout (that was not just hanging after the tests are done) possibly due to hitting the swap or something similar. This still have different behavior for |
3f08f8e
to
2c2ecbc
Compare
(jl_value_t*)m, b); | ||
if (jl_expr_nargs(ex) == 1) | ||
return gf; | ||
} else if (jl_is_symbol(fname)) { | ||
jl_value_t **bp=NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote a more complete diff for this file while attempting to do something else:
https://gist.github.com/vtjnash/3775a58db1efe7489e5922ad1eb117f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the handling in codegen.cpp also needs to be updated for this case
(rr (if (or (symbol-like? rhs) (atom? rhs)) rhs (make-ssavalue)))) | ||
`(block | ||
,.(if (eq? rr rhs) '() `((= ,rr ,(expand-forms rhs)))) | ||
(call (core setfield!) ,a (quote ,b) ,rr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be valid to lower this line to (= ,lhs ,rr)
. that should save us from needing to change the meaning of setfield. it looks like it should be handled correctly since #10403
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What commit are you talking about? #10403 is an issue not a PR and all commits referenced in that issue are older than this one and I'm pretty sure $(GlobalRef(...)) = ...
is not handled anywhere when I wrote this.
2315a4d
to
e6a42ba
Compare
Rebased on top of master and Jameson's Also moved the handling of There's still a difference between |
* Convert `GlobalRef` back to flisp. Closes #14893
e6a42ba
to
173cc40
Compare
This could use a NEWS mention given how commonly macros were hitting this. |
adds to: JuliaCloud#103 ref: JuliaLang/julia#15850
There is a surprising number of base code that relies on the wrong behavior....
One broken test/code that need to be fixed on this commit is the MacroGlobalFunction test. The test doesn't work if the macro is used outside the module so I think the fix is correct. However, should the macro expander detect this case and avoid modifying the function name that is defined to be global already?
Closes #14893
c.c. @JeffBezanson about the test mentioned above and since the code was added a long time ago (605bc65) I can't really find a explanation why the check is necessary.