Skip to content

Avoid generating or emitting NullablePublicOnlyAttribute when no other nullable attributes are emitted#37019

Merged
cston merged 3 commits into
dotnet:masterfrom
cston:36977
Jul 9, 2019
Merged

Avoid generating or emitting NullablePublicOnlyAttribute when no other nullable attributes are emitted#37019
cston merged 3 commits into
dotnet:masterfrom
cston:36977

Conversation

@cston

@cston cston commented Jul 5, 2019

Copy link
Copy Markdown
Contributor

Fixes #36977

@cston cston requested a review from a team as a code owner July 5, 2019 21:23
@cston

cston commented Jul 5, 2019

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler please review.

}

if ((attribute & (EmbeddableAttributes.NullableAttribute | EmbeddableAttributes.NullableContextAttribute)) != 0 &&
modifyCompilation)

@RikkiGibson RikkiGibson Jul 5, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so do we expect that in batch compilation, something passes modifyCompilation: true here, and in SemanticModel or whatnot we don't get here or we pass modifyCompilation: false? #ByDesign

@RikkiGibson RikkiGibson Jul 5, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess I'm really wondering when/why modifyCompilation would be false. #ByDesign

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like we pass modifyCompilation: false in cases where we want to report diagnostics but don't expect to emit any attributes - in particular binding lambdas and local functions.


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

@RikkiGibson RikkiGibson added this to the 16.3.P2 milestone Jul 5, 2019
var comp = CreateCompilation(sources, options: options, parseOptions: parseOptions);
CompileAndVerify(comp, symbolValidator: AssertNoNullablePublicOnlyAttribute);

comp = CreateCompilation(sources, options: options, parseOptions: parseOptions.WithFeature("nullablePublicOnly"));

@333fred 333fred Jul 8, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

parseOptions.WithFeature("nullablePublicOnly") [](start = 78, length = 46)

Consider making a TestOptions option for these, so we don't have to keep typing the flag out. #Pending

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will add that in a subsequent PR.


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

@333fred 333fred left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM (commit 3) other than small test suggestion.


private bool _usesNullableAttributes;
private int _needsGeneratedAttributes;
private bool _needsGeneratedAttributes_IsFrozen;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: should this field be renamed, since now used for freezing both "needsGenerated" and "usesNullable"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I considered renaming the field but didn't find a better name.


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

private void SetUsesNullableAttributes()
{
Debug.Assert(!_needsGeneratedAttributes_IsFrozen);
_usesNullableAttributes = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_usesNullableAttributes = true; [](start = 12, length = 31)

just to confirm, we don't need any special operation to ensure this set is atomic, correct?

@cston cston Jul 9, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No need - reading and writing a bool is atomic.


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

_state.SpinWaitComplete(CompletionPart.FinishValidatingReferencedAssemblies, cancellationToken);
break;

case CompletionPart.StartMemberChecks:

@jcouv jcouv Jul 9, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

case [](start = 20, length = 4)

I didn't understand why this could be removed. Aren't we losing some diagnostics? Never mind, we were dicarding those diagnostics anyways. #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We were reporting those diagnostics before, but now emitting of this attribute is tied to the other attributes so any diagnostics will be reported from those attributes.


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

{
var compilation = DeclaringCompilation;
return compilation.EmitNullablePublicOnly &&
compilation.IsFeatureEnabled(MessageID.IDS_FeatureNullableReferenceTypes);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We used to check the feature flag, but I didn't see whether that is still handled somehow. Was that unnecessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We only emit NullablePublicOnlyAttribute if we're also emitting NullableAttribute or NullableContextAttribute.


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

@jcouv jcouv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 3)

@jcouv jcouv self-assigned this Jul 9, 2019
@cston cston merged commit eb170a1 into dotnet:master Jul 9, 2019
@cston cston deleted the 36977 branch July 9, 2019 02:58
canton7 added a commit to canton7/roslyn that referenced this pull request Jul 9, 2019
…ncat-order

* upstream/master: (1532 commits)
  Ensure we have stack spilling support for the recently-added expression node `BoundReadOnlySpanFromArray` (dotnet#37057)
  Review feedback
  Avoid generating or emitting NullablePublicOnlyAttribute when no other nullable attributes are emitted (dotnet#37019)
  Respond to more feedback
  Fixes from feedback
  Call `.WithoutNullability()` less
  Fix ngen for assets from nuget
  Make NullableWalker aware of calls to Interlocked.CompareExchange
  fix error
  Update AnonymousObjectCreation implementation to be more robust to errors by using MemberIndexOpt. Address minor PR comments.
  Add support to ngen assets included from nuget package
  Modified node removal to keep original leading trivia
  Fix Solution.WithDocumentFilePath not updating the file path of the tree
  Improve docs.
  PR Feedback cleanup.
  Use pattern-matching in MetadataWriter for readability and possibly performance. (dotnet#36219)
  Renamed helpers in SyntaxFactsService.
  More RefactoringHelpers tests (mostly for extraction).
  Add general tests for RefactoringHelpersService.
  Optimize flow analysis assembly
  ...
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.

Avoid emitting NullablePublicOnlyAttribute when no other nullable attributes are emitted

4 participants