Added offset to the token location#11823
Conversation
|
Thanks for your pull request and interest in making D better, @AsterMiha! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#11823" |
You can simply add the version here (as long as you are only using dmd/test/tools/unit_test_runner.d Lines 246 to 260 in 5fda4ea |
|
cc @jacob-carlborg How does this look? |
|
The whole point of using offsets was to reduce the size of |
|
@thewilsonator That is a different point. This change is trying to add offset location for tools that use dmd as a library. As you can see it is hided by a compiler version. The refactoring that you are talking about may be the subject of a different PR and indeed might help save some space, but the purpose of this PR is entirely different. |
|
Actually, thinking more about it, this does seem like a great opportunity for optimization. |
Thanks for the suggestion! I will attempt to do this optimization but in a different PR. |
@thewilsonator This PR is to store the offset of a token from the start of the source buffer, i.e. byte count. This is required to be able to do source code refactorings. |
src/dmd/globals.d
Outdated
There was a problem hiding this comment.
I'm wondering if there are other places in the code that needs to be updated as well. I know there are other places in the code which creates locations, not just the lexer.
|
Looking good, just a few minor things left. |
|
Looks good, just the extra tokens left: #11823 (comment). |
|
If you are interested in optimizing source location tracking, I strongly advise reading up on how Clang does that. It has a very efficient implementation. DMD's "Loc" size = 64 + 32 + 32 = 128 bits. Clang's is 32bits. |
|
@JohanEngelen Thank you! I will look into it. |
|
@AsterMiha in the future, when fixing something in a PR related to a specific comment. Please replay to that comment that the issue has been fixed and resolve the conversation. This will make it easier for reviewers to see that a particular comment has been addressed. |
I added a field to the Loc structure but to address the concerns raised here these changes should only be available when building for a certain version. At the moment, the version part is commented so the lexer unittest I added could run.
How can I make this test run only when building with the correct version?