Skip to content

Commit 39489c2

Browse files
Merge pull request swiftlang#28540 from ravikandhadai/oslog-transparent-to-compiler-eval
[stdlib/private][oslog] Make tiny helper functions of struct OSLogMessage constant_evaluable instead of transparent
2 parents b7537cf + 05be088 commit 39489c2

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

stdlib/private/OSLog/OSLog.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ internal func osLog(
6666
let preamble = message.interpolation.preamble
6767
let argumentCount = message.interpolation.argumentCount
6868
let bufferSize = message.bufferSize
69+
let uint32bufferSize = UInt32(bufferSize)
6970
let argumentClosures = message.interpolation.arguments.argumentClosures
7071

7172
let formatStringPointer = _getGlobalStringTablePointer(formatString)
@@ -91,7 +92,7 @@ internal func osLog(
9192
logLevel,
9293
formatStringPointer,
9394
bufferMemory,
94-
UInt32(bufferSize))
95+
uint32bufferSize)
9596

9697
// The following operation extends the lifetime of stringStorageObjects
9798
// and also of the objects stored in it till this point.

stdlib/private/OSLog/OSLogIntegerTypes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ extension OSLogArguments {
155155

156156
/// Return the number of bytes needed for serializing an integer argument as
157157
/// specified by os_log. This function must be constant evaluable.
158-
@inlinable
159158
@_semantics("constant_evaluable")
160-
@_effects(readonly)
159+
@inlinable
161160
@_optimize(none)
162161
internal func sizeForEncoding<T>(
163162
_ type: T.Type
@@ -167,8 +166,9 @@ internal func sizeForEncoding<T>(
167166

168167
/// Serialize an integer at the buffer location that `position` points to and
169168
/// increment `position` by the byte size of `T`.
170-
@usableFromInline
169+
@inlinable
171170
@_alwaysEmitIntoClient
171+
@inline(__always)
172172
internal func serialize<T>(
173173
_ value: T,
174174
at bufferPosition: inout ByteBufferPointer

stdlib/private/OSLog/OSLogMessage.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ public enum Privacy {
4343
/// Maximum number of arguments i.e., interpolated expressions that can
4444
/// be used in the string interpolations passed to the log APIs.
4545
/// This limit is imposed by the ABI of os_log.
46-
@_transparent
46+
@_semantics("constant_evaluable")
47+
@inlinable
48+
@_optimize(none)
4749
public var maxOSLogArgumentCount: UInt8 { return 48 }
4850

49-
@usableFromInline
50-
@_transparent
51+
@_semantics("constant_evaluable")
52+
@inlinable
53+
@_optimize(none)
5154
internal var logBitsPerByte: Int { return 3 }
5255

5356
/// Represents a string interpolation passed to the log APIs.
@@ -303,7 +306,8 @@ public struct OSLogMessage :
303306
/// The byte size of the buffer that will be passed to the C os_log ABI.
304307
/// It will contain the elements of `interpolation.arguments` and the two
305308
/// summary bytes: preamble and argument count.
306-
@_transparent
309+
@_semantics("constant_evaluable")
310+
@inlinable
307311
@_optimize(none)
308312
public var bufferSize: Int {
309313
return interpolation.totalBytesForSerializingArguments + 2
@@ -353,8 +357,9 @@ internal struct OSLogArguments {
353357

354358
/// Serialize a UInt8 value at the buffer location pointed to by `bufferPosition`,
355359
/// and increment the `bufferPosition` with the byte size of the serialized value.
356-
@usableFromInline
360+
@inlinable
357361
@_alwaysEmitIntoClient
362+
@inline(__always)
358363
internal func serialize(
359364
_ value: UInt8,
360365
at bufferPosition: inout ByteBufferPointer)

stdlib/private/OSLog/OSLogStringTypes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ extension OSLogArguments {
102102
/// evaluator, this function returns the byte size of Int, which must equal the
103103
/// word length of the target architecture and hence the pointer size.
104104
/// This function must be constant evaluable.
105+
@_semantics("constant_evaluable")
105106
@inlinable
106107
@_optimize(none)
107-
@_effects(readonly)
108-
@_semantics("constant_evaluable")
109108
internal func sizeForEncoding() -> Int {
110109
return Int.bitWidth &>> logBitsPerByte
111110
}
@@ -114,8 +113,9 @@ internal func sizeForEncoding() -> Int {
114113
/// pointed by `bufferPosition`. When necessary, this function would copy the
115114
/// string contents to a storage with a stable pointer. If that happens, a reference
116115
/// to the storage will be added to `storageObjects`.
117-
@usableFromInline
116+
@inlinable
118117
@_alwaysEmitIntoClient
118+
@inline(__always)
119119
internal func serialize(
120120
_ stringValue: String,
121121
at bufferPosition: inout ByteBufferPointer,

test/SILOptimizer/OSLogConstantEvaluableTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Run the (mandatory) passes on which constant evaluator depends, and run the
55
// constant evaluator on the SIL produced after the dependent passes are run.
66
//
7-
// RUN: %target-sil-opt -silgen-cleanup -raw-sil-inst-lowering -allocbox-to-stack -mandatory-inlining -constexpr-limit 1024 -test-constant-evaluable-subset %t/OSLogConstantEvaluableTest_silgen.sil > %t/OSLogConstantEvaluableTest.sil 2> %t/error-output
7+
// RUN: %target-sil-opt -silgen-cleanup -raw-sil-inst-lowering -allocbox-to-stack -mandatory-inlining -constexpr-limit 2048 -test-constant-evaluable-subset %t/OSLogConstantEvaluableTest_silgen.sil > %t/OSLogConstantEvaluableTest.sil 2> %t/error-output
88
//
99
// RUN: %FileCheck %s < %t/error-output
1010
//

0 commit comments

Comments
 (0)