Skip to content

Sema: Correct composition of property wrappers. #26326

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

jckarter
Copy link
Contributor

@jckarter jckarter commented Jul 24, 2019

Fixes rdar://problem/53407949 | SR-11138. Previously, we'd only look at the outermost property wrapper to decide whether the wrapped property's getter and setter were mutating (or exist at all). In reality, this requires considering the semantics of the composed accesses of each wrapper layer's wrappedValue property. Fixing this systematically addresses a number of issues:

  • As SR-11138 reported, composing a nonmutating-get-set wrapper ought to produce a composed wrapper that's nonmutating.

  • We would previously allow a property wrapper with a mutating getter to be nested inside one with only a getter, even though the resulting implementation was unsound (because there's no mutable context for the inner wrapper to execute its get on.)

  • Similarly, we would construct unsound setters in cases where the setter can't exist, such as when the nested wrapper isn't settable but the outer wrapper is.

@jckarter jckarter requested a review from DougGregor July 24, 2019 03:39
@jckarter jckarter force-pushed the property-wrapper-composition-mutatiness branch 2 times, most recently from 11b365e to cc94dd3 Compare July 25, 2019 19:47
@jckarter jckarter force-pushed the property-wrapper-composition-mutatiness branch from cc94dd3 to 84ad55c Compare July 26, 2019 21:34
@jckarter jckarter changed the title [WIP] Fix property wrapper mutatiness Sema: Correct composition of property wrappers. Jul 26, 2019
@jckarter jckarter requested a review from slavapestov July 26, 2019 21:36
@jckarter jckarter marked this pull request as ready for review July 26, 2019 21:36
@jckarter
Copy link
Contributor Author

@swift-ci Please test

// mutating-ness of either the getter or setter, since we need both to
// perform a writeback cycle.
case Mutating:
if (Setter == DoesntExist) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need a special case? If the setter is DoesntExist, std::max() will always end up returning DoesntExist, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose not. It seems worth calling this out as a specific rule, though.

Fixes rdar://problem/53407949 | SR-11138. Previously, we'd only look at the outermost property wrapper to decide whether the wrapped property's getter and setter were `mutating` (or exist at all). In reality, this requires considering the semantics of the composed accesses of each wrapper layer's
`wrappedValue` property. Fixing this systematically addresses a number of issues:

- As SR-11138 reported, composing a nonmutating-get-set wrapper ought to produce a composed wrapper
  that's nonmutating.

- We would previously allow a property wrapper with a mutating getter to be nested inside one with
  only a getter, even though the resulting implementation was unsound (because there's no mutable
  context for the inner wrapper to execute its get on.)

- Similarly, we would construct unsound setters in cases where the setter can't exist, such as when
  the nested wrapper isn't settable but the outer wrapper is.
@jckarter jckarter force-pushed the property-wrapper-composition-mutatiness branch from 84ad55c to fa4dd15 Compare July 26, 2019 23:10
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 84ad55c3af86597e07001d63b1ef85066fec7167

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 84ad55c3af86597e07001d63b1ef85066fec7167

@jckarter
Copy link
Contributor Author

@swift-ci Please test source compatibility

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