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

Move ArrayBuilder.GetInstance helpers to Microsoft.CodeAnalysis.PooledObjects package #76971

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tmat
Copy link
Member

@tmat tmat commented Jan 30, 2025

These helpers are generally useful to consumers of the package. Especially when combining Roslyn source packages - see #76937

They were defined in Workspace layer since we do not want to allow using them in the compiler (due to perf concerns when used widely). To keep this intentional constraint the change adds them to compiler-specific banned API list.

@tmat tmat requested review from a team as code owners January 30, 2025 03:54
@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 30, 2025
@@ -8,9 +8,7 @@
namespace Microsoft.CodeAnalysis.PooledObjects;

[NonCopyable]
Copy link
Member Author

Choose a reason for hiding this comment

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

Adds [NonCopyable] attribute to the type definition.

Copy link
Member

Choose a reason for hiding this comment

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

What about just requiring the consumer to provide this attribute in all cases?

Copy link
Member Author

@tmat tmat Feb 1, 2025

Choose a reason for hiding this comment

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

Isn't the analyzer Roslyn specific? I would rather not impose more requirements on consumers of this source package.

That said, I'm working on another source package (say Microsoft.CodeAnalysis.Contracts) with basic contracts and exception utilities, which are used by our threading utilities (extracted to source package #76937).

We can include NonCopyable there. It's a contract after all, so it would fit.

Copy link
Member Author

@tmat tmat Feb 1, 2025

Choose a reason for hiding this comment

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

#76997 (Add Microsoft.CodeAnalysis.Contracts source package)

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@@ -720,5 +720,24 @@ public ImmutableArray<S> SelectDistinct<S>(Func<T, S> selector)
set.Free();
return result.ToImmutableAndFree();
}

public static PooledDisposer<ArrayBuilder<T>> GetInstance(out ArrayBuilder<T> instance)
Copy link
Member

Choose a reason for hiding this comment

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

Definitely need compiler sign off here. This will maje some unusable members show up in completion for a very common type.

Copy link
Member

Choose a reason for hiding this comment

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

Why is this an unusable member?

Copy link
Member Author

@tmat tmat Feb 1, 2025

Choose a reason for hiding this comment

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

Perhaps instead of banning the API we can wrap these in #if !COMPILERCORE . If we do, it'd be better to rename the symbol to something more descriptive, e.g. ROSLYN_COMPILER_CORE as it would appear in any repo consuming the source package.
@dotnet/roslyn-compiler Which approach do you prefer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants