-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Lifetimes: handle MutableSpan reassignment and 'inout' arguments #85076
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
@swift-ci test |
0775f96 to
2b0c452
Compare
Contributor
Author
|
@swift-ci test |
2b0c452 to
febad34
Compare
Handle applies that reassign the lifetime of their operand vs. the value of their operand.
Allow diagnosing values that have no relevant users. Such as an @inout argument.
Handle cases where there's no relevant operand.
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.
Fixes rdar://157796728 ([nonescapable] [miscompile] No diagnostic error when an inout MutableSpan is reassigned to a different lifetime source)
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 { ... }
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 `unwind` but fail to actually materialize that end_access.
febad34 to
630f28d
Compare
Contributor
Author
|
@swift-ci test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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