Skip to content

Conversation

@RikkiGibson
Copy link
Member

Doc for upcoming breaking change

See dotnet/roslyn#80684. TensorShape's constructor was the only break I found when compiling the libraries. I fixed this by extracting the collection-expression to the top level.

Copilot AI review requested due to automatic review settings October 15, 2025 21:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an upcoming breaking change in C# related to the safe-context rules for span-valued collection expressions. The change modifies how collection expressions for Span/ReadOnlySpan types are handled when passed to constructors or methods.

Key Changes:

  • Extracts a span-valued collection expression from within a conditional block to the top level of the method to comply with new safe-context rules

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@tannergooding tannergooding left a comment

Choose a reason for hiding this comment

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

LGTM.

We probably need to backport this, since the local lifetime is incorrect without this change.

It would be nice if Roslyn could generate slightly better IL as well, but that's separate

@RikkiGibson
Copy link
Member Author

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18543984013

@tannergooding tannergooding merged commit 51c8f3c into dotnet:main Oct 16, 2025
82 of 86 checks passed
artl93 pushed a commit that referenced this pull request Oct 29, 2025
…ction expressions (#120774)

Backport of #120771 to release/10.0

/cc @RikkiGibson

## Customer Impact

- [ ] Customer reported
- [X] Found internally

Customers could end up with incorrect behavior due to the backing
storage for a collection expression having the wrong lifetime relative
to the local that tracked it.

## Regression

- [ ] Yes
- [x] No

C# took a late breaking change to fix a lifetime issue around collection
expressions and the IL it was emitting. This behavior has been around
since collection expressions were introduced.

## Testing

Explicit validation of the IL was done.

## Risk

Low. This is the only place in the repo that was impacted by the break
and was updated to use an appropriate lifetime for the collection
expression.

Co-authored-by: Rikki Gibson <[email protected]>
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.

3 participants