-
Notifications
You must be signed in to change notification settings - Fork 480
Implement trait support - Part 2/3 - New ink! codegen #470
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #470 +/- ##
==========================================
- Coverage 84.83% 80.90% -3.93%
==========================================
Files 125 133 +8
Lines 5374 5630 +256
==========================================
- Hits 4559 4555 -4
- Misses 815 1075 +260
Continue to review full report at Codecov.
|
This new codegen is based on the (also) new ink! IR.
…ctors Also this implementation avoids a lot of code duplication with the similar code generation for dispatch trait impl of ink! messages.
…fault New default is set to "false" so only contracts that actually use this feature need to specify it. Also renamed to dynamic_storage_allocator to better carry intention.
ascjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP
ascjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
53/62
…nt-trait-codegen # Conflicts: # lang/src/lib.rs
These will be re-enabled for the follow-up PR.
Was duplicated for events and storage structs.
ascjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cmichi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Trait Support - New ink! Codegen
This PR implements the new ink! codegen to provide support for ink! trait implementations.
Follow-up PRs
3.0.0.ink_lang_irandink_lang_codegencrates fromink_lang_macro. (Part 3)__ink_prefixed identifiers generically to be usable by all ink! language macros.ink_core/envprovided hasheshash_rawto hash some raw input byteshash_encodedto hash some SCALE encodable entity of typeTink_core/hashmodule and move all linkers to the above definitions.ink_coreAPI specific to this purpose.Env::Hash.topics[0]as the event's hashed signature if the ink! event is not anonymous.MAX_EVENT_TOPICSbut cannot distinguish between existing special-casedtopics[0]or not we need to make sure that non-anonymous events can actually only have up toMAX_EVENT_TOPICS - 1topics.ToDo List
#[ink(anonymous)]ink! event definitions.topics[0]as the hash of its signature.storage_allocink! config todynamic_storage_allocator.EnvTypestrait: Generalize EnvTypes to just Env, add MAX_EVENT_TOPICS constant #469payable. They implicitly are alwayspayabledue to endowment.Envtype alias. Should be no longer needed ideally and instead rely onink_lang::ContractEnvtrait implementation for the storage struct.BaseEventbug: [ink!3.0] the traitBaseEventis not implemented #483#[ink::trait_definition]proc. macro that asserts that the given trait definition respects certain rules.proc-macro-errorcrate is actually useful for us for error reporting in theink_lang_ircrate.CallBuilderet. al.InstantiateBuilderet. al. (now calledCreateBuilder)EnvTypestrait#[ink(storage)]) structEmitEventtrait implementation#[ink(impl)]defined impl blocks with no ink! specific itemsDispatchUsingModeimplConstrandMsgimplementations more concrete around trait implsDescription
The entire codegen library is going to be based on the new ink! IR that has been added in this previous PR.
In the end the
lang_lang_macrocrate that is the actual proc. macro will only have dependencies toink_lang_irandink_lang_codegenin order to completely do its job of generating the ink! smart contract code.API
The target API is for
ink_lang_codegenis kept minimal:Problematic Behavior
Default Trait Impls
Read more about this potential footgun here:
https://gist.github.com/Robbepop/de8a16d6b476a7d0b3bf88f343ac8384
New ink_core::env::call module
The
ink_core::env::callmodule got significantly cleaned up. Usage should be more clear now.Also its builders are now checking more properly the construction process and should have even less overhead than before.
Generated Metadata
Here is the metadata for the Flipper example contract generated with the new codegen:
{ "metadata_version": "0.1.0", "source": { "hash": "0x5f9c6583fab4323caebd7db0e57266c6973e3299406dc5ac3324f71017c4edbe", "language": "ink! 2.1.0", "compiler": "rustc 1.47.0-nightly" }, "contract": { "name": "flipper", "version": "2.1.0", "authors": [ "Parity Technologies <[email protected]>" ] }, "spec": { "constructors": [ { "args": [ { "name": "init_value", "type": { "displayName": [ "bool" ], "id": 1 } } ], "docs": [], "name": [ "new" ], "selector": "0xd183512b" }, { "args": [], "docs": [], "name": [ "default" ], "selector": "0x6a3712e2" } ], "docs": [], "events": [], "messages": [ { "args": [], "docs": [], "isPayable": false, "mutates": true, "name": [ "flip" ], "returnType": null, "selector": "0xc096a5f3" }, { "args": [], "docs": [], "isPayable": false, "mutates": false, "name": [ "get" ], "returnType": { "displayName": [ "bool" ], "id": 1 }, "selector": "0x1e5ca456" } ] }, "storage": { "struct": { "fields": [ { "layout": { "cell": { "key": "0x0000000000000000000000000000000000000000000000000000000000000000", "ty": 1 } }, "name": "value" } ] } }, "types": [ { "def": { "primitive": "bool" } } ] }