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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

{
var ensureStackMethod = F.WellKnownMethod(
WellKnownMember.System_Runtime_CompilerServices_RuntimeHelpers__EnsureSufficientExecutionStack,
isOptional: true);
if (ensureStackMethod is not null)
{
block.Add(F.ExpressionStatement(
F.Call(receiver: null, ensureStackMethod)));
}
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11395,17 +11395,17 @@ protected virtual bool PrintMembers(System.Text.StringBuilder builder)

CheckEncLog(reader1,
Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
Row(19, TableIndex.TypeRef, EditAndContinueOperation.Default),
Row(20, TableIndex.TypeRef, EditAndContinueOperation.Default),
Row(21, TableIndex.TypeRef, EditAndContinueOperation.Default),
Row(22, TableIndex.TypeRef, EditAndContinueOperation.Default),
Row(4, TableIndex.TypeSpec, EditAndContinueOperation.Default),
Row(3, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
Row(10, TableIndex.MethodDef, EditAndContinueOperation.Default)); // R.PrintMembers

CheckEncMap(reader1,
Handle(19, TableIndex.TypeRef),
Handle(20, TableIndex.TypeRef),
Handle(21, TableIndex.TypeRef),
Handle(22, TableIndex.TypeRef),
Handle(10, TableIndex.MethodDef),
Handle(3, TableIndex.StandAloneSig),
Handle(4, TableIndex.TypeSpec),
Expand Down
Loading