Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Dec 4, 2025

Relates to test plan #80613

@dotnet-policy-service dotnet-policy-service bot added the Needs API Review Needs to be reviewed by the API review council label Dec 4, 2025
@dotnet-policy-service
Copy link
Contributor

This PR modifies public API files. Please follow the instructions at https://github.com/dotnet/roslyn/blob/main/docs/contributing/API%20Review%20Process.md for ensuring all public APIs are reviewed before merging.

// as it could be capturing local data, we conservatively restrict it to the local scope.
var safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type)
? SafeContext.CallingMethod
: _localScopeDepth;
Copy link
Member Author

Choose a reason for hiding this comment

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

intentionally changed this. SafeContext.ReturnOnly feels wrong to me based on my undersrtanding of ref-safety. If we have no-elements, or we know we are creating a span out of a program data segment, then it should be safe to pass this value to the calling-method, since there's no way it could actually be capturing a local ref to anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

there are several tests taht validate this.

@CyrusNajmabadi CyrusNajmabadi changed the title WIP: with(...) ref-safety. Ref-safety for with(...) elements. Dec 4, 2025
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review December 4, 2025 09:56
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner December 4, 2025 09:56
@CyrusNajmabadi
Copy link
Member Author

@RikkiGibson @333fred @jcouv this is ready for review.

@RikkiGibson RikkiGibson self-requested a review December 4, 2025 17:53
@RikkiGibson
Copy link
Member

I'll try to take a look after I'm done with unions reviews

Diagnostic(ErrorCode.ERR_CollectionExpressionEscape, "[local]").WithArguments("R").WithLocation(10, 16));
}

[Theory, WorkItem("https://github.com/dotnet/roslyn/issues/75802")]
Copy link
Member

Choose a reason for hiding this comment

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

Should this and similar tests be linking to #81520 instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

enh :) I'm fine wither way.

@RikkiGibson
Copy link
Member

I believe that RefSafetyAnalysis.VisitCollectionExpression should be also modified to do an "arg mixing" check on the with-element, and related tests added. That can happen in a follow-up PR if you wish. Just want to make sure we don't forget.

I was meaning to take the writeup I send you directly and open it as a spec update to csharplang. I'll try to do that tomorrow.

Copy link
Member

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

Implementation changes LGTM, not going to be able to review tests until tomorrow.

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

Labels

Area-Compilers Feature - Collection Arguments Collection expression with() arguments Needs API Review Needs to be reviewed by the API review council

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants