Skip to content

Remove unused private members#61064

Merged
jcouv merged 22 commits intodotnet:mainfrom
Youssef1313:remove-unused
Jun 12, 2022
Merged

Remove unused private members#61064
jcouv merged 22 commits intodotnet:mainfrom
Youssef1313:remove-unused

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Apr 30, 2022

No description provided.

@Youssef1313 Youssef1313 requested review from a team as code owners April 30, 2022 10:49
@ghost ghost added Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Apr 30, 2022
}

[Obsolete("Use VisitCollectionElementInitializer(BoundCollectionElementInitializer node, TypeSymbol containingType, bool delayCompletionForType) instead.", true)]
private new void VisitCollectionElementInitializer(BoundCollectionElementInitializer node)
Copy link
Contributor

@cston cston May 1, 2022

Choose a reason for hiding this comment

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

VisitCollectionElementInitializer

It looks like this method was added intentionally, to catch cases where a specific method should be used instead. #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.

@cston I added it back, but I don't get what's the problem removing it. The Obsolete attribute will catch cases where this method shouldn't be used. But deleting it will also ensure that it's not used (because it doesn't exist in the first place)

I'd like to understand more what kind of issues can happen if this is removed. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

This method hides the base class method with the same signature. I believe this method definition is intended to prevent calling the base method.

}

[Obsolete("Use IsIncrementalAndFactoryContextMatches")]
private new bool IsIncremental
Copy link
Contributor

@cston cston May 1, 2022

Choose a reason for hiding this comment

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

IsIncremental

It looks like this property was added intentionally, to catch cases where IsIncrementalAndFactoryContextMatches should be used instead. #Closed

o1 OPERATOR s2, //-ObjectKIND
o1 OPERATOR o2 //-ObjectKIND" + Postfix;

private const string PostfixIncrementTemplate = Prefix + @"
Copy link
Contributor

@cston cston May 1, 2022

Choose a reason for hiding this comment

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

PostfixIncrementTemplate

Consider keeping (and perhaps comment out?) since there is a commented out reference in TestOperatorOverloadResolution(). #Closed

Assert.Same(varI102, varC204.Interfaces()[1]);
}

private void TestBaseTypeResolutionHelper3(AssemblySymbol[] assemblies)
Copy link
Contributor

@cston cston May 1, 2022

Choose a reason for hiding this comment

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

TestBaseTypeResolutionHelper3

Consider keeping (and commenting out?) since there is a commented out reference in Test1(). #Closed

Assert.IsAssignableFrom<MissingMetadataTypeSymbol>(arg);
}
}
// private void TestBaseTypeResolutionHelper3(AssemblySymbol[] assemblies)
Copy link
Member

@jcouv jcouv May 6, 2022

Choose a reason for hiding this comment

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

nit: consider commenting out with /* ... */ instead of // ... (as you did in some other tests) #Closed


#if DEBUG
#if DEBUG
#pragma warning disable IDE0051 // Remove unused private members
Copy link
Member

@jcouv jcouv May 6, 2022

Choose a reason for hiding this comment

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

