-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add support for inout lifetime dependence #80452
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
Conversation
@swift-ci test |
…atibleOwnership to inferLifetimeDependenceKind
@swift-ci test |
@swift-ci test |
@swift-ci test |
@@ -631,6 +631,7 @@ function(_compile_swift_files | |||
|
|||
list(APPEND swift_flags "-enable-experimental-feature" "NonescapableTypes") | |||
list(APPEND swift_flags "-enable-experimental-feature" "LifetimeDependence") | |||
list(APPEND swift_flags "-enable-experimental-feature" "InoutLifetimeDependence") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to keep adding experimental feature flags to the stdlib command line? Can't this be a non-experimental "baseline" feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the experimental feature to ensure old compilers that recognize LifetimeDependence
feature but don't have support for @lifetime(&arg)
to parse the new stdlib interface containing this new syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should support the syntax as a baseline feature but only make it an error to use borrow
for an inout
argument under the experimental flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the feature flag, I understand now that it is only meant to protect against an older compiler parsing the new stdlib interface. Any code outside the stdlib that uses MutableSpan simply needs to be updated--we don't expect that to be a problem in practice.
@@ -8171,6 +8171,9 @@ ERROR(lifetime_dependence_invalid_inherit_escapable_type, none, | |||
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none, | |||
"invalid use of borrow dependence with consuming ownership", | |||
()) | |||
ERROR(lifetime_dependence_cannot_use_default_escapable_consuming, none, | |||
"invalid lifetime dependence on Escapable value with %0 ownership", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be consistent with using full grammar:
dependence on an Escapable value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic! Just a couple questions...
lib/AST/LifetimeDependence.cpp
Outdated
diagnose(loc, diag::lifetime_dependence_invalid_inherit_escapable_type, | ||
descriptor.getString()); | ||
return std::nullopt; | ||
} | ||
return kind; | ||
return parsedLifetimeKind == ParsedLifetimeDependenceKind::Inherit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be more self-documenting as a switch over ParsedLifetimeDependenceKind instead of code that does not mention Inout
, which is really they thing being handled specially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@@ -631,6 +631,7 @@ function(_compile_swift_files | |||
|
|||
list(APPEND swift_flags "-enable-experimental-feature" "NonescapableTypes") | |||
list(APPEND swift_flags "-enable-experimental-feature" "LifetimeDependence") | |||
list(APPEND swift_flags "-enable-experimental-feature" "InoutLifetimeDependence") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should support the syntax as a baseline feature but only make it an error to use borrow
for an inout
argument under the experimental flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stdlib changes are as expected. Thanks!
@swift-ci test |
Add support for spelling lifetime dependencies on mutable sources as
@lifetime(&arg)
. Previously this was spelled as@lifetime(borrow arg)
and caused some confusion to developers. This is purely a syntactic change and does not change how these dependencies are represented in SIL.rdar://146310571