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

Expand #line to support columns #46526

Closed
NTaylorMullen opened this issue Aug 3, 2020 · 5 comments
Closed

Expand #line to support columns #46526

NTaylorMullen opened this issue Aug 3, 2020 · 5 comments
Labels
Area-Compilers Feature Request Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@NTaylorMullen
Copy link
Contributor

The problem

The current restrictions of the #line pragma don't bode well for embedded languages. For instance in Razor the core "transition into C#" mechanism has various implications on the #line pragma's lacking support of a column. For instance, lets consider:

@DateTime.Now

At runtime this renders:

#line 1 "Foo.razor"

Write(DateTime.Now);

#line default

At design time this renders:

#line 1 "Foo.razor"

__o = DateTime.Now;

#line default

Now consider the implications of this at debug & edit time.

  1. Errors. Any error that maps to DateTime.Now is instantly misaligned because @DateTime.Now exists at the front of the line.
  2. Breakpoints. Any breakpoint can't possibly understand how to bind to the original language document properly without understanding the difference in columns.

Suggestion:

  • Allow line pragmas to provide a column & exist in the middle of expressions/statements and work properly at error/debug time (they currently don't):
<p>The current time is: @DateTime.Now</p>
Write(
#line 1 25 "Foo.razor"
DateTime.Now
#line default
);
  • OR allow a column, mapped offset and length to enable unmapped code to exist in the line pragma:
<p>The current time is: @DateTime.Now</p>
#line 1 25 6 12 "Foo.razor"
Write(DateTime.Now);
#line default

/cc @tmat

@tmat
Copy link
Member

tmat commented Aug 3, 2020

Would it be possible for Razor to emit indented code like so?

__o = 
#line 1 "Foo.razor"
   DateTime.Now
#line default
;

then it could control the column precisely.

@NTaylorMullen
Copy link
Contributor Author

then it could control the column precisely.

Yup we could and actually do in some Blazor scenarios; however, it ends up resulting in pieces not being debuggable: #43432 which is why we haven't done it everywhere

😢

@tmat
Copy link
Member

tmat commented Aug 3, 2020

Yeah, I see. So the problem is really the placements of the sequence points if #line is in the middle of a statement. I guess we have two options in the compiler how to handle that - either we implement column mapping syntax or we change the handling of the #line directive when in the middle a statement. The former seems cleaner since the latter is gonna likely have a bunch of odd corner cases.

@tmat
Copy link
Member

tmat commented Aug 3, 2020

@gafter FYI

@tmat
Copy link
Member

tmat commented May 6, 2021

I'm working on a proposal for adding column to #line directive.

@tmat tmat closed this as completed Jul 7, 2021
@tmat tmat added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature Request Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

3 participants