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

Ensure inlined_ids eltype of StdVector is correct #112

Merged
merged 1 commit into from
Sep 13, 2023
Merged

Conversation

omus
Copy link
Member

@omus omus commented Sep 12, 2023

The GetObjectRefs function requires that a StdVector{ObjectID} is passed in for the inlined_ids argument. If we update serializer.object_ids to return a Set{ObjectID} things break in an unexpected way as StdVector(collect(Set{ObjectID}())) isa StdVector{Any} where as StdVector(collect(Set{ObjectIDAllocated}())) isa StdVector{ObjectID}.

Here's an overview which may help those trying to understand what's going on:

julia> using ray_julia_jll: ObjectID, ObjectIDAllocated

julia> using CxxWrap.StdLib: StdVector

julia> StdVector(ObjectIDAllocated[])
0-element CxxWrap.StdLib.StdVectorAllocated{ObjectID}

julia> StdVector(ObjectID[])
0-element CxxWrap.StdLib.StdVectorAllocated{Any}

julia> StdVector{ObjectID}(ObjectIDAllocated[])
ERROR: MethodError: no method matching StdVector{ObjectID}(::Vector{ObjectIDAllocated})

Closest candidates are:
  StdVector{ObjectID}()
   @ ray_julia_jll ~/.julia/packages/CxxWrap/aXNBY/src/CxxWrap.jl:624

Stacktrace:
 [1] top-level scope
   @ REPL[10]:1

julia> StdVector(ObjectIDAllocated[])::StdVector{ObjectID}
0-element CxxWrap.StdLib.StdVectorAllocated{ObjectID}

julia> StdVector(ObjectID[])::StdVector{ObjectID}
ERROR: TypeError: in typeassert, expected StdVector{ObjectID}, got a value of type CxxWrap.StdLib.StdVectorAllocated{Any}
Stacktrace:
 [1] top-level scope
   @ REPL[12]:1

The type checks here should provide some protection about accidental changes.

Related to: JuliaInterop/CxxWrap.jl#367

@omus omus self-assigned this Sep 12, 2023
@codecov
Copy link

codecov bot commented Sep 12, 2023

Codecov Report

Merging #112 (654d12a) into main (5c1c1fd) will not change coverage.
The diff coverage is 50.00%.

@@           Coverage Diff           @@
##             main     #112   +/-   ##
=======================================
  Coverage   75.06%   75.06%           
=======================================
  Files           8        8           
  Lines         369      369           
=======================================
  Hits          277      277           
  Misses         92       92           
Flag Coverage Δ
Ray.jl 75.06% <50.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/runtime.jl 53.72% <50.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@kleinschmidt kleinschmidt left a comment

Choose a reason for hiding this comment

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

seems liek the root cause here is that ObjectID is an abstract type adn julia just punts and turns it into Any? Or is ti CxxWrap's fault? Either way LGTM

Comment on lines 235 to 239
buffer = ray_jll.LocalMemoryBuffer(serialized_arg, serialized_arg_size, true)
metadata = ray_jll.NullPtr(ray_jll.Buffer)
inlined_ids = collect(serializer.object_ids)
inlined_refs = ray_jll.GetObjectRefs(worker, StdVector(inlined_ids))
inlined_ids = StdVector(collect(serializer.object_ids))::StdVector{ray_jll.ObjectID}
inlined_refs = ray_jll.GetObjectRefs(worker, inlined_ids)
ray_obj = ray_jll.RayObject(buffer, metadata, inlined_refs, false)
Copy link
Member

Choose a reason for hiding this comment

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

orthogonal to this PR but it seems liek these lines are identical to what's below and fiddly enough that they'd benefit from refactoring

Copy link
Member Author

Choose a reason for hiding this comment

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

I've left these lines duplicated for now as the Python code has minor differences. If we adopt those differences in our Julia code they will differ.

@omus
Copy link
Member Author

omus commented Sep 13, 2023

seems liek the root cause here is that ObjectID is an abstract type adn julia just punts and turns it into Any? Or is ti CxxWrap's fault? Either way LGTM

This seems to be another CxxWrap corner case with empty vectors as having any elements in the Vector is fine:

julia> x = [FromRandom(ObjectID)]
1-element Vector{ObjectIDAllocated}:
 ObjectIDAllocated(Ptr{Nothing} @0x0000600001cd8660)

julia> StdVector(x)
1-element CxxWrap.StdLib.StdVectorAllocated{ObjectID}:
 ray_julia_jll.ObjectIDDereferenced(Ptr{Nothing} @0x0000600001e6c3c0)

julia> y = ObjectID[FromRandom(ObjectID)]
1-element Vector{ObjectID}:
 ObjectIDAllocated(Ptr{Nothing} @0x0000600001cd8630)

julia> StdVector(y)
1-element CxxWrap.StdLib.StdVectorAllocated{ObjectID}:
 ray_julia_jll.ObjectIDDereferenced(Ptr{Nothing} @0x0000600001e8a790)

@omus omus merged commit 717ac03 into main Sep 13, 2023
3 of 4 checks passed
@omus omus deleted the cv/safe-inlined-ids branch September 13, 2023 04:34
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