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

CodeGenerator.EmitStackAlloc - Avoid capturing blob array #76660

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

alrz
Copy link
Member

@alrz alrz commented Jan 7, 2025

I'm not sure if conditional code on dotnet version is acceptable as this API is only available in 8.0+.

@alrz alrz requested a review from a team as a code owner January 7, 2025 16:35
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 7, 2025
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jan 7, 2025
@@ -45,7 +45,11 @@ private void EmitStackAlloc(TypeSymbol type, BoundArrayInitialization? inits, Bo
var sizeInBytes = elementType.EnumUnderlyingTypeOrSelf().SpecialType.SizeInBytes();

ImmutableArray<byte> data = GetRawData(initExprs);
#if NET8_0_OR_GREATER
if (!data.AsSpan().ContainsAnyExcept(data[0]))
Copy link
Member

Choose a reason for hiding this comment

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

We don't generally have a problem with conditional code, but we usually want to have a good reason to have it; do you have benchmarks or other data indicating this capture is a problem?

@@ -45,7 +45,11 @@ private void EmitStackAlloc(TypeSymbol type, BoundArrayInitialization? inits, Bo
var sizeInBytes = elementType.EnumUnderlyingTypeOrSelf().SpecialType.SizeInBytes();

ImmutableArray<byte> data = GetRawData(initExprs);
#if NET8_0_OR_GREATER
if (!data.AsSpan().ContainsAnyExcept(data[0]))
Copy link
Contributor

@AlekseyTs AlekseyTs Jan 8, 2025

Choose a reason for hiding this comment

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

if (!data.AsSpan().ContainsAnyExcept(data[0]))

We can add an overload of All which takes an extra argument and passes it to the predicate. I think that would be preferred over a conditional compilation in this case. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact we already have the overload in ImmutableArrayExtensions:

public static bool All<T, TArg>(this ImmutableArray<T> array, Func<T, TArg, bool> predicate, TArg arg)

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

@alrz alrz requested review from 333fred and AlekseyTs January 9, 2025 08:56
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 3)

@AlekseyTs AlekseyTs enabled auto-merge (squash) January 9, 2025 16:23
@AlekseyTs AlekseyTs merged commit f68a47a into dotnet:main Jan 10, 2025
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jan 10, 2025
@AlekseyTs
Copy link
Contributor

@alrz Thanks for the contribution

333fred added a commit to 333fred/roslyn that referenced this pull request Jan 14, 2025
* upstream/main: (368 commits)
  Cleanup tests
  Add test
  Add test
  Add test
  Fix issue parsing regex category
  Properly simplify pattern when converting to pattern matching
  update publishdata after VS 17.13 snap
  Simplify
  Docs
  Do not lift type parameters in extract method declared within the selected region
  Fix ExtractMethod in VB elseif blocks
  Rework our Helix Process (dotnet#76703)
  Stash and restore original culture in CultureNormalizer (dotnet#76713)
  PR comments
  Adding checks for mutable structs.
  Add additional tests for string escape sequences
  CodeGenerator.EmitStackAlloc - Avoid capturing blob array (dotnet#76660)
  Update comments and exception type for LSP stdio configuration based on review feedback
  Fix race generating Microsoft.Managed.Core.CurrentVersions.targets (dotnet#76701)
  Update FileDownloader.cs
  ...
@dibarbet dibarbet modified the milestones: Next, 17.14 P1 Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants