<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-07-10 14:05 GMT+09:00 Xiaodi Wu <span dir="ltr">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This would be very useful, but the spelling needs dramatic improvement.<br><br>&quot;Available unavailable&quot; is already challenging to read, but at least it is learnable with time. The example where &quot;@available(*, deprecated, access: internal) open&quot; means &quot;fileprivate&quot; is entirely unreasonable.<br><br></blockquote><div><br></div><div>I agree, but I couldn&#39;t come up with a better spelling.</div><div><br></div><div><font face="monospace, monospace">// &quot;deprecated&quot; if the access is from &quot;outside&quot; of &quot;fileprivate&quot; scope.</font></div><div><font face="monospace, monospace">@available(*, deprecated, outside: fileprivate) </font><span style="font-family:monospace,monospace">open</span></div><div><div><br></div></div><div>Hmm.. 🤔</div><div><br></div><div>Any suggestions will be greatly appreciated!</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><div><div class="gmail-m_465776830666725481m_5773591088566474201gmail-h5"><div dir="ltr">On Sun, Jul 9, 2017 at 22:40 rintaro ishizaki via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-m_465776830666725481m_5773591088566474201gmail-h5"><div dir="ltr">Hi evolution community,<div><br></div><div>I would like to propose &quot;Scoped @available&quot; attribute.</div><div><br></div><div>What I want to achieve is to declare something that is publicly unavailable, but still usable from narrower scope. A concrete example is <font face="monospace, monospace">IndexableBase</font> in the standard library:</div><div><div><a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift#L18-L20" target="_blank">https://github.com/apple/swift<wbr>/blob/master/stdlib/public/cor<wbr>e/Collection.swift#L18-L20</a><br></div><div>Workaround for this problem in stdlib is to use <font face="monospace, monospace">typealias</font> to underscored declaration. However, we can&#39;t use this technique in our module because underscored declarations are still visible and usable from outside.</div><div><br></div></div><div>As a solution, I propose to add <font face="monospace, monospace">&quot;access&quot;</font> parameter to <font face="monospace, monospace">@available</font> attribute, which limits the effect of <font face="monospace, monospace">@available</font> attribute to the specified value or outer.<br><br></div><div>---</div><div><font face="monospace, monospace">// Module: Library<br><br>/// This protocol is available for internal, but deprecated for public.<br>@available(*, deprecated, access: public, message: &quot;it will be </font><span style="font-family:monospace,monospace">removed</span><font face="monospace, monospace"> in future&quot;)<br>public protocol OldProtocol {<br>    /* ... */<br>}<br><br>public Foo: OldProtocol { // No diagnostics<br>}</font></div><div><font face="monospace, monospace"><br></font><div>---</div><font face="monospace, monospace">// Module: main</font></div><div><font face="monospace, monospace"><br>import Library<br><br>public Bar: OldProtocol { // warning: &#39;OldProtocol&#39; is deprecated: it will be removed in future<br>}</font></div><div><font face="monospace, monospace"><br></font></div><div><div>---</div></div><div><br></div><div>I think this is useful when you want to stop exposing declarations, but want to keep using them internally.</div><div><br></div><div>More examples:</div><div><br></div><div><font face="monospace, monospace">// is `open`, going to be `filerprivate`</font></div><div><font face="monospace, monospace">@available(*, deprecated, access: internal)</font></div><div><font face="monospace, monospace">open class Foo {}</font></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">// was `internal`, now `private`</font></div><div><font face="monospace, monospace">@available(*, unavailable, access: fileprivate)</font></div><div><font face="monospace, monospace">var value: Int</font></div><div><font face="monospace, monospace"><br></font></div></div><div><font face="monospace, monospace">// No effect (invisible from public anyway): emit a warning</font></div><div><div><font face="monospace, monospace">@available(*, unavailable, access: public)</font></div><div><font face="monospace, monospace">internal struct Foo {}</font></div></div><div><br></div><div>What do you think?</div></div></div></div>
______________________________<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>
</blockquote></div>
</blockquote></div><br></div></div>