Lifetimes: handle MutableSpan reassignment and 'inout' arguments #85076
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.
Fix miscompilations involving MutableSpan.
[NFC] add a new entry point for DiagnoseDependence.reportError
Allow diagnosing values that have no relevant users. Such as an @inout argument.
[NFC] LifetimeDependenceDefUseWalker.inoutDependence entry point
Handle cases where there's no relevant operand.
[NFC] Add ApplySite.fullyAssigns(Operand) query
Fix LifetimeDependenceDefUseWalker for @inout reassignment
Extend AddressInitializationWalker.findSingleInitializer
Handle applies that reassign the lifetime of their operand vs. the value of
their operand.
LocalVariableReachableAccess: handle lifetime reassignment
A ~Escapable inout apply operand that does not propagate its own lifetime can be
treated as being assigned a new lifetime in the caller.
@Lifetime(arg: copy source)
func foo<T: ~Escapable>(arg: inout T, source: T) {
arg = source
}
A call to 'foo' initializes the lifetime of 'arg', thereby ending the lifetime
of the previous value.
[NFC] Rename ArgumentConventions.parameterIndex(ofArgumentIndex:)
[NFC] Add ApplySite.parameterDependence(target:source:)
Fix LifetimeDependenceDefUseWalker to follow inout dependence
Fixes rdar://157796728 ([nonescapable] [miscompile] No diagnostic error when an
inout MutableSpan is reassigned to a different lifetime source)
[NFC] LocalVariableAccessInfo.description
LocalVariableUtils add non-escaping closure capture support
Don't always consider an inout_aliasable argument to have
escaped. AccessEnforcementSelection has already done that analysis and left
begin_access [dynamic] artifacts if the argument has escaped in any meaningful
way. Use that information to
Essential for supporting autoclosures that call mutating methods on span-like
things. Such as UTF8Span.UnicodeScalarIterator.skipForward():
e.g. while numSkipped < n && skipForward() != 0 { ... }
[NFC] extend AddressInitializationWalker to report address reads
Fix LocalVariableReachableAccess to handle potential reassignment.
Define LocalAccessInfo._isFullyAssigned to mean that the access does not read
the incoming value. Then treat any assignment that isn't full as a potential read.
LocalVariableUtils: precisely handle function live-out
Only record an outgoingArgument access when the current allocation is an
outgoing argument and the function exiting instruction is ReturnInst.
This avoids invalid SIL where we attempt to extend end_access up to an
unwindbutfail to actually materialize that end_access.
Test lifetime reassignment
Test noescape closure capture lifetimes
Update tests for local variable reachability for debug output
Update lifetime tests for improved diagnostics