-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support access level on import statements #1683
Conversation
This feels like a lot of overlap with #1393 that added I'm also not sure this can be done on a per module bases. If a given @FranzBusch @gjcairo your thoughts in this space since I think you were the ones to look the most at the impl only support. |
It can't as such Swift code wouldn't compile, however, to me this is simply a misconfiguration. But yeah I could add some validation steps if that's required.
That's right. Basically, the access level you can use depends on the level of types you generate. We could go further and make We could introduce
Any configurations that would produce invalid Swift code could either be validated or left to fail in compile-time. The choice is yours. |
I don't think I immediately see how this is how this is a per module decision then, seems like it would make more sense to module model it just a single option since it has to line up with the generated access level. Maybe even just a boolean to say if access level imports should be generated and they should then be inferred from the generated access level? |
This would restrict what you can do with access level on imports. @_exported public import ModuleWithReExportedProtos
public import ModuleWithProtosWithPublicVisibility
import InternalProtos
struct ProtoGeneratedAsinternal {
var a: MessageFromReExportedModule
var b: MessageFromPublicModule
var c: MessageFromInternalModule
} |
I agree with @thomasvl here that I also don't fully see how this can be done on a per module level. In your last example why would you publicly import a module if the generated protos are internal? Can't we simply this and say that the generated access level should match the import access level? (Taking |
We can't because the import access level means much more. You may still want to expose your transitive dependencies differently. Imagine a scenario like this:
Now, because you're using The same is if you additionally wish to re-export In the future the So this is module-based, you decide how each dependency is exposed to the end-client. |
Can you post a small SwiftPM package example showing the case you say is getting a warning? You should be able to do it with some trivial sources that don't involve protos, just basic Swift. It would be safer to make sure everyone is considering the same cases when discussion things. Is the warning the same between Swift 5.x and Swift 6? It's possible the compiler has tweaked the behavior between versions. I'm also sorta curing about the mention of implicit in that error message. It makes me wonder if an explicit |
I think that's the key here and I wasn't aware that restriction existed. Now that makes total sense. The access level of imports is checked module wide and not on a per file basis. |
Oh, I have missed that, yes explicit internal solves this! Thanks, for pointing that out!
True, but I've just found out they're reducing it to the most visible declaration, and they only validate that declarations are not relying on imports with a lower access. And I've found this in the proposal as a confirmation, and it works in the code too!
Ok, I think we can go with a simpler approach here as was suggested. Would you like me to modify this PR? |
Yes please. I think we can just match the generated access level |
Done ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you squash the commits since I don't think we need the first one any more since it is a different approach?
I think you might be able to make some examples in https://github.com/apple/swift-protobuf/tree/main/PluginExamples by explicitly enabling the features in the Package.swift` files to actually have checked usages of this. Does it still work with 5.8 or does it need newer Swift versions to allow us to do that?
It's available since Swift 5.9, but you need to enable it manually in the hosting package/project. swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport"),
.enableUpcomingFeature("InternalImportsByDefault") // optionally this too
] |
eef4b77
to
aaa453d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated and applied all your remarks, please take a look.
I've also noticed that the |
I've missed fixing some switch expressions to compile for Swift 5.8, it should be all now. |
it now fails on
not sure why, the target is there 🤔 |
@thomasvl can we try re-triggering the CI? This works locally for me. |
Triggered a rerun of the failed one and it failed again. |
…s level on import statements
… the protoc plugin is compiled with, update docs to explain interoperability of UseAccessLevelOnImports and ImplementationOnlyImports
2c65dd3
to
ea48eb9
Compare
…xpressions (introduced Swift 5.9)
ea48eb9
to
3f34c41
Compare
Thank you! |
This PR brings in the possibility to define access level on import statements generated through
ProtoPathModuleMappings
plugin option.Access level on import statements is a new feature of Swift 6, but it can already be enabled in Swift 5.9 builds.
See https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md