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

Scope issue with @static #17584

Closed
andreasnoack opened this issue Jul 23, 2016 · 7 comments
Closed

Scope issue with @static #17584

andreasnoack opened this issue Jul 23, 2016 · 7 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@andreasnoack
Copy link
Member

I'm seeing some weird interaction between cglobal and immutable inside @static.

These two are okay

module A
    @static if true
        const B = cglobal((:ompi_mpi_wchar, :libmpi))
    end
end

module A
    @static if true
        immutable T end
        const B = :B
    end
end

but

julia> module A
    @static if true
        immutable T end
        const B = cglobal((:ompi_mpi_wchar, :libmpi))
    end
end
WARNING: replacing module A
ERROR: error compiling anonymous: type definition not allowed inside a local scope
julia> versioninfo()
Julia Version 0.5.0-pre+5651
Commit 17c34e7* (2016-07-23 19:42 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin15.6.0)
  CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT NO_AFFINITY HASWELL)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)
@andreasnoack andreasnoack added the bug Indicates an unexpected problem or unintended behavior label Jul 23, 2016
@yuyichao
Copy link
Contributor

Dup of #2586

@andreasnoack
Copy link
Member Author

@yuyichao Why is cglobal triggering the issue?

@vtjnash
Copy link
Member

vtjnash commented Jul 23, 2016

The at-static here is redundant and unnecessary (actually, it's pretty rare to need it)

@yuyichao
Copy link
Contributor

Why is cglobal triggering the issue?

It's an intrinsic

@andreasnoack
Copy link
Member Author

@vtjnash I think I have to use @static. The example here was just the smallest possible. In the real use case, I have to construct immutables to match C structs depending on which MPI implementation is linked. It's true that I can make the definitions with cglobal without the @static but then I need to repeat the same condition twice - once with @static and once without. Naively, I would expect that

module A
    @static if true
        immutable T end
        const B = cglobal((:ompi_mpi_wchar, :libmpi))
    end
end

and

module A
    immutable T end
    const B = cglobal((:ompi_mpi_wchar, :libmpi))
end

would be equivalent. Wouldn't that be desirable?

@vtjnash
Copy link
Member

vtjnash commented Jul 24, 2016

Sure, but note that the definition of @static is simply "evaluates the conditional at the toplevel scope", which is redundant where you are also evaluating the @static at the toplevel scope.

@yuyichao
Copy link
Contributor

Wouldn't that be desirable?

Yes. But more fundamentally a @static block is equivalent to a normal block and you can reproduce the same bug with a normal block i.e. begin ... end. In any case, #2586 should clearly be fixed and this has nothing to do with @static at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants