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

Annotate System.Linq.Expressions with RequiresDynamicCode #90456

Merged
merged 11 commits into from
Aug 15, 2023

Conversation

agocke
Copy link
Member

@agocke agocke commented Aug 12, 2023

All this ended up with an RDC on Expression.Compile due to new arrays. I could potentially silence this warning with a feature flag, but it is a real risk in AOT, and one that users could maybe work around if alerted to the problem.

All this ended up with an RUC on Expression.Compile due to new arrays.
I could potentially silence this warning with a feature flag, but it is a
real risk, and one that users could maybe work around if alterted to the problem.
@ghost
Copy link

ghost commented Aug 12, 2023

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

Issue Details

All this ended up with an RDC on Expression.Compile due to new arrays. I could potentially silence this warning with a feature flag, but it is a real risk in AOT, and one that users could maybe work around if alerted to the problem.

Author: agocke
Assignees: agocke
Labels:

area-System.Linq.Expressions

Milestone: -

@@ -134,11 +134,15 @@ internal static MethodInfo GetCompileMethod(Type lambdaExpressionType)
/// Produces a delegate that represents the lambda expression.
/// </summary>
/// <returns>A delegate containing the compiled version of the lambda.</returns>
[RequiresDynamicCode(Expression.NewArrayRequiresDynamicCode)]
Copy link
Member

Choose a reason for hiding this comment

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

This message is a bit weird (IMO). Anytime someone tries to compile an expression, they will get the warning

"Creating arrays at runtime requires dynamic code generation. This warning can be suppressed if there are no new array nodes in the expression tree."

But won't they already get the warning from the call that actually creates new array nodes in the expression tree? Therefore, we don't need to also warn them at Compile().

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, hadn't thought of that. The problem is that something like Expression<Func<int[]>> e = () => new[] { 1 }; won't produce an analyzer warning since we don't see the call site, but maybe that can be OK for now and we can treat it as an analyzer improvement to fix later.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, wouldn't it be fine? There's code there for a new int[].

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, maybe. Replace int with your favorite custom struct. That likely wouldn't work.

agocke and others added 2 commits August 13, 2023 14:04
@agocke
Copy link
Member Author

agocke commented Aug 14, 2023

@eerhardt Took your suggestion. There's now a suppression at the NewArrayExpression conversion routine.

@stephentoub stephentoub requested a review from cston August 14, 2023 21:24
Co-authored-by: Stephen Toub <stoub@microsoft.com>
@agocke agocke merged commit 067a357 into dotnet:main Aug 15, 2023
105 checks passed
@agocke agocke deleted the annotate-s-l-e branch August 15, 2023 02:45
@eerhardt
Copy link
Member

@agocke - looks like this just missed the 8.0 cutoff. Do we want to backport this into .NET 8?

@agocke
Copy link
Member Author

agocke commented Aug 15, 2023

I think it would be a good idea, given that people are hitting this in the wild

@agocke
Copy link
Member Author

agocke commented Aug 15, 2023

/backport to release/8.0-rc1

@github-actions
Copy link
Contributor

Started backporting to release/8.0-rc1: https://github.com/dotnet/runtime/actions/runs/5870002616

@ghost ghost locked as resolved and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants