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 properties, not fields #60

Merged
merged 1 commit into from
Jun 28, 2022
Merged

use properties, not fields #60

merged 1 commit into from
Jun 28, 2022

Conversation

aplavin
Copy link
Member

@aplavin aplavin commented Jun 22, 2022

fix #59

src/ConstructionBase.jl Outdated Show resolved Hide resolved
src/ConstructionBase.jl Outdated Show resolved Hide resolved
@jw3126
Copy link
Member

jw3126 commented Jun 22, 2022

@rafaqz what do you think? Should we just drop julia < v1.7 support? The alternative would be to base getproperties on fieldnames/propertynames based on the julia version. Which I think is a bad idea.

@jw3126
Copy link
Member

jw3126 commented Jun 22, 2022

If this works for getproperties, it might also be possible to remove the @generated here https://github.com/JuliaObjects/ConstructionBase.jl/blob/master/src/ConstructionBase.jl#L37 ?

@aplavin
Copy link
Member Author

aplavin commented Jun 22, 2022

Should we just drop julia < v1.7 support?

Well, the same function works, but slower - not for the tightest loops.

See the new commit: it keeps the current behavior on 1.6-, throwing when fields != properties. 1.7+ get the correct properties handling.

Also, maybe there are better ways to get struct properties as a namedtuple?

@codecov-commenter
Copy link

codecov-commenter commented Jun 22, 2022

Codecov Report

Merging #60 (16ba039) into master (dec3c28) will increase coverage by 0.08%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   98.16%   98.24%   +0.08%     
==========================================
  Files           3        3              
  Lines         109      114       +5     
==========================================
+ Hits          107      112       +5     
  Misses          2        2              
Impacted Files Coverage Δ
src/ConstructionBase.jl 97.53% <100.00%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dec3c28...16ba039. Read the comment docs.

src/ConstructionBase.jl Outdated Show resolved Hide resolved
src/ConstructionBase.jl Outdated Show resolved Hide resolved
src/ConstructionBase.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
@rafaqz
Copy link
Member

rafaqz commented Jun 22, 2022

Julia v1.6 is LTS and this package has ~ 500 dependants.

It worries me a lot dropping 1.6 support.

@aplavin
Copy link
Member Author

aplavin commented Jun 22, 2022

It worries me a lot dropping 1.6 support.

Nothing gets dropped. Users on Julia 1.7+ get the bug fixed, users on 1.6- get a cleaner error instead of a confusing exception or silently wrong behavior.
All tests of this package and major dependants pass on all julia versions.

Copy link
Member

@jw3126 jw3126 left a comment

Choose a reason for hiding this comment

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

LGTM (the downstream package tests hack needs to be removed before merge)

@aplavin
Copy link
Member Author

aplavin commented Jun 22, 2022

@jw3126 as you asked about @generated more generally, please see the last commit: it simplifies two other constructors, getting rid of @generated. Doesn't look like it was necessary there in the first place...

src/ConstructionBase.jl Outdated Show resolved Hide resolved
src/ConstructionBase.jl Outdated Show resolved Hide resolved
@rafaqz
Copy link
Member

rafaqz commented Jun 22, 2022

@aplavin this is what I'm worried about

Well, the same function works, but slower

It has to be a compile time operation on 1.6

(This package is used in extremely performance critical code because it compiles away. If we add any cost at all to the methods here it will have very bad consequences, and effectively remove the possibility to use 1.6, even if it "still works")

@aplavin
Copy link
Member Author

aplavin commented Jun 22, 2022

@rafaqz that comment of mine referred to an older version of this PR. Currently, there should be no performance regression.
For example, all Accessors.jl performance tests pass.

@jw3126
Copy link
Member

jw3126 commented Jun 27, 2022

I would like to merge this? Any objections?

src/ConstructionBase.jl Outdated Show resolved Hide resolved
@jw3126
Copy link
Member

jw3126 commented Jun 28, 2022

@aplavin can you merge master into this so the integration tests run with this PR? After they pass I will merge this PR!

Co-authored-by: Jan Weidner <jw3126@gmail.com>
@jw3126 jw3126 merged commit 9fa5044 into JuliaObjects:master Jun 28, 2022
@jw3126
Copy link
Member

jw3126 commented Jun 28, 2022

Thanks again @aplavin this PR is a huge improvement!

@ancapdev
Copy link

ancapdev commented Jun 28, 2022

Just pulled this in to some code that now breaks.

While this solves the issue for anyone who wants to operate on custom properties, the scope of usability seems rather narrow as it breaks any type that has computed properties (trying to to call a constructor with all those properties as arguments) which you'd never want to set nor construct from.

@aplavin
Copy link
Member Author

aplavin commented Jun 28, 2022

@ancapdev this PR just fixes a bug in ConstructionBase: earlier, getproperties returned properties, but used field names instead of property names. This makes little sense conceptually, and (I think) was implemented because older julia versions didn't allow making the proper behavior performant.

There has been work on introducing getfields in #54, sounds like fields may better suit your usecase than properties.
By the way, getproperties docs specifically mention that in your (computed) case it makes sense to define getproperties(::MyType) explicitly.

@jw3126
Copy link
Member

jw3126 commented Jun 28, 2022

@ancapdev thanks a lot this is valuable feedback for us. Is some of that code open source, I would like to take a look at it?

@ancapdev
Copy link

@aplavin Thanks, that's a good option, we could define getproperties directly. Our use case is indirect through Setfield.jl.

@jw3126 The affected code we have is not public, unfortunately, but it's nothing particularly complex. We simply had some structs with a few computed properties, and we were using Setfield.@set to update underlying fields on some of these objects.

@jw3126
Copy link
Member

jw3126 commented Jun 28, 2022

If you are only interested in Setfield.@set I would directly overload ConstructionBase.setproperties and not touch getproperties.

@ancapdev
Copy link

That also makes sense, thanks

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.

Actually use properties, not fields
5 participants