@@ -680,11 +680,12 @@ private LightLambdaExpression CreateFunctionLambda() {
680680 InitializeParameters ( init , needsWrapperMethod , parameters ) ;
681681
682682 List < MSAst . Expression > statements = new List < MSAst . Expression > ( ) ;
683- // add beginning sequence point
684- var start = GlobalParent. IndexToLocation( StartIndex ) ;
685- statements . Add ( GlobalParent . AddDebugInfo (
686- AstUtils . Empty ( ) ,
687- new SourceSpan ( new SourceLocation ( 0 , start . Line , start . Column ) , new SourceLocation ( 0 , start . Line , int . MaxValue ) ) ) ) ;
683+
684+ // Add beginning sequence point. For async functions this body is deferred into the nested Async/AsyncEnumerable lambda,
685+ // and the outer factory (which runs first, and is the only one traced today) re-emits its own entry point at StartIndex;
686+ // anchor this one at HeaderIndex (end of the signature) so the two occupy distinct source locations should the deferred
687+ // body ever become traceable. For single-line signatures both still land on the same line (differing only in column).
688+ statements . Add( MakeFunctionEntrySequencePoint ( IsAsync ? HeaderIndex : StartIndex) ) ;
688689
689690
690691 // For generators/coroutines, we need to do a check before the first statement for Generator.Throw() / Generator.Close().
@@ -739,6 +740,7 @@ private LightLambdaExpression CreateFunctionLambda() {
739740 var throwSlot = AsyncThrowSlot;
740741 body = MSAst. Expression. Block(
741742 [ cts , excBox , sendSlot , throwSlot] ,
743+ MakeFunctionEntrySequencePoint( StartIndex ) ,
742744 MSAst. Expression. Assign( cts , MSAst. Expression. New( typeof ( CancellationTokenSource ) ) ) ,
743745 MSAst. Expression. Assign( excBox , MSAst. Expression. New( typeof ( StrongBox < Exception> ) ) ) ,
744746 MSAst. Expression. Assign( sendSlot , MSAst. Expression. New( typeof ( StrongBox < object > ) ) ) ,
@@ -758,6 +760,7 @@ private LightLambdaExpression CreateFunctionLambda() {
758760 // rather than whatever context happened to be current at construction.
759761 body = MSAst. Expression. Block(
760762 [ cts , excBox] ,
763+ MakeFunctionEntrySequencePoint( StartIndex ) ,
761764 MSAst. Expression. Assign( cts , MSAst. Expression. New( typeof ( CancellationTokenSource ) ) ) ,
762765 MSAst. Expression. Assign( excBox , MSAst. Expression. New( typeof ( StrongBox < Exception> ) ) ) ,
763766 Ast. Call(
@@ -805,6 +808,13 @@ private LightLambdaExpression CreateFunctionLambda() {
805808
806809 internal FunctionCode FunctionCode => GetOrMakeFunctionCode( ) ;
807810
811+ private MSAst. Expression MakeFunctionEntrySequencePoint( int index) {
812+ var loc = GlobalParent. IndexToLocation( index ) ;
813+ return GlobalParent. AddDebugInfo(
814+ AstUtils . Empty( ) ,
815+ new SourceSpan( new SourceLocation( 0 , loc. Line, loc. Column) , new SourceLocation ( 0 , loc. Line, int . MaxValue) ) ) ;
816+ }
817+
808818 private static MSAst. Expression/*!*/ AddDefaultReturn( MSAst . Expression/*!*/ body, Type returnType) {
809819 if ( body . Type == typeof ( void ) && returnType != typeof ( void ) ) {
810820 body = Ast. Block( body , Ast. Default( returnType ) ) ;
0 commit comments