onflow / atree

Atree provides scalable arrays and scalable ordered maps.
https://onflow.org
Apache License 2.0
39 stars 13 forks source link

Remove ContainerStorable.EncodeAsElement #354

Closed fxamacker closed 8 months ago

fxamacker commented 8 months ago

Updates https://github.com/onflow/atree/issues/292

Currently, EncodeAsElement is used to encode inlined array and map, while Encode is used to encode standalone array and map.

This PR simplifies encoding API by using Encode() to encode both inlined/standalone array/map.

This helps simplify Cadence integration at https://github.com/onflow/cadence/pull/2882.


codecov-commenter commented 8 months ago

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (7ab6f5e) 62.53% compared to head (acdb685) 62.57%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## feature/array-map-inlining #354 +/- ## ============================================================== + Coverage 62.53% 62.57% +0.03% ============================================================== Files 15 15 Lines 10612 10599 -13 ============================================================== - Hits 6636 6632 -4 + Misses 3024 3017 -7 + Partials 952 950 -2 ``` | [Files](https://app.codecov.io/gh/onflow/atree/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow) | Coverage Δ | | |---|---|---| | [array.go](https://app.codecov.io/gh/onflow/atree/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow#diff-YXJyYXkuZ28=) | `68.18% <100.00%> (+0.09%)` | :arrow_up: | | [encode.go](https://app.codecov.io/gh/onflow/atree/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow#diff-ZW5jb2RlLmdv) | `79.74% <100.00%> (+3.27%)` | :arrow_up: | | [storable.go](https://app.codecov.io/gh/onflow/atree/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow#diff-c3RvcmFibGUuZ28=) | `59.37% <ø> (-0.83%)` | :arrow_down: | | [storable\_slab.go](https://app.codecov.io/gh/onflow/atree/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow#diff-c3RvcmFibGVfc2xhYi5nbw==) | `26.38% <0.00%> (-1.15%)` | :arrow_down: | | [map.go](https://app.codecov.io/gh/onflow/atree/pull/354?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow#diff-bWFwLmdv) | `65.41% <81.25%> (+0.06%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

fxamacker commented 8 months ago

Is this fixing the case we ran into on Friday in Cadence, the encoding of SomeStorable was triggering Encode instead of EncodeAsElement? If so, could you please add a test for it?

This was the simplification I mentioned in Friday's meeting as being in progress. It was annoying to have both functions but there were bigger fish to fry.

Will look into adding tests, etc. to this PR after resolving urgent edge case I found on Sunday (related to cadence.SomeStorable if it contains inlined array or map).

fxamacker commented 8 months ago

@turbolent

Is this fixing the case we ran into on Friday in Cadence, the encoding of SomeStorable was triggering Encode instead of EncodeAsElement? If so, could you please add a test for it?

This was the simplification I mentioned in Friday's meeting as being in progress. It was annoying to have both functions but there were bigger fish to fry.

Will look into adding tests, etc. to this PR after resolving urgent edge case I found on Sunday (related to cadence.SomeStorable if it contains inlined array or map).

UPDATE: I made changes to Cadence with commit https://github.com/onflow/cadence/pull/2882/commits/aa087cf0b697711822031aedc8ec000dabf580b4 and it has more detailed description in the commit message.

Given this, I will add tests for StorableSlab with SomeStorable (in separate PR) after you confirm https://github.com/onflow/cadence/pull/2882/commits/aa087cf0b697711822031aedc8ec000dabf580b4 is OK so I can mimic that behavior in Atree tests.