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

GCC Rich Locations #97

Open
philberty opened this issue Dec 23, 2020 · 2 comments
Open

GCC Rich Locations #97

philberty opened this issue Dec 23, 2020 · 2 comments
Labels
diagnostic diagnostic static analysis enhancement GCC

Comments

@philberty
Copy link
Member

This relates to something I had thought about doing, but not in enough detail to open an enhancement issue. gcc supports something called "rich locations" in which three actual locations are encoded - a "start" location, a "caret" location, and an "end" location - basically like a location range with a specified value highlighted.

I couldn't find the page that I thought I originally read this in, but here's a quote from here:

As of GCC 6, ordinary locations changed from supporting just a point in the user’s source code to supporting three points: the caret location, plus a start and a finish:

      a = foo && bar;
          ~~~~^~~~~~
          |   |    |
          |   |    finish
          |   caret
          start

Instead of accessing start_location and end_location separately, these could be integrated into a single location value. There's also the technicality that the current definition of get_closing_locus() technically gets the beginning location of the last statement rather than the end location of the block (i.e. the right curly bracket), assuming that this would be the preferred behaviour.

The lexer would have to be modified to reflect this rich location system, and the parser and AST probably would have to be too (i.e. make a new location from the "start" location from one token and the "end" location of a different one). Also, the backend-independent Location abstraction would have to be modified to support this.

Originally posted by @SimplyTheOther in #90 (comment)

@davidmalcolm
Copy link
Contributor

Strictly speaking, a rich_location is zero or more location_t, where a location_t has start, caret, and end. The rich_location can also optionally have per location_t-labels, along with zero or more fix-it hints. It's intended to be a short-lived on-stack object, for emitting diagnostics.

So I think initially you mean to populate the location_t with ranges, rather than points.

Sorry that I made the naming confusing.

@philberty
Copy link
Member Author

One concept i think will help out AST and HIR will be to bring in the notion of Spans which rustc uses to solve this. Currently in our type inferencing code there are 2 messages for the case of expected i32 but got bool of example: one warning for the reference location and the other warning for where it was declared which is quite ugly and not right.

@philberty philberty added the diagnostic diagnostic static analysis label Apr 12, 2021
philberty added a commit that referenced this issue Apr 15, 2021
Adding rich location will improve our error message diagnostics, this is
an initial building block to keep a wrapper over the GCC stuff we call.

Addresses: #97
Fixes: #327
philberty added a commit that referenced this issue Apr 15, 2021
Adding rich location will improve our error message diagnostics, this is
an initial building block to keep a wrapper over the GCC stuff we call.

Addresses: #97
bors bot added a commit that referenced this issue Apr 17, 2021
374: Add basic wrapper over gcc rich_location r=philberty a=philberty

Adding rich location will improve our error message diagnostics, this is
an initial building block to keep a wrapper over the GCC stuff we call.

Addresses: #97 
Fixes: #327 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
philberty added a commit that referenced this issue Apr 17, 2021
Adding rich location will improve our error message diagnostics, this is
an initial building block to keep a wrapper over the GCC stuff we call.

Addresses: #97
bors bot added a commit that referenced this issue Apr 17, 2021
374: Add basic wrapper over gcc rich_location r=philberty a=philberty

Adding rich location will improve our error message diagnostics, this is
an initial building block to keep a wrapper over the GCC stuff we call.

Addresses: #97 
Fixes: #327 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
tschwinge added a commit that referenced this issue Sep 23, 2021
... in preparation for a merge from GCC upstream, where we otherwise run into
several different build errors.

Follow-up to commit ed651fc
"Add basic wrapper over gcc rich_location".
tschwinge added a commit that referenced this issue Sep 24, 2021
... in preparation for a merge from GCC upstream, where we otherwise run into
several different build errors.

Follow-up to commit ed651fc
"Add basic wrapper over gcc rich_location".
bors bot added a commit that referenced this issue Sep 24, 2021
690: A bit of 'RichLocation' C++ tuning [#247], [#97, #374] r=philberty a=tschwinge

... in preparation for a merge from GCC upstream, where we otherwise run into
several different build errors.

Follow-up to commit ed651fc
"Add basic wrapper over gcc rich_location".


Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis enhancement GCC
Projects
None yet
Development

No branches or pull requests

2 participants