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

Remove ContainerStorable.EncodeAsElement #354

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

fxamacker
Copy link
Member

Updates #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 onflow/cadence#2882.


  • Targeted PR against main branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

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

This commit simplifies encoding API by using Encode() to encode
both inlined/standalone array/map.
@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2023

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
@@                      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 Coverage Δ
array.go 68.18% <100.00%> (+0.09%) ⬆️
encode.go 79.74% <100.00%> (+3.27%) ⬆️
storable.go 59.37% <ø> (-0.83%) ⬇️
storable_slab.go 26.38% <0.00%> (-1.15%) ⬇️
map.go 65.41% <81.25%> (+0.06%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice!

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?

encode.go Outdated
Writer: w,
CBOR: streamEncoder,
encMode: encMode,
inlinedExtraData: newInlinedExtraData(),
Copy link
Member

Choose a reason for hiding this comment

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

Can this be created lazily, if needed?

@fxamacker
Copy link
Member Author

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).

Copy link
Contributor

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

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

Looks good to me.

This commit makes StorableSlab.Encode() return
error if it contains inlined array or inlined map.
@fxamacker
Copy link
Member Author

@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 onflow/cadence@aa087cf 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 onflow/cadence@aa087cf is OK so I can mimic that behavior in Atree tests.

@fxamacker fxamacker merged commit cb82995 into feature/array-map-inlining Oct 24, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants