Accessor effect of member subscripts #1825
Replies: 4 comments 4 replies
|
IIUC currently the variant of a member subscript bundle couples the two knobs, as if having public conformance Array: Collection {
...
public subscript(self: inout Self, _ position: Int): Element {
let { ... }
inout { ... }
}
}The obvious limitation of this is that it limits us to fixing the access variant of public conformance Array: Collection {
...
public subscript(self: inout Self, _ position: Int): Element {
let Self, let yield { ... }
inout Self, set yield { ... }
set Self, set yield { ... }
...
}
}I don't know what effect would this have on the varaint selection algorithm, but I suspect it won't be happy. |
|
I will explain what the new front-end does, because I think I reached a more principled model that is also simpler to describe. Functions and subscripts can be declared in bundles. In source syntax that is signaled by declaring the effect of the call operator to be The variant that will be used when referring to a bundle depends on the way the result of the bundle is used. The decision happens in two steps:
The parameters of a bundle can be declared Nothing more sophisticated happens for members, since the effect of the call is implicitly the effect of the receiver. For example, if We cannot control the two "knobs" independently because there are only so many ways we can direct inference to select a specific variant automatically. |
Surely you mean that x is a let parameter. |
|
One variant that cannot currently be spelled in this model is the one that produces an In fact I think it may be important for simply iterating over the elements of the slice or for that matter any immutable collection, since the iterator needs to be both bound to the lifetime of the collection and mutated. IIUC the current workaround is to “project” the mutable thing as an |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Method Bundles
We can annotate methods defined in a method bundle of a struct with
sink,let,inout, (maybeset?) to define the access for the implicitselfparameter (the receiver):Free subscript bundles
Free subscripts can also be declared in a bunfle, but IIUC there we indicate the access of the yielded value. In the standard library I only found
letaccessors in bundles, and this instance. I don't know why these cannot be in one bundle. Also, why would be there a need foryielded& what does that mean exactly?Subscript bundle as a member
It's also possible to define member subscripts:
To me it seems that we ought to have both control knobs in this case: controlling whether we take
selfasinout/let/sink, and whether the projected value is projected asinout/let.What is happening in the current design? What's the reason for not exposing both of these knobs? E.g. why shouldn't we have member subscripts that yield a
setvalue but take the receiver asinout?This might be a related discussion: https://github.com/orgs/hylo-lang/discussions/1061
All reactions