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

Use SimpleUnPack.jl instead of UnPack.jl #2288

Closed
wants to merge 1 commit into from
Closed

Conversation

devmotion
Copy link
Member

In this PR, I propose to switch from UnPack to SimpleUnPack, for reasons described in its README: https://github.com/devmotion/SimpleUnPack.jl

@@ -70,7 +70,7 @@ using PrecompileTools, Reexport

import Graphs: SimpleDiGraph, add_edge!, incidence_matrix

@reexport using UnPack
@reexport using SimpleUnPack
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'm a bit surprised about this re-export, is this actually needed? Or could it be limited to

Suggested change
@reexport using SimpleUnPack
@reexport using SimpleUnPack: @unpack

?

@YingboMa
Copy link
Member

We cannot do this because we actually overload the unpack function.

@YingboMa YingboMa closed this Sep 28, 2023
@YingboMa YingboMa deleted the dw/simpleunpack branch September 28, 2023 21:23
@devmotion
Copy link
Member Author

devmotion commented Sep 28, 2023

We cannot do this because we actually overload the unpack function.

Yes, I saw that and removed it in the PR - but it seems it's just forwarded to getproperty which is what SimpleUnPack uses anyway. So it should be completely fine to remove the unpack overload.

@devmotion devmotion restored the dw/simpleunpack branch September 28, 2023 21:41
@devmotion
Copy link
Member Author

@YingboMa or did you mean something else? Is this unpack overload used by some downstream package? In that case, probably the downstream packages could be switched to getproperty as well.

@YingboMa
Copy link
Member

No, unpack is deliberately overloaded to have a different behavior, and using getproperty is wrong in places where unpack is used.

@YingboMa YingboMa deleted the dw/simpleunpack branch September 28, 2023 21:44
@@ -1800,10 +1800,6 @@ function compose(syss...; name = nameof(first(syss)))
end
Base.:(∘)(sys1::AbstractSystem, sys2::AbstractSystem) = compose(sys1, sys2)

function UnPack.unpack(sys::ModelingToolkit.AbstractSystem, ::Val{p}) where {p}
getproperty(sys, p; namespace = false)
Copy link
Member

Choose a reason for hiding this comment

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

unpack changes the default. It doesn't just forwards.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I missed the namespace keyword argument - I guess that's the problem here?

@devmotion
Copy link
Member Author

Even if #2288 (comment) is problematic and this overload can't be removed, I think the PR should be reconsidered. Many uses of @unpack in the package do not deal with AbstractSystems and are just extracting properties (one example is

@unpack structure, fullvars = state
) - and for these SimpleUnPack or the destructuring syntax in Julia >= 1.7 is much better than UnPack.

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