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

Symbol.pos returns NoPosition at runtime #8259

Open
scabug opened this issue Feb 10, 2014 · 6 comments
Open

Symbol.pos returns NoPosition at runtime #8259

scabug opened this issue Feb 10, 2014 · 6 comments
Milestone

Comments

@scabug
Copy link

scabug commented Feb 10, 2014

On the one hand, we don't pickle positions. On the other hand, we can't even read the SourceFile classfile attribute via official API in java.lang.Class. This means that it's currently impossible to use reflection API to figure out the source file and line number where a symbol was defined.

I think the best solution here would be to pickle symbol positions. Hopefully, a relative file + a long wouldn't increase the size of our classfiles much.

@scabug
Copy link
Author

scabug commented Feb 10, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8259?orig=1
Reporter: @xeno-by
See #7044

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@gkossakowski said:

Hopefully, a relative file + a long wouldn't increase the size of our classfiles much.

Relative to what?

Also, I'll lower the priority of this issue. Critical seems to be a little bit too high.

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@xeno-by said:
Relative to the package the class is in. Concretely, something that's written into the SourceFile attribute of the classfile.

Btw do you know any way to read SourceFile given a java.lang.Class?

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@gkossakowski said:
I see. Makes sense.

I don't think you can read any of class file attributes using reflection (including SourceFileAttribute).

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@dragos said:
Since Java reflection won't give you even the name of the source file, I think it's fine for the Scala implementation to behave the same.

Moreover, positions have a wide contract: they need to be able to retrieve a source file (with contents), get the line number based on an offset, and many others implemented in terms of SourceFile. Since the application may run somewhere without any sourcefiles in sight, you'd be re-implementing positions to only work for some methods, and not others. Maybe it's better to consider an alternative interface, if this serves an important use-case (what's the main use-case for this enhancement?)

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@xeno-by said:
The motivation for this enhancement comes from the fact that positions are second-class citizens in our reflection API. This is fine from an implementation PoV, but we can definitely do a better job in exposing positions to the wide public (code analysis tools, editor plugins).

The main use-case here is "go to definition" functionality for precompiled code. Way back then, when I was hacking ENSIME, we had to use associatedFile + ASM to parse the SourceFile attribute, in order for it to work. Jason tells me that there's some presentation compiler API that deals with this, but not everyone has a luxury / complexity budget of running a presentation compiler.

The Position API is indeed quite big right now. I've somewhat addressed that by deprecating a lot of convenience methods, but Position.source is still there and it still exposes a huge API surface. That's something that I'll have to work on in Scala 2.12.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants