# Opaque closure and code\_typed

**URL:** https://discourse.julialang.org/t/opaque-closure-and-code-typed/102690
**Category:** Internals & Design
**Tags:** question, closure
**Created:** [August 10, 2023, 6:25pm UTC](https://discourse.julialang.org/t/opaque-closure-and-code-typed/102690 "2023-08-10T18:25:38Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![willtebbutt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willtebbutt/32/6790_2.png) [@willtebbutt](https://discourse.julialang.org/u/willtebbutt)
#### Post date: [August 10, 2023, 6:25pm UTC](https://discourse.julialang.org/t/opaque-closure-and-code-typed/102690/1 "2023-08-10T18:25:38Z")

</div>

I’m playing around with opaque closures. I’ve have managed to construct the following toy example:

```julia
struct Foo
    x::Float64
end

(x::Foo)(y) = cos(sin(getfield(x, 1) * y))

@eval function make_opaque_closure(x)
    return $(Expr(
        :new_opaque_closure,
        Tuple{Float64},
        Float64,
        Float64,
        Expr(
            :opaque_closure_method,
            nothing,
            1,
            false,
            LineNumberNode(0, nothing),
            only(code_lowered(Foo(5.0), (Float64, ))),
        ),
        :x,
    ))
end

f = make_opaque_closure(5.0)

```

(I took inspiration from the tests in the main Julia repo).

If I now ask for the `@code_typed` associated with `f`, I get:

```julia
@code_typed optimize=true f(4.0)
CodeInfo(
1 ─ %1 = Main.getfield(x, 1)
│ %2 = %1 * y
│ %3 = Main.sin(%2)
│ %4 = Main.cos(%3)
└── return %4
) => Float64

```

which doesn’t appear to have types associated with it.  
However, if I benchmark `f(4.0)`, it looks very much like it’s got good performance, so I assume that type inference must be happening somewhere.

_My question_: is there a way to get to the actual typed `CodeInfo` / `IRCode` associated with an opaque closure that I’ve constructed in this way, or am I going about this in entirely the wrong way?

I’m running `Julia Version 1.10.0-beta1`
