<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Marc,<div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 11, 2015, at 3:06 AM, Marc Knaup via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hey guys,<div class=""><br class=""></div><div class="">I'm working on a proposal and the question arose why the declaration modifier <font face="monospace, monospace" class="">indirect</font> can only be specified for the whole enum <font face="monospace, monospace" class="">case</font> and the whole <font face="monospace, monospace" class="">enum</font> but not for the actual parameter which is indirect.</div><div class=""><br class=""></div><div class="">I.e. is there any technical reason which would prevent something like the following?</div><div class=""><br class=""></div><div class=""><ol class="" style="border: 0px; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; line-height: 1.6em; list-style: none; font-family: Helvetica, Arial, sans-serif; background-repeat: initial initial;"><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background:transparent" class=""><code class="" style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;background:transparent"><span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background:transparent">enum</span> <span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">ArithmeticExpression</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background:transparent" class=""><code class="" style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;background:transparent"> <span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background:transparent">case</span> <span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">Number</span>(<span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">Int</span>)</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background:transparent" class=""><code class="" style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;background:transparent"> <span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background:transparent">case</span> <span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">Addition</span>(<span style="color:rgb(170,51,145);font-size:11.9px;line-height:22.4px" class="">indirect </span><span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">ArithmeticExpression</span>, <span style="color:rgb(170,51,145);font-size:11.9px;line-height:22.4px" class="">indirect </span><span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">ArithmeticExpression</span>)</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background:transparent" class=""><code class="" style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;background:transparent"> <span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background:transparent">case</span> <span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">Multiplication</span>(<span style="color:rgb(170,51,145);font-size:11.9px;line-height:22.4px" class="">indirect </span><span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">ArithmeticExpression</span>, <span style="color:rgb(170,51,145);font-size:11.9px;line-height:22.4px" class="">indirect </span><span class="" style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background:transparent">ArithmeticExpression</span>)</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background:transparent" class=""><code class="" style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;background:transparent">}</code></li></ol></div></div></div></blockquote><div class=""><br class=""></div><div class="">Right now, notice that direct and indirect cases look the same from the perspective of the type system.</div><div class=""><br class=""></div>With your proposal, the fact that the entire tuple payload can be matched by a pattern implies that ‘indirect’ has to become a formal type in the language, since you will now be able to write down a value of type '(indirect ArithmeticExpression, Int)’, for example. It also raises the issue of how these indirect values are wrapped and unwrapped, since now the ‘indirect ArithmeticExpression’ is itself a value.</div><div class=""><br class=""></div><div class="">An alternative is to make ‘indirect’ a non-materializable type, like ‘inout’. ‘inout’ can appear inside tuple types, but is not a first class value. This creates lots of special cases for ‘inout’ and you can imagine it will be equally difficult for ‘indirect’.</div><div class=""><br class=""></div><div class="">If you want an ‘indirect’ that can be nested inside a tuple type, you could just define ‘class Box<T> { let payload: T }’ and tolerate a bit of verbosity when wrapping and unwrapping values. As long as the payload is immutable, you will still have value semantics using this trick.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><br class=""></div><div class="">Also is there any technical reason which would prevent <font face="monospace, monospace" class="">indirect</font> from being used for structs?</div></div></div></div></blockquote><div class=""><br class=""></div>Like an ‘indirect’ modifier for stored properties on structs? Yes, this should be possible, however note that right now enum payloads are not themselves lvalues, which means that assignment of indirect enum cases only has to update the reference count of the box to maintain value semantics, since the contents of the box will never change. Presumably for structs you would need to be able to define an ‘indirect var’ with a mutable payload — immutable-only indirect stored properties don’t seem very useful.</div><div class=""><br class=""></div><div class="">Making the indirect payload mutable will require either copying the box upon assignment, or alternatively, a copy-on-write scheme could be used. The SIL @box type that implements indirect cases isn’t set up to support either of those right now. Also, unlike enums, indirect fields of structs won’t give you any new generality that was not possible before — its just a performance change. A value type that contains a cycle through an ‘indirect’ struct field is still invalid, for example, because the resulting type is still infinite.</div><div class=""><br class=""></div><div class="">Slava</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><br class=""></div>Thanks,</div><div class=""> Marc</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=NLTid1W7V2mxBEfr5Y3KfTntaxSmOQp5vjACZc9Eh1-2FH-2Fej3R0Z4mS437WqlI1ZHGDmechBex8wNnLcJAHS6eiylKs3WYt15t33yHp9mn7CB7YyRdAiuVdlIEZ5ZSycYp-2FI-2Fye5YAEe-2BJ4JGvHQKwIkodfRQ4j1PO0QRgL5XH9IBuZwtywxGv6RtPHTbFFl-2FWHkI317MHZLEjSP5REx3kUUnTjy4X4Zqh4JcvTGKFv0-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""></div></blockquote></div><br class=""></div></body></html>