-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make debugger significantly faster #12645
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
Changes from all commits
a53b184
bf12aed
50123f2
adbd083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #pragma once | ||
| ///@file | ||
|
|
||
| #include <cinttypes> | ||
| #include <functional> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #include "pos-table.hh" | ||
|
|
||
| #include <algorithm> | ||
|
|
||
| namespace nix { | ||
|
|
||
| /* Position table. */ | ||
|
|
||
| Pos PosTable::operator[](PosIdx p) const | ||
| { | ||
| auto origin = resolve(p); | ||
| if (!origin) | ||
| return {}; | ||
|
|
||
| const auto offset = origin->offsetOf(p); | ||
|
|
||
| Pos result{0, 0, origin->origin}; | ||
| auto lines = this->lines.lock(); | ||
| auto linesForInput = (*lines)[origin->offset]; | ||
|
|
||
| if (linesForInput.empty()) { | ||
| auto source = result.getSource().value_or(""); | ||
| const char * begin = source.data(); | ||
| for (Pos::LinesIterator it(source), end; it != end; it++) | ||
| linesForInput.push_back(it->data() - begin); | ||
| if (linesForInput.empty()) | ||
| linesForInput.push_back(0); | ||
| } | ||
| // as above: the first line starts at byte 0 and is always present | ||
| auto lineStartOffset = std::prev(std::upper_bound(linesForInput.begin(), linesForInput.end(), offset)); | ||
|
|
||
| result.line = 1 + (lineStartOffset - linesForInput.begin()); | ||
| result.column = 1 + (offset - *lineStartOffset); | ||
| return result; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #pragma once | ||
| ///@file | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
@@ -18,9 +19,12 @@ public: | |
| private: | ||
| uint32_t offset; | ||
|
|
||
| Origin(Pos::Origin origin, uint32_t offset, size_t size): | ||
| offset(offset), origin(origin), size(size) | ||
| {} | ||
| Origin(Pos::Origin origin, uint32_t offset, size_t size) | ||
| : offset(offset) | ||
| , origin(origin) | ||
| , size(size) | ||
| { | ||
| } | ||
|
|
||
| public: | ||
| const Pos::Origin origin; | ||
|
|
@@ -72,6 +76,17 @@ public: | |
| return PosIdx(1 + origin.offset + offset); | ||
| } | ||
|
|
||
| /** | ||
| * Convert a byte-offset PosIdx into a Pos with line/column information. | ||
| * | ||
| * @param p Byte offset into the virtual concatenation of all parsed contents | ||
| * @return Position | ||
| * | ||
| * @warning Very expensive to call, as this has to read the entire source | ||
| * into memory each time. Call this only if absolutely necessary. Prefer | ||
| * to keep PosIdx around instead of needlessly converting it into Pos by | ||
| * using this lookup method. | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, using an In my profiling |
||
| Pos operator[](PosIdx p) const; | ||
|
|
||
| Pos::Origin originOf(PosIdx p) const | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am guessing
experimental-features.hhis the easy thing to make more abstractI was planning on doing that anyways for a new settings system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to write down more thoughts.
While it would be good to slim down
nix-utiland have more things in libraries with well-defined scopes, I think it's ok to considerPosto be part of a text handling component; not the evaluator. This frees it up to be used innix.conflogic and other file types.