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

test changes #1473

Merged
merged 3 commits into from
Nov 5, 2022
Merged

test changes #1473

merged 3 commits into from
Nov 5, 2022

Conversation

xermicus
Copy link
Contributor

@xermicus xermicus commented Nov 5, 2022

No description provided.

@xermicus xermicus marked this pull request as ready for review November 5, 2022 18:04
@xermicus xermicus requested review from SkymanOne and removed request for ascjones, cmichi and HCastano November 5, 2022 18:04
Copy link
Contributor

@SkymanOne SkymanOne left a comment

Choose a reason for hiding this comment

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

Thanks for help! I like cleaner approach to the syntactical check, but renaming the trait may not be a good idea

@@ -1035,12 +1035,12 @@ where
///
/// # Important Note
/// Only use this factory with constructors!
pub trait TransformType {
pub trait ConstructorReturnType {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is misleading IMO. It doesn't reflect the functionality of the trait. The whole idea behind this trait is to transform/convert the return type into either () or Result<(), E> . this doesn't necessary mean it can only be applied to constructors. Additionally we already have ConstructorReturnType<C> in ink::codegen::dispatch module. This can also arise confusion in future

Copy link
Contributor Author

@xermicus xermicus Nov 5, 2022

Choose a reason for hiding this comment

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

Additionally we already have ConstructorReturnType

Ooh that's my bad. I wasn't aware of this. So I do agree we should change it to something not already present.

The whole idea behind this trait is to transform/convert the return type into either () or Result<(), E>

I can't see the "transforming" part for the trait name, neither the "new" part in the traits method name. Implementing this trait for some type T indicates what the return type spec of this T will be inside the metadata, given T is used as the result of a constructor.

this doesn't necessary mean it can only be applied to constructors.

I can't think of another use case here. Besides that, how would this interface exactly work? It only allows to implement one "transformation" per particular type. How would this be useful e.g. for a type that is returned by a constructor and is also used for something else which needs a conflicting "transformation"? I don't think we should prematurely solve this problem right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inspired by ConstructorReturnType I renamed the trait to ConstructorReturnSpec. Lines like this look much cleaner to me now, what do you think?

match ret_ty {
None => {
quote! {
::ink::metadata::ReturnTypeSpec::new(::core::option::Option::None)
}
}
Some(syn::Type::Path(syn::TypePath { qself: None, path }))
Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely cleaner approach!

@codecov-commenter
Copy link

Codecov Report

Merging #1473 (4f1dfd6) into gn/constructor-metadata (f5ec420) will decrease coverage by 0.00%.
The diff coverage is 66.66%.

@@                     Coverage Diff                     @@
##           gn/constructor-metadata    #1473      +/-   ##
===========================================================
- Coverage                    64.41%   64.41%   -0.01%     
===========================================================
  Files                          201      201              
  Lines                         6239     6236       -3     
===========================================================
- Hits                          4019     4017       -2     
+ Misses                        2220     2219       -1     
Impacted Files Coverage Δ
crates/metadata/src/lib.rs 0.00% <ø> (ø)
crates/metadata/src/tests.rs 100.00% <ø> (ø)
crates/metadata/src/specs.rs 89.64% <50.00%> (ø)
crates/ink/codegen/src/generator/metadata.rs 82.55% <75.00%> (-1.01%) ⬇️
crates/allocator/src/bump.rs 87.39% <0.00%> (+1.68%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@SkymanOne
Copy link
Contributor

LGTM!

@SkymanOne SkymanOne merged commit 4959e4c into gn/constructor-metadata Nov 5, 2022
@SkymanOne SkymanOne deleted the cl/1460 branch November 5, 2022 22:59
SkymanOne pushed a commit that referenced this pull request Nov 7, 2022
* generates correct metadata for Self type

* generate metadata for Result type

* generate metadata for Result<Self, ...>

* docs and comments

* cargo fmt

* fix the metadata tests

* makes compatible with new tests

* rewrite return type transformation to support aliases

* test changes (#1473)

* test changes

* rename trait to ConstructorReturnSpec

* adapt test

* remove unecessary helper fn (#1475)

* remove unecessary helper fn

* fix some comments

* rename var

* Update crates/ink/codegen/src/generator/metadata.rs

Co-authored-by: Cyrill Leutwiler <cyrill@parity.io>

* Add test for metadata generator (#1477)

* Add test for metadata generator

* nightly fmt

Co-authored-by: Cyrill Leutwiler <cyrill@parity.io>
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.

3 participants