-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
3f42b5c
to
ec71a0c
Compare
@dotnet/roslyn-compiler for review on a fairly small records change. |
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.
LGTM Thanks (iteration 2)
@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) |
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.
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?)
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.
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.
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. |
Related to dotnet/roslyn-analyzers#5068
Related to dotnet/csharplang#4951
Related to #48646