-
Notifications
You must be signed in to change notification settings - Fork 455
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.
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
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.
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
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_ir
andink_lang_codegen
crates fromink_lang_macro
. (Part 3)__ink_
prefixed identifiers generically to be usable by all ink! language macros.ink_core/env
provided hasheshash_raw
to hash some raw input byteshash_encoded
to hash some SCALE encodable entity of typeT
ink_core/hash
module and move all linkers to the above definitions.ink_core
API specific to this purpose.Env::Hash
.topics[0]
as the event's hashed signature if the ink! event is not anonymous.MAX_EVENT_TOPICS
but 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 - 1
topics.ToDo List
#[ink(anonymous)]
ink! event definitions.topics[0]
as the hash of its signature.storage_alloc
ink! config todynamic_storage_allocator
.EnvTypes
trait: Generalize EnvTypes to just Env, add MAX_EVENT_TOPICS constant #469payable
. They implicitly are alwayspayable
due to endowment.Env
type alias. Should be no longer needed ideally and instead rely onink_lang::ContractEnv
trait implementation for the storage struct.BaseEvent
bug: [ink!3.0] the traitBaseEvent
is not implemented #483#[ink::trait_definition]
proc. macro that asserts that the given trait definition respects certain rules.proc-macro-error
crate is actually useful for us for error reporting in theink_lang_ir
crate.CallBuilder
et. al.InstantiateBuilder
et. al. (now calledCreateBuilder
)EnvTypes
trait#[ink(storage)]
) structEmitEvent
trait implementation#[ink(impl)]
defined impl blocks with no ink! specific itemsDispatchUsingMode
implConstr
andMsg
implementations 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_macro
crate that is the actual proc. macro will only have dependencies toink_lang_ir
andink_lang_codegen
in order to completely do its job of generating the ink! smart contract code.API
The target API is for
ink_lang_codegen
is 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::call
module 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: