Skip to content

Don't emit DebuggerStepThroughAttribute for runtime async methods#81035

Merged
333fred merged 12 commits intomainfrom
copilot/update-attribute-generation-async
Nov 8, 2025
Merged

Don't emit DebuggerStepThroughAttribute for runtime async methods#81035
333fred merged 12 commits intomainfrom
copilot/update-attribute-generation-async

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

✅ Completed: Fix DebuggerStepThroughAttribute for Runtime Async Methods

  • Understand the current state by exploring the codebase and identifying where DebuggerStepThroughAttribute is synthesized
  • Modify SourceMethodSymbol.cs to NOT emit DebuggerStepThroughAttribute when runtime async is enabled
  • Check for other attributes that might need similar conditioning (none found - only DebuggerStepThroughAttribute is synthesized)
  • Create tests to validate the fix using CreateRuntimeAsyncCompilation helper
  • Build and test the changes
  • Run broader test suite to ensure no regressions
  • Run code review and security scanning (CodeQL: no issues detected)
  • Address review feedback - use CreateRuntimeAsyncCompilation helper
  • Address review feedback from Julien and Aleksey

Summary of Changes

Production Code

File: src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbol.cs

  • Added check for compilation.IsRuntimeAsyncEnabledIn(target) before emitting DebuggerStepThroughAttribute
  • The attribute was being incorrectly added to all async methods, even when runtime async is enabled
  • When runtime async is enabled, no state machine is generated, so the attribute is not needed

Test Code

File: src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Synthesized.cs

  • Added AsyncStateMachineAttribute_RuntimeAsync test with Debug and Release variants for regular async methods
  • Added AsyncStateMachineAttribute_RuntimeAsync_Lambda test with Debug and Release variants for async lambdas
  • Added AsyncStateMachineAttribute_RuntimeAsync_LocalFunction test with Debug and Release variants for async local functions
  • Uses CreateRuntimeAsyncCompilation helper for proper runtime async compilation setup
  • Made symbolValidator static as requested in review
  • Inlined attributes variable for conciseness
  • Removed unnecessary MetadataImportOptions.All
  • Uses GetTypeMembers() to enumerate nested types instead of checking specific names
  • Validates that when runtime async is enabled:
    • No DebuggerStepThroughAttribute is emitted on async methods, lambdas, or local functions
    • No state machine types are generated

Test Results

✅ All 6 runtime async attribute tests pass (regular methods, lambdas, local functions - each with Debug and Release)
✅ All broader AsyncStateMachineAttribute tests pass
✅ CodeQL security scan: No issues detected

Key Findings

  • Only DebuggerStepThroughAttribute needed fixing: Other attributes like AsyncStateMachineAttribute were already correctly handled (only added when state machine exists)
  • Lambdas and local functions supported: Runtime async works with lambdas and local functions, no state machines generated
  • Minimal change: Only 7 lines of production code changed (added conditional check)
  • No breaking changes: All existing tests continue to pass

Relates to test plan #75960


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 4, 2025 22:19
- Modified SourceMethodSymbol.AddSynthesizedAttributes to check IsRuntimeAsyncEnabledIn before adding DebuggerStepThroughAttribute
- Added test AsyncStateMachineAttribute_RuntimeAsync to verify the fix
- When runtime async is enabled, no state machine is generated, so the attribute is not needed

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
- Updated AsyncStateMachineAttribute_RuntimeAsync test to use local verify function
- Follows the pattern used in CodeGenAsyncTests.cs for runtime async tests

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
Copilot AI changed the title [WIP] Update synthesized attribute generation for runtime async methods Don't emit DebuggerStepThroughAttribute for runtime async methods Nov 4, 2025
Copilot AI requested a review from 333fred November 4, 2025 22:32
@333fred
Copy link
Member

333fred commented Nov 4, 2025

@copilot src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Synthesized.cs:1836-1843
Update the test to use the helpers as I specified, not create its own thing

- Removed manual parse options and compilation setup
- Now using CreateRuntimeAsyncCompilation helper as specified
- Helper automatically handles runtime-async feature flag and SYSLIB5007 suppression

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Synthesized.cs:1836-1843
Update the test to use the helpers as I specified, not create its own thing

Updated to use CreateRuntimeAsyncCompilation helper in commit ffac6ec.

@333fred 333fred marked this pull request as ready for review November 4, 2025 23:16
@333fred 333fred requested a review from a team as a code owner November 4, 2025 23:16
@333fred
Copy link
Member

333fred commented Nov 4, 2025

@dotnet/roslyn-compiler for review.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (commit 4)

@jcouv jcouv self-assigned this Nov 5, 2025
- Added AsyncStateMachineAttribute_RuntimeAsync_Lambda test
- Added AsyncStateMachineAttribute_RuntimeAsync_LocalFunction test
- Both tests verify no state machine types are generated when runtime async is enabled
- All 6 runtime async tests now pass (2 for regular methods, 2 for lambdas, 2 for local functions)

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
@333fred
Copy link
Member

333fred commented Nov 5, 2025

