Skip to content

Fix DiagnoseStaticExclusivity for lifetime dependent sub-objects#88595

Open
atrick wants to merge 1 commit intoswiftlang:mainfrom
atrick:fix-dependent-subobject
Open

Fix DiagnoseStaticExclusivity for lifetime dependent sub-objects#88595
atrick wants to merge 1 commit intoswiftlang:mainfrom
atrick:fix-dependent-subobject

Conversation

@atrick
Copy link
Copy Markdown
Contributor

@atrick atrick commented Apr 21, 2026

For example:

struct InoutPair: ~Escapable, ~Copyable {
  @_lifetime(self: &x)
  mutating func insertX(_ x: inout Int) {...}

  @_lifetime(self: &y)
  mutating func insertY(_ y: inout Int) {...}
}

struct Pair {
  var x: Int
  var y: Int

  mutating func run() {
    var inoutPair = InoutPair()
    inoutPair.insertX(&x)
    inoutPair.insertY(&y)

    take(inoutPair) // The access of both &x and &y are extended up to here
  }
}

In the Pair.run method, the accesses to &x and &y are overlapping because the
final value of inoutPair depends on both. Fix DiagnoseStaticExclusivity to
recognize that these accesses are to independent subobjects even though that
have a lifetime dependency.

Fixes rdar://175271283 ([exclusivity] handle simultaneous sub-object exclusivity
with lifetime dependencies)

We can consider a more robust design in the future:
rdar://175275018 ([nonescapable] create mark_dependence on the projection rather than the base)

But in the meantime, this problem basically makes it impossible to have dependencies on multiple sub-objects.

@atrick atrick requested a review from a team as a code owner April 21, 2026 19:27
@atrick
Copy link
Copy Markdown
Contributor Author

atrick commented Apr 21, 2026

@swift-ci test

@atrick atrick requested review from jckarter and tbkka April 21, 2026 19:29
@atrick
Copy link
Copy Markdown
Contributor Author

atrick commented Apr 21, 2026

I tagged a bunch of potential reviewers here because it's an easy one-line fix and I'm not sure who has time to look at it.

@atrick atrick requested a review from kavon April 21, 2026 19:40
For example:
```
struct InoutPair: ~Escapable, ~Copyable {
  @_lifetime(self: &x)
  mutating func insertX(_ x: inout Int) {...}

  @_lifetime(self: &y)
  mutating func insertY(_ y: inout Int) {...}
}

struct Pair {
  var x: Int
  var y: Int

  mutating func run() {
    var inoutPair = InoutPair()
    inoutPair.insertX(&x)
    inoutPair.insertY(&y)

    take(inoutPair) // The access of both &x and &y are extended up to here
  }
}
```

In the `Pair.run` method, the accesses to &x and &y are overlapping because the
final value of `inoutPair` depends on both. Fix DiagnoseStaticExclusivity to
recognize that these accesses are to independent subobjects even though that
have a lifetime dependency.

Fixes rdar://175271283 ([exclusivity] handle simultaneous sub-object exclusivity
with lifetime dependencies)
@atrick atrick force-pushed the fix-dependent-subobject branch from 80f23a5 to 014aef8 Compare April 21, 2026 20:38
@atrick
Copy link
Copy Markdown
Contributor Author

atrick commented Apr 21, 2026

@swift-ci test

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.

1 participant