Consider adding an Obsolete attribute and making the "unused member" analysis recognize the Obsolete attribute (ie. shouldn't complain). #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.

I'm not sure why this method would be obsolete? It can be used for debugging purposes right?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but we don't reference it from source. Typically we invoke it from EE.
Fine to leave as-is

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the case, pls consider adding a comment saying that this is invoked dynamically.

Partial Friend Class BoundSequencePointExpression

#If DEBUG Then
Private Sub Validate()
Copy link
Member

@jcouv jcouv May 6, 2022

Choose a reason for hiding this comment

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

We should probably add HasValidate="true" to BoundSequencePointExpression in VB's BoundNodes.xml instead #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.

Nice! I didn't know this was a thing!

{
private readonly Microsoft.CodeAnalysis.FindUsages.SourceReferenceItem _roslynSourceReferenceItem;

#pragma warning disable IDE0051 // Remove unused private members
Copy link
Member

@jcouv jcouv May 6, 2022

Choose a reason for hiding this comment

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

nit: How/where is this constructor used? #Closed

Copy link
Member Author

@Youssef1313 Youssef1313 May 22, 2022

Choose a reason for hiding this comment

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

It's not used. But I don't know if F# can be calling it via reflection or something?

Copy link
Member

Choose a reason for hiding this comment

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

Might be. Let's keep to be safe

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.

Done with review pass (iteration 13)

@jcouv jcouv self-assigned this May 6, 2022

<!-- Use this in the event that the sequence point must be applied to expression.-->
<Node Name="BoundSequencePointExpression" Base="BoundExpression">
<Node Name="BoundSequencePointExpression" Base="BoundExpression" HasValidate="true">
Copy link
Member Author

Choose a reason for hiding this comment

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

@333fred @jcouv @cston This is what causing the CI failure. This is what I see in the dump

image

The CompileMethod call in the stack trace is attempting to compile this method:

Public Function ParseSourceXml(sources As XElement,
parseOptions As VisualBasicParseOptions,
Optional ByRef assemblyName As String = Nothing,
Optional ByRef spans As IEnumerable(Of IEnumerable(Of TextSpan)) = Nothing) As IEnumerable(Of SyntaxTree)
If sources.@name IsNot Nothing Then
assemblyName = sources.@name
End If
Dim sourcesTreesAndSpans = From f In sources.<file> Select CreateParseTreeAndSpans(f, parseOptions)
spans = From t In sourcesTreesAndSpans Select s = t.spans
Return From t In sourcesTreesAndSpans Select t.tree
End Function

What happens is:

Public Overrides Function VisitSequencePointExpression(node As BoundSequencePointExpression) As BoundNode
Dim expression As BoundExpression = DirectCast(Me.Visit(node.Expression), BoundExpression)
Dim type as TypeSymbol = Me.VisitType(node.Type)
Return node.Update(expression, type)
End Function

node.Update is expecting expression.Type and type to be the same. type is originating from here:

Public NotOverridable Overrides Function VisitType(type As TypeSymbol) As TypeSymbol
If type Is Nothing Then
Return type
End If
Return type.InternalSubstituteTypeParameters(Me.TypeMap).Type
End Function

I'm unable to investigate that further :(

Debug.Assert(value.Type is { } && (value.Type.Equals(placeholder.Type, TypeCompareKind.AllIgnoreOptions) || value.HasErrors));
}

#if DEBUG
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be needed. If it's needed, that should be fixed in the analyzer. The analyzer shouldn't fire in a certain configuration for a method if the method is conditional and doesn't apply to that configuration.

Copy link
Member Author

@Youssef1313 Youssef1313 May 27, 2022

Choose a reason for hiding this comment

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

it looks like it can be removed if the callsite removed #if DEBUG too. I can make that update along with fixing the current failure (which feels a bit tricky to me :( )

Copy link
Member

Choose a reason for hiding this comment

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

If this is deemed to be an analyzer bug, I wouldn't make a further effort than what you have to work around it here, unless the change is very straightforward.

Let's just make sure we've filed the bug in the appropriate place. It would be good to add a comment linking to the bug wherever our workaround is (in this commit, it would be above the #if DEBUG here.)

Copy link
Contributor

@Neme12 Neme12 May 27, 2022

Choose a reason for hiding this comment

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

it looks like it can be removed if the callsite removed #if DEBUG too. I can make that update along with fixing the current failure (which feels a bit tricky to me :( )

Yes, but that seems like a workaround too. I feel like the analyzer should understand Conditional and not mark the member as unused if it's not even compiled.

EDIT: Oh, but the method is still compiled in release, even though it doesn't need to be.

@jcouv
Copy link
Member

jcouv commented May 27, 2022

Looks like there's a legitimate failure in Correctness_Build leg.

@Youssef1313
Copy link
Member Author

Youssef1313 commented May 27, 2022

@jcouv Yup. I've commented my observation, but unable to investigate further

@Youssef1313
Copy link
Member Author

@jcouv btw, the artifacts on CI don't contain a dump. I had to run eng/test-build-correctness.cmd -configuration Release -enableDumps to get a dump.

@jcouv
Copy link
Member

jcouv commented Jun 8, 2022

@Youssef1313 Any luck with the bootstrapping issue? I'll mark this PR as draft for now. Ping when ready for another look. Thanks

@jcouv jcouv marked this pull request as draft June 8, 2022 16:13
auto-merge was automatically disabled June 8, 2022 16:13

Pull request was converted to draft

@Youssef1313
Copy link
Member Author

@jcouv Not yet. I'll revert the change causing it and open an issue for it.

@Youssef1313 Youssef1313 marked this pull request as ready for review June 8, 2022 16:23
private const int NullableContextSize = 3;

private const int HasDeclaredRequiredMembersOffset = NullableContextOffset + NullableContextSize;
private const int HasDeclaredRequiredMembersSize = 2;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is currently unused. The next time a flag is added, this will need to be added back (so that the new flag offset will be the latest flag offset + latest flag size).

Let me know if you prefer a suppression?

Copy link
Member

Choose a reason for hiding this comment

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

How about commenting that line out?
@cston Do you have a preference?

Copy link
Contributor

Choose a reason for hiding this comment

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

Commenting the line out seems reasonable to me.

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

@jcouv
Copy link
Member

jcouv commented Jun 10, 2022

There still seems to be a bootstrapping issue in the correctness leg :-/

@Youssef1313
Copy link
Member Author

@jcouv I'll take another look to see what's going on. Converting to draft for now as I won't be able to do that soon.

@Youssef1313 Youssef1313 marked this pull request as draft June 10, 2022 16:42
@Youssef1313 Youssef1313 marked this pull request as ready for review June 12, 2022 14:58
@Youssef1313
Copy link
Member Author

@jcouv CI is green now! 🎉

@jcouv jcouv merged commit a528fe2 into dotnet:main Jun 12, 2022
@ghost ghost added this to the Next milestone Jun 12, 2022
@Youssef1313 Youssef1313 deleted the remove-unused branch June 12, 2022 18:26
@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
333fred added a commit to 333fred/roslyn that referenced this pull request Nov 8, 2025
This was removed in dotnet#61064, and broke visualization of BasicBlocks. I've restored it and left a comment indicating its current use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants