Skip to content

Conversation

@ihnorton
Copy link
Member

This PR adds an implicit __LOCATION__ &meta argument (line/file info) to all macros, automatically added in lowering for macro definitions, and in the parser for macro calls. Fixes #9577. The main goal is better Cxx/Gallium error reporting (location information for C++ string macros), but it may also be useful for macro-heavy users such as JuMP.

The main downsides I know of are:

  • makes AST round-tripping more complicated (one block of tests in show.jl is currently commented-out for this reason, but those should be "fixable" with some string-replace hackery)
  • it is really ugly

Comments?

(FWIW, Clojure also accomplishes this goal using implicit macro arguments: &env and &form; but I am quite sure that this implementation is ... considerably less graceful)

@StefanKarpinski
Copy link
Member

The fact that Clojure does this with implicit arguments is actually the most compelling argument (see what I did there?) that I've heard for doing it this way.

and use for `@__FILE__` and `@__LINE__` macros.
@ihnorton ihnorton force-pushed the ihn/macrocall_pass_loc branch from 4cf6919 to eb73258 Compare September 29, 2015 02:48
@ihnorton
Copy link
Member Author

For kicks, I renamed the argument to &meta after Clojure. It seems less ugly now. The downside to naming it that way is that the argument can only be accessed through constructed symbol names (... possibly a good thing?). I also re-implemented @__LINE__ and @__FILE__ using &meta.

@timholy
Copy link
Member

timholy commented Sep 29, 2015

Any chance we can do more with @generated functions? It may be a consequence of nested-genfunctions, but with Interpolations.jl I get nothing useful in terms of profiling backtraces.

@ihnorton
Copy link
Member Author

@timholy I see what you are doing here! 😄

I haven't fully grokked the isstaged handling yet, but a quick look leads me to doubt that missing debug information is directly related to the fact that @generated is a macro. From playing with the @generated example in the manual, it seems like the AST does at least get top-level line information. In a more complicated example, missing info could well be due to the fact that we strip line info during inlining (I need to get back to that).

If you wouldn't mind to file an issue with a small example, I'll be happy to take a look (requiring Interpolations.jl or whatever other package is fine).

@vtjnash
Copy link
Member

vtjnash commented Mar 25, 2016

i think this has been resolved and can be deleted?

@tkelman
Copy link
Contributor

tkelman commented Mar 29, 2016

By what?

@StefanKarpinski
Copy link
Member

#9577, #13339, #21746

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.

Function for getting source location inside string macros

5 participants