Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/GRPCCodeGen/CodeGenerationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public struct CodeGenerationRequest {
public var item: Item?

/// The access level to be included in imports of this dependency.
public var accessLevel: SourceGenerator.Configuration.AccessLevel
public var accessLevel: SourceGenerator.Config.AccessLevel

/// The name of the imported module or of the module an item is imported from.
public var module: String
Expand All @@ -106,7 +106,7 @@ public struct CodeGenerationRequest {
module: String,
spi: String? = nil,
preconcurrency: PreconcurrencyRequirement = .notRequired,
accessLevel: SourceGenerator.Configuration.AccessLevel
accessLevel: SourceGenerator.Config.AccessLevel
) {
self.item = item
self.module = module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
/// }
///```
struct ClientCodeTranslator: SpecializedTranslator {
var accessLevel: SourceGenerator.Configuration.AccessLevel
var accessLevel: SourceGenerator.Config.AccessLevel

init(accessLevel: SourceGenerator.Configuration.AccessLevel) {
init(accessLevel: SourceGenerator.Config.AccessLevel) {
self.accessLevel = accessLevel
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
struct IDLToStructuredSwiftTranslator: Translator {
func translate(
codeGenerationRequest: CodeGenerationRequest,
accessLevel: SourceGenerator.Configuration.AccessLevel,
accessLevel: SourceGenerator.Config.AccessLevel,
accessLevelOnImports: Bool,
client: Bool,
server: Bool
Expand Down Expand Up @@ -81,7 +81,7 @@ struct IDLToStructuredSwiftTranslator: Translator {
}

extension AccessModifier {
fileprivate init(_ accessLevel: SourceGenerator.Configuration.AccessLevel) {
fileprivate init(_ accessLevel: SourceGenerator.Config.AccessLevel) {
switch accessLevel.level {
case .internal: self = .internal
case .package: self = .package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
/// }
///```
struct ServerCodeTranslator: SpecializedTranslator {
var accessLevel: SourceGenerator.Configuration.AccessLevel
var accessLevel: SourceGenerator.Config.AccessLevel

init(accessLevel: SourceGenerator.Configuration.AccessLevel) {
init(accessLevel: SourceGenerator.Config.AccessLevel) {
self.accessLevel = accessLevel
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
/// the server code translation or the client code translation.
protocol SpecializedTranslator {

/// The ``SourceGenerator.Configuration.AccessLevel`` object used to represent the visibility level used in the generated code.
var accessLevel: SourceGenerator.Configuration.AccessLevel { get }
/// The ``SourceGenerator.Config.AccessLevel`` object used to represent the visibility level used in the generated code.
var accessLevel: SourceGenerator.Config.AccessLevel { get }

/// Generates an array of ``CodeBlock`` elements that will be part of the ``StructuredSwiftRepresentation`` object
/// created by the ``Translator``.
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPCCodeGen/Internal/Translator/Translator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protocol Translator {
/// - Throws: An error if there are issues translating the codeGenerationRequest.
func translate(
codeGenerationRequest: CodeGenerationRequest,
accessLevel: SourceGenerator.Configuration.AccessLevel,
accessLevel: SourceGenerator.Config.AccessLevel,
accessLevelOnImports: Bool,
client: Bool,
server: Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
struct TypealiasTranslator: SpecializedTranslator {
let client: Bool
let server: Bool
let accessLevel: SourceGenerator.Configuration.AccessLevel
let accessLevel: SourceGenerator.Config.AccessLevel

init(client: Bool, server: Bool, accessLevel: SourceGenerator.Configuration.AccessLevel) {
init(client: Bool, server: Bool, accessLevel: SourceGenerator.Config.AccessLevel) {
self.client = client
self.server = server
self.accessLevel = accessLevel
Expand Down
18 changes: 9 additions & 9 deletions Sources/GRPCCodeGen/SourceGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
public struct SourceGenerator: Sendable {
/// The options regarding the access level, indentation for the generated code
/// and whether to generate server and client code.
public var configuration: Configuration
public var config: Config

public init(configuration: Configuration) {
self.configuration = configuration
public init(config: Config) {
self.config = config
}

/// User options for the CodeGeneration.
public struct Configuration: Sendable {
public struct Config: Sendable {
/// The access level the generated code will have.
public var accessLevel: AccessLevel
/// Whether imports have explicit access levels.
Expand Down Expand Up @@ -85,14 +85,14 @@ public struct SourceGenerator: Sendable {
_ request: CodeGenerationRequest
) throws -> SourceFile {
let translator = IDLToStructuredSwiftTranslator()
let textRenderer = TextBasedRenderer(indentation: self.configuration.indentation)
let textRenderer = TextBasedRenderer(indentation: self.config.indentation)

let structuredSwiftRepresentation = try translator.translate(
codeGenerationRequest: request,
accessLevel: self.configuration.accessLevel,
accessLevelOnImports: self.configuration.accessLevelOnImports,
client: self.configuration.client,
server: self.configuration.server
accessLevel: self.config.accessLevel,
accessLevelOnImports: self.config.accessLevelOnImports,
client: self.config.client,
server: self.config.server
)
let sourceFile = try textRenderer.render(structured: structuredSwiftRepresentation)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ extension ClientRPCExecutor.HedgingExecutor {
@usableFromInline
struct State: Sendable {
@usableFromInline
let _maximumAttempts: Int
let _maxAttempts: Int
@usableFromInline
private(set) var attempt: Int
@usableFromInline
private(set) var hasUsableResponse: Bool

@inlinable
init(policy: HedgingPolicy) {
self._maximumAttempts = policy.maximumAttempts
self._maxAttempts = policy.maxAttempts
self.attempt = 1
self.hasUsableResponse = false
}
Expand Down Expand Up @@ -487,14 +487,14 @@ extension ClientRPCExecutor.HedgingExecutor {

@inlinable
mutating func nextAttemptNumber() -> NextAttemptResult? {
if self.hasUsableResponse || self.attempt > self._maximumAttempts {
if self.hasUsableResponse || self.attempt > self._maxAttempts {
return nil
} else {
let attempt = self.attempt
self.attempt += 1
return NextAttemptResult(
nextAttempt: attempt,
scheduleNext: self.attempt <= self._maximumAttempts
scheduleNext: self.attempt <= self._maxAttempts
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extension ClientRPCExecutor.RetryExecutor {
let delaySequence = RetryDelaySequence(policy: self.policy)
var delayIterator = delaySequence.makeIterator()

for attempt in 1 ... self.policy.maximumAttempts {
for attempt in 1 ... self.policy.maxAttempts {
do {
let attemptResult = try await self.transport.withStream(
descriptor: method,
Expand Down Expand Up @@ -253,15 +253,15 @@ extension ClientRPCExecutor.RetryExecutor {
switch error.metadata.retryPushback {
case .retryAfter(let delay):
// Pushback: only retry if our config permits it.
shouldRetry = (attempt < self.policy.maximumAttempts) && !throttled
shouldRetry = (attempt < self.policy.maxAttempts) && !throttled
retryDelayOverride = delay
case .stopRetrying:
// Server told us to stop trying.
shouldRetry = false
retryDelayOverride = nil
case .none:
// No pushback: only retry if our config permits it.
shouldRetry = (attempt < self.policy.maximumAttempts) && !throttled
shouldRetry = (attempt < self.policy.maxAttempts) && !throttled
retryDelayOverride = nil
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum ClientRPCExecutor {
/// - Parameters:
/// - request: The request to execute.
/// - method: A description of the method to execute the request against.
/// - configuration: The execution configuration.
/// - options: RPC options.
/// - serializer: A serializer to convert input messages to bytes.
/// - deserializer: A deserializer to convert bytes to output messages.
/// - transport: The transport to execute the request on.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
internal enum ClientStreamExecutor {
/// Execute a request on the stream executor.
///
/// The ``run()`` method must be running at the same time as this method.
///
/// - Parameters:
/// - request: A streaming request.
/// - method: A description of the method to call.
/// - context: The client context.
/// - attempt: The attempt number for the RPC that will be executed.
/// - serializer: A request serializer.
/// - deserializer: A response deserializer.
/// - stream: The stream to excecute the RPC on.
/// - Returns: A streamed response.
@inlinable
static func execute<Input: Sendable, Output: Sendable>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ struct RetryDelaySequence: Sequence {
}

@inlinable
var _maximumBackoffSeconds: Double {
Self._durationToTimeInterval(self.policy.maximumBackoff)
var _maxBackoffSeconds: Double {
Self._durationToTimeInterval(self.policy.maxBackoff)
}

@inlinable
mutating func next() -> Duration? {
defer { self.n += 1 }

/// The nth retry will happen after a randomly chosen delay between zero and
/// `min(initialBackoff * backoffMultiplier^(n-1), maximumBackoff)`.
/// `min(initialBackoff * backoffMultiplier^(n-1), maxBackoff)`.
let factor = pow(self.policy.backoffMultiplier, Double(self.n - 1))
let computedBackoff = self._initialBackoffSeconds * factor
let clampedBackoff = Swift.min(computedBackoff, self._maximumBackoffSeconds)
let clampedBackoff = Swift.min(computedBackoff, self._maxBackoffSeconds)
let randomisedBackoff = Double.random(in: 0.0 ... clampedBackoff)

return Self._timeIntervalToDuration(randomisedBackoff)
Expand Down
Loading
Loading