Skip to content

Commit 1d6783e

Browse files
Re-enable interceptor API on debug builds
But not on release builds to avoid the non-trivial overhead of interception.
1 parent bda3fd4 commit 1d6783e

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Sources/CLI/Run/Run.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ struct Run: ParsableCommand {
5454
}
5555

5656
let interceptor = try deriveInterceptor()
57+
#if !DEBUG
58+
guard interceptor == nil else {
59+
fatalError("Internal Error: Interceptor API is unavailable with Release build due to performance reasons")
60+
}
61+
#endif
5762
defer { interceptor?.finalize() }
5863

5964
let invoke: () throws -> Void

Sources/WasmKit/Execution/Instructions/Control.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ extension ExecutionState {
119119

120120
private mutating func endOfFunction(runtime: Runtime, currentFrame: Frame) throws {
121121
// When reached at "end" of function
122-
// if let address = currentFrame.address {
123-
// runtime.interceptor?.onExitFunction(address, store: runtime.store)
124-
// }
122+
#if DEBUG
123+
if let address = currentFrame.address {
124+
runtime.interceptor?.onExitFunction(address, store: runtime.store)
125+
}
126+
#endif
125127
let values = stack.popValues(count: currentFrame.arity)
126128
stack.popFrame()
127129
stack.push(values: values)

Sources/WasmKit/Execution/Runtime/ExecutionState.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ extension ExecutionState {
6262
/// > Note:
6363
/// <https://webassembly.github.io/spec/core/exec/instructions.html#invocation-of-function-address>
6464
mutating func invoke(functionAddress address: FunctionAddress, runtime: Runtime) throws {
65-
// runtime.interceptor?.onEnterFunction(address, store: runtime.store)
65+
#if DEBUG
66+
runtime.interceptor?.onEnterFunction(address, store: runtime.store)
67+
#endif
6668

6769
switch try runtime.store.function(at: address) {
6870
case let .host(function):

0 commit comments

Comments
 (0)