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

Change in macro hygiene on 0.6? #19587

Closed
rdeits opened this issue Dec 13, 2016 · 5 comments
Closed

Change in macro hygiene on 0.6? #19587

rdeits opened this issue Dec 13, 2016 · 5 comments

Comments

@rdeits
Copy link
Contributor

rdeits commented Dec 13, 2016

I'm trying to understand why PyCall.jl is currently broken on Julia master: JuliaPy/PyCall.jl#332

The issue seems to be a change in the macro hygiene behavior between 0.5 and 0.6. As an example, I'll use the basic @assert macro from the metaprogramming docs

macro assert(ex)
    return :( $ex ? nothing : throw(AssertionError($(string(ex)))) )
end

function foo(x)
    @assert x == 1
end

foo(1)

On julia v0.5 this works fine. On master, I get:

± julia-0.6 macro_test.jl                                                                               16:30:58
ERROR: LoadError: UndefVarError: x not defined
 in foo(::Int64) at /Users/rdeits/locomotion/explorations/point-cloud-signed-distance/packages/v0.5/PyCall/macro_test.jl:18
 in include_from_node1(::String) at ./loading.jl:532
 in include_from_node1(::String) at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in include(::String) at ./sysimg.jl:14
 in include(::String) at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in process_options(::Base.JLOptions) at ./client.jl:271
 in _start() at ./client.jl:335
 in _start() at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib:?
while loading /Users/rdeits/locomotion/explorations/point-cloud-signed-distance/packages/v0.5/PyCall/macro_test.jl, in expression starting on line 21

The fix is to replace $ex with $(esc(ex)). But then it's not clear why it should have worked on 0.5 but not on master. Is this a case of 0.5 being too permissive with something that was technically incorrect?

versioninfo() for my Julia master is:

Julia Version 0.6.0-dev.1556
Commit 66ba9ca (2016-12-13 11:54 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, sandybridge)
@KristofferC
Copy link
Member

#15850

@rdeits
Copy link
Contributor Author

rdeits commented Dec 13, 2016

I see. So it was the case that 0.5 was relying on incorrect behavior?

@yuyichao
Copy link
Contributor

Yes, it's a 3yrs+ old bug that a surprisingly number of packages are relying on.

@rdeits
Copy link
Contributor Author

rdeits commented Dec 13, 2016

Got it. Thanks! I'll see if I can put together a PR to fix PyCall.

rdeits added a commit to rdeits/PyCall.jl that referenced this issue Dec 13, 2016
Macros that attempt to interpolate expressions should do so with

```julia
$(esc(ex))
```

rather than

```julia
$ex
```

This worked on 0.5 (though it apparently shouldn't have), but is now
broken on 0.6.

Fixes JuliaPy#332

See the discussion at JuliaLang/julia#19587
@rdeits
Copy link
Contributor Author

rdeits commented Dec 13, 2016

...and now I notice that @yuyichao already did that. Oh well.

evetion added a commit to evetion/ArchGDAL.jl that referenced this issue Sep 30, 2017
yeesian pushed a commit to yeesian/ArchGDAL.jl that referenced this issue Oct 1, 2017
* Fix deprecations

* Drop support for 0.5

* Allow fails on Julia nightly and finish fast.

* Hardcoded 0.6 release for travis

* Fixed several macros on 0.6, see JuliaLang/julia#19587

* Fixed Array(T, x) warnings.

* Added color for travis julia output.

* Replaced pointer_to_array, included projection tests.

* Forgot to uncomment temp dir creation.
yeesian pushed a commit to yeesian/ArchGDAL.jl that referenced this issue Mar 27, 2018
* Fix deprecations

* Drop support for 0.5

* Allow fails on Julia nightly and finish fast.

* Hardcoded 0.6 release for travis

* Fixed several macros on 0.6, see JuliaLang/julia#19587

* Fixed Array(T, x) warnings.

* Added color for travis julia output.

* Replaced pointer_to_array, included projection tests.

* Forgot to uncomment temp dir creation.


Former-commit-id: 15d963b
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

No branches or pull requests

3 participants