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

Store nullable attribute constructor params in a field: #33668

Merged
merged 4 commits into from
Feb 27, 2019

Conversation

chsienki
Copy link
Contributor

  • Add a derived nullable attribute symbol
  • Add a constructor symbol that allows assignment to a field
  • Generate the appropriate constructors for byte and byte[] versions of the attribute
  • Add tests

Closes #30143

- Add a derived nullable attribute symbol
- Add a constructor symbol that allows assignment to a field
- Generate the appropriate constructors for byte and byte[] versions of the attribute
- Add tests
_constructors = getConstructors(compilation, this, diagnostics);
}
else
if (generateDefaultConstructors)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hate this. Any ideas on a better approach most welcome.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps replace the _constructors field with an abstract Constructors property, and have two derived types, one that returns a single constructor with no parameters.


In reply to: 260050571 [](ancestors = 260050571)

@chsienki chsienki marked this pull request as ready for review February 26, 2019 01:27
@chsienki chsienki requested a review from a team as a code owner February 26, 2019 01:27
@chsienki
Copy link
Contributor Author

@dotnet/roslyn-compiler for review please.

@jcouv jcouv added this to the 16.1.P1 milestone Feb 26, 2019
{
private readonly ImmutableArray<FieldSymbol> _fields;

private readonly TypeSymbolWithAnnotations _byteType;
Copy link
Member

Choose a reason for hiding this comment

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

TypeSymbolWithAnnotations [](start = 25, length = 25)

Can be stored as TypeSymbol.


internal sealed class SynthesizedEmbeddedAttributeConstructorWithBodySymbol : SynthesizedInstanceConstructor
{
ImmutableArray<ParameterSymbol> _parameters;
Copy link
Member

Choose a reason for hiding this comment

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

ImmutableArray [](start = 12, length = 14)

private readonly

{
ImmutableArray<ParameterSymbol> _parameters;

readonly Action<SyntheticBoundNodeFactory, ArrayBuilder<BoundStatement>, ImmutableArray<ParameterSymbol>> _getConstructorBody;
Copy link
Member

Choose a reason for hiding this comment

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

readonly [](start = 12, length = 8)

private

);
}

internal sealed class SynthesizedEmbeddedAttributeConstructorWithBodySymbol : SynthesizedInstanceConstructor
Copy link
Member

Choose a reason for hiding this comment

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

internal [](start = 8, length = 8)

private

}

[Fact]
public void Field_Contains_ConstuctorArugments_SingleByteConstructor()
Copy link
Member

Choose a reason for hiding this comment

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

Constuctor [](start = 35, length = 10)

Typo, here and test below.

@@ -1686,6 +1689,107 @@ static void F(B<A<(object?, (object, object?), object, object?, object, object?,
type.GetMember<PropertySymbol>("Property").ToTestDisplayString());
}

[Fact]
public void Field_Exists()
Copy link
Member

Choose a reason for hiding this comment

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

Field_ [](start = 20, length = 6)

The test names are a little confusing since it's not clear what "Field" refers to (at least it won't be clear outside of this PR). Perhaps name these tests "NullableAttribute_" or "NullableAttributeField_" as approriate.

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{

internal class SynthesizedEmbeddedNullableAttributeSymbol : SynthesizedEmbeddedAttributeSymbol
Copy link
Member

Choose a reason for hiding this comment

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

class [](start = 13, length = 5)

sealed

@@ -305,42 +303,36 @@ private void CreateEmbeddedAttributeItselfIfNeeded(DiagnosticBag diagnostics)
private void CreateEmbeddedAttributeIfNeeded(
ref SynthesizedEmbeddedAttributeSymbol symbol,
DiagnosticBag diagnostics,
AttributeDescription description,
Func<CSharpCompilation, NamedTypeSymbol, DiagnosticBag, ImmutableArray<MethodSymbol>> getConstructors = null)
AttributeDescription description)
{
if ((object)symbol == null)
Copy link
Member

@jaredpar jaredpar Feb 27, 2019

Choose a reason for hiding this comment

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

symbol is null #Resolved

new SynthesizedEmbeddedAttributeConstructorSymbol(
containingType,
m => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, byteArray, 0, RefKind.None))));
if ((object)symbol == null)
Copy link
Member

@jaredpar jaredpar Feb 27, 2019

Choose a reason for hiding this comment

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

symbol is null #Resolved

private readonly ModuleSymbol _module;

protected ImmutableArray<MethodSymbol> _constructors;
Copy link
Member

Choose a reason for hiding this comment

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

protected values should be PascalCased and not _ prefixed.

new SynthesizedFieldSymbol(
this,
byteArrayType.TypeSymbol,
"nullableFlags",
Copy link
Member

Choose a reason for hiding this comment

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

Given this is public it should be PascalCased

@jaredpar
Copy link
Member

Done with review pass (iteration 1)

- Split SynthesizedEmbeddedAttribute into a base class and implementation
- Rename nullableFlags to NullableFlags
- Rename tests

/// <summary>
/// When implemented by a more derived type, gets a list of constructors to synthesize for the attribute
/// </summary>
Copy link
Member

Choose a reason for hiding this comment

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

Blank line below.

Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

:shipit:

/// 4) It has System.Runtime.CompilerServices.CompilerGeneratedAttribute
/// 5) It has a parameter-less constructor
/// </summary>
internal abstract class SynthesizedEmbeddedAttributeSymbolBase : NamedTypeSymbol
Copy link
Member

Choose a reason for hiding this comment

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

SynthesizedEmbeddedAttributeSymbolBase [](start = 28, length = 38)

Consider leaving this type in SynthesizedEmbeddedAttributeSymbol.cs, along with the derived type, so the changes in this PR are clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@chsienki chsienki merged commit 509277e into dotnet:master Feb 27, 2019
@chsienki chsienki deleted the nullable_attribute_field branch February 27, 2019 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants