@@ -3,7 +3,7 @@ module FunctionWrappersWrappers
33using FunctionWrappers
44import TruncatedStacktraces
55
6- export FunctionWrappersWrapper
6+ export FunctionWrappersWrapper, unwrap, wrapped_signatures, wrapped_return_types
77
88struct FunctionWrappersWrapper{FW, FB}
99 fw:: FW
@@ -48,4 +48,106 @@ function FunctionWrappersWrapper(
4848 FunctionWrappersWrapper {typeof(fwt), FB} (fwt)
4949end
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+
51153end
0 commit comments