-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Better syntax for declaring nested mappings. #8499
Comments
Thanks for your suggestion, @amaxx! I'm wondering whether you really need a data structure that support "partial evaluation" or if what you really need is tuples as keys for mappings. So it would rather be
and you would use It would also have the benefit that you only need to compute one hash instead of 4. |
Perhaps using the tuple syntax we have is more clear:
|
Btw @Amxx, it occurred to me that you can (almost) already do this albeit at a memory cost: can use a single So basically the tuple syntax is a memory-efficient and more easy to ready alternative to the above. We should keep in mind that potentially the codegen should be able to avoid the memory overhead, if it is clever enough. |
We discussed it briefly today and it does not look like it's compatible with the direction we want the language to go. It's a nice bit of syntactic sugar but conflicts with the fact that we'd like mappings to eventually stop being special and become a user-defined generic type provided by the standard library, implementable using other language primitives. We're also planning to introduce proper, nameable tuple types at some point. This should be a good enough alternative to this feature and would work the way @axic has shown above: #8499 (comment). |
I would consider this a solution to this issue! Any timeframe on this ? |
Not sure actually. It's not directly on the roadmap but I think it might be a prerequisite of some other roadmap task. @ekpyron? |
We haven't really discussed the timeframe of those yet - it's one of the issues that makes our type system more regular and would prepare it for an easier transition to a type system including full generics, like tying data locations to types instead of variables. We could target them in the vicinity of #13365 (which is staged for Q2), but yeah, not entirely clear yet. |
At some point today I found myself declaring the following mapping:
mapping(bytes32 => mapping(bytes32 => mapping(bytes32 => mapping(uint256 => MyEntry)))) internal m_lookuptable;
I get this is a bit of an extreme case, but I might not be the only one nesting mappings. So I wondered, why not replace it with:
mapping(bytes32 => bytes32 => bytes32 => uint256 => MyEntry) internal m_lookuptable;
It should be pretty easy for the parser to adapt to this syntax, no backend modification should be necessary, and the result would be much more readable.
Also, it doesn't break anything, so backward compatibility would be unaffected.
The text was updated successfully, but these errors were encountered: