Skip to content

Commit d3ef09d

Browse files
authored
Default UseAccessLevelOnImports to false (grpc#2047)
## Motivation After the discussion on grpc#2042 (comment), I played a bit more with `InternalImportsByDefault` and the different generator options, got to the following conclusions: - If you add `import Foo` to some file, where `Foo` is also being imported with an explicit `internal` access-level modifier _in the generated code_, it will work as long as `InternalImportsByDefault` is enabled. - If you disable `InternalImportsByDefault` for the corresponding target in `Package.swift`, you get an `"Ambiguous implicit access level for import of 'Foo'; it is imported as 'internal' elsewhere"` **error** (not a warning). This means that if the code generator plugin(s) begin adding the access level modifiers by default based on how they're built, they could cause source-breakages for users unintentionally. - _This isn't any different between language mode 5 or 6_ - I tried changing the target's language mode and the behaviour is the same as described above in either case. Given all this, defaulting `UseAccessLevelOnImports` to `false` **always** for now may be the easiest (and least surprising, from a users' perspective) thing to do, until `InternalImportsByDefault` are enabled by default in a future Swift >6.0 version (as the proposal states), where we can default to `true` again: ``` #if compiler(>=6.x) // where x is the version where internal imports by default is enabled // default to true #else // default to false #endif ``` The rationale behind this is that adding access levels to imports on your code is currently totally optional. If you choose to start adding them explicitly, then it's okay to also have to tell your tooling/generators that they should also add them explicitly. If you don't, they'll keep generating things the exact same way they've been doing it, which is what users of the generator would expect. ## Modifications - Default `UseAccessLevelOnImports` to `false` always. - Regenerate protos - Remove `InternalImportsByDefault` from test and executable targets, since it doesn't make a lot of sense to have access level modifiers on imports here anyways as these targets cannot be imported.
1 parent 1b060a3 commit d3ef09d

24 files changed

+65
-76
lines changed

Examples/v2/echo/Generated/echo.grpc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
// For information on using the generated types, please see the documentation:
2222
// https://github.com/grpc/grpc-swift
2323

24-
internal import GRPCCore
25-
internal import GRPCProtobuf
24+
import GRPCCore
25+
import GRPCProtobuf
2626

2727
internal enum Echo_Echo {
2828
internal static let descriptor = GRPCCore.ServiceDescriptor.echo_Echo

Examples/v2/echo/Subcommands/Collect.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
internal import ArgumentParser
18-
private import GRPCCore
19-
private import GRPCHTTP2Core
20-
private import GRPCHTTP2TransportNIOPosix
17+
import ArgumentParser
18+
import GRPCCore
19+
import GRPCHTTP2Core
20+
import GRPCHTTP2TransportNIOPosix
2121

2222
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
2323
struct Collect: AsyncParsableCommand {

Examples/v2/hello-world/Generated/helloworld.grpc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
// For information on using the generated types, please see the documentation:
2222
// https://github.com/grpc/grpc-swift
2323

24-
internal import GRPCCore
25-
internal import GRPCProtobuf
24+
import GRPCCore
25+
import GRPCProtobuf
2626

2727
internal enum Helloworld_Greeter {
2828
internal static let descriptor = GRPCCore.ServiceDescriptor.helloworld_Greeter

Examples/v2/hello-world/HelloWorld.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
internal import ArgumentParser
17+
import ArgumentParser
1818

1919
@main
2020
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)

Examples/v2/hello-world/Subcommands/Greet.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
internal import ArgumentParser
18-
internal import GRPCHTTP2Transport
19-
internal import GRPCProtobuf
17+
import ArgumentParser
18+
import GRPCHTTP2Transport
19+
import GRPCProtobuf
2020

2121
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
2222
struct Greet: AsyncParsableCommand {

Examples/v2/hello-world/Subcommands/Serve.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
internal import ArgumentParser
18-
internal import GRPCHTTP2Transport
19-
internal import GRPCProtobuf
17+
import ArgumentParser
18+
import GRPCHTTP2Transport
19+
import GRPCProtobuf
2020

2121
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
2222
struct Serve: AsyncParsableCommand {

Examples/v2/route-guide/Generated/route_guide.grpc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
// For information on using the generated types, please see the documentation:
2222
// https://github.com/grpc/grpc-swift
2323

24-
internal import GRPCCore
25-
internal import GRPCProtobuf
24+
import GRPCCore
25+
import GRPCProtobuf
2626

2727
internal enum Routeguide_RouteGuide {
2828
internal static let descriptor = GRPCCore.ServiceDescriptor.routeguide_RouteGuide

[email protected]

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ extension Target {
346346
],
347347
swiftSettings: [
348348
.swiftLanguageMode(.v6),
349-
.enableUpcomingFeature("ExistentialAny"),
350-
.enableUpcomingFeature("InternalImportsByDefault")
349+
.enableUpcomingFeature("ExistentialAny")
351350
]
352351
)
353352
}
@@ -710,8 +709,7 @@ extension Target {
710709
path: "Examples/v2/echo",
711710
swiftSettings: [
712711
.swiftLanguageMode(.v6),
713-
.enableUpcomingFeature("ExistentialAny"),
714-
.enableUpcomingFeature("InternalImportsByDefault")
712+
.enableUpcomingFeature("ExistentialAny")
715713
]
716714
)
717715
}
@@ -773,8 +771,7 @@ extension Target {
773771
],
774772
swiftSettings: [
775773
.swiftLanguageMode(.v6),
776-
.enableUpcomingFeature("ExistentialAny"),
777-
.enableUpcomingFeature("InternalImportsByDefault")
774+
.enableUpcomingFeature("ExistentialAny")
778775
]
779776
)
780777
}
@@ -837,8 +834,7 @@ extension Target {
837834
],
838835
swiftSettings: [
839836
.swiftLanguageMode(.v6),
840-
.enableUpcomingFeature("ExistentialAny"),
841-
.enableUpcomingFeature("InternalImportsByDefault")
837+
.enableUpcomingFeature("ExistentialAny")
842838
]
843839
)
844840
}

Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec03-step04-gen-grpc.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ $ protoc --plugin=.build/debug/protoc-gen-grpc-swift \
22
-I Protos \
33
--grpc-swift_out=Sources/Generated \
44
--grpc-swift_opt=_V2=true \
5-
--grpc-swift_opt=UseAccessLevelOnImports=false \
65
Protos/route_guide.proto

Sources/performance-worker/BenchmarkClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
private import Foundation
18-
internal import GRPCCore
19-
private import NIOConcurrencyHelpers
20-
private import Synchronization
17+
import Foundation
18+
import GRPCCore
19+
import NIOConcurrencyHelpers
20+
import Synchronization
2121

2222
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
2323
final class BenchmarkClient: Sendable {

0 commit comments

Comments
 (0)