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

feat: fromCell method for maps #1271

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Gusarich
Copy link
Member

Issue

Closes #1229.

Checklist

  • I have updated CHANGELOG.md
  • I have documented my contribution in docs/ and made the build locally
  • I have added tests to demonstrate the contribution is correctly implemented: this usually includes both positive and negative tests, showing the happy path(s) and featuring intentionally broken cases
  • I have run all the tests locally and no test failure was reported
  • I have run the linter, formatter and spellchecker
  • I did not do unrelated and/or undiscussed refactorings

@Gusarich Gusarich requested a review from a team as a code owner December 29, 2024 00:44
@anton-trunov anton-trunov added this to the v1.6.0 milestone Dec 29, 2024
@anton-trunov anton-trunov self-assigned this Dec 29, 2024
Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

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

  1. Let's change the syntax here to make it consistent with fromCell for structs/messages.

  2. We need negative tests showing what happens when the cell does not represent a valid map. We need to validate the cell and it seems to me we could use TVM's LDDICTS instruction here and check the remainder is an empty slice. Or is there a better approach? What do you think?

Comment on lines +374 to +375
let fizz: map<Int, Int> = emptyMap();
fizz.fromCell(cell);
Copy link
Member

Choose a reason for hiding this comment

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

hmmm, this should be consistent with what we have for structs:

struct Fizz { foo: Int }
let fizzCell = ...
let parsedFizz: Fizz = Fizz.fromCell(fizzCell);

So I would expect something like:

let fizz = map<Int, Int>.fromCell(cell);

This makes parsing harder but it seems it's too late to do it differently

@Gusarich
Copy link
Member Author

Gusarich commented Dec 29, 2024

2. We need negative tests showing what happens when the cell does not represent a valid map. We need to validate the cell and it seems to me we could use TVM's LDDICTS instruction here and check the remainder is an empty slice. Or is there a better approach? What do you think?

@anton-trunov LDDICTS doesn't check anything, and there are no TVM instructions for checking the whole dictionary for "correctness" actually. Implementation would have to iterate over the whole tree, which is very gas-consuming.

@anton-trunov
Copy link
Member

anton-trunov commented Dec 29, 2024

@Gusarich The TVM docs say this for LDDICTS:

Loads (parses) a (Slice-represented) dictionary s' from Slice s, and returns the remainder of s as s''

So, if a cell is map, then the remainder should be an empty slice, if I understand this correctly.

@Gusarich
Copy link
Member Author

Gusarich commented Dec 29, 2024

So, if a cell is map, then the remainder should be an empty slice, if I understand this correctly.

@anton-trunov LDDICTS doesn't even check the header of the map, it just checks the one single bit indicating whether it's empty or not when it's represented as Maybe X (similarly to what .load_dict() does.

https://github.com/ton-blockchain/ton/blob/ea0dc161639ef2640876d6de06f7224ac5873847/crypto/vm/dictops.cpp#L121-L146

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.

fromCell is missing for maps
2 participants