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

Struct layout check – break an infinite generic expansion cycle that doesn’t include the target struct (a cycle at the end of the path) #75702

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

AlekseyTs
Copy link
Contributor

Fixes #66844

…doesn’t include the target struct (a cycle at the end of the path)

Fixes dotnet#66844
@AlekseyTs AlekseyTs requested a review from a team as a code owner November 1, 2024 15:28
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 1, 2024
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

3 similar comments
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@@ -219,6 +219,196 @@ public void GenericStructWithPropertyUsingStruct()
Diagnostic(ErrorCode.ERR_StructLayoutCycle, "P").WithArguments("S<T>.P", "S<T[]>?").WithLocation(3, 13));
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/66844")]
public void InstanceMemberExplosion_01()
Copy link
Member

@jjonescz jjonescz Nov 6, 2024

Choose a reason for hiding this comment

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

Consider testing ref structs with ref fields. #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 ref structs with ref fields.

Wy do you think this will be interesting in context of this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Ref fields cannot cause cycles in the struct layout, but I think an error would be reported today. However, since ref to ref struct is an error anyway, it's probably fine, and unrelated to the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion this scenario is not interesting for the purpose of this PR regardless whether ref fields are considered as a possible source of cycle. Because this PR doesn't change what fields are looked at. It simply ensures we do not infinitely expand types in the process.

@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For the second review.

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For the second review.

@jaredpar jaredpar requested a review from cston November 7, 2024 17:08
@jaredpar
Copy link
Member

jaredpar commented Nov 7, 2024

@cston for second review.

struct D<T>
{
static C<D<T>> x;
}
Copy link
Member

@cston cston Nov 8, 2024

Choose a reason for hiding this comment

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

Are we testing a mix of static and instance members? For instance:

struct C<T>
{
    static D<T> x;
}
struct D<T>
{
    C<D<T>> x;
}
``` #Resolved

Copy link
Contributor Author

@AlekseyTs AlekseyTs Nov 8, 2024

Choose a reason for hiding this comment

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

Are we testing a mix of static and instance members? For instance:

These are not interesting in context of the problem we are facing because cycles across static and instance fields are detected separately and by different methods.
Cycles between static and instance fields never intersect.

Copy link
Member

Choose a reason for hiding this comment

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

The example above currently compiles, but peverify fails, and the native compiler reports a cycle. Do we need to log an issue?

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 to log an issue?

Please do, we can investigate in more details later..

Copy link
Member

Choose a reason for hiding this comment

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

}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/66844")]
Copy link
Member

@cston cston Nov 8, 2024

Choose a reason for hiding this comment

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

#66844

Are these static cases affected by this issue? #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.

Are these static cases affected by this issue?

The scenario is not broken, if that is what you are asking. But I consider the test related to the issue.

{
// found a possibly expanding cycle, for example
// struct X<T> { public T t; }
// struct W<T> { X<W<W<T>>> x; }
// while not explicitly forbidden by the spec, it should be.
partialClosure.Add(on);
typesWithCycle.Add(type.OriginalDefinition);
Copy link
Member

Choose a reason for hiding this comment

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

typesWithCycle.Add

Are there any examples where typesWithCycle willl have more than one item?

Copy link
Contributor Author

@AlekseyTs AlekseyTs Nov 8, 2024

Choose a reason for hiding this comment

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

Are there any examples where typesWithCycle willl have more than one item?

I see nothing preventing that. If that is what you are asking.

Copy link
Member

Choose a reason for hiding this comment

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

If it's possible, it would be useful to have a test that has multiple entries in typesWithCycle, to prevent us from changing this to a single value in the future.

@AlekseyTs AlekseyTs enabled auto-merge (squash) November 11, 2024 23:50
@AlekseyTs
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jjonescz jjonescz added this to the 17.13 P2 milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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.

Stack overflow due to struct layout cycle
4 participants