Skip to content

Remove checkData from copy constructor and assignment operator in Fields - #1533

Merged
ZedThree merged 6 commits into
nextfrom
remove_checkdata_field_constructors
Feb 4, 2019
Merged

Remove checkData from copy constructor and assignment operator in Fields#1533
ZedThree merged 6 commits into
nextfrom
remove_checkdata_field_constructors

Conversation

@d7919

@d7919 d7919 commented Jan 31, 2019

Copy link
Copy Markdown
Member

This allows us to copy and assign from empty fields.

@ZedThree

Copy link
Copy Markdown
Member

I think we test for this behaviour, so you'll likely need to remove those tests as well

@d7919

d7919 commented Jan 31, 2019

Copy link
Copy Markdown
Member Author

I think we test for this behaviour, so you'll likely need to remove those tests as well

It passed all the unit tests locally!

Edit Ah, it probably depends on the check level.

@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #1533 into next will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #1533      +/-   ##
==========================================
- Coverage   43.06%   43.05%   -0.02%     
==========================================
  Files         201      201              
  Lines       27257    27252       -5     
==========================================
- Hits        11738    11733       -5     
  Misses      15519    15519
Impacted Files Coverage Δ
src/field/field2d.cxx 78.63% <ø> (-0.19%) ⬇️
src/field/fieldperp.cxx 100% <ø> (ø) ⬆️
src/field/field3d.cxx 57.88% <ø> (-0.17%) ⬇️
tests/unit/field/test_field3d.cxx 100% <100%> (ø) ⬆️

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 2a68fee...168aa54. Read the comment docs.

@ZedThree

Copy link
Copy Markdown
Member

Not sure why CodeCov has chimed in!

Any major objections to this? I think this is the right thing to do (see #1385)

@d7919

d7919 commented Jan 31, 2019

Copy link
Copy Markdown
Member Author

One possible objection is operator= with mixed types (e.g 3d = 2d) have to do checkdata but same types (3d=3d) don't.

@johnomotani

Copy link
Copy Markdown
Contributor

I agree this is the right thing to do 👍

@ZedThree

ZedThree commented Feb 1, 2019

Copy link
Copy Markdown
Member

For the mixed types assignment, I think we need at least the check the rhs is allocated (else the copy won't work), but we could change what we do with that information, e.g. if the rhs is not allocated, deallocate the lhs and return. Otherwise, do the copy without checking if the rhs is finite.

@d7919

d7919 commented Feb 1, 2019

Copy link
Copy Markdown
Member Author

For the mixed types assignment, I think we need at least the check the rhs is allocated (else the copy won't work), but we could change what we do with that information, e.g. if the rhs is not allocated, deallocate the lhs and return. Otherwise, do the copy without checking if the rhs is finite.

Yes I thought about that a bit but decided for now that I'd just do the simplest thing (i.e. leave the checks in place). Happy to replace those with an isAllocated type check though.

@bendudson

Copy link
Copy Markdown
Contributor

I think having an isAllocated check, and invalidating the LHS if the RHS is invalid is probably the most consistent approach. I have some worry that not checking for invalid data will make tracking down bugs harder, but a user can always add calls to checkData for debugging.

@d7919

d7919 commented Feb 1, 2019

Copy link
Copy Markdown
Member Author

I think having an isAllocated check, and invalidating the LHS if the RHS is invalid is probably the most consistent approach. I have some worry that not checking for invalid data will make tracking down bugs harder, but a user can always add calls to checkData for debugging.

I hope this shouldn't impact debugging too much as we still rigorously checkData on the input and output of most operations so at the point of doing any calculation with the fields we should catch this.

Comment thread src/field/field3d.cxx

/// Check that the data is allocated
ASSERT1(rhs.isAllocated());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Instead of ASSERT here we could just choose to return the unallocated Field3D so that we allow assignment from unallocated fields -- I'm not sure that would be good but is an option.

@ZedThree

ZedThree commented Feb 4, 2019

Copy link
Copy Markdown
Member

Merging this now to immediately update #1345, but we may want to revisit mixed-type assignment for uninitialised fields

@ZedThree
ZedThree merged commit f3b3dcb into next Feb 4, 2019
@ZedThree
ZedThree deleted the remove_checkdata_field_constructors branch February 4, 2019 13:36
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.

5 participants