# Return CodeInfo instead of expression from a generated function?

**URL:** <https://discourse.julialang.org/t/return-codeinfo-instead-of-expression-from-a-generated-function/18804>\
**Category:** General Usage\
**Created:** [December 18, 2018, 6:48pm UTC](https://discourse.julialang.org/t/return-codeinfo-instead-of-expression-from-a-generated-function/18804 "2018-12-18T18:48:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [December 18, 2018, 6:48pm UTC](https://discourse.julialang.org/t/return-codeinfo-instead-of-expression-from-a-generated-function/18804/1 "2018-12-18T18:48:15Z")

</div>

Is it possible to return a `CodeInfo` object instead of expression from a generated function? I’ve seen it in a couple of packages recently, but I can’t find any docs for it and my naive implementation fails with segfault:

```julia
foo(x) = 2x + 1

@generated function inspect(f, args...)
    ci = code_lowered(f.instance, args)[1]
    # do something
    return ci
end

inspect(foo, 9.0)

```

gives

```julia
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Core.Compiler.SlotInfo, (2,)}[
  Core.Compiler.SlotInfo(defs=Array{Int64, (0,)}[], uses=Array{Int64, (0,)}[], any_newvar=false),
  Core.Compiler.SlotInfo(defs=Array{Int64, (0,)}[], uses=Array{Int64, (0,)}[], any_newvar=false)], i=(Core.Compiler.UnitRange{Int64}(start=1, stop=3),))
rec_backtrace at /buildworker/worker/package_linux64/build/src/stackwalk.c:94
...
unknown function (ip: 0xffffffffffffffff)
Allocations: 4114249 (Pool: 4113306; Big: 943); GC: 8
Segmentation fault (core dumped)

```
