-
Notifications
You must be signed in to change notification settings - Fork 188
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
feat: add [dojo::interface] attribute #1594
Conversation
Here the first part of the issue related to
|
b739cad
to
4d10c48
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1594 +/- ##
==========================================
+ Coverage 69.09% 69.55% +0.45%
==========================================
Files 265 266 +1
Lines 26859 27213 +354
==========================================
+ Hits 18559 18927 +368
+ Misses 8300 8286 -14 ☔ View full report in Codecov by Sentry. |
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.
First quick review of the draft, very nice start!
Left only minor comments for now, good job!
4d10c48
to
a3dca4a
Compare
Thanks ser ! 🙏 I don't know why but if a trait contains other elements than a function, when I copy these elements with For example, I tried with a constant dojo/crates/dojo-lang/src/interface.rs Lines 28 to 44 in a3dca4a
|
ef91c9b
to
c7fc610
Compare
I rewrote the code for I updated the I still need to look at a weird issue when I add a constant in a trait with the Now, I will also have a look at CI errors ;-) |
c7fc610
to
6c28119
Compare
After some tests, I found that if I add |
eb089be
to
14bd96f
Compare
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.
@remybar thanks for the update!
A small comment about testing.
Also, would you mind updating the spawn-and-move
example with the new syntax? This example is usually taken as an example and showcasing the dojo stack. :)
Add a new `[dojo::interface]` attribute which is expanded in `[starknet::interface]`, allowing the user to ignore `TContractState` type and `self` parameter.
`self` parameter is not mandatory anymore in dojo::contract. If not present, it will be automatically added during code expansion. if a `world: IWorldDispatcher` parameter is given, it is removed and replace by the `let world = self.world_dispatcher.read();` statement at the beginning of the function body.
14bd96f
to
ce78cf1
Compare
Sure ! I updated the example 👍 Thanks for the review ! |
trait INominalTrait { | ||
fn do_no_param(); | ||
fn do_no_param_but_self(self: @TContractState); | ||
fn do_params(p1: dojo_examples::models::Direction, p2: u8); | ||
fn do_params_and_self(self: @TContractState, p2: u8); | ||
fn do_return_value(p1: u8) -> u16; | ||
fn do_ref_self(ref self: TContractState); | ||
|
||
#[my_attr] | ||
fn do_with_attrs(p1: u8) -> u16; | ||
} |
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.
We still miss a non-faulty test case, no? The ref self
and the #[my_attr]
should go into the faulty one, or you're thinking of adding one more?
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.
Ah yes, I will move ref self
to the faulty trait !
For #[my_attr]
, from the code expansion point of view, this is not an error. If a function has some attributes, they will be copied. But from Dojo point of view, maybe it's strange to have some attributes on functions in a contract trait ? So, if you think it is better to move this case in the faulty trait, I will do it 👍
@@ -83,8 +82,7 @@ mod actions { | |||
); | |||
} | |||
|
|||
fn move(self: @ContractState, direction: Direction) { | |||
let world = self.world_dispatcher.read(); | |||
fn move(direction: Direction, world: IWorldDispatcher) { |
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.
Seeing this, we must inline and remove the world: IWorldDispatcher
from arguments if and only if it's the first argument. We shouldn't allow two arguments with this type either (an other faulty one to add! hehe).
Because at ABI level, removing world
at first position can be understood. If it's randomly placed in the list of inputs of the function, it can quickly become difficult to call the systems.
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.
Thanks ! I will update the code accordingly 👍
Co-authored-by: glihm <[email protected]>
So, to summarize:
|
5273928
to
a5cd4d5
Compare
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.
Awesome work man, some comments here that I think should be almost the latest on my end. It looks great!
@tarrencev when commenting on the issue I didn't get well the fact that the world
is only injected in the impl
. The interface is super clean and the Devex is very nice.
'land' | ||
} | ||
|
||
#[external(v0)] |
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.
abi(embed_v0)
is a bit more painful to use as it can't be used on standalone function. But external(v0)
is expected to be deprecated. Would it be possible to switch to abi(embed_v0)
in this PR?
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.
Hum, from what I understand, these attributes are not really important in this system
file because they are not really used by the plugin to generate some specific code. But it is better to have at least one attribute on each functions to be sure that function attributes are well copied in the output code.
I've updated the code to use abi(embed_v0)
on Impl
block and external(v0)
on free functions. What should we use instead of external(v0)
for free functions ? Or do we have to put external/public functions in a Impl
block to have them exported in the ABI file maybe ?
a5cd4d5
to
5b2eeef
Compare
Related to DOJ-132, #1458.
Add a new
[dojo::interface]
attribute which is expanded in[starknet::interface]
, allowing the user to ignoreTContractState
type andself
parameter.