again, i should reiterate, most users aren’t compiler engineers and so most people use access modifiers as a means of code organization. being able to diagnose when a “private” symbol is being referenced from somewhere it shouldn’t be is very important; the linking and mangling details should be handled by the compiler underneath all of that.
On Mon, Oct 2, 2017 at 11:45 PM, Slava Pestov <spes...@apple.com> wrote: > > On Oct 2, 2017, at 9:15 PM, Xiaodi Wu <xiaodi...@gmail.com> wrote: > > > On Mon, Oct 2, 2017 at 22:23 Slava Pestov <spes...@apple.com> wrote: > >> On Oct 2, 2017, at 8:06 PM, Xiaodi Wu <xiaodi...@gmail.com> wrote: >> >> On Mon, Oct 2, 2017 at 9:55 PM, Slava Pestov <spes...@apple.com> wrote: >> >>> >>> On Oct 2, 2017, at 7:52 PM, Kelvin Ma <kelvin1...@gmail.com> wrote: >>> >>> Is this only a problem with fileprivate or does it extend to private >>> members too? I feel like this would be a very valuable feature to support. >>> >>> >>> Private members too. Consider this example, >>> >>> struct S { >>> private func f() {} >>> } >>> >>> The member S.f mangles as _T06struct1SV1f33_ >>> AB643CAAAE0894CD0BC8584D7CA3AD23LLyyF. In this case, I suppose we won’t >>> need the private discriminator because there can only be one S.f that’s >>> directly a member of S, and not an extension. However imagine if two >>> different source files both defined extensions of S, with a private member >>> f. You would need to disambiguate them somehow. >>> >> >> The simple-minded way to do this would be to require @_versioned >> annotations on private and fileprivate members to supply an internally >> unique alternative name to be used for mangling-as-though-internal (i.e. >> `@_versioned(my_extension_f)`). Such a function becoming public in an >> ABI-compatible way would require renaming the "actual" name to the unique >> @_versioned name. >> >> >> We have _silgen_name for that, but we really don’t want to expose this >> more generally because people have been abusing it to make things visible >> to C, and they should be using @_cdecl instead. >> > > The difference here would be that the "@_versioned name" would be subject > to mangling. It's essentially equivalent to a way of specifying a custom > discriminator to be hashed so that the source file name is omitted and not > ABI. Not that I think it'd be elegant, but it would not be abusable like > _silgen_name. > > > That wouldn’t solve the problem where removing @_versioned(name) and > adding public would change the symbol’s name. > > However, your idea of mangling versioned private symbols like internal and > diagnosing conflicts might be workable. > > Slava > > > >> A more elegant refinement could be to have @_versioned private and >> fileprivate members mangled as though internal, erroring if two or more >> members with the same name are both @_versioned--would that work? >> >> >> If you’re going to do that what is the value in having the capability at >> all? >> > > Solely to have some way of preventing members in one file from calling > members in another file at compile time. > > >
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution