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

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

Merged
merged 3 commits into from
Jul 9, 2019

Conversation

cston
Copy link
Member

@cston cston commented Jul 5, 2019

Fixes #36977

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

cston commented Jul 5, 2019

@dotnet/roslyn-compiler please review.

@@ -456,6 +469,12 @@ private void EnsureEmbeddableAttributeExists(EmbeddableAttributes attribute, Dia
{
SetNeedsGeneratedAttributes(attribute);
}

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

@RikkiGibson RikkiGibson Jul 5, 2019

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

Copy link
Contributor

@RikkiGibson RikkiGibson Jul 5, 2019

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
Member 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"));
Copy link
Member

@333fred 333fred Jul 8, 2019

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
Member 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)

Copy link
Member

@333fred 333fred left a comment

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.

@@ -28,6 +28,7 @@ public partial class CSharpCompilation
/// </summary>
private Symbol[] _lazyWellKnownTypeMembers;

private bool _usesNullableAttributes;
private int _needsGeneratedAttributes;
private bool _needsGeneratedAttributes_IsFrozen;
Copy link
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
Member 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
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?

Copy link
Member Author

@cston cston Jul 9, 2019

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)

@@ -255,18 +255,6 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok
_state.SpinWaitComplete(CompletionPart.FinishValidatingReferencedAssemblies, cancellationToken);
break;

case CompletionPart.StartMemberChecks:
Copy link
Member

@jcouv jcouv Jul 9, 2019

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
Member 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
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
Member 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)

Copy link
Member

@jcouv jcouv left a comment

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