MasonProtter / Bumper.jl

Bring Your Own Stack
MIT License
152 stars 6 forks source link

[Breaking] Replace `alloc` with `@alloc` #20

Closed MasonProtter closed 9 months ago

MasonProtter commented 9 months ago

This is safer, and also in some situations faster. Before you'd write

function f(x::Vector{Int})
    @no_escape begin # This called default_buffer()
        y = alloc(Int, length(x)) # This also called default_buffer()
        y .= x .+ 1
        sum(y)
    end
end

and now you write

function f(x::Vector{Int})
    @no_escape begin  # Only this calls default_buffer()
        y = @alloc(Int, length(x)) # this uses whatever buffer `@no_escape` uses.
        y .= x .+ 1
        sum(y)
    end
end

@alloc no longer takes an optional buffer argument, it is always associated with the @no_escape block that encloses it, and it cannot be used outside of a @no_escape block.

This makes @alloc a bit more like alloca in some senses. I think it was a mis-feature to allow alloc to be used lexically outside of a @no_escape block.

I also spruced up the README a little and added docstrings to the API functions. Preview of the new README here: https://github.com/MasonProtter/Bumper.jl/blob/alloc-macro/README.org

codecov-commenter commented 9 months ago

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (8126213) 63.15% compared to head (4186def) 85.86%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #20 +/- ## =========================================== + Coverage 63.15% 85.86% +22.71% =========================================== Files 1 2 +1 Lines 76 92 +16 =========================================== + Hits 48 79 +31 + Misses 28 13 -15 ``` | [Files](https://app.codecov.io/gh/MasonProtter/Bumper.jl/pull/20?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mason+Protter) | Coverage Δ | | |---|---|---| | [src/Bumper.jl](https://app.codecov.io/gh/MasonProtter/Bumper.jl/pull/20?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mason+Protter#diff-c3JjL0J1bXBlci5qbA==) | `75.00% <50.00%> (+11.84%)` | :arrow_up: | | [src/internals.jl](https://app.codecov.io/gh/MasonProtter/Bumper.jl/pull/20?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mason+Protter#diff-c3JjL2ludGVybmFscy5qbA==) | `86.36% <86.36%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.