-
Notifications
You must be signed in to change notification settings - Fork 67
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
Strange convert
method
#313
Comments
The next function Base.convert(to_type::Type{<:Ref{T1}}, p::T2) where {BaseT,DerivedT, T1 <: BaseT, T2 <: SmartPointer{DerivedT}}
return to_type(convert(T1,p))
end |
The first one (returning x) fixes an ambiguity (see issue #301) CxxWrap.jl/test/inheritance.jl Line 58 in 36c7f3a
The last one is also to fix some ambiguity I think. |
I am not saying these methods are not necessary, but I am saying their
This reference to a "derived type" and "base type" seems like a red herring, though? Given that this method can be simplified to the following: function Base.convert(::Type{T1}, p::SmartPointer) where {T1}
return cxxupcast(T1, p[])[]
end So then if I have a But what it instead does is to return |
I think that simplification will indeed work, I need to do some more tests for this. Unfortunately, it still remains a convert-to-any method. |
I've simplified the methods a bit in PR #322. That way at least when we come across this code again in the future it'll be slightly easier to reason about :-) |
I also have some issues with conversion. I get an error like ERROR: LoadError: MethodError: convert(::Type{Observable}, ::CxxWrap.StdLib.SharedPtrAllocated{MeshLib.Mesh}) is ambiguous. Candidates:
convert(::Type{T1}, p::CxxWrap.CxxWrapCore.SmartPointer) where T1 in CxxWrap.CxxWrapCore at /home/jan/.julia/packages/CxxWrap/IdOJ
a/src/CxxWrap.jl:275
convert(::Type{T}, x) where T<:Observable in Observables at /home/jan/.julia/packages/Observables/jbVpe/src/Observables.jl:128
Possible fix, define
convert(::Type{T}, ::CxxWrap.CxxWrapCore.SmartPointer) where T<:Observable It is a tricky issue. Can maybe function Base.convert(::Type{T1}, p::SmartPointer) where {T1}
return cxxupcast(T1, p[])[]
end I am not familiar with CxxInternals, but AFAICT somewhere code like Or other ideas how to solve this? |
Yes, the |
The context is I want to add Makie plotting support to a Cxx wrapped type. Makie internally needs to convert stuff to observables and hits this error. |
Ok that sounds excessive, do you know if that causes practical problems? Like degrading package load time or dynamic dispatch time? One option might be instead of Base.convert(::Type{MyClass{S1}} ...
Base.convert(::Type{MyClass{S2}} ...
Base.convert(::Type{MyClass{S3}} ... to generate Base.convert(::Type{<:MyClass} ... |
It seems redefining the convert method signature as follows fixes this. No idea why, it feels like a dubious trick. See PR #334 function Base.convert(::Type{T1}, p::SmartPointer{T2}) where {T1, T2 <: T1} |
Oh, interesting. The devil is in the details with these tricky dispatch specificity cases. |
But makes sense, that this cannot clash with convert(::Type{Observable}, ::SmartPointer{<:Observable}) which probably never ever will happen. |
This is fixed by #338, which essentially removes automatic unboxing of smart pointers, which include these method this issue is about. Without that patch, loading CxxWrap there kills most of the benefits of the great new feature there, which caches generated native code across Julia invocations. I think it already is bad now (as it causes lots of code invalidations) but the effects in Julia 1.10 (resp. 1.9, as the plan is to backport this feature) is devastating. See this comment for some benchmarking. |
I've recently had reason to again check for
convert(Any, ...)
methods and discovered that CxxWrap still exports two:The first method just returns
x
, but the second does not. Indeed, itswhere
clause is really weird; it looks as if it meant to enforce a common overtype, but of courseAny
always is one, so I am not sure what the real idea is.@barche I'd suggest a fix... except I am not sure what this is meant to do, so I can't really suggest one
The text was updated successfully, but these errors were encountered: