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

Specially handle more scenarios for type parameters with 'allows ref struct' constraint #73059

Merged

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

@AlekseyTs AlekseyTs requested a review from a team as a code owner April 17, 2024 00:18
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 17, 2024

[Theory]
[CombinatorialData]
public void AnonymousDelegateType_01_ActionDisallowsRefStruct(bool s2IsRefStruct)
Copy link
Contributor

@jjonescz jjonescz Apr 17, 2024

Choose a reason for hiding this comment

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

Consider testing a scenario where we infer delegate type from a method with a parameter that has a default value (so we are forced to synthesize a delegate type for that) - the resulting synthesized delegate type should have T : allows ref struct even if it's not used with a ref struct or "allows ref struct" type parameter. (And it should not have that constraint on Net7.) #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider testing a scenario where we infer delegate type from a method with a parameter that has a default value (so we are forced to synthesize a delegate type for that) - the resulting synthesized delegate type should have T : allows ref struct even if it's not used with a ref struct or "allows ref struct" type parameter. (And it should not have that constraint on Net7.)

I do not find this scenario interesting. Constraints on type parameters do not depend on specific type arguments used for specific call sites. Effects of default values and specific types involved into specific signature are not related to each other. In my opinion the added tests adequately cover affected code paths and various flavors of generic anonymous delegate types. Please let me know if you disagree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, there is a test with a pointer type, which is not a ref struct.

@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review.

2 similar comments
@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review.

@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review.

get { return false; }
get
{
return _container.IsDelegateType() && _container.Manager.Compilation.SourceAssembly.RuntimeSupportsByRefLikeGenerics;
Copy link
Member

@cston cston Apr 19, 2024

Choose a reason for hiding this comment

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

Manager.Compilation.SourceAssembly

Consider simplifying to ContainingAssembly. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Manager.Compilation.SourceAssembly

Consider simplifying to ContainingAssembly.

Will do for the next PR.

@cston
Copy link
Member

cston commented Apr 19, 2024

        comp.VerifyDiagnostics(

The original test (before S2<T2> was added) reported warnings only. Consider splitting the S2<T2> case into a separate test, and for this test, use VerifyEmitDiagnostics() to verify we can successfully emit the other cases, even if not supported. #Resolved


Refers to: src/Compilers/CSharp/Test/Emit3/RefStructInterfacesTests.cs:17484 in 26c51ef. [](commit_id = 26c51ef, deletion_comment = False)

var comp = CreateCompilation(src, targetFramework: s_targetFrameworkSupportingByRefLikeGenerics, options: TestOptions.ReleaseExe);

var verifier = CompileAndVerify(
comp, expectedOutput: ExecutionConditionUtil.IsMonoOrCoreClr ? @"<>F`2[S1,S2] Test1 S1" : null,
Copy link
Member

@cston cston Apr 19, 2024

Choose a reason for hiding this comment

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

ExecutionConditionUtil.IsMonoOrCoreClr ? @"<>F`2[S1,S2] Test1 S1" : null

Consider adding a helper method for this pattern, for example RefFieldTests.IncludeExpectedOutput(). #WontFix

namespace System
{
public delegate void Action<T1, T2>(T1 x, T2 y);
}
Copy link
Member

@cston cston Apr 19, 2024

Choose a reason for hiding this comment

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

Do we need both this definition and TargetFramework.Net70? Same question for the next test. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need both this definition and TargetFramework.Net70? Same question for the next test.

I prefer to explicitly set up the desired test environment.

@AlekseyTs
Copy link
Contributor Author

AlekseyTs commented Apr 19, 2024

        comp.VerifyDiagnostics(

The original test (before S2<T2> was added) reported warnings only. Consider splitting the S2<T2> case into a separate test, and for this test, use VerifyEmitDiagnostics() to verify we can successfully emit the other cases, even if not supported.

Will do in the next PR


In reply to: 2066991719


Refers to: src/Compilers/CSharp/Test/Emit3/RefStructInterfacesTests.cs:17484 in 26c51ef. [](commit_id = 26c51ef, deletion_comment = False)

@AlekseyTs AlekseyTs merged commit 1841565 into dotnet:features/RefStructInterfaces Apr 19, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Feature - RefStructInterfaces untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants