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

trace-compile generates invalid output for types with parameters generated via gensym() #32574

Closed
tehrengruber opened this issue Jul 13, 2019 · 1 comment

Comments

@tehrengruber
Copy link

Consider the following artificial example of a struct A{##363} with ##363 a symbol generated by gensym and further a function call to some function foo with argument A or equivalently A{##363} where ##363.

macro add_parametric_type(expr)
  push!(expr.args[2].args, gensym())
  esc(expr)
end

@add_parametric_type struct A{} end

foo(::T) where T = 1

foo(A)

Now executing julia with the --trace-compile option results in the following (invalid) trace file:

precompile(Tuple{getfield(Main, Symbol("#@foo")), LineNumberNode, Module, Expr})
precompile(Tuple{typeof(Main.foo), Type{Main.A{363} where 363}})

Apparently julia just stripes away the ## and outputs the number assigned to the generated symbol which is obviously not correct.

I would be willing to fix this myself, but I'm not sure how to handle this correctly. The generated symbol can not be used directly since the resulting code would be invalid just as well and replacing it by a different "regular" symbol, e.g. A{##363} where ##363 by A{B} where B, is problematic since B might collide with other parameters in general.

Context:
I'm trying to use PackageCompiler to statically compile one of my packages which relies on some macros that append type parameters named via gensym.

Versioninfo:

Julia Version 1.1.1
Commit 55e36cc308 (2019-05-16 04:10 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_PARDISO = /usr/local/lib/pardiso/
@KristofferC
Copy link
Member

Dup of #28808, feel free to add more examples there.

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

2 participants