-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Comment out apparently dead code in src\System.Private.Xml\System.Pri… #18395
Conversation
…vate.Xml.sln N.B. This is purely for code review
@@ -1150,7 +1150,7 @@ public class DerivedTypeWithDifferentOverrides : BaseType | |||
|
|||
new public string Name3 { get; set; } | |||
|
|||
new internal string Name4 { get; set; } | |||
// new internal string Name4 { get; set; } |
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.
I expect this is the likely cause of all of the build failures.
// private String DefaultFunction() | ||
// { | ||
// return "Default Function"; | ||
// } |
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.
Typically functions like this are used via reflection. Do we know they're not being used?
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.
Unless there is code coverage anything accessed via reflection will be missed
Assert.True(Enumerable.SequenceEqual(value.HexBinaryContent, actual.HexBinaryContent), "Actual HexBinaryContent was not as expected."); | ||
} | ||
// [Fact] | ||
// static void Xml_TypeWithTypesHavingCustomFormatter() |
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.
Looks like this test should have been public and should be changed to be public rather than being deleted.
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.
cc: @shmao
@@ -85,6 +85,6 @@ public override IEnumerator GetEnumerator() | |||
return list.GetEnumerator(); | |||
} | |||
|
|||
private object debuggerDisplayProxy { get { return index < 1 ? null : (object)new XPathNavigator.DebuggerDisplayProxy(Current); } } | |||
// private object debuggerDisplayProxy { get { return index < 1 ? null : (object)new XPathNavigator.DebuggerDisplayProxy(Current); } } |
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.
This is being used, by the DebuggerDisplay attribute. Please be very careful about deleting things like this. We should really have tests that validate such attributes, as we do in other projects.
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.
cc: @sepidehms
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.
Found similar issues when I deleted 18.5k lines of Roslyn which is why I flagged the branch as for review only. The other issues with Roslyn were regression (code should have been called), partial implementation (specifically of tests), non-conditional compilation.
return Mode == SerializationMode.ReflectionOnly || Mode == SerializationMode.ReflectionAsBackup; | ||
} | ||
} | ||
// private static bool ReflectionMethodEnabled |
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.
The name of this suggests it might be used by code somewhere via reflection. Do we know it's not?
Thanks, @zebmason. I'll let @krwq, @sepidehms, and @shmao comment on whether this is something we'd like to do. In general, we're happy to see dead code removed, but if we do go ahead with it, we'd want to see it deleted rather than just commented out. We also need to be very careful about the deletions; some of them are actually not dead, and deleting them will result in problems, e.g. private members used by a debugger via reflection for debugger display attributes. |
@zebmason with any change it woudl also be good to build a few configurations locally (eg at least windows) before putting a PR up. :) |
@zebmason if you want to help us clean up some dead code, we have a tracking issue with action items here: #17905 Also please check out #17619 how best to help. Our contribution guidance is on our main page. |
Thanks I'll try to get this cleaned up next week. Unfortunately I've been nursing my build machine back to health over the last fortnight but I'm still switching to safe mode too often which kills my wi-fi and thus a lot of the tests. I had noticed that at the time of forking that not all tests were passing so I was more cavalier than normal. The tool I've written which detects the dead code is still producing too many false positives and has absolutely no idea when it comes to reflection. So the process is run - build/test - revert - build/test - revert... |
My motivation is the development of a tool that I'm currently working on. I'm happy to submit further changes to this project if you find that those changes are useful. Note that my build machine is still somewhat ill and thus a pull request may unfortunately cause tests to fail, which I will then try to address. When I was requested to split a large pull request for msbuild (so that it could be dealt with within that teams process) I instead offered to licence the tool to Microsoft but that was declined. i.e. I have no desire to do re-do grunt work. If you would like a beta version of the tool this is possible. |
This is unrelated to your change: #18431 |
@@ -1,4 +1,4 @@ | |||
// Licensed to the .NET Foundation under one or more agreements. | |||
// Licensed to the .NET Foundation under one or more agreements. |
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.
What's changing here and other places where the first line is showing as modified? Is the file's BOM changing?
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 could be, my code optionally re-writes the files to make the lines commented out (will change to deleted out during the week). I did copy some example C# code from a Microsoft help page on how to detect encoding but couldn't see anything about the BOM and wondered at the time what would happen. Suppose it could also be the line ending but obviously it happens in only one place. Time for a binary diff.
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.
After processing the file is now pre-pended with EF BB BF. i.e. the BOM for UTF-8 which was not there before.
@@ -27,9 +27,6 @@ namespace System.Xml.Serialization | |||
|
|||
internal class Compiler | |||
{ | |||
#if !XMLSERIALIZERGENERATOR | |||
private bool _debugEnabled = DiagnosticsSwitches.KeepTempFiles.Enabled; | |||
#endif |
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.
@krwq, @sepidehms, are there any builds where we don't set XMLSERIALIZERGENERATOR? I'm wondering if we could remove the define across the codebase.
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.
The tool takes in a series of defines so I never set this hence why it was detected as unused.
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.
@stephentoub XMLSERIALIZERGENERATOR
is used when we build SGen on core, Microsoft.XmlSerializer.Generaton
.
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.
We don't set XMLSERIALIZERGENERATOR in any of the System.Private.Xml builds. Some of the Xml code is being referenced by Microsoft.XmlSerializer.Generator and that contract sets this define. In this case, looks like System.Private.Xml is no longer using this bool and it can be removed.
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.
@sepidehms Thanks, I think this means that the code is shared between projects and thus my tool is operating in an unsafe manner and shouldn't have detected this. i.e. I have some work to do
@@ -84,7 +84,5 @@ public override IEnumerator GetEnumerator() | |||
{ | |||
return list.GetEnumerator(); | |||
} | |||
|
|||
private object debuggerDisplayProxy { get { return index < 1 ? null : (object)new XPathNavigator.DebuggerDisplayProxy(Current); } } |
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.
As I previously commented, this must not be deleted. It's being used by the debugger display attribute... see the attribute on the type declaration.
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.
Sorry I meant to add to my main message that the merge should be done by someone who knows what they are doing, hence why I left in such things to ensure that it would flag as a bad merge
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.
How does removing this flag it as a bad merge?
I'm unclear as to the purpose of this PR. Did you intend to get it into a state where we could simply hit the Merge button in GitHub? Or was your goal here just to highlight code that could potentially be deleted but expect this PR to be closed rather than merged?
Thanks.
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.
The purpose of the PR was for a review rather than a merge as I don't have the background to determine whether something is truly unused. i.e. due to regressions, partially implemented code, used only in the debugger, etc.
So I expected someone with the appropriate competence to fork my branch, review and revert as appropriate then merge. Does that sound sensible?
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.
@zebmason got it. I think probably the most likely way to take such changes would be for you to open an issue pointing at your tool. We can have a list of libraries with a checkbox for each, simliar to https://github.com/dotnet/corefx/issues/17905. Then anyone interested can try it out and clean up a PR for a library.
If your tool could read the existing ILLinkTrim.xml files that would make it easier as those could be used to help avoid false positives. if it makes sense, flags on the tool might make it easier to select modes that are more "reliable"
Speaking for the full time contributors on this project, we'd certainly like to remove dead code where it exists but after the recent cleanup of the worst cases it's not something we're likely to get to anytime soon. So setting up an issue for community folk to look at if interested would be best. They are likely to start there rather than volunteer to clean up a PR from someone else.
Does that sound reasonable?
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.
Also as you see in the others issue it would be very handy if it could find dead shared code across assemblies as ILLink cannot.
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.
BTW please don't take this as discouragement... it would certainly help the project to remove more dead code. We'd welcome help doing that.
I'm going to close as we don't want to continue with this PR as is. I certainly encourage contributions as suggested above. Thanks for this. |
…vate.Xml.sln
N.B. This is purely for code review purposes. Let me know if this is useful as I did a rather large commit for Roslyn using the same tool - dotnet/roslyn#17630