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

fix(dojo-lang): remove restriction for u256 as keys in models #2890

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bengineer42
Copy link
Contributor

@bengineer42 bengineer42 commented Jan 10, 2025

Description

Allows use of u256 as a key in a dojo model

Related issue

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Added a new struct Foo3 with modified key field type
    • Updated member parsing logic in the attribute macros
  • Code Changes

    • Simplified member creation process in parsing function
    • Removed previous validation checks for member attributes

Copy link

coderabbitai bot commented Jan 10, 2025

Walkthrough

Ohayo, sensei! The pull request introduces a new struct Foo3 in the Cairo test models and modifies the parse_members function in the Dojo language attribute macros. The Foo3 struct extends the existing model structure by changing the first key field's type from u8 to u256. In the element parsing logic, the changes simplify member creation by removing conditional filtering and diagnostic error handling, potentially altering how members are processed during parsing.

Changes

File Change Summary
crates/dojo/core-cairo-test/src/tests/model/model.cairo Added new Foo3 struct with modified key type k1: u256
crates/dojo/lang/src/attribute_macros/element.rs Replaced filter_map with map in parse_members, removing member validation and error handling

Sequence Diagram

sequenceDiagram
    participant Parser
    participant Members
    
    Parser->>Members: map() instead of filter_map()
    Note over Parser,Members: Unconditional member creation
    Members-->>Parser: Return all members without validation
Loading

Sensei, the changes look intriguing! The unconditional member parsing might introduce some interesting dynamics in the Dojo language processing. Ohayo and happy coding! 🥷🏼🔧


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@glihm glihm changed the title Added dojo support for u256 as keys in models fix(dojo-lang): remove restriction for u256 as keys in models Jan 10, 2025
@glihm
Copy link
Collaborator

glihm commented Jan 10, 2025

Needs to be checked at Torii level, since multiple felt key are not supported at the moment.
@Larkooo for u256 we may have an exception since it will be stored as one string like a felt, and not like a struct.

@Larkooo
Copy link
Collaborator

Larkooo commented Jan 13, 2025

Needs to be checked at Torii level, since multiple felt key are not supported at the moment. @Larkooo for u256 we may have an exception since it will be stored as one string like a felt, and not like a struct.

I think it should be all good as we directly use the raw felts to serialize them into our keys string. We should still do some testing to be sure there are no other unexpected issues though

@Larkooo
Copy link
Collaborator

Larkooo commented Jan 13, 2025

and at that point, we could also use any type as the key. as they are all serializable to felt. if at the dojo level it is supported, we could support enums as keys

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
crates/dojo/lang/src/attribute_macros/element.rs (1)

Line range hint 42-42: Unused parameter diagnostics

Ohayo, sensei! The diagnostics parameter in the parse_members function is now unused due to the removal of the validation logic. To keep the code clean, consider removing this parameter.

Apply this diff to remove the unused parameter:

 pub fn parse_members(
     db: &dyn SyntaxGroup,
     members: &[MemberAst],
-    diagnostics: &mut Vec<PluginDiagnostic>,
 ) -> Vec<Member> {
🧹 Nitpick comments (3)
crates/dojo/lang/src/attribute_macros/element.rs (1)

Line range hint 3-3: Remove unused imports

Ohayo, sensei! The imports cairo_lang_diagnostics::Severity and TypedStablePtr are no longer used and can be removed to tidy up the code.

Apply this diff to remove the unused imports:

 use cairo_lang_defs::patcher::RewriteNode;
-use cairo_lang_diagnostics::Severity;
 use cairo_lang_defs::plugin::PluginDiagnostic;
 use cairo_lang_syntax::node::ast::Member as MemberAst;
 use cairo_lang_syntax::node::db::SyntaxGroup;
-use cairo_lang_syntax::node::TypedStablePtr;
 use cairo_lang_syntax::node::helpers::QueryAttrs;

Also applies to: 7-7

crates/dojo/core-cairo-test/src/tests/model/model.cairo (2)

28-37: Include Foo3 in namespace_def() for proper testing

Ohayo, sensei! The new model Foo3 with a u256 key has been defined but is not included in the namespace_def() function. To ensure Foo3 is properly registered and tested, please add it to the namespace_def() resources.

Apply this diff to include Foo3:

 fn namespace_def() -> NamespaceDef {
     NamespaceDef {
         namespace: "dojo_cairo_test", resources: [
             TestResource::Model(m_Foo::TEST_CLASS_HASH.try_into().unwrap()),
             TestResource::Model(m_Foo2::TEST_CLASS_HASH.try_into().unwrap()),
+            TestResource::Model(m_Foo3::TEST_CLASS_HASH.try_into().unwrap()),
         ].span()
     }
 }

28-37: Add tests for Foo3 to validate u256 key functionality

Ohayo, sensei! To fully ensure that the u256 key functions correctly, consider adding tests for Foo3 similar to the existing tests for Foo and Foo2. This will help confirm that the changes meet the desired objectives.

Do you want me to help generate the test cases for Foo3?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80ac6d1 and 2db1882.

⛔ Files ignored due to path filters (1)
  • crates/dojo/core-cairo-test/Scarb.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • crates/dojo/core-cairo-test/src/tests/model/model.cairo (1 hunks)
  • crates/dojo/lang/src/attribute_macros/element.rs (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: ci
crates/dojo/lang/src/attribute_macros/element.rs

[error] 3-3: Unused import: 'cairo_lang_diagnostics::Severity'


[error] 7-7: Unused import: 'TypedStablePtr'


[error] 42-42: Unused variable: 'diagnostics'. Consider prefixing with underscore if intentional


[error] 42-42: Inefficient argument type: '&mut Vec' should be '&mut [PluginDiagnostic]'

🔇 Additional comments (1)
crates/dojo/lang/src/attribute_macros/element.rs (1)

46-49: Simplification aligns with PR objectives

Ohayo, sensei! The changes to the parse_members function remove the previous validation logic, allowing u256 to be used as keys. This aligns perfectly with the PR objective to remove restrictions on u256 keys. The simplification enhances code readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants