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

Arbcall refactor #57

Merged
merged 10 commits into from
Sep 4, 2020
Merged

Arbcall refactor #57

merged 10 commits into from
Sep 4, 2020

Conversation

saschatimme
Copy link
Collaborator

This refactors the arbcall logic to fix #55 and to hopefully avoid things like this happening in the future.
This also adds some more features:

  • Defines constants for the type unions we consider equivalent, e.g., const ArbLike = Union{Arb,ArbRef,Ptr{arb_struct}}.
  • Overloads the show method for these constants to get more readable output:
# before
  Closest candidates are:
    add!(::Union{ArbVector, Arblib.arb_vec_struct}, ::Union{ArbVector, Arblib.arb_vec_struct}, ::Union{ArbVector, Arblib.arb_vec_struct}; n, prec) at /Users/sascha/code/Arblib.jl/src/arbcall.jl:275

# now
  Closest candidates are:
    add!(::ArbVectorLike, ::ArbVectorLike, ::ArbVectorLike; n, prec) at /Users/sascha/code/Arblib.jl/src/arbcall.jl:275
  • The detection of length arguments is better now. If the argument is an Int and the previous argument ArbVectorLike or AcbVectorLike then the name of this argument is moved to be a kwarg, but only if the name is n or starts with len.
  • I also enabled in a separate commit the possibility to automatically also generate the true arb signature, i.e., without moving any positional argument to a keyword argument.

This also probably needs some more tests, but this not a task for 10pm :D

@kalmarek
Copy link
Owner

kalmarek commented Sep 4, 2020

I'm happy with the changes, but @Joel-Dahne have a look at this as well

@saschatimme
Copy link
Collaborator Author

@Joel-Dahne @kalmarek and myself are both happy with the changes and think that it's a good idea to always also generated the original signature as an escape hatch if our replacement logic is non-sensical. What do you think?

@saschatimme saschatimme mentioned this pull request Sep 4, 2020
6 tasks
Copy link
Collaborator

@Joel-Dahne Joel-Dahne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue with the automatic length is that you can still pass in two vectors with different lengths and crash Julia. So all of these methods should be considered unsafe. If we ever add exported versions of them we need to add proper bounds checks when wrapping them.

src/arbcall.jl Outdated
Comment on lines 214 to 223
# Automatic detection of length arguments for vectors
elseif (startswith(string(name(carg)), "len") || carg == Carg{Clong}(:n, false)) &&
rawtype(cargs[i-1]) ∈ (ArbVector, AcbVector) &&
name(carg) ∉ len_keywords

vec_name = name(cargs[i-1])
push!(kwargs, Expr(:kw, :($(name(carg))::Integer), :(length($vec_name))))
push!(len_keywords, name(carg))

else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we factor this out as a separate method? Mainly to make it easier to test independently since this is quite delicate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I factored it out and added some tests

src/types.jl Outdated
Comment on lines 231 to 245
const ArbTypes = Union{
Arf,
Arb,
ArbRef,
Acb,
AcbRef,
ArbVector,
AcbVector,
ArbMatrix,
AcbMatrix,
ArbRefVector,
AcbRefVector,
ArbRefMatrix,
AcbRefMatrix,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but can we either keep the Ref versions just under the default version or have all of them in the end, to make it easier to see directly what is going on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Joel-Dahne
Copy link
Collaborator

I did a very quick review of the code. In general I think it looks good, less code now. I think generating the original signature as well is reasonable! If we merge this then I can update #32 before merging that.

@saschatimme saschatimme merged commit 00973ac into master Sep 4, 2020
@Joel-Dahne Joel-Dahne mentioned this pull request Sep 6, 2020
@saschatimme saschatimme deleted the arbcall-refactor branch September 7, 2020 09:37
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.

len detection in arbcall is broken
3 participants