[5.9] Fix ManagedValue::isPlusOne for addresses #65644
Merged
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.
Explanation: Fix ManagedValue::isPlusOne for addresses.
In some cases, SILGen would reuse an address value after it was
consumed. This is incorrect according to SIL's memory
rules. In-memory values cannot be reused after deinitialization.
Change this API to return false for address values that don't have a
cleanup and therefore cannot be destroyed.
Scope of Issue: Before this fix, memory verification catches the
incorrect SIL that SILGen produces for resilient enums that require
a protocol conformance thunk for initialization. For example:
public protocol ObjectProtocol {
static func entityReference(_ id: EntityIdentifier) -> Self
}
public enum Object : ObjectProtocol {
case entityReference(EntityIdentifier)
}
If we don't fix this, then SIL verification will continue to assert
for real-world code. SIL verification is currently disabled by
default for release compilers, but we rely on it for testing and
triage.
Risk: SILGen could potentially generate more copies, but they would
be cheap copies. We don't know of any cases where this would be a
problem. This was discused among the team and determined that we
don't want to allow SILGen to perform optimizations where memory is
reused after it is deinitialized. Performance improved after this
change in many more benchmarks that it regressed.
PR to main: Fix SILGen ManagedValue::isPlusOne for addresses #65579
Reviewed By: Joe Groff and Michael Gottesman
Resolves: rdar://108001491 (SIL verification failed: Found mutating or
consuming use of an in_guaranteed parameter?!:
!ImmutableAddressUseVerifier().isMutatingOrConsuming(fArg))