Skip to content

Commit 2bd4bd0

Browse files
Merge branch 'main' into migrate-to-dependabot
2 parents dd37d5b + 8b0b14a commit 2bd4bd0

4 files changed

Lines changed: 161 additions & 1 deletion

File tree

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ updates:
66
directory: "/" # Location of package manifests
77
schedule:
88
interval: "weekly"
9+
ignore:
10+
- dependency-name: "crate-ci/typos"
11+
update-types: ["version-update:semver-patch", "version-update:semver-minor"]
912
- package-ecosystem: "julia"
1013
directories:
1114
- "/"

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ version = "0.1.4"
55

66
[deps]
77
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
8+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
89
TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77"
910

1011
[compat]
1112
FunctionWrappers = "1"
13+
PrecompileTools = "1"
1214
TruncatedStacktraces = "1"
1315
julia = "1.6"
1416

src/FunctionWrappersWrappers.jl

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module FunctionWrappersWrappers
33
using FunctionWrappers
44
import TruncatedStacktraces
55

6-
export FunctionWrappersWrapper
6+
export FunctionWrappersWrapper, unwrap, wrapped_signatures, wrapped_return_types
77

88
struct FunctionWrappersWrapper{FW, FB}
99
fw::FW
@@ -48,4 +48,106 @@ function FunctionWrappersWrapper(
4848
FunctionWrappersWrapper{typeof(fwt), FB}(fwt)
4949
end
5050

51+
"""
52+
unwrap(fww::FunctionWrappersWrapper)
53+
54+
Return the original function that was wrapped. This is useful for debugging
55+
wrapped functions - you can use the returned function with debugging tools
56+
like Debugger.jl or Infiltrator.jl.
57+
58+
# Example
59+
60+
```julia
61+
using FunctionWrappersWrappers
62+
63+
# Create a wrapped function
64+
fww = FunctionWrappersWrapper(sin, (Tuple{Float64},), (Float64,))
65+
66+
# Get the original function for debugging
67+
f = unwrap(fww) # Returns sin
68+
69+
# Now you can debug with Debugger.jl:
70+
# using Debugger
71+
# @enter f(0.5)
72+
73+
# Or use Infiltrator.jl in your original function definition
74+
```
75+
76+
See also: [`wrapped_signatures`](@ref), [`wrapped_return_types`](@ref)
77+
"""
78+
unwrap(fww::FunctionWrappersWrapper) = first(fww.fw).obj[]
79+
80+
"""
81+
wrapped_signatures(fww::FunctionWrappersWrapper)
82+
83+
Return a tuple of the argument type signatures that the `FunctionWrappersWrapper`
84+
can dispatch on. Each element is a `Tuple` type representing the argument types.
85+
86+
# Example
87+
88+
```julia
89+
using FunctionWrappersWrappers
90+
91+
fww = FunctionWrappersWrapper(+, (Tuple{Float64, Float64}, Tuple{Int, Int}), (Float64, Int))
92+
wrapped_signatures(fww) # Returns (Tuple{Float64, Float64}, Tuple{Int, Int})
93+
```
94+
95+
See also: [`unwrap`](@ref), [`wrapped_return_types`](@ref)
96+
"""
97+
function wrapped_signatures(fww::FunctionWrappersWrapper)
98+
map(fw -> typeof(fw).parameters[2], fww.fw)
99+
end
100+
101+
"""
102+
wrapped_return_types(fww::FunctionWrappersWrapper)
103+
104+
Return a tuple of the return types for each wrapped function signature.
105+
106+
# Example
107+
108+
```julia
109+
using FunctionWrappersWrappers
110+
111+
fww = FunctionWrappersWrapper(+, (Tuple{Float64, Float64}, Tuple{Int, Int}), (Float64, Int))
112+
wrapped_return_types(fww) # Returns (Float64, Int64)
113+
```
114+
115+
See also: [`unwrap`](@ref), [`wrapped_signatures`](@ref)
116+
"""
117+
function wrapped_return_types(fww::FunctionWrappersWrapper)
118+
map(fw -> typeof(fw).parameters[1], fww.fw)
119+
end
120+
121+
using PrecompileTools
122+
123+
@setup_workload begin
124+
@compile_workload begin
125+
# Precompile common use cases with Float64 and Int types
126+
# These are the most common type combinations for numerical computations
127+
128+
# Binary operation with multiple type combinations (common pattern)
129+
fw_binary = FunctionWrappersWrapper(
130+
+,
131+
(Tuple{Float64, Float64}, Tuple{Int, Int}),
132+
(Float64, Int)
133+
)
134+
fw_binary(1.0, 2.0)
135+
fw_binary(1, 2)
136+
137+
# Unary operation with multiple types (common pattern)
138+
fw_unary = FunctionWrappersWrapper(
139+
abs,
140+
(Tuple{Float64}, Tuple{Int}),
141+
(Float64, Int)
142+
)
143+
fw_unary(1.0)
144+
fw_unary(1)
145+
146+
# Precompile introspection functions
147+
unwrap(fw_unary)
148+
wrapped_signatures(fw_binary)
149+
wrapped_return_types(fw_binary)
150+
end
151+
end
152+
51153
end

test/runtests.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,56 @@ using Test
1313
@test fwexp2(4.0f0) === 16.0f0
1414
@test fwexp2(4) === 16.0
1515
end
16+
17+
@testset "Introspection functions" begin
18+
# Test with a simple function
19+
fwsin = FunctionWrappersWrapper(sin, (Tuple{Float64},), (Float64,))
20+
21+
@testset "unwrap" begin
22+
f = unwrap(fwsin)
23+
@test f === sin
24+
@test f(0.5) == sin(0.5)
25+
end
26+
27+
@testset "wrapped_signatures" begin
28+
sigs = wrapped_signatures(fwsin)
29+
@test sigs == (Tuple{Float64},)
30+
end
31+
32+
@testset "wrapped_return_types" begin
33+
rets = wrapped_return_types(fwsin)
34+
@test rets == (Float64,)
35+
end
36+
37+
# Test with multiple signatures
38+
fwplus = FunctionWrappersWrapper(+, (Tuple{Float64, Float64}, Tuple{Int, Int}), (
39+
Float64, Int))
40+
41+
@testset "unwrap with multiple signatures" begin
42+
f = unwrap(fwplus)
43+
@test f === +
44+
@test f(1, 2) == 3
45+
end
46+
47+
@testset "wrapped_signatures with multiple signatures" begin
48+
sigs = wrapped_signatures(fwplus)
49+
@test sigs == (Tuple{Float64, Float64}, Tuple{Int, Int})
50+
end
51+
52+
@testset "wrapped_return_types with multiple signatures" begin
53+
rets = wrapped_return_types(fwplus)
54+
@test rets == (Float64, Int)
55+
end
56+
57+
# Test with a custom function
58+
my_func(x) = x^2
59+
fwcustom = FunctionWrappersWrapper(my_func, (Tuple{Float64}, Tuple{Int}), (
60+
Float64, Int))
61+
62+
@testset "unwrap with custom function" begin
63+
f = unwrap(fwcustom)
64+
@test f === my_func
65+
@test f(3) == 9
66+
@test f(2.5) == 6.25
67+
end
68+
end

0 commit comments

Comments
 (0)