-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use a singleton sentinel for empty type-parameters for non-generic named-types and methods. #68131
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
987c5bf
Use a singleton for empty type-parameters for named types
CyrusNajmabadi f54b275
move type parameters down
CyrusNajmabadi 8f7e812
Optimize methods as well
CyrusNajmabadi 83aadc9
Always create indirection
CyrusNajmabadi 3c7c4fa
Move type
CyrusNajmabadi 72929c5
Apply suggestions from code review
CyrusNajmabadi ae7ec30
speeling
CyrusNajmabadi b99b695
nrt
CyrusNajmabadi bd8840c
Merge branch 'namedTypeParams' of https://github.com/CyrusNajmabadi/r…
CyrusNajmabadi e4e430c
Inline
CyrusNajmabadi 8849e06
Merge remote-tracking branch 'upstream/main' into namedTypeParams
CyrusNajmabadi d17689f
Simplify
CyrusNajmabadi 7223446
Change to abstract override
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/Compilers/CSharp/Portable/Symbols/Source/TypeParameterInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable disable | ||
CyrusNajmabadi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
{ | ||
/// <summary> | ||
/// Wrapper around type-parameter/constraints/constraint-kind info. We wrap this information (instead of inlining | ||
/// directly within type/method symbols) as most types/methods are not generic. As such, all those non-generic | ||
/// types can point at the singleton sentivel <see cref="Empty"/> value, and avoid two pointers of overhead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! |
||
/// </summary> | ||
internal sealed class TypeParameterInfo | ||
{ | ||
public ImmutableArray<TypeParameterSymbol> LazyTypeParameters; | ||
|
||
/// <summary> | ||
/// A collection of type parameter constraint types, populated when | ||
/// constraint types for the first type parameter are requested. | ||
/// </summary> | ||
public ImmutableArray<ImmutableArray<TypeWithAnnotations>> LazyTypeParameterConstraintTypes; | ||
|
||
/// <summary> | ||
/// A collection of type parameter constraint kinds, populated when | ||
/// constraint kinds for the first type parameter are requested. | ||
/// </summary> | ||
public ImmutableArray<TypeParameterConstraintKind> LazyTypeParameterConstraintKinds; | ||
|
||
public static readonly TypeParameterInfo Empty = new TypeParameterInfo( | ||
ImmutableArray<TypeParameterSymbol>.Empty, ImmutableArray<ImmutableArray<TypeWithAnnotations>>.Empty, ImmutableArray<TypeParameterConstraintKind>.Empty); | ||
|
||
public TypeParameterInfo() : this(default, default, default) | ||
{ | ||
} | ||
|
||
private TypeParameterInfo( | ||
ImmutableArray<TypeParameterSymbol> typeParameters, | ||
ImmutableArray<ImmutableArray<TypeWithAnnotations>> typeParameterConstraintTypes, | ||
ImmutableArray<TypeParameterConstraintKind> typeParameterConstraintKinds) | ||
{ | ||
LazyTypeParameters = typeParameters; | ||
LazyTypeParameterConstraintTypes = typeParameterConstraintTypes; | ||
LazyTypeParameterConstraintKinds = typeParameterConstraintKinds; | ||
} | ||
|
||
public static TypeParameterInfo Create(ImmutableArray<TypeParameterSymbol> typeParameters) | ||
{ | ||
// If we have no type parameters (common case), we can just point at the singleton empty instance. | ||
return typeParameters.IsEmpty ? Empty : new TypeParameterInfo(typeParameters, default, default); | ||
CyrusNajmabadi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
methods were odd. _typeParameters was in SourceOrdinaryMethodSymbolBase (not SourceOrdinaryMethodSymbol), but was always empty for all other types. So this pushed this value down into SourceOrdinaryMethodSymbol, which could then use the new TypeParameterInfo object. All other methods just return 'Empty' from their
TypeParameters
helpers.Note: this also ends up saving this extra pointer from all other source methods.