@AlekseyTs @jcouv feedback addressed, please take another look

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (commit 8)

Copilot AI requested a review from jcouv November 6, 2025 01:39
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (commit 9)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 6, 2025

Done with review pass (commit 9) #Closed

@333fred
Copy link
Member

333fred commented Nov 6, 2025

@AlekseyTs for another review pass please

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 11)

@333fred 333fred enabled auto-merge (squash) November 7, 2025 16:51
@333fred 333fred merged commit f2df0ad into main Nov 8, 2025
24 of 25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 8, 2025
@333fred 333fred deleted the copilot/update-attribute-generation-async branch November 8, 2025 00:36
333fred added a commit to 333fred/roslyn that referenced this pull request Nov 10, 2025
* upstream/main:
  Simplify sequence point display (dotnet#81104)
  [main] Update dependencies from dotnet/arcade (dotnet#81129)
  [main] Update dependencies from dotnet/arcade (dotnet#81105)
  Target typed conditional expression recovery (dotnet#81025)
  dotnet#81118: Fix dropdown in "Move static members" dialog (dotnet#81119)
  Don't emit DebuggerStepThroughAttribute for runtime async methods (dotnet#81035)
@jcouv
Copy link
Member

jcouv commented Nov 11, 2025

@333fred Consider trimming the content that goes into merge/squash commit message. I see this in commit history, which doesn't seem very useful:

commit f2df0ad6d3ef30ed033a794e7150a5600be50a95 (async2-instrumentation)
Author: Copilot <198982749+Copilot@users.noreply.github.com>
Date:   Sat Nov 8 00:06:25 2025 +0000

    Don't emit DebuggerStepThroughAttribute for runtime async methods (#81035)

    ## ✅ Completed: Fix DebuggerStepThroughAttribute for Runtime Async
    Methods

    - [x] Understand the current state by exploring the codebase and
    identifying where DebuggerStepThroughAttribute is synthesized
    - [x] Modify `SourceMethodSymbol.cs` to NOT emit
    DebuggerStepThroughAttribute when runtime async is enabled
    - [x] Check for other attributes that might need similar conditioning
    (none found - only DebuggerStepThroughAttribute is synthesized)
    - [x] Create tests to validate the fix using
    CreateRuntimeAsyncCompilation helper
    - [x] Build and test the changes
    - [x] Run broader test suite to ensure no regressions
    - [x] Run code review and security scanning (CodeQL: no issues detected)
    - [x] Address review feedback - use CreateRuntimeAsyncCompilation helper
    - [x] Address review feedback from Julien and Aleksey

    ## Summary of Changes

    ### Production Code
    **File**:
    `src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbol.cs`
    - Added check for `compilation.IsRuntimeAsyncEnabledIn(target)` before
    emitting `DebuggerStepThroughAttribute`
    - The attribute was being incorrectly added to all async methods, even
    when runtime async is enabled
    - When runtime async is enabled, no state machine is generated, so the
    attribute is not needed

    ### Test Code
    **File**:
    `src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Synthesized.cs`
    - Added `AsyncStateMachineAttribute_RuntimeAsync` test with Debug and
    Release variants for regular async methods
    - Added `AsyncStateMachineAttribute_RuntimeAsync_Lambda` test with Debug
    and Release variants for async lambdas
    - Added `AsyncStateMachineAttribute_RuntimeAsync_LocalFunction` test
    with Debug and Release variants for async local functions
    - Uses `CreateRuntimeAsyncCompilation` helper for proper runtime async
    compilation setup
    - Made symbolValidator static as requested in review
    - Inlined attributes variable for conciseness
    - Removed unnecessary MetadataImportOptions.All
    - Uses GetTypeMembers() to enumerate nested types instead of checking
    specific names
    - Validates that when runtime async is enabled:
    - No `DebuggerStepThroughAttribute` is emitted on async methods,
    lambdas, or local functions
      - No state machine types are generated

    ## Test Results
    ✅ All 6 runtime async attribute tests pass (regular methods, lambdas,
    local functions - each with Debug and Release)
    ✅ All broader AsyncStateMachineAttribute tests pass
    ✅ CodeQL security scan: No issues detected

    ## Key Findings
    - **Only DebuggerStepThroughAttribute needed fixing**: Other attributes
    like `AsyncStateMachineAttribute` were already correctly handled (only
    added when state machine exists)
    - **Lambdas and local functions supported**: Runtime async works with
    lambdas and local functions, no state machines generated
    - **Minimal change**: Only 7 lines of production code changed (added
    conditional check)
    - **No breaking changes**: All existing tests continue to pass

    Relates to test plan https://github.com/dotnet/roslyn/issues/75960

    <!-- START COPILOT CODING AGENT TIPS -->
    ---

    ✨ Let Copilot coding agent [set things up for
    you](https://github.com/dotnet/roslyn/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
    — coding agent works faster and does higher quality work when set up for
    your repo.

    ---------

    Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
    Co-authored-by: Fredric Silberberg <frsilb@microsoft.com>

    ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants