Skip to content

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

Merged
merged 8 commits into from
Apr 4, 2025

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Apr 1, 2025

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

@meg-gupta
Copy link
Contributor Author

@swift-ci test

…atibleOwnership to inferLifetimeDependenceKind
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta requested review from atrick and glessard and removed request for ahoppen, hborla, hamishknight and eeckstein April 3, 2025 17:06
@@ -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")
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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",
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

@atrick atrick left a 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...

diagnose(loc, diag::lifetime_dependence_invalid_inherit_escapable_type,
descriptor.getString());
return std::nullopt;
}
return kind;
return parsedLifetimeKind == ParsedLifetimeDependenceKind::Inherit
Copy link
Contributor

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.

Copy link
Contributor Author

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")
Copy link
Contributor

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?

Copy link
Contributor

@glessard glessard left a 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!

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta enabled auto-merge April 4, 2025 00:33
@meg-gupta meg-gupta merged commit 50ea777 into swiftlang:main Apr 4, 2025
4 of 5 checks passed
meg-gupta added a commit that referenced this pull request Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants