Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking] Replace alloc with @alloc #20

Merged
merged 8 commits into from
Oct 22, 2023
Merged

[Breaking] Replace alloc with @alloc #20

merged 8 commits into from
Oct 22, 2023

Conversation

MasonProtter
Copy link
Owner

@MasonProtter MasonProtter commented Oct 21, 2023

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
Copy link

codecov-commenter commented Oct 21, 2023

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
@@             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 Coverage Δ
src/Bumper.jl 75.00% <50.00%> (+11.84%) ⬆️
src/internals.jl 86.36% <86.36%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MasonProtter MasonProtter merged commit c964717 into main Oct 22, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants