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

RFC: Pass file/column/line information to custom string literals (#9577) #9579

Closed
wants to merge 1 commit into from

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 3, 2015

This is one possible way to handle #9577, but I'm not sure if it's ideal, because it forces people to declare the arguments to every _str macro even if they have no intention of doing anything with it. The other alternative I mentioned in #9577 is to save this information in a global variable that can be retrieved through a function call. That alternative seems more hacky though as it adds new global state and I'm not sure what would happen with quoted string literals. Alternative thoughts appreciated.

@Keno
Copy link
Member Author

Keno commented Jan 3, 2015

Alternatively it occurs to me, we could pass a LineNumberNode as the second argument. That would feel more macro-y.

Keno added a commit to JuliaInterop/Cxx.jl that referenced this pull request Jan 3, 2015
This relies on JuliaLang/julia#9579, but should be easy to
adapt to whatever final solution is adopted. As a nice side effect, we now also get
proper source locations for C++ code :):

In the REPL:

```
C++ > foobar a;
In file included from :1:
REPL:1:1: error: unknown type name 'foobar'
foobar a;
^
```

Or in a file

```
shell> cat test.jl
cxx"""
foobar a;
"""

julia> include("test.jl")
/Users/kfischer/.julia/Cxx/test/test.jl:2:1: error: unknown type name 'foobar'
foobar a;
^
```
@Keno
Copy link
Member Author

Keno commented Jun 11, 2015

@JeffBezanson I'm still very interested in getting location information for my string macros. Any new ideas as to the best way to do that?

@StefanKarpinski
Copy link
Member

It seems like having a mandatory additional StringLiteralInfo argument that includes all of this as a single object might be easier and allow for more info to be added without breaking code in the future.

@Keno
Copy link
Member Author

Keno commented Jun 12, 2015

Yes, that would be nice to have.

@ScottPJones
Copy link
Contributor

Does it need to be a mandatory argument (which would break all current string macros)?
Does it need to be limited to string macros?
Instead, for all macros, could it have a local symbol bound to an object with all that information?
(file name, line number, enclosing module, enclosing type or method...)
That would not break anything at all, and would be more generally useful to boot.

@Keno
Copy link
Member Author

Keno commented Jun 12, 2015

String macros can't have optional arguments, so it either needs to be mandatory (though it's generally possible to do define the macros in a backwards compatible way) or some more fancy mechanism needs to be used. I suppose it would be possible to do this for all macros, though I haven't found any use for it yet. I worry that exposing too much scope information would open the door to macros that are extremely context sensitive. Right now, macros nicely only operate on the syntax they are passed. I'm sure @JeffBezanson has strong opinions here.

@ScottPJones
Copy link
Contributor

@Keno What I've suggested is no different that C/C++ code being able to use __LINE__ and __FILE__, in macros or in the source code. I'm saying that it should be an explicit argument, but rather, something that gets bound implicitly (like __FILE__ and __LINE__), could be something like: __LOCATION__, that wouldn't even have anything created if it isn't referenced within the macro.
This isn't really about making extremely context sensitive macros, but it allows macros to be able to save away information for debugging or error reporting, for example, or for documentation purposes.
It would be easy to document that all macros implicitly get passed this argument.

@Keno
Copy link
Member Author

Keno commented Jun 12, 2015

I'm fine with line and file that seems useful, I have a problem with enclosing module, enclosing type or method....

@ScottPJones
Copy link
Contributor

@Keno Those are very useful (necessary?) if you want to try to associate documentation with particular fields within a type, for example. What are you concerned about in particular with having the extra information?
Also, what do you think about the approach I came up with for handling this without breaking anything?

@mbauman mbauman mentioned this pull request Jul 14, 2015
8 tasks
@ihnorton
Copy link
Member

ihnorton commented Aug 4, 2015

Related: Laurence Tratt's recent post about "Debugging Layers" in Converge (h/t @jakebolewski).

@vtjnash
Copy link
Member

vtjnash commented Mar 25, 2016

i think this has been resolved (via introduction of @__LINE__) and can be deleted?

@quinnj quinnj closed this May 9, 2016
@Keno
Copy link
Member Author

Keno commented May 9, 2016

This is not resolved. @__LINE__ is resolved during parsing, so not useful here.

@vtjnash
Copy link
Member

vtjnash commented Jun 16, 2017

Rebased as jn/kf-linecolstr. But need to fix the column numbers for macros to point at the the first symbol of the first argument for this to be useful for its original purpose. (currently, it tries to describe the @ sign, but I think pointing at the first symbol of the first argument is reasonable, given that we aren't planning on describing the line/column ranges for the entire parse tree).

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.

6 participants