-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add NullableContextAttribute #36152
Merged
Merged
Add NullableContextAttribute #36152
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
dd4779e
Add NullableContextAttribute
cston cf0b03c
Fix tests
cston 89766b6
Fix tests
cston f5db1fb
Fix tests
cston 35b4a24
More tests
cston 6eda1db
PR feedback
cston e9069c9
PR feedback
cston b92ae07
Fix test
cston 6db6043
Report error for explicit use of attributes
cston b5a3b73
Fix formatting
cston 6acd5ca
PR feedback
cston 14a9376
Add NullablePublicOnlyAttribute.IncludesInternals field
cston 1858ffe
Move check for NullablePublicOnlyAttribute
cston f610924
PR feedback
cston 510fcfb
Invoke GetNullableContextValue lazily
cston a40a302
PR feedback
cston f83fd06
Cache full nullable context value
cston 5ed7323
Delegate to containing symbol for accessibility
cston b64cf78
PR feedback
cston 2dfe52a
PR feedback
cston b238d9c
Use GetInterfacesToEmit
cston 12648ee
Move handling of dynamic and tuple attributes
cston b40be6d
Misc.
cston 2ca9546
Fix typo
cston f28acab
Fix test
cston 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
95 changes: 95 additions & 0 deletions
95
src/Compilers/CSharp/Portable/Emitter/Model/MostCommonNullableValueBuilder.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,95 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.CodeAnalysis.CSharp.Symbols; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp | ||
{ | ||
internal struct MostCommonNullableValueBuilder | ||
{ | ||
private int _value0; | ||
private int _value1; | ||
private int _value2; | ||
|
||
internal byte? MostCommonValue | ||
{ | ||
get | ||
{ | ||
int max; | ||
byte b; | ||
if (_value1 > _value0) | ||
{ | ||
max = _value1; | ||
b = 1; | ||
} | ||
else | ||
{ | ||
max = _value0; | ||
b = 0; | ||
} | ||
if (_value2 > max) | ||
{ | ||
return 2; | ||
} | ||
return max == 0 ? (byte?)null : b; | ||
} | ||
} | ||
|
||
internal void AddValue(byte value) | ||
{ | ||
switch (value) | ||
{ | ||
case 0: | ||
_value0++; | ||
break; | ||
case 1: | ||
_value1++; | ||
break; | ||
case 2: | ||
_value2++; | ||
break; | ||
default: | ||
throw ExceptionUtilities.UnexpectedValue(value); | ||
} | ||
} | ||
|
||
internal void AddValue(byte? value) | ||
{ | ||
if (value != null) | ||
{ | ||
AddValue(value.GetValueOrDefault()); | ||
} | ||
} | ||
|
||
internal void AddValue(TypeWithAnnotations type) | ||
{ | ||
var builder = ArrayBuilder<byte>.GetInstance(); | ||
type.AddNullableTransforms(builder); | ||
AddValue(GetCommonValue(builder)); | ||
builder.Free(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the common value if all bytes are the same value. | ||
/// Otherwise returns null. | ||
/// </summary> | ||
internal static byte? GetCommonValue(ArrayBuilder<byte> builder) | ||
{ | ||
int n = builder.Count; | ||
if (n == 0) | ||
{ | ||
return null; | ||
} | ||
byte b = builder[0]; | ||
for (int i = 1; i < n; i++) | ||
{ | ||
if (builder[i] != b) | ||
{ | ||
return null; | ||
} | ||
} | ||
return b; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.
It feels like, either
member
should be taken into account here, or the parameter should be removed. #Closed