-
Notifications
You must be signed in to change notification settings - Fork 388
Add skipautoprops feature #912
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
Merged
MarcoRossignoli
merged 3 commits into
coverlet-coverage:master
from
MarcoRossignoli:skipautoprops
Aug 3, 2020
+217
−168
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
test/coverlet.core.tests/Coverage/CoverageTests.AutoProps.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Coverlet.Core.Samples.Tests; | ||
using Xunit; | ||
|
||
namespace Coverlet.Core.Tests | ||
{ | ||
public partial class CoverageTests | ||
{ | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void SkipAutoProps(bool skipAutoProps) | ||
{ | ||
string path = Path.GetTempFileName(); | ||
try | ||
{ | ||
FunctionExecutor.Run(async (string[] parameters) => | ||
{ | ||
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<AutoProps>(instance => | ||
{ | ||
instance.AutoPropsNonInit = 10; | ||
instance.AutoPropsInit = 20; | ||
int readVal = instance.AutoPropsNonInit; | ||
readVal = instance.AutoPropsInit; | ||
return Task.CompletedTask; | ||
}, | ||
persistPrepareResultToFile: parameters[0], skipAutoProps: bool.Parse(parameters[1])); | ||
|
||
return 0; | ||
}, new string[] { path, skipAutoProps.ToString() }); | ||
|
||
if (skipAutoProps) | ||
{ | ||
TestInstrumentationHelper.GetCoverageResult(path) | ||
.Document("Instrumentation.AutoProps.cs") | ||
.AssertNonInstrumentedLines(BuildConfiguration.Debug, 12, 12) | ||
.AssertLinesCoveredFromTo(BuildConfiguration.Debug, 7, 11) | ||
.AssertLinesCovered(BuildConfiguration.Debug, (13, 1)); | ||
} | ||
else | ||
{ | ||
TestInstrumentationHelper.GetCoverageResult(path) | ||
.Document("Instrumentation.AutoProps.cs") | ||
.AssertLinesCoveredFromTo(BuildConfiguration.Debug, 7, 13); | ||
} | ||
} | ||
finally | ||
{ | ||
File.Delete(path); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/coverlet.core.tests/Samples/Instrumentation.AutoProps.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Coverlet.Core.Samples.Tests | ||
{ | ||
public class AutoProps | ||
{ | ||
private int _myVal = 0; | ||
public AutoProps() | ||
{ | ||
_myVal = new Random().Next(); | ||
} | ||
public int AutoPropsNonInit { get; set; } | ||
public int AutoPropsInit { get; set; } = 10; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One reason I use explicit backing fields is to prevent the overhead of frequent method calls. It's probably bad for performance
Uh oh!
There was an error while loading. Please reload this page.
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 think that autoprops are inlined by jitter, take a look here https://sharplab.io/#v2:C4LghgzgtgPgAgJgIwFgBQcDMACR2DC2A3utmbjvgBQCUp5Ja5z2ACgE4D2ADhNgLzYkABgDc9MgF8JFbAEsAdsDZdexAOYBTYKIjbR0tIfTosuBNgCy6Rsxlm4AFmwAVTRGC0ZtlmUIBjAWwFTQB3AlpxJl9cJABOKn8AOg4eCBoo5kk7I3QgA=
Also I agree in case of hot loops, but here this properties are accessed only one time on msbuild task usage.
What do you think?
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.
@jkotas, sorry to bother you, can you confirm that autoprops are inlined by jitter?
Uh oh!
There was an error while loading. Please reload this page.
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 was referring more to the general case because we're targeting .NET standard. Inlining of auto props is an implementation detail of the JIT, at least I don't recall it being in the CLI spec. Do we have any plans to support other runtimes beyond .NET Core?
Uh oh!
There was an error while loading. Please reload this page.
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 support .NET Framework at the moment(not yet on collectors but I'm waiting some answer from vstest team). In this case(inlining apart) I would prefer clean syntax over perf...I mean this code is called only one time for asm, we spend a lot of time on IL instrumentation(I think mangnitude orders), btw I won't oppose if you prefer custom back field, let me know!It was instinctive from my side 😄
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.
Any runtime where performance matters will inline auto-properties just fine. It is certainly the case for both .NET Framework and .NET Core.
If you wanted to optimize for hypothetical runtimes that are missing basic optimizations, your code would look very unnatural. You would want to e.g. prefer public fields over properties, minimize number of methods and making methods as big as possible, etc. It does not sounds like a good idea.