-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Property delegates as custom attributes #23701
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
Property delegates as custom attributes #23701
Conversation
e51404e
to
7f0096e
Compare
@DougGregor Would it be possible to have a toolchain created to play around with Property Delegates? I'd like to use them to improve a library Im working on as a way to test them out. |
@hartbit let me make sure things are back in a working state now, and once they are I'll build a toolchain. I just got to the point where they work end-to-end, so long as you don't touch |
4a265c1
to
d53d93f
Compare
That's a lot of toolchains 😂 |
@swift-ci please please please please please build toolchain |
@swift-ci please build toolchain |
@swift-ci please smoke test |
@swift-ci build toolchain |
@swift-ci build toolchain Linux |
@swift-ci please smoke test Linux |
2fad2c9
to
8f39205
Compare
@swift-ci please smoke test |
@swift-ci please build toolchain |
d2fcc35
to
7cac37a
Compare
@swift-ci please test |
@swift-ci please build toolchain |
Build failed |
Build failed |
@swift-ci please smoke test macOS |
With the implementation in the toolchain, the @propertyDelegate
struct DelayedMutable<Value> {
private var _value: Value? = nil
var value: Value {
get {
guard let value = _value else {
fatalError("property accessed before being initialized")
}
return value
}
set {
_value = newValue
}
}
/// "Reset" the delegate so it can be initialized again.
mutating func reset() {
_value = nil
}
}
class Foo {
@DelayedMutable var x: Int
init() {
// We don't know "x" yet, and we don't have to set it
} // error: Return from initializer without initializing all stored properties
func getX() -> Int {
return x // Will crash if 'self.x' wasn't initialized
}
} Is this known? |
@hartbit ah, thank you! that should be |
@DougGregor The |
@hartbit The |
Used for property delegates.
Nonmutating setters for properties with attached delegates inside value-semantic types cause SIL verifier errors. Avoid performing DI on them for now.
ASan is magic. Thank you, ASan.
… type. Fixes the crash-on-invalid in rdar://problem/49982937.
…ibutes When a custom attribute is given a direct initializer, save and re-use the initializer context we create so that it can be associated with the enclosing pattern binding. Fixes assertions involving explicit closures in property delegates.
When we encounter a custom attributes on a property (via a pattern binding), visit those custom attributes. Provides basic indexing support.
And... another rebase is incoming. |
ba095ef
to
faa176f
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
…ivate. When the property delegate type overrides the delegate value by providing a delegateValue property, name the backing storage $$foo and make it private.
@swift-ci please smoke test and merge |
@swift-ci please smoke test and merge |
@DougGregor - sigh this broke the windows build :-( https://dev.azure.com/compnerd/windows-swift/_build/results?buildId=1697 |
This is an implementation of property delegates as custom attributes, under discussion in this pitch thread. The implementation is mostly complete, although there are some annoying known bugs:
lazy
is similarly broken and always has been!)