Skip to content
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 macroexpansion scope miscalculation #23247

Merged
merged 1 commit into from
Aug 17, 2017
Merged

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Aug 14, 2017

previously, we were treating hygienic-scope as also introducing a new scope-block
that was wrong (and inconsistent with previous behavior)

also, we were failing to set the outermost flag when entering a
hygienic-scope block, further compounding the above error

fix #23239

@JeffBezanson
Copy link
Sponsor Member

I'm hoping this also changes the behavior of the test at

@test isdefined(M16096, :foo16096)

test/parse.jl Outdated
@test_broken typeof(local_foo16096).name.module === M16096
@test_broken typeof(local_foo16096).name.mt.module === M16096
@test_broken getfield(M16096, typeof(local_foo16096).name.mt.name) === local_foo16096
@test_broken !isdefined(@__MODULE__, typeof(local_foo16096).name.mt.name)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't think the current behavior is broken. I interpret the purpose of this macro as defining a method in the caller's module. If you consider e.g. the vectorize macros, if my module defines foo and I write @vectorize_1arg foo, I want it to add a new method in my module, not in Base.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hygiene means that you either need esc (so hygiene rules don't apply), or it'll gensym the name (so you'll define #1#foo#). I suppose either case is actually OK to me. I was thinking it might make more sense to not be creating a global with a gensym name – but the goal of this PR was only to restore the v0.6 behavior for these cases, not propose changes.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No matter what the name is, the type introduced by this macro should be in the caller's module, not M16096. I'm not proposing a behavior change, just that this test should be inverted and test_broken should be changed to test.

Copy link
Sponsor Member Author

@vtjnash vtjnash Aug 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as defining a method in the caller's module

Also, fwiw, it's best to be precise in terminology, since this test has nothing to do with Method, but instead is testing for the properties of the function's type. Macroexpand (and expand in general) would require severe contortions (spliced in calls to eval) to affect that property (the module of a method). This instead is testing specifically for whether the macro added a new global bindings (and where).

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types always have global bindings. Hygiene can only affect whether the function object has a global name, which is not the issue here.

@@ -407,10 +407,30 @@
(and (eq? (car e) '=) (length= e 3)
(eventually-call? (cadr e))))))

;; count hygienic / escape pairs
;; and fold together a list resulting from applying the function to
;; and block at the same hygienic scope
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to say "applying the function to a block at the same hygienic scope" ?

@stevengj
Copy link
Member

For completeness, can we add a test specifically for the @evalpoly inference issue in #23239, and another test for the correctness issue identified in this comment by @dlfivefifty?

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Aug 15, 2017

@stevengj Yes, that case was reduced to create the tests added to core.jl (including the @inferred): https://github.com/JuliaLang/julia/pull/23247/files#diff-75b23cc61d190dd99feab17b8e297ee3R5005

@ararslan
Copy link
Member

Any idea whether this also fixes BenchmarkTools?

@ararslan
Copy link
Member

Doesn't appear to. Was it intended to?

previously, we were treating hygienic-scope as also introducing a new scope-block
that was wrong (and inconsistent with previous behavior)

also, we were failing to set the outermost flag when entering a
hygienic-scope block, further compounding the above error

fix #23239
@vtjnash vtjnash merged commit 6898379 into master Aug 17, 2017
@vtjnash vtjnash deleted the jn/hygienic-recursion branch August 17, 2017 15:30
@stevengj stevengj mentioned this pull request Aug 17, 2017
@ararslan
Copy link
Member

...I'll take that as a no then?

@quinnj
Copy link
Member

quinnj commented Aug 17, 2017

I think @vtjnash mentioned elsewhere that this would be a partial fix, but not all the way.

@ararslan
Copy link
Member

Okay thanks, I didn't see that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

at-evalpoly is broken
6 participants