Skip to content
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

Replace dependsOn with @lifetime #76834

Merged
merged 11 commits into from
Oct 9, 2024

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Oct 2, 2024

  • Adds support for specifying the target for lifetime dependence with : @lifetime(target: source1...source)

  • Delete dependsOn syntax

  • Update all tests with dependsOn with @lifetime

@meg-gupta meg-gupta force-pushed the lifetimedepmultiple branch 5 times, most recently from 53895b6 to 3a82b2c Compare October 3, 2024 19:18
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta force-pushed the lifetimedepmultiple branch from 3a82b2c to dd27ef6 Compare October 3, 2024 20:19
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta force-pushed the lifetimedepmultiple branch 4 times, most recently from 03843d4 to cb1f841 Compare October 4, 2024 22:23
@meg-gupta
Copy link
Contributor Author

@swift-ci test

Lifetime dependencies will now be represented with @Lifetime attribute in the language.

dependsOn is a type modifier and was represented as a LifetimeDependentTypeRepr in the AST.

I am deleting dependsOn syntax parsing support and retaining LifetimeDependentTypeRepr support.

We may want to represent lifetime dependencies in a function type with a type attribute in the future.
If we use a decl attribute instead, then support for LifetimeDependentTypeRepr can be deleted.
@meg-gupta meg-gupta force-pushed the lifetimedepmultiple branch from cb1f841 to 5e88075 Compare October 7, 2024 07:37
@meg-gupta
Copy link
Contributor Author

@swift-ci test

loc, diag::lifetime_dependence_cannot_use_inferred_scoped_consuming);
return LifetimeDependenceKind::Scope;
}
if (type->isEscapable() && !isBitwiseCopyable(type, ctx)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an !isBitwiseCopyable check here that didn't used to be. I'm not sure why. We cannot inherit a lifetime from a BitwiseCopyable thing.

auto lParenLoc = consumeToken();

std::optional<LifetimeDescriptor> targetDescriptor;
if (Tok.isAny(tok::identifier, tok::integer_literal, tok::kw_self) &&
Copy link
Member

Choose a reason for hiding this comment

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

I just want to clarify. Is @lifetime(self: something) and @lifetime(1: something) considered valid syntax? Because the latter won’t parse in the new parser since 1 is not a valid argument label.

Copy link
Contributor Author

@meg-gupta meg-gupta Oct 8, 2024

Choose a reason for hiding this comment

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

We were planning to use integer indices in the case of dependsOn especially for function types which may not have parameter names. @lifetime(1: 0) doesn't read as well as a positional dependsOn(0) would. We likely can delete support for integer target indices. SIL tests still use the positional @lifetime with integer index for source. I'll follow with a separate PR for this.

Copy link
Member

Choose a reason for hiding this comment

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

I would be in favor of deleting integer target indices.


if (!Tok.isFollowingLParen()) {
diagnose(Tok, diag::expected_lparen_after_lifetime_dependence);
if (!Tok.isFollowingLParen()) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you disallow spaces between the attribute name and the (, similar to what I did in #71237?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I am now using consumeAttributeLParen()

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.

This all looks good to me, except the one comment about BitwiseCopyable. I barely skimmed the syntax support since I'm not familiar with that. It looks like @ahoppen reviewed that part, thanks!

@Lifetime(target: source1, source2...) where target can be any
parameter or 'self'. We cannot have @Lifetime attributes with duplicate targets.

Also, update the internal data structures. Previously LifetimeEntry stored
pairwise (target, source) dependencies. Now, LifetimeEntry will store an optional
target descriptor and an array of source descriptors.
Lifetime dependencies in SIL tests continue to be represented as a type modifier on the target.

As before, they are represented as a LifetimeDependentTypeRepr in the AST.
@meg-gupta meg-gupta force-pushed the lifetimedepmultiple branch from 5e88075 to 2711434 Compare October 8, 2024 22:22
SIL's @Lifetime continues to be positional. Don't parse 'target:' in this case.
@meg-gupta
Copy link
Contributor Author

@ahoppen swiftlang/swift-syntax#2876 deletes dependsOn support in swift-syntax

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta merged commit 4df55a1 into swiftlang:main Oct 9, 2024
5 checks passed
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