Add regression test for EnC nullable attribute assertion during unmodified type completion #80657
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #79320
Problem
During Edit and Continue (EnC) compilation, when a modified method calls a method in an unmodified type, the compiler needs to complete the unmodified type (e.g., to check if the called method is virtual). During type completion, if the type has members with nullable annotations, the compiler attempts to ensure
NullableContextAttribute
exists by callingEnsureEmbeddableAttributeExists
withmodifyCompilation: true
.This could trigger an assertion failure:
The assertion fires because the
_needsGeneratedAttributes_IsFrozen
flag may already be set when completing unmodified types during EnC delta compilation.Solution
The code already has the correct fix through special handling in
PEModuleBuilder.GetNeedsGeneratedAttributesInternal()
:When compiling an EnC delta (
PEDeltaAssemblyBuilder
), we passfreezeState: false
, which prevents the Compilation's_needsGeneratedAttributes_IsFrozen
flag from being set. This allows late completion of unmodified types without triggering the assertion.Changes
This PR adds a regression test
NullableContextAttribute_UnmodifiedTypeCompletion
that:NullableContextAttribute
generation)Testing
EditAndContinueTests
continue to pass with no regressionsFollow-up
As mentioned in the issue, a benchmark test should be added to the
dotnet/performance
repository to measure EnC performance and ensure the performance gains from #71254 are maintained. This will be tracked separately as it requires work in a different repository.Original prompt
This section details on the original issue you should resolve
<issue_title>Assertion fails in CSharpCompilation.EnsureEmbeddableAttributeExists when compiling EnC delta</issue_title>
<issue_description>Repro:
see #79320
Assertion:
Debug.Assert(!modifyCompilation || !_needsGeneratedAttributes_IsFrozen);
Values:
Call stack: