Skip to content

Commit b221b81

Browse files
committed
methods should’ve been inlinable, ABI is not important
1 parent af561ae commit b221b81

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

Sources/Logging/Docs.docc/Proposals/SLG-0006-task-local-logger.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ as a parameter to avoid repeated task-local lookups inside the closure body.
163163
/// parameter so the body does not need to re-read ``Logger/current``.
164164
/// - Returns: The value returned by `operation`.
165165
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
166+
@inlinable
166167
public func withLogger<Result, Failure: Error>(
167168
_ logger: Logger,
168169
_ operation: (Logger) throws(Failure) -> Result
@@ -177,6 +178,7 @@ public func withLogger<Result, Failure: Error>(
177178
/// a parameter so the body does not need to re-read ``Logger/current``.
178179
/// - Returns: The value returned by `operation`.
179180
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
181+
@inlinable
180182
public nonisolated(nonsending) func withLogger<Result, Failure: Error>(
181183
_ logger: Logger,
182184
_ operation: nonisolated(nonsending) (Logger) async throws(Failure) -> Result
@@ -209,6 +211,7 @@ public nonisolated(nonsending) func withLogger<Result, Failure: Error>(
209211
/// merged logger as a parameter.
210212
/// - Returns: The value returned by `operation`.
211213
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
214+
@inlinable
212215
public func withLogger<Result, Failure: Error>(
213216
mergingMetadata metadata: @autoclosure () -> Logger.Metadata,
214217
_ operation: (Logger) throws(Failure) -> Result
@@ -225,6 +228,7 @@ public func withLogger<Result, Failure: Error>(
225228
/// merged logger as a parameter.
226229
/// - Returns: The value returned by `operation`.
227230
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
231+
@inlinable
228232
public nonisolated(nonsending) func withLogger<Result, Failure: Error>(
229233
mergingMetadata metadata: @autoclosure () -> Logger.Metadata,
230234
_ operation: nonisolated(nonsending) (Logger) async throws(Failure) -> Result
@@ -265,6 +269,7 @@ public nonisolated(nonsending) func withLogger<Result, Failure: Error>(
265269
/// modified logger as a parameter.
266270
/// - Returns: The value returned by `operation`.
267271
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
272+
@inlinable
268273
public func withLogger<Result, Failure: Error>(
269274
logLevel: Logger.Level? = nil,
270275
handler: (any LogHandler)? = nil,
@@ -290,6 +295,7 @@ public func withLogger<Result, Failure: Error>(
290295
/// the modified logger as a parameter.
291296
/// - Returns: The value returned by `operation`.
292297
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
298+
@inlinable
293299
public nonisolated(nonsending) func withLogger<Result, Failure: Error>(
294300
logLevel: Logger.Level? = nil,
295301
handler: (any LogHandler)? = nil,
@@ -328,15 +334,16 @@ clause. Each new symbol carries `@available(macOS 10.15, iOS 13.0, tvOS 13.0, wa
328334
to match `@TaskLocal`'s runtime availability. Callers targeting older deployment versions
329335
keep working; they just can't call the task-local API.
330336

331-
**ABI and resilience.** The `withLogger` overloads, `Logger.current`, and the task-local
332-
storage are intentionally **not** `@inlinable` / `@usableFromInline` in this proposal.
333-
The bodies are still evolving — future iterations are expected to factor parts of the
334-
implementation through value-level `Logger.withMetadata(...)` methods (see Future
335-
directions) — and committing to `@inlinable` now would freeze the current shape into
336-
ABI. The trade-off is one non-inlined function call per `withLogger` scope entry, which
337-
is negligible relative to the structured-concurrency machinery already involved.
338-
`@inlinable` annotations can be added in a non-breaking follow-up once the shape is
339-
settled and benchmarks justify the ABI commitment.
337+
**ABI and resilience.** The `withLogger` overloads are `@inlinable`: their bodies are thin
338+
glue — read `Logger.current`, copy-and-modify the logger, then bind it for the scope — so
339+
inlining them removes a cross-module call at each scope entry. The internal
340+
`withTaskLocalLogger` bridge over `TaskLocal.withValue` is `@usableFromInline` (not
341+
`@inlinable`), letting the inlinable bodies reach it without exposing the `@TaskLocal`
342+
storage. That storage, the bridge, and `Logger.current` all stay non-`@inlinable`, so the
343+
genuinely evolvable state — how the task-local is stored and how the unbound default is
344+
resolved — remains behind a resilient boundary and can change without breaking
345+
already-compiled clients. Only the small, settled control flow of the wrappers is committed
346+
to ABI.
340347

341348
**Source compatibility caveat.** The name `withLogger` is added at the top-level namespace.
342349
Codebases that previously defined their own free `withLogger` function may need to

0 commit comments

Comments
 (0)