# Constrain protocol usage outside the module

**URL:** <https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832>\
**Category:** Pitches\
**Created:** [January 25, 2018, 9:03am UTC](https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832 "2018-01-25T09:03:18Z")\
**Posts on this page:** 1\
**Showing post:** 72

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [January 31, 2018, 5:21pm UTC](https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832/72 "2018-01-31T17:21:26Z")

</div>

> [@DevAndArtist](#):
>
> I understand your point, but to be fair, that is not true at all. If this statement were true then public enums with no public API and with no cases would also be elided by the compiler. Yet we have Never in stdlib.

I must be botching my message. Let me restate again: I’m arguing that protocols are fundamentally different from types precisely because you would never elide a type, not even (as you point out) an uninhabitable type. This is why I argue it’s entirely consistent for classes not to be open by default and protocols to behave differently.

> [@DevAndArtist](#):
>
> At the point of the proposal of Never if closed protocols have existed already then who knows if we’d now have public protocol Never {} (closed is implied).

We would definitely not have that, and for at least three reasons:

- A “closed” (now called “frozen”) enum as envisioned can never have any cases if it does not currently have cases. What you call a “closed” protocol is only forbidden from ever having _external_ cases. When the design is completed, we will be able to guarantee for all time that `public frozen enum Never` will always be uninhabited. But in your design it would be possible for a later version of the standard library to conform a type to `public protocol Never`. That is not a suitable design for a bottom type.

- An existential `P` does not conform to protocol `P`. However, in a completed implementation of a type system with a bottom type, the bottom type would conform to all protocols. We’d never be able to complete a design where `Never` is both a protocol and a bottom type. This cannot even be improved by somehow making `P` conform to `P`: the protocol `P` would not be at the bottom of the hierarchy because the existential type `P` would then conform to it. In other words, the bottom type must always be a type and not a protocol. Except, with this protocol-based design, you would have both a bottom type and an identically named extraneous protocol `P` to which it conforms with no particular purpose.

- `Never` receives no special treatment from the compiler. Any uninhabitable type behaves identically to `Never`. You can demonstrate this for yourself by creating your own enum with no cases: you will find that you can use that type in place of `Never`. Even if the theoretical barriers above did not exist, it would not change the fact that enums with no case are uninhabitable and therefore a way of expressing the bottom type. It would not make sense to introduce new syntax to enable a second way to express the same thing.

This is all to demonstrate, in a different setting, how types and protocols differ in some fundamental ways.

---

_[View the full topic](https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832)._
