Just copying a relevant insight I had here:
Semantically, all the issues of fileprivate
conformances are shared by this example we can produce today:
// Module A
extension UInt: Collection { ... } // the numbers from 0 to `self`
// Module B
extension UInt: Collection { ... } // powers of 2 in self's representation
// Module C, File1.swift
import A
...
// Module C, File2.swift
import B
...
As long as nobody else imports A
or B
, the conformance from A
is effectively private to File1.swift, and the one from B
is effectively private to File2.swift, so the above would be equivalent to:
// Module C, File1.swift
extension UInt: fileprivate Collection { ... } // the numbers from 0 to `self`
...
// Module C, File2.swift
extension UInt: fileprivate Collection { ... } // powers of 2 in self's representation
...
Similarly, the semantic issues of internal
conformances are shared by this example:
// Module A
extension UInt: Collection { ... } // the numbers from 0 to `self`
// Module A1, all files
import A
// Module B
extension UInt: Collection { ... } // powers of 2 in self's representation
// Module B1, all files
import B
which (as long as nobody else imports A
or B
), would be equivalent to:
// Module A1
extension UInt: internal Collection { ... } // the numbers from 0 to `self`
// Module B1
extension UInt: internal Collection { ... } // powers of 2 in self's representation
Scoped conformances provide the ability to eliminate:
- module
A
- module
B
- all the metadata associated with exposing those conformances publicly
The latter goal was the original motivation for this pitch.
[Of course all of this depends on the idea that I understand the intended semantics of distinct imports in different files of the same module, which is currently probably buggy]