-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add line-level debug info #4247
Merged
jonmeow
merged 2 commits into
carbon-language:trunk
from
dwblaikie:debug_info_source_locations
Aug 26, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just to be sure, this is assuming the locations are valid and in the current file. Should that be checked? For example,
loc.line_number <= 0
orloc.column_number <= 0
would indicate unknown. You can see some of this in FormatSnippetDoing something on the file could just be a TODO.
Not sure how much we test multi-file lowering today, but might still be worth adding some resilience and/or todos.
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.
Hmm - 0 is an OK value for the debug info (it means "we can't assign this instruction to any particular source line") and I think we use 0 for invalid column number too. Is it just 0 for invalid, or are really <= 0? (carrying some extra information about kinds of invalidity or something in this?)
What causes invalid values but successful code generation? (happy to add some test coverage)
The multi-file issue is due to the unimpleented/trivially implemented context callback passed to the ConvertLoc call?
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.
-1 is used for "unknown", it's the default value for both (https://github.com/carbon-language/carbon-lang/blob/trunk/toolchain/diagnostics/diagnostic.h#L61-L64).
The default value is sometimes used, for example here:
https://github.com/carbon-language/carbon-lang/blob/trunk/toolchain/parse/tree_node_diagnostic_converter.h#L48-L51
I know this comes up in check:
https://github.com/search?q=repo%3Acarbon-language%2Fcarbon-lang+path%3Atestdata%2F+%22.carbon%3A+%22&type=code
I'm not sure what test coverage would look like. However, it might still be good to handle it since it's allowed by the API call.
No, this is just what the location converter is up to. A location can be either a node_id or a import_ir_id. In the latter case, it's referencing an imported instruction. Again, not sure it'll happen right now. OTOH, probably will start coming up as complexity increases, e.g. for template expansions or maybe inlining code.
Not sure why you're looking at the context though... To be sure, the DiagnosticLoc has a field "filename" for this. You'd need to ensure that everything you're using is a Parse::Node in order to be guaranteed it's in the file. e.g., something like:
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.
Note, an option is to just leave a guardrail, e.g.:
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.
Note, you could also look at changing
line_number
to be0
-defaulted, to help DebugInfo. I think I'd chosen-1
in order to avoid accidents with0
versus1
as the first correct value: although comments don't specify, I think1
is where it starts, but a bug could lead to0
and it'd stick out a little more.But if you change that, do add comments specifying why the values are chosen that way.
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.
FYI,
line: 4294967295
does appear in the .carbon testdata files as a result of this change.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.
Thanks for pointing that out, I hadn't been looking the right way to notice that.