Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Suppress compiler warnings in release mode. #179

Merged
merged 2 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 9 additions & 7 deletions Sources/NIO/EventLoopFuture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public final class EventLoopFuture<T> {
self.value = value
self._fulfilled = Atomic(value: value != nil)

if _isDebugAssertConfiguration() {
debugOnly {
if let me = eventLoop as? SelectableEventLoop {
me.promiseCreationStoreAdd(future: self, file: file, line: line)
}
Expand All @@ -335,13 +335,15 @@ public final class EventLoopFuture<T> {
}

deinit {
if _isDebugAssertConfiguration(), let eventLoop = self.eventLoop as? SelectableEventLoop {
let creation = eventLoop.promiseCreationStoreRemove(future: self)
if !fulfilled {
fatalError("leaking promise created at \(creation)", file: creation.file, line: creation.line)
debugOnly {
if let eventLoop = self.eventLoop as? SelectableEventLoop {
let creation = eventLoop.promiseCreationStoreRemove(future: self)
if !fulfilled {
fatalError("leaking promise created at \(creation)", file: creation.file, line: creation.line)
}
} else {
precondition(fulfilled, "leaking an unfulfilled Promise")
}
} else {
precondition(fulfilled, "leaking an unfulfilled Promise")
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/NIO/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ private func darwinCoreCount() -> Int {
}
#endif

/// A utility function that runs the body code only in debug builds, without
/// emitting compiler warnings.
///
/// This is currently the only way to do this in Swift: see
/// https://forums.swift.org/t/support-debug-only-code/11037 for a discussion.
internal func debugOnly(_ body: () -> Void) {
assert({ body(); return true }())
}

/// Allows to "box" another value.
final class Box<T> {
let value: T
Expand Down