<div dir="ltr">On Fri, Aug 5, 2016 at 2:46 AM, rintaro ishizaki <span dir="ltr"><<a href="mailto:fs.output@gmail.com" target="_blank">fs.output@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">2016-08-05 16:20 GMT+09:00 Xiaodi Wu <span dir="ltr"><<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span>On Fri, Aug 5, 2016 at 2:06 AM, rintaro ishizaki <span dir="ltr"><<a href="mailto:fs.output@gmail.com" target="_blank">fs.output@gmail.com</a>></span> wrote:<br></span><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span><div style="font-size:14px">> ```</div><div style="font-size:14px">> extension MemoryLayout {</div><div style="font-size:14px">> static func size(ofValue _: T) -> Int { return MemoryLayout.size }</div><div style="font-size:14px">> // etc.</div><div style="font-size:14px">> }</div><div>> ```</div><div><br></div></span><div><div>I don't think we can do this while we have:</div><div><br></div></div><div><div><font face="monospace, monospace"> public static var size: Int {</font></div></div></div></blockquote><div><br></div></span><div>Why not?</div></div></div></div></blockquote><div><br></div></span><div>My bad. Sorry, never mind. </div><div>I didn't know we can have such overloads (property and func, same basename) :O</div></div></div></div></blockquote><div><br></div><div>As I mentioned above, it's not only possible but already used in the standard library. For instance, `first` and `first(where:)` for Collection types.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">maybe `<span style="font-size:14px"><font face="monospace, monospace">sizeOf(value _: T) -> Int</font></span>` ?<div><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-08-04 11:28 GMT+09:00 Xiaodi Wu via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>On Wed, Aug 3, 2016 at 8:47 PM, Erica Sadun via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>> On Aug 3, 2016, at 2:43 PM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
><br>
> Having seen the effects in the standard library and in other<br>
> code, I'm concerned that we may have made a mistake in removing<br>
> `sizeofValue` et al without providing a replacement. In the standard<br>
> library, we ended up adding an underscored API that allows<br>
><br>
> MemoryLayout._ofInstance(someE<wbr>xpression).size<br>
><br>
> Where someExpression is an autoclosure, and thus not evaluated. I<br>
> wanted to bring up the possibility of introducing a replacement as a<br>
> bufix.<br>
><br>
> I propose that the way to express the above should be:<br>
><br>
> MemoryLayout.of(type(of: someExpression)).size<br>
><br>
> implementable as:<br>
><br>
> extension MemoryLayout {<br>
> @_transparent<br>
> public<br>
> static func of(_: T.Type) -> MemoryLayout<T>.Type {<br>
> return MemoryLayout<T>.self<br>
> }<br>
> }<br>
><br>
> I think this API would solve the concerns I had about confusability that<br>
> led me to advocate dropping the ability to ask for the size of a value.<br>
> The only way to use it is to pass a type and these two expressions have<br>
> equivalent meaning:<br>
><br>
> MemoryLayout<Int><br>
> MemoryLayout.of(Int.self)<br>
><br>
> It also has the benefit of isolating the autoclosure magic to type(of:).<br>
><br>
> ,----[ Aside ]<br>
> | A slightly cleaner use site is possible with a larger API change:<br>
> |<br>
> | MemoryLayout(type(of: someExpression)).size<br>
> |<br>
> | Which would involve changing MemoryLayout from an `enum` to<br>
> | a `struct` and adding the following:<br>
> |<br>
> | extension MemoryLayout {<br>
> | public init(_: T.Type) {}<br>
> |<br>
> | public var size: Int { return MemoryLayout.size }<br>
> | public var stride: Int { return MemoryLayout.stride }<br>
> | public var alignment: Int { return MemoryLayout.alignment }<br>
> | }<br>
> |<br>
> | However I am concerned that dropping ".of" at the use site is worth the<br>
> | added API complexity.<br>
> `----<br>
><br>
> Thoughts?<br>
> --<br>
> -Dave<br>
<br>
<br>
</div></div>I don't think using "of" is a great burden.<br></blockquote><div><br></div></div></div><div>Agreed, but I do think "memory layout of type of my value, size" is a mouthful compared to "size of value". Moreover, something doesn't sit right with me that MemoryLayout<T> and MemoryLayout.of(T.self) would be one and the same thing.</div><div><br></div><div>Could I suggest an alternative? It's conservative in that it mimics the relationships we had before the proposal was implemented and also maintains the simplicity of the caseless enum:</div><div><br></div><div>```</div><div>extension MemoryLayout {</div><div> static func size(ofValue _: T) -> Int { return MemoryLayout.size }</div><div> // etc.</div><div>}</div><div>```</div><span><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><font color="#888888"><br>
-- E<br>
</font></span><div><div><br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
</div></div></blockquote></span></div><br></div></div>
<br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div></div></div><br></div></div>
</blockquote></div></div><br></div></div>
</blockquote></div><br></div></div>