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

Call EnsureSufficientExecutionStack in PrintMembers #54967

Merged
merged 2 commits into from
Jul 21, 2021

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Jul 20, 2021

@RikkiGibson RikkiGibson marked this pull request as ready for review July 20, 2021 17:34
@RikkiGibson RikkiGibson requested a review from a team as a code owner July 20, 2021 17:34
@RikkiGibson
Copy link
Contributor Author

@dotnet/roslyn-compiler for review on a fairly small records change.

@jcouv jcouv self-assigned this Jul 20, 2021
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 2)

@RikkiGibson
Copy link
Contributor Author

@dotnet/roslyn-compiler for a second review

@@ -131,6 +131,18 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState,
return;
}
block = ArrayBuilder<BoundStatement>.GetInstance();

if (!ContainingType.IsRecordStruct)
Copy link
Member

@alrz alrz Jul 21, 2021

Choose a reason for hiding this comment

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

Could we only do this when there's actually a cycle in declaration? afaik it's possible to determine statically.
(And if true, I wonder why a warning is not a viable option in such declarations?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

afaik it's possible to determine statically.

We can determine if a cycle is possible. We speculate that in some situations where a cycle is possible it will be irritating to warn the user on the basis of the declaration alone. For example, if a mutable record field is of an 'object' or interface type, the value in the field could be some record that leads back to the original record, and we stack overflow.

We are considering several possible strategies for how to warn on a cyclic record, since ideally we would deliver something which is a warning by default in new .NET projects, and would strongly prefer that the warnings occur only in "something is definitely wrong" scenarios.

We also don't have to worry about derived records as much with this strategy. For example, a derived record doesn't need to insert a potentially "redundant" call to EnsureSufficientExecutionStack, and it doesn't need to be suspicious that at runtime its base class may contain different private fields than it did at compile time, for example. It can simply assume that its base record derived from object does the check.

@T3sT3ro
Copy link

T3sT3ro commented Aug 30, 2023

Has this been backported or something to the version that Unity uses? I encountered this problem today in the Unity, and it would be nice to have it, but I assume what they can do alone is limited without the work in the roslyn itself. Correct me if I'm wrong, I'm not sure how it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants