Skip to content

Bugfix SmartParameter source code generation#2041

Merged
adamsitnik merged 3 commits intodotnet:masterfrom
mawosoft:fix-SmartParamBuilder
Jul 21, 2022
Merged

Bugfix SmartParameter source code generation#2041
adamsitnik merged 3 commits intodotnet:masterfrom
mawosoft:fix-SmartParamBuilder

Conversation

@mawosoft
Copy link
Contributor

@mawosoft mawosoft commented Jul 17, 2022

SmartParameter codegen must use the target type for casting, not the type of the source value.
Basically, this is a follow up to PR #1228 (1678a49), which fixed this problem for SmartArgument.
EDIT: Fixes #2011. Probably also #1812 and a few similar issues reported in the past.
Fixes #2011, fixes #1812, fixes #1177.

@adamsitnik
Not sure yet if the fix is complete or if the shortcuts in SmartParamBuilder.CreateForParams() that bypass the creation of SmartParameter instances have to be removed. Same for BenchmarkConverter.GetValidValues().
(test failures are unrelated, though)

SmartParameter codegen must use the target type for casting, not the type of the source value.
Basically, this is a follow up to PR dotnet#1228 (1678a49), which fixed this problem for SmartArgument.
Fixes dotnet#2011.
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

@mawosoft overall it looks good to me, but could you please add a test that verifies the fix?

https://github.com/dotnet/BenchmarkDotNet/blob/master/tests/BenchmarkDotNet.IntegrationTests/ArgumentsTests.cs

@mawosoft
Copy link
Contributor Author

@adamsitnik
Should the tests go into ArgumentsTests or did you mean that as a template for more thoroughly tests? There are also these

https://github.com/dotnet/BenchmarkDotNet/blob/master/tests/BenchmarkDotNet.IntegrationTests/ParamSourceTests.cs

https://github.com/dotnet/BenchmarkDotNet/blob/master/tests/BenchmarkDotNet.IntegrationTests/ParamsAttributeStaticTest.cs

https://github.com/dotnet/BenchmarkDotNet/blob/master/tests/BenchmarkDotNet.IntegrationTests/ParamsTests.cs

As I said, I have to take a second look to see if the fix is complete, but with added tests, I should get an answer to this.

@adamsitnik
Copy link
Member

Just adding a failing test to one of the mentioned files should be enough

Copy link
Contributor Author

@mawosoft mawosoft left a comment

Choose a reason for hiding this comment

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

@adamsitnik I added some tests, should be ready for review now.
I didn't rebase this branch, so the NativeAOT test failures will still pop up.

Comment on lines +170 to +171
// - TODO op_Explicit is currently not supported by InProcessEmitToolchain (See TryChangeType() in Toolchains/InProcess.Emit.Implementation/Runnable/RunnableReflectionHelpers.cs)
public static explicit operator TargetType(PublicSource @this) => @this != null ? new TargetType(@this.Data) : null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if op_Explicit support should be added to TryChangeType().

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

Overall looks great, as soon as you remove the reflection, I am going to merge it!

Thanks for writing so many tests @mawosoft ! 👍

PR fixes the following issues: fixes dotnet#2011, fixes dotnet#1812, fixes dotnet#1177.
@mawosoft mawosoft requested a review from adamsitnik July 20, 2022 18:10
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

:shipit: ! thank you one more time @mawosoft !

@adamsitnik adamsitnik merged commit e4ff20f into dotnet:master Jul 21, 2022
@adamsitnik adamsitnik added this to the v0.13.x milestone Jul 21, 2022
@adamsitnik adamsitnik modified the milestones: v0.13.x, v0.13.2 Jul 21, 2022
@mawosoft mawosoft deleted the fix-SmartParamBuilder branch July 21, 2022 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants