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

Implement new trait definition codegen 🚀 #665

Merged
merged 516 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
516 commits
Select commit Hold shift + click to select a range
f65aaa1
fix spelling error in docs
Robbepop Sep 25, 2021
a4e0fb0
remove commented-out code
Robbepop Sep 25, 2021
acc157e
move query_amount_{constructors,messages} utilities into own functions
Robbepop Sep 25, 2021
894ec32
implement codegen for constructor decoder enum type
Robbepop Sep 25, 2021
24b896f
slightly refactor AcceptsPayments and EnablesDynamicStorageAllocator
Robbepop Sep 25, 2021
fe6ce66
fix bug that spans of ink! trait messages have not been registered
Robbepop Sep 25, 2021
7ee4b7d
add codegen for ExecuteDispatchable for constructor decoder
Robbepop Sep 25, 2021
6811177
add codegen for expr to query if any ink! message if payable
Robbepop Sep 25, 2021
8c79589
implement preliminary codegen for new ink! dispatch entry points
Robbepop Sep 25, 2021
0961b7a
add ink_lang::execute_constructor_2 utility dispatch function
Robbepop Sep 25, 2021
6eb20db
demand ExecuteDispatch trait impl from generated decoder types
Robbepop Sep 25, 2021
4781e53
trait-incrementer constructor now takes and sets initial value
Robbepop Sep 25, 2021
47c50bd
apply rustfmt
Robbepop Sep 25, 2021
0c22563
implement message decoder type codegen for new dispatch
Robbepop Sep 25, 2021
c3e3e70
enable entry point codegen for new dispatch
Robbepop Sep 25, 2021
4d57a8d
fix doc comment
Robbepop Sep 25, 2021
7e9128d
remove old dispatch codegen
Robbepop Sep 25, 2021
8a833a7
rename dispatch2 module to dispatch
Robbepop Sep 25, 2021
5250fb9
apply rustfmt
Robbepop Sep 25, 2021
8600023
generate dispatch info trait impls always
Robbepop Sep 25, 2021
3cb6cec
no longer generate unnecessary braces in new dispatch codegen
Robbepop Sep 25, 2021
c0a0393
adjust UI tests for new dispatch codegen
Robbepop Sep 25, 2021
82d74ff
no longer derive core::fmt::Debug for dispatch decoder types
Robbepop Sep 25, 2021
a9953e8
fix bug in dispatcher utility method
Robbepop Sep 25, 2021
8202069
remove all no longer needed types and traits from ink_lang crate
Robbepop Sep 25, 2021
d05b57c
fix UI test
Robbepop Sep 25, 2021
87e1338
silence non-minimal bool clippy warning in expanded code
Robbepop Sep 25, 2021
b3a67a8
fix bug in dispatch codegen
Robbepop Sep 26, 2021
b1647e8
add IsDocAttribute::extract_docs utility method for ink! IR
Robbepop Sep 27, 2021
b4076c5
overhaul ink! metadata codegen
Robbepop Sep 27, 2021
618de63
silence bad clippy warning
Robbepop Sep 27, 2021
aa70e3c
rename execute_{message_2, constructor_2} to execute_{message, constr…
Robbepop Sep 27, 2021
7a6192f
make ink! root contract messages revert state when returning Result::…
Robbepop Sep 27, 2021
c1cb26a
fix some formatting issues
Robbepop Sep 27, 2021
429185a
extend is_result_{type, err} unit tests
Robbepop Sep 27, 2021
5c38477
improve error messages for invalid ink! input and output types
Robbepop Sep 27, 2021
fafe9c6
add missing UI test expectation files
Robbepop Sep 27, 2021
b3abfb9
add UI tests for many ink! message and constructor inputs and outputs
Robbepop Sep 27, 2021
d148e58
move noop contract UI test
Robbepop Sep 27, 2021
5183077
normalize UI test
Robbepop Sep 27, 2021
545e954
add passing UI tests for payable and selector properties
Robbepop Sep 27, 2021
66f8460
improve passing ink! message selector UI test
Robbepop Sep 27, 2021
7b60f64
add passing UI test for ink! constructor selector property
Robbepop Sep 27, 2021
661bad2
add UI tests for ink! storage structs with various fields
Robbepop Sep 27, 2021
98aede5
add passing UI tests for ink! events
Robbepop Sep 27, 2021
ed86a03
add passing packed ink! storage struct UI test
Robbepop Sep 27, 2021
4d6deec
improve macro hygiene in StorageLayout derive impl
Robbepop Sep 27, 2021
0bdb371
add no-implicit-prelude passing UI test
Robbepop Sep 27, 2021
819649d
add impl alias passing UI test
Robbepop Sep 27, 2021
18951bd
modernize passing UI test for ink! storage struct derives
Robbepop Sep 27, 2021
f630bd2
modernize flipper example contract passing UI test
Robbepop Sep 27, 2021
0bba5b3
add new trait-flipper example passing UI test
Robbepop Sep 27, 2021
9855df6
add new passing UI test for #[ink(impl)] property
Robbepop Sep 27, 2021
4762b96
rename 03-incrementer-contract UI test
Robbepop Sep 27, 2021
d31fecb
modernize example incrementer passing UI test
Robbepop Sep 27, 2021
21f7c19
apply rustfmt to UI test
Robbepop Sep 27, 2021
92d6bcd
fix a doc test in ink_storage_derive crate
Robbepop Sep 27, 2021
04c44ce
add passing UI test for trait based incrementer example ink! smart co…
Robbepop Sep 27, 2021
a450b71
apply rustfmt to UI test
Robbepop Sep 27, 2021
7a9a5c1
add passing UI tests for #[ink::contract] configs
Robbepop Sep 27, 2021
f317596
add passing UI test for #[ink::contract(env = ..)] config
Robbepop Sep 27, 2021
f510ebc
modernize env-access passing UI test
Robbepop Sep 27, 2021
82cf1db
modernize passing UI test to assert Rust items are properly expanded
Robbepop Sep 27, 2021
e9c0e59
add passing UI test to assert existence of aliases for all env types
Robbepop Sep 27, 2021
cfe8764
rename remaining passing UI tests
Robbepop Sep 27, 2021
10579bb
move commented out UI test to top
Robbepop Sep 27, 2021
0cce1f8
move passing UI contract example tests to end
Robbepop Sep 27, 2021
dd116b4
fix StorageLayout derive unit tests
Robbepop Sep 27, 2021
dd66528
replace vec! by plain old arrays in StorageLayout derive expansion
Robbepop Sep 27, 2021
f764473
remove plenty of usages of vec! macro in the ink! codebase
Robbepop Sep 27, 2021
752db02
improve macro hygiene in call_builder codegen
Robbepop Sep 27, 2021
31e7551
slightly reformat erc20 UI test
Robbepop Sep 28, 2021
28073d5
add ink! event passing UI tests
Robbepop Sep 28, 2021
0b84f77
move minimal ink! smart contract UI test case to front
Robbepop Sep 28, 2021
032c3dc
modernize simple definition UI test
Robbepop Sep 28, 2021
3adb955
add simple no-implicit-prelude UI test for ink::trait_definition macro
Robbepop Sep 28, 2021
99b46f9
add some #[ink::trait_definition] UI tests
Robbepop Sep 28, 2021
9668272
rename #[ink::trait_definition] UI tests
Robbepop Sep 28, 2021
df3abd4
add UI tests for #[ink::trait_definition] with async and const messages
Robbepop Sep 28, 2021
c19799b
add more UI tests for #[ink::trait_definition]
Robbepop Sep 28, 2021
505ac66
normalize #[ink::trait_definition] UI tests
Robbepop Sep 28, 2021
c58350e
normalize some UI tests
Robbepop Sep 28, 2021
083ed0e
add new UI tests for #[ink::trait_definition]
Robbepop Sep 28, 2021
6e39eca
add more UI tests for #[ink::trait_definition]
Robbepop Sep 28, 2021
fdfd625
add more UI tests for #[ink::trait_definition]
Robbepop Sep 28, 2021
ed3c4c3
generate guards for scale::Codec message inputs and outputs for ink! …
Robbepop Sep 28, 2021
689b9f7
add UI tests for non-codec message inputs and outputs for #[ink::trai…
Robbepop Sep 28, 2021
9e1f8c2
fix spelling issue
Robbepop Sep 28, 2021
88a4da3
Merge branch 'master' of github.com:paritytech/ink into robin-impl-dy…
Robbepop Sep 28, 2021
62832c8
apply rustfmt to test case
Robbepop Sep 28, 2021
61cc4dc
fix some spelling issues
Robbepop Sep 28, 2021
484e21d
implement ink! trait message selector and payable property guards
Robbepop Sep 28, 2021
d7d7c73
add UI tests for ink! trait message payable and selector property guards
Robbepop Sep 28, 2021
0adab4a
add passing UI tests for payable and selector property guards
Robbepop Sep 28, 2021
7692171
fix ERC-1155 example ink! smart contract
Robbepop Sep 28, 2021
2dcb14a
disallow #[ink(namespace)] property on ink! trait impl blocks
Robbepop Sep 28, 2021
b346322
add UI tests for #[ink(namespace)] attribute
Robbepop Sep 28, 2021
aa86357
fix unit tests that make use of #[ink(namespace = ..)]
Robbepop Sep 28, 2021
5df2616
update UI test case expectations
Robbepop Sep 28, 2021
4e0f2e5
use "diff" crate feature of trybuild crate
Robbepop Sep 28, 2021
213339b
fix some ink! specific error messages
Robbepop Sep 30, 2021
ce7b371
fix and improve some attribute error messages
Robbepop Sep 30, 2021
be28a2f
modernize failing #[ink::contract] UI tests
Robbepop Sep 30, 2021
74ec85e
fix some UI tests
Robbepop Sep 30, 2021
651d0b9
use wildcards in UI test inclusion pattern
Robbepop Sep 30, 2021
34e1dae
rename InkTraitDefinitionRegistry -> TraitDefinitionRegistry
Robbepop Sep 30, 2021
2b7b528
fix some tests
Robbepop Sep 30, 2021
4029219
apply rustfmt
Robbepop Sep 30, 2021
dfd6404
rename ink_lang::type_check module to codegen and make it a folder
Robbepop Sep 30, 2021
dcad588
rename BaseEvent trait to ContractEventBase
Robbepop Sep 30, 2021
c601e23
replace static_assertions usage by custom solution
Robbepop Sep 30, 2021
da4ccb2
remove static_assertions dependency from ink_lang
Robbepop Sep 30, 2021
c081d4d
apply rustfmt
Robbepop Sep 30, 2021
871a0bd
fix some examples
Robbepop Sep 30, 2021
2ae4259
move TraitMessage{Payable,Selector} into codegen submodule
Robbepop Sep 30, 2021
0115078
remove superflous True trait from ink_lang
Robbepop Sep 30, 2021
5b7b020
add ExecuteMessageConfig
Robbepop Sep 30, 2021
41299a2
refactor ink_lang dispatch definitions
Robbepop Sep 30, 2021
852496f
add show-codegen-docs crate feature to ink_lang to unhide the codegen…
Robbepop Sep 30, 2021
1f7347f
fix docs and add doc example tests to IsSameType
Robbepop Oct 1, 2021
e6f1556
add doc example tests to DispatchInput and DispatchOutput types
Robbepop Oct 1, 2021
d94f06a
fix spelling issues
Robbepop Oct 1, 2021
dc6e0dc
fix trait definition UI tests
Robbepop Oct 1, 2021
5095b81
rename TraitImplementer -> TraitImplementedById and move into codegen…
Robbepop Oct 1, 2021
7822260
apply rustfmt
Robbepop Oct 1, 2021
d33c0ff
move ImpliesReturn to ink_lang::codegen module and improve doc comments
Robbepop Oct 1, 2021
012e9f1
remove re-export of ImpliesReturn from ink_lang
Robbepop Oct 1, 2021
c650b7d
fix spelling issues
Robbepop Oct 1, 2021
78edcae
fix UI tests
Robbepop Oct 1, 2021
c6562bc
move ink! trait definition codegen definitions into trait_def submodule
Robbepop Oct 1, 2021
3e1fb54
move TraitDefinitionRegistry into new ink_lang::reflect module
Robbepop Oct 1, 2021
5db1bf3
unhide docs for TraitDefinitionRegistry
Robbepop Oct 1, 2021
9ac99c0
enable no-implicit-prelude UI test
Robbepop Oct 1, 2021
486fe91
add doc comment to reflect module
Robbepop Oct 1, 2021
fd649c4
update docs of TraitDefinitionRegistry
Robbepop Oct 1, 2021
1efe6af
move definitions for dispatch reflections into reflect submodule
Robbepop Oct 1, 2021
0fa0141
add usage example to COntractAmountDispatchables reflect trait
Robbepop Oct 1, 2021
0a05e39
add doc comment note to ContractAmountDispatchables trait
Robbepop Oct 1, 2021
00d81d4
add enforced newline to docs
Robbepop Oct 1, 2021
e5ba75f
improve docs
Robbepop Oct 1, 2021
55e1728
update docs for ContractDispatchableMessages trait
Robbepop Oct 1, 2021
52cb2e8
improve doc test
Robbepop Oct 1, 2021
69a12da
update docs of ContractDispatchableConstructors trait
Robbepop Oct 1, 2021
3320918
apply rustfmt
Robbepop Oct 1, 2021
ab7f9ec
fix hunspell dict
Robbepop Oct 1, 2021
778a46a
Merge branch 'master' of github.com:paritytech/ink into robin-impl-dy…
Robbepop Oct 1, 2021
c44c79e
remove non-existing optional UI test comments
Robbepop Oct 2, 2021
c6be743
merge UI tests into one fat one
Robbepop Oct 2, 2021
96e1b15
Merge branch 'master' of github.com:paritytech/ink into robin-impl-dy…
Robbepop Oct 4, 2021
ada8b61
use new selector_id! macro instead of raw values in doc tests
Robbepop Oct 4, 2021
8fb55b8
add usage docs to DispatchableMessageInfo trait
Robbepop Oct 4, 2021
1ebf078
improve doc test
Robbepop Oct 4, 2021
dca7804
add usage example to DispatchableConstructorInfo trait docs
Robbepop Oct 4, 2021
ebfa89e
add note and usage example for ContractMessageDecoder docs
Robbepop Oct 4, 2021
9b59754
add usage example to ContractConstructorDecoder docs
Robbepop Oct 4, 2021
95388bb
improve docs of some reflect types in ink_lang
Robbepop Oct 4, 2021
cad6876
improve docs
Robbepop Oct 4, 2021
ce59d8f
move TraitMessageInfo into reflect submodule
Robbepop Oct 4, 2021
b2696ee
remove invalid static_assertions imports
Robbepop Oct 4, 2021
5b44a93
take &mut [u8; 32] instead of &mut [u8] for blake2b output
Robbepop Oct 4, 2021
d06ae5d
make local_id of trait_def equal to selector of the message identifier
Robbepop Oct 4, 2021
95604c1
modernize payable_message UI trait_def passing test
Robbepop Oct 4, 2021
f579a9f
add usage example to TraitMessageInfo trait
Robbepop Oct 4, 2021
466eaa7
fix composed selector calculation for empty ink! trait namespaces
Robbepop Oct 4, 2021
21a613f
apply rustfmt
Robbepop Oct 4, 2021
8a14d37
extend usage example for TraitMessageInfo trait docs
Robbepop Oct 4, 2021
2168656
hopefully fix some weird spelling issues
Robbepop Oct 4, 2021
3139e70
make ink! trait definitions actually use the namespace config
Robbepop Oct 4, 2021
8c3a5cb
extend usage example for TraitMessageInfo docs
Robbepop Oct 4, 2021
798d48a
Merge branch 'master' of github.com:paritytech/ink into robin-impl-dy…
Robbepop Oct 5, 2021
f980060
rework some ink! trait definition passing UI tests
Robbepop Oct 5, 2021
cfbc354
add new passing UI test for ink! trait definitions concerning namespaces
Robbepop Oct 5, 2021
60de455
add fail UI tests for ink! trait definitions concerning overlapping s…
Robbepop Oct 5, 2021
6ab7912
move ContractName into reflect sub-module and add docs and usage example
Robbepop Oct 5, 2021
03e8fb3
move ContractEnv trait to reflect module and add extensive docs and u…
Robbepop Oct 5, 2021
f05ddd2
apply clippy suggestions
Robbepop Oct 5, 2021
e8d410f
move ContractReference trait to reflect module
Robbepop Oct 5, 2021
b2904e6
apply rustfmt
Robbepop Oct 5, 2021
368558e
fix some usage doc tests
Robbepop Oct 5, 2021
c013553
add extensive docs and usage example to ContractReference trait
Robbepop Oct 5, 2021
4f9efdf
improve docs
Robbepop Oct 5, 2021
004d517
improve docs (2)
Robbepop Oct 5, 2021
86c2968
move DispatchError to the reflect submodule
Robbepop Oct 5, 2021
51a64a7
add new event topic guards codegen to ink! codegen
Robbepop Oct 6, 2021
f6aa4fd
apply rustfmt and fix PhantomData import
Robbepop Oct 6, 2021
7d8c419
re-export RespectTopicLimit trait
Robbepop Oct 6, 2021
23ff499
modernize trait_erc20 example contract
Robbepop Oct 6, 2021
7399ea2
move Env and StaticEnv into ink_lang::codegen module
Robbepop Oct 6, 2021
b590a35
conditionally import EmitEvent trait anonymously for ink! impl blocks
Robbepop Oct 6, 2021
1a6748c
fix some UI tests
Robbepop Oct 6, 2021
f94130d
move EmitEvent trait to ink_lang::codegen module
Robbepop Oct 6, 2021
0a984a1
fix UI tests
Robbepop Oct 6, 2021
03e2a0a
fix UI tests
Robbepop Oct 6, 2021
f6b714b
add passing UI test for self.env() and Self::env() syntax
Robbepop Oct 6, 2021
e24f651
add failing UI tests for missing #[ink(impl)] annotation
Robbepop Oct 6, 2021
8eb1be8
move ContractEventBase trait to ink_lang::reflect submodule
Robbepop Oct 6, 2021
18a6ec4
apply rustfmt
Robbepop Oct 6, 2021
b3294ed
add usage example to ContractEventBase docs
Robbepop Oct 6, 2021
23c0e6c
move TraitModulePath to ink_lang::reflect submodule
Robbepop Oct 6, 2021
716e275
move ink! trait call builder codegen facilities to ink_lang::codegen …
Robbepop Oct 6, 2021
4febf96
move ContractCallBuilder to ink_lang::codegen submodule
Robbepop Oct 6, 2021
bc92311
move IsSameType and identity_type into ink_lang::codegen::utils module
Robbepop Oct 6, 2021
3eec2e3
rename identity_type to consume_type
Robbepop Oct 6, 2021
0b1c17a
apply rustfmt
Robbepop Oct 6, 2021
048ce44
add usage examples to consume_type docs (+ missing rename)
Robbepop Oct 6, 2021
b74772b
fix codegen to allow for environmental type usage in ink! trait defin…
Robbepop Oct 6, 2021
e368bf8
add UI test that uses environmental types in ink! trait definition
Robbepop Oct 6, 2021
46accaf
apply rustfmt
Robbepop Oct 6, 2021
4ab8a86
remove unused Selector::unique_id method
Robbepop Oct 6, 2021
7b978c2
remove Selector::from_bytes
Robbepop Oct 6, 2021
aa54576
rename Selector::new -> Selector::compute
Robbepop Oct 6, 2021
8d4f3ad
fix some UI tests for rename
Robbepop Oct 6, 2021
a406b84
change API: Selector::as_bytes -> Selector::to_bytes and return by value
Robbepop Oct 6, 2021
ca9fa3c
add payability to hunspell dict
Robbepop Oct 7, 2021
49b1340
use ink! trait info object instead of uniqe trait ID for TraitCallFor…
Robbepop Oct 7, 2021
88995a9
adjust UI tests
Robbepop Oct 7, 2021
3a70166
apply rustfmt
Robbepop Oct 7, 2021
1b71efd
remove TraitUniqueId trait
Robbepop Oct 7, 2021
2106c44
remove TraitImplementedById and utilities to compute ink! trait verif…
Robbepop Oct 7, 2021
41b3652
remove unused CannotCallTraitConstructor variant
Robbepop Oct 9, 2021
061b4c7
Update to using trybuild version 1.0.49
Robbepop Oct 9, 2021
ea5c995
add comment that explains why we have both result checks in execution
Robbepop Oct 9, 2021
a511128
introduce DecodeDispatch trait
Robbepop Oct 9, 2021
53ab40b
use selector_bytes! in UI test
Robbepop Oct 9, 2021
02da59f
slightly improve fail UI tests
Robbepop Oct 9, 2021
8f1c4ea
fix warning in passing UI test
Robbepop Oct 9, 2021
b522fef
add new UI test to guard against trait message selector overlaps
Robbepop Oct 9, 2021
b9b2aaf
move UI tests from ink_lang_macro to ink_lang crate directory
Robbepop Oct 9, 2021
551da20
adjust UI tests after moving
Robbepop Oct 9, 2021
14c11fb
remove unused dev-dependencies from ink_lang_macro after moving UI tests
Robbepop Oct 9, 2021
1ca57ae
fix compilation error with Wasm target
Robbepop Oct 9, 2021
4a92351
fix CI with formatting checks for UI tests
Robbepop Oct 9, 2021
ebd2be3
add unpayable to hunspell dictionary
Robbepop Oct 9, 2021
f92ab20
fix hunspell spelling issues
Robbepop Oct 9, 2021
36123df
move ink-experimental-engine to ink_lang crate
Robbepop Oct 9, 2021
acd9d8b
Merge branch 'master' of github.com:paritytech/ink into robin-impl-dy…
Robbepop Oct 19, 2021
321aefe
update UI tests for new nightly compiler
Robbepop Oct 19, 2021
3caa44b
add missing fixed UI tests
Robbepop Oct 19, 2021
f081583
fix spelling issue in UI test
Robbepop Oct 19, 2021
d97da21
add docs explaining usage of AccumulatorRef et.al. in delegator example
Robbepop Oct 19, 2021
5c08ccf
extend is_result unit tests
Robbepop Oct 19, 2021
3d29b86
re-add pretty assertions
Robbepop Oct 19, 2021
629c24e
normalize used version in ink-metadata crate
Robbepop Oct 19, 2021
7db14d9
add skeleton for ink! 3.0-rc7 in RELEASES
Robbepop Oct 19, 2021
f72bfaf
add release information about this PR to RELEASES.md
Robbepop Oct 19, 2021
f1b0bd6
use ink! 3.0-rc6 in multisig example contract
Robbepop Oct 19, 2021
e6bd613
fix docs
Robbepop Oct 20, 2021
d2a44dd
remove commented out code
Robbepop Oct 20, 2021
74cd0b2
use unzip to partition input_bindings and input_types (thanks andrew!)
Robbepop Oct 20, 2021
a903971
improve #[ink(extension)] missing parameter error message
Robbepop Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 6 additions & 2 deletions .config/cargo_spellcheck.dic
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ defrag
defragmentation
deploy
dereferencing
deserializes
dispatchable
deserialize/S
dispatchable/S
encodable
evaluable
fuzzer
Expand Down Expand Up @@ -95,4 +95,8 @@ runtime/S
struct/S
vec/S
vector/S
implementer/S
deduplicated
wildcard/S
payability
unpayable
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ fmt:
script:
- cargo fmt --verbose --all -- --check
# For the UI tests we need to disable the license check
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/macro/tests/ui/contract/{pass,fail}/*.rs
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/tests/ui/contract/{pass,fail}/*.rs
- cargo fmt --verbose --all -- --check --config=license_template_path="" crates/lang/tests/ui/trait_def/{pass,fail}/*.rs


#### stage: examples
Expand Down
44 changes: 44 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
# Version 3.0-rc7 (UNRELEASED)

This is the 7th release candidate for ink! 3.0.

## Added

- The ink! codegen now heavily relies on static type information based on traits defined in `ink_lang`.
- Some of those traits and their carried information can be used for static reflection of ink!
smart contracts. Those types and traits reside in the new `ink_lang::reflect` module and is
publicly usable by ink! smart contract authors.

## Changed

- ink! Contract via `#[ink::contract]`:
- ink! smart contracts now always generated two contract types. Given `MyContract`:

- `MyContract` will still be the storage struct.
However, it can now additionally be used as static dependency in other smart contracts.
Static dependencies can be envisioned as being directly embedded into a smart contract.
- `MyContractRef` is pretty much the same of what we had gotten with the old `ink-as-dependency`.
It is a typed thin-wrapper around an `AccountId` that is mirroring the ink! smart contract's API
and implemented traits.
- ink! Trait Definitions via `#[ink::trait_definition]`:
- ink! trait definitions no longer can define trait constructors.
- ink! trait implementations now inherit `selector` and `payable` properties for trait messages.
- Now explicitly setting `selector` or `payable` property for an implemented ink! trait method
will only act as a guard that the set property is in fact the same as defined by the ink!
trait definition.
- Improve quite a few ink! specific compile errors:
- For example when using ink! messages and constructors that have inputs or outputs that cannot
be encoded or decoded using the SCALE codec.
- Simplified selector computation for ink! trait methods.
- Now selectors are encoded as `blake2b({namespace}::{trait_identifier}::{message_identifier})[0..4]`.
If no `namespace` is set for the ink! trait definition then the formula is
`blake2b({trait_identifier}::{message_identifier})[0..4]`.
Where `trait_identifier` and `message_identifier` both refer to the identifiers of the ink! trait
definition and ink! trait message respectively.

## Fixed

- Contracts that are compiled as root (the default) now properly revert the transaction if a message
returned `Result::Err`.
- This does not apply to ink! smart contracts that are used as dependencies. Therefore it is still possible to match against a result return type for a called dependency.

# Version 3.0-rc6

This is the 6th release candidate for ink! 3.0.
Expand Down
15 changes: 13 additions & 2 deletions crates/lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ ink_lang_macro = { version = "3.0.0-rc6", path = "macro", default-features = fal

scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from"] }
static_assertions = "1.1"

[dev-dependencies]
# required for the doctest of `env_access::EnvAccess::instantiate_contract`
ink_lang_ir = { version = "3.0.0-rc6", path = "ir" }
ink_metadata = { version = "3.0.0-rc6", default-features = false, path = "../metadata" }

trybuild = { version = "1.0.49", features = ["diff"] }
# Required for the doctest of `env_access::EnvAccess::instantiate_contract`
scale-info = { version = "1.0", default-features = false, features = ["derive"] }

[features]
Expand All @@ -43,3 +46,11 @@ std = [
"ink_lang_macro/std",
"scale/std",
]
show-codegen-docs = []

# Due to https://github.com/rust-lang/cargo/issues/6915 features that affect a dev-dependency
# currently can't be enabled by a parent crate, hence `["ink_env/ink-experimental-engine"]` does
# not work.
# After we switch to the new off-chain environment with https://github.com/paritytech/ink/issues/565
# we can remove the feature altogether.
ink-experimental-engine = []
68 changes: 68 additions & 0 deletions crates/lang/codegen/src/enforced_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2018-2021 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use impl_serde::serialize as serde_hex;
use quote::format_ident;

/// Errors which may occur when forwarding a call is not allowed.
///
/// We insert markers for these errors in the generated contract code.
/// This is necessary since we can't check these errors at compile time
/// of the contract.
/// `cargo-contract` checks the contract code for these error markers
/// when building a contract and fails if it finds markers.
#[derive(scale::Encode, scale::Decode)]
pub enum EnforcedErrors {
/// The below error represents calling a `&mut self` message in a context that
/// only allows for `&self` messages. This may happen under certain circumstances
/// when ink! trait implementations are involved with long-hand calling notation.
#[codec(index = 1)]
CannotCallTraitMessage {
/// The trait that defines the called message.
trait_ident: String,
/// The name of the called message.
message_ident: String,
/// The selector of the called message.
message_selector: [u8; 4],
/// Is `true` if the `self` receiver of the ink! message is `&mut self`.
message_is_mut: bool,
},
}

impl EnforcedErrors {
/// Create the identifier of an enforced ink! compilation error.
fn into_ident(self) -> syn::Ident {
format_ident!(
"__ink_enforce_error_{}",
serde_hex::to_hex(&scale::Encode::encode(&self), false)
)
}

/// Creates an enforced linker error to signal that an invalid
/// implementation of an ink! trait message has been called.
pub fn cannot_call_trait_message(
trait_ident: &syn::Ident,
message_ident: &syn::Ident,
message_selector: ir::Selector,
message_is_mut: bool,
) -> syn::Ident {
Self::CannotCallTraitMessage {
trait_ident: trait_ident.to_string(),
message_ident: message_ident.to_string(),
message_selector: message_selector.to_bytes(),
message_is_mut,
}
.into_ident()
}
}
104 changes: 104 additions & 0 deletions crates/lang/codegen/src/generator/arg_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2018-2021 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use heck::CamelCase;
use proc_macro2::{
Span,
TokenStream as TokenStream2,
};
use quote::{
format_ident,
quote,
quote_spanned,
};

/// Returns the associated output type for an ink! trait message.
pub fn output_ident(message_name: &syn::Ident) -> syn::Ident {
format_ident!("{}Output", message_name.to_string().to_camel_case())
}

/// Returns the sequence of artificial input parameter bindings for the message.
///
/// # Note
///
/// This returns `__ink_binding_N` for every message input where `N` is the number
/// of the input from first to last.
pub fn input_bindings(inputs: ir::InputsIter) -> Vec<syn::Ident> {
inputs
.enumerate()
.map(|(n, _)| format_ident!("__ink_binding_{}", n))
.collect::<Vec<_>>()
}

/// Returns the sequence of input types for the message.
pub fn input_types(inputs: ir::InputsIter) -> Vec<&syn::Type> {
inputs.map(|pat_type| &*pat_type.ty).collect::<Vec<_>>()
}

/// Returns a tuple type representing the types yielded by the input types.
pub fn input_types_tuple(inputs: ir::InputsIter) -> TokenStream2 {
let input_types = input_types(inputs);
if input_types.len() != 1 {
// Pack all types into a tuple if they are not exactly 1.
// This results in `()` for zero input types.
quote! { ( #( #input_types ),* ) }
} else {
// Return the single type without turning it into a tuple.
quote! { #( #input_types )* }
}
}

/// Returns a tuple expression representing the bindings yielded by the inputs.
pub fn input_bindings_tuple(inputs: ir::InputsIter) -> TokenStream2 {
let input_bindings = input_bindings(inputs);
match input_bindings.len() {
0 => quote! { _ },
1 => quote! { #( #input_bindings ),* },
_ => quote! { ( #( #input_bindings ),* ) },
}
}

/// Builds up the `ink_env::call::utils::ArgumentList` type structure for the given types.
pub fn generate_argument_list<'b, Args>(args: Args) -> TokenStream2
where
Args: IntoIterator<Item = &'b syn::Type>,
<Args as IntoIterator>::IntoIter: Iterator,
{
use syn::spanned::Spanned as _;
args.into_iter().fold(
quote! { ::ink_env::call::utils::EmptyArgumentList },
|rest, arg| {
let span = arg.span();
quote_spanned!(span=>
::ink_env::call::utils::ArgumentList<::ink_env::call::utils::Argument<#arg>, #rest>
)
}
)
}

/// Generates code to uniquely identify a trait by its unique ID given only its identifier.
///
/// # Note
///
/// As with all Rust macros identifiers can shadow each other so the given identifier
/// needs to be valid for the scope in which the returned code is generated.
pub fn generate_reference_to_trait_info(
span: Span,
trait_path: &syn::Path,
) -> TokenStream2 {
quote_spanned!(span=>
<::ink_lang::reflect::TraitDefinitionRegistry<Environment>
as #trait_path>::__ink_TraitInfo
)
}
Loading