Skip to content

SILGen: Don't emit key path descriptors for properties with mutating getters [4.2] #15250

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,10 @@ static bool doesPropertyNeedDescriptor(AbstractStorageDecl *decl) {
if (!decl->getGetter())
return false;

// If the getter is mutating, we cannot form a keypath to it at all.
if (decl->isGetterMutating())
return false;

// TODO: If previous versions of an ABI-stable binary needed the descriptor,
// then we still do.

Expand Down
13 changes: 13 additions & 0 deletions test/SILGen/keypath_property_descriptors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,18 @@ public struct A {
internal subscript<T>(d x: T) -> T { return x }
fileprivate subscript<T>(e x: T) -> T { return x }
private subscript<T>(f x: T) -> T { return x }

// no descriptor
public var count: Int {
mutating get {
_count += 1
return _count
}
set {
_count = newValue
}
}

private var _count: Int = 0
}