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

ConstructionBase integration #99

Merged
merged 9 commits into from
Jul 18, 2023
Merged

ConstructionBase integration #99

merged 9 commits into from
Jul 18, 2023

Conversation

kleinschmidt
Copy link
Member

@kleinschmidt kleinschmidt commented Jul 6, 2023

Due to the possibility of parametric record types, this is a bit more complex than just creating a namedtuple, so I opted to include a method for each @version inside the outer constructors block.

There's an unfortunate bit of copy-paste required from ConstructionBase due to how ConstructionBase checks for propertynames vs. fieldnames in versions before 1.7; that can be removed if we stop supporting 1.6.

closes #97


@kleinschmidt
Copy link
Member Author

Hm, not clear why 1.6 is failing. Here's the error msg:

  The function `Base.propertynames` was overloaded for type `ParentV1`.
  Please make sure the following methods are also overloaded for this type:
  ```julia
  ConstructionBase.setproperties
  ConstructionBase.getproperties # optional in VERSION >= julia v1.7
  ```

@kleinschmidt kleinschmidt marked this pull request as ready for review July 11, 2023 18:04
Project.toml Show resolved Hide resolved
src/schemas.jl Show resolved Hide resolved
test/runtests.jl Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
Comment on lines +215 to +218

a = A91V1(; a=1)
a2 = @set a.a = 2
@test a2.a == 2
Copy link
Member

Choose a reason for hiding this comment

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

Why are these tests needed? Seems like the later testset covers this. At the very least this should be made into a separate testset inside this module

Copy link
Member Author

Choose a reason for hiding this comment

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

just to make sure that the ConstructionBase name is interpolated correctly as well, since we generate code with $ConstructionBase. in teh macro

Copy link
Member

Choose a reason for hiding this comment

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

Okay, would have been nice to have this as a separate testcase inside the submodule as mentioned. I'll leave this unresolved

src/Legolas.jl Outdated Show resolved Hide resolved
Comment on lines +356 to +360
nt = ConstructionBase.getproperties(r)
nt_new = merge(nt, patch)
ConstructionBase.check_patch_properties_exist(nt_new, nt, r, patch)
args = Tuple(nt_new) # old julia inference prefers if we wrap in Tuple
return ConstructionBase.constructorof(R)(args...)
Copy link
Member

Choose a reason for hiding this comment

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

At first I was curious about improving performance as this converts to a NamedTuple first. As this is also what Tables.rowmerge already does this seems perfectly fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I was starting to go down that rabbit hole and eventually decided this was probably good enough...

@kleinschmidt kleinschmidt merged commit 0d9ec27 into main Jul 18, 2023
5 checks passed
@kleinschmidt kleinschmidt deleted the dfk/construction branch July 18, 2023 21:56
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.

Accessors.jl support (lack of positional argument constructors)
2 participants