diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 64a4f48..70a19d8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -24,8 +24,6 @@ jobs: matrix: version: - '1.10' - - '1.6' - - 'nightly' os: - ubuntu-latest arch: diff --git a/Project.toml b/Project.toml index a8bf417..fdcd770 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MistyClosures" uuid = "dbe65cb8-6be2-42dd-bbc5-4196aaced4f4" -authors = ["Will Tebbutt", "Frames White", "and Hong Ge"] -version = "1.0.0-DEV" +authors = ["Will Tebbutt", "Frames White", "Hong Ge"] +version = "1.0.0" [compat] julia = "1.10" diff --git a/README.md b/README.md index 1ce94ec..5816161 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,32 @@ [![Build Status](https://github.com/compintell/MistyClosures.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/compintell/MistyClosures.jl/actions/workflows/CI.yml?query=branch%3Amain) [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) + +Marginally less opaque closures. + +Specifically, a `MistyClosure` is comprises an `OpaqueClosure` and an `IRCode`. +This is useful if you generate an `OpaqueClosure` from an `IRCode`, and want to be able to retrieve the `IRCode` later on. + +## Recommended Use + +```julia +# 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 +```julia +mc = MistyClosure(existing_opaque_closure, ir) +``` +Of course, it is _your_ responsibility so ensure that `ir` and `existing_opaque_closure` are in agreement. diff --git a/src/MistyClosures.jl b/src/MistyClosures.jl index 4e25e83..c63dbf4 100644 --- a/src/MistyClosures.jl +++ b/src/MistyClosures.jl @@ -1,5 +1,17 @@ module MistyClosures -# Write your package code here. +using Core: OpaqueClosure +using Core.Compiler: IRCode + +struct MistyClosure{Toc<:OpaqueClosure} + oc::Toc + ir::IRCode +end + +MistyClosure(ir::IRCode; kwargs...) = MistyClosure(OpaqueClosure(ir; kwargs...), ir) + +(mc::MistyClosure)(x::Vararg{Any, N}) where {N} = mc.oc(x...) + +export MistyClosure end diff --git a/test/runtests.jl b/test/runtests.jl index 40a62b4..941017f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,15 @@ -using MistyClosures -using Test +using MistyClosures, Test + +using Core: OpaqueClosure @testset "MistyClosures.jl" begin - # Write your tests here. + ir = Base.code_ircode_by_type(Tuple{typeof(sin), Float64})[1][1] + + # Recommended constructor. + mc = MistyClosure(ir; do_compile=true) + @test @inferred(mc(5.0)) == sin(5.0) + + # Default constructor. + mc_default = MistyClosure(OpaqueClosure(ir; do_compile=true), ir) + @test @inferred(mc_default(5.0) == sin(5.0)) end