-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Improve BoundsError reporting for AbstractArrays #9607
Conversation
i think the main optimization necessary to lessen the likelyhood of a performance issue to prohibit inlining of the vargs form of the BoundsError constructor |
@vtjnash I'm not sure I follow. Do you mean avoiding the actual construction of tuples like
unless actually needed? And if so, would adding |
Yes. Although the constructor is actually at Line 9 in da5013b
|
The other effect of possible significance is in |
ok, which means at the moment I have no idea what to do then...
What if we forced inlining of all the |
Yes
That might work. Perhaps Jeff can comment. It also just might not be too much of an issue. I suspect Jeff's Tuple rewrite will fix this anyways |
Ok thanks I'll give it a try and update this PR then. |
Prodromic to BoundsError reporting improvement
covers AbstractArray indexing
7c7d49d
to
359d5d3
Compare
Ok this is now updated with the discussed inline/noinline changes - see last commit. |
359d5d3
to
f98fb72
Compare
I have redone the manual inlining/noinlining thing. Hopefully this time it should be working. I had to do some ugly things in order to make it compile. |
f98fb72
to
a1ffab5
Compare
this should help avoiding unnecessary tuple allocations, i.e. delaying allocation until an error actually occurs
a1ffab5
to
46087b9
Compare
Updated with just a little less ugliness. (I'm still non sure it's actually doing what it's supposed to.) |
I tried a couple of benchmarks and couldn't find any significant difference. Any suggestions on what cases to test? Other comments? Otherwise this could be merged I think. |
Sorry, I totally missed this when it came out. Nice! Is another option to wait to define Anyway, assuming we need to define it early, LGTM. I'd encourage merging (since you wrote this there are now merge conflicts---again, sorry for the delay in noticing this). |
Yes I got sidetracked. I'll look into this again as soon as I have some time to make it up to date again, and then merge (after trying again to avoid the ugly |
I think a simpler solution to macro _inline_expr()
Expr(:meta, :inline)
end
f() = (@_inline_expr(); …) (See |
@mbauman : that was my first attempt, but see 359d5d3#commitcomment-9175007. When I tested it, it did not work. |
That's different. This does work because it's using a macro to insert the appropriate syntax (and not just creating a value): julia> macro _noinline_expr()
Expr(:meta, :noinline)
end
julia> f() = (@_noinline_expr(); 1)
g() = f()
g (generic function with 1 method)
julia> @code_llvm g()
define i64 @julia_g_331067() {
top:
%0 = call i64 @julia_f_331068(), !dbg !1795
ret i64 %0, !dbg !1795
} |
Ah I see. Nice trick! |
This is now superseded by #10525, closing. |
This uses the new interface of
BoundsError
in thecheckbounds
functions, which is used by AbstractArrays (including Arrays in some cases). In order to do that, I had to split the external (exported and documented) version ofcheckbounds
and the internal one, which used a different - undocumented - interface. I called_checkbounds
the latter, but suggestions for better names are indeed welcome, even if it's just and internal function.Using BitArrays as an example, here is a before/after:
Before:
After:
I tried to avoid extra allocations etc, but I'm submitting as a PR for review just to confirm that there should be no performance issues (cc @vtjnash which did the new BoundsError interface).
Out of necessity, the reporting is also not particularly precise in more convoluted cases, e.g.:
where the whole indexing expression is reported; it's still much better then before though.
If this is OK I'll proceed improving the error reporting in other areas as well (e.g. Strings).