Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 1.51 KB

README.md

File metadata and controls

34 lines (25 loc) · 1.51 KB

MistyClosures

Build Status Code Style: Blue ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

Marginally less opaque closures.

Specifically, a MistyClosure is comprises an OpaqueClosure paired with the IRCode that defines it. This is useful if you generate an OpaqueClosure, and want to be able to retrieve the IRCode later on.

Recommended Use

# Get the `IRCode` associated to `sin(5.0)`.
ir = Base.code_ircode_by_type(Tuple{typeof(sin), Float64})[1][1]

# Produce a `MistyClosure` using it. All kwargs are passed to the `OpaqueClosure`
# constructor.
mc = MistyClosure(ir; do_compile=true)

# Call it.
mc(5.0) == sin(5.0)

Alterative Use

Sometimes you'll already have an OpaqueClosure lying around, and not want to produce a new one from an IRCode (as this often takes a surprisingly large amount of time). If ths is the case, you can simply use the default constructor for MistyClosure. That is, write

mc = MistyClosure(existing_opaque_closure, ir)

Of course, it is your responsibility so ensure that ir and existing_opaque_closure are in agreement.