Skip to content

Commit

Permalink
Handle Unions / UnionAlls of Tuples in zero_rdata (#284)
Browse files Browse the repository at this point in the history
* Handle unions and unionalls of tuples

* Bump patch

* Add comment

* Refine new tests

* Refine implementation

* Refine implementation further

* Add comment
  • Loading branch information
willtebbutt authored Oct 7, 2024
1 parent 534fc19 commit d4285ef
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Mooncake"
uuid = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
authors = ["Will Tebbutt, Hong Ge, and contributors"]
version = "0.4.8"
version = "0.4.9"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
1 change: 1 addition & 0 deletions src/fwds_rvs_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ obtained from `P` alone.
R == NoRData && return true
isabstracttype(P) && return false
(isconcretetype(P) || P <: Tuple) || return false
(P <: Tuple && !(P isa DataType)) && return false # catch Unions and UnionAlls
(P <: Tuple && Base.datatype_fieldcount(P) === nothing) && return false

# For general structs, just look at their fields.
Expand Down
4 changes: 3 additions & 1 deletion test/fwds_rvs_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ end
@testset "zero_rdata_from_type checks" begin
@test Mooncake.can_produce_zero_rdata_from_type(Vector) == true
@test Mooncake.zero_rdata_from_type(Vector) == NoRData()
@test Mooncake.can_produce_zero_rdata_from_type(FwdsRvsDataTestResources.Foo) == false
@test !Mooncake.can_produce_zero_rdata_from_type(FwdsRvsDataTestResources.Foo)
@test Mooncake.can_produce_zero_rdata_from_type(Tuple{Float64, Type{Float64}})
@test ==(
Mooncake.zero_rdata_from_type(FwdsRvsDataTestResources.Foo),
Mooncake.CannotProduceZeroRDataFromType(),
)
@test !Mooncake.can_produce_zero_rdata_from_type(Tuple)
@test !Mooncake.can_produce_zero_rdata_from_type(Union{Tuple{Float64}, Tuple{Int}})
@test !Mooncake.can_produce_zero_rdata_from_type(Tuple{T, T} where {T<:Integer})
end
@testset "lazy construction checks" begin
# Check that lazy construction is in fact lazy for some cases where performance
Expand Down

2 comments on commit d4285ef

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/116751

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.9 -m "<description of version>" d4285efab2f0799bfeb26644eeb475eb755d1354
git push origin v0.4.9

Please sign in to comment.