diff --git a/crates/dojo-core/src/model/metadata.cairo b/crates/dojo-core/src/model/metadata.cairo index affc619aa5..7a8e18080c 100644 --- a/crates/dojo-core/src/model/metadata.cairo +++ b/crates/dojo-core/src/model/metadata.cairo @@ -52,13 +52,13 @@ pub impl ResourceMetadataModel of Model { ResourceMetadataTrait::from_values(*keys.at(0), ref values) } - fn set(self: @ResourceMetadata, world: IWorldDispatcher,) { + fn set_model(self: @ResourceMetadata, world: IWorldDispatcher,) { IWorldDispatcherTrait::set_entity( world, Self::selector(), ModelIndex::Keys(self.keys()), self.values(), Self::layout() ); } - fn delete(self: @ResourceMetadata, world: IWorldDispatcher,) { + fn delete_model(self: @ResourceMetadata, world: IWorldDispatcher,) { world.delete_entity(Self::selector(), ModelIndex::Keys(self.keys()), Self::layout()); } diff --git a/crates/dojo-core/src/model/model.cairo b/crates/dojo-core/src/model/model.cairo index 63aa9ec645..6b11143ca0 100644 --- a/crates/dojo-core/src/model/model.cairo +++ b/crates/dojo-core/src/model/model.cairo @@ -17,9 +17,12 @@ pub trait ModelEntity { fn id(self: @T) -> felt252; fn values(self: @T) -> Span; fn from_values(entity_id: felt252, ref values: Span) -> T; + // Get is always used with the trait path, which results in no ambiguity for the compiler. fn get(world: IWorldDispatcher, entity_id: felt252) -> T; - fn update(self: @T, world: IWorldDispatcher); - fn delete(self: @T, world: IWorldDispatcher); + // Update and delete can be used directly on the entity, which results in ambiguity. + // Therefore, they are implemented with the `update_entity` and `delete_entity` names. + fn update_entity(self: @T, world: IWorldDispatcher); + fn delete_entity(self: @T, world: IWorldDispatcher); fn get_member( world: IWorldDispatcher, entity_id: felt252, member_id: felt252, ) -> Span; @@ -27,11 +30,15 @@ pub trait ModelEntity { } pub trait Model { + // Get is always used with the trait path, which results in no ambiguity for the compiler. fn get(world: IWorldDispatcher, keys: Span) -> T; // Note: `get` is implemented with a generated trait because it takes // the list of model keys as separated parameters. - fn set(self: @T, world: IWorldDispatcher); - fn delete(self: @T, world: IWorldDispatcher); + + // Set and delete can be used directly on the entity, which results in ambiguity. + // Therefore, they are implemented with the `set_model` and `delete_model` names. + fn set_model(self: @T, world: IWorldDispatcher); + fn delete_model(self: @T, world: IWorldDispatcher); fn get_member( world: IWorldDispatcher, keys: Span, member_id: felt252, diff --git a/crates/dojo-core/src/tests/benchmarks.cairo b/crates/dojo-core/src/tests/benchmarks.cairo index 96a43a4df7..298057be2a 100644 --- a/crates/dojo-core/src/tests/benchmarks.cairo +++ b/crates/dojo-core/src/tests/benchmarks.cairo @@ -17,7 +17,7 @@ use dojo::model::introspect::Introspect; use dojo::storage::{database, storage}; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use dojo::tests::helpers::{Foo, Sword, Case, case, Character, Abilities, Stats, Weapon}; +use dojo::tests::helpers::{Foo, Sword, Case, CaseStore, case, Character, Abilities, Stats, Weapon}; use dojo::utils::test::{spawn_test_world, GasCounterTrait}; #[derive(Drop, Serde)] diff --git a/crates/dojo-lang/src/inline_macros/delete.rs b/crates/dojo-lang/src/inline_macros/delete.rs index 36e0f70b59..fc51eb28fc 100644 --- a/crates/dojo-lang/src/inline_macros/delete.rs +++ b/crates/dojo-lang/src/inline_macros/delete.rs @@ -92,7 +92,7 @@ impl InlineMacroExprPlugin for DeleteMacro { builder.add_str(&format!( " let __delete_model_instance__ = {}; - dojo::model::Model::delete(@__delete_model_instance__, {}); + dojo::model::Model::delete_model(@__delete_model_instance__, {}); ", entity, world.as_syntax_node().get_text(db), diff --git a/crates/dojo-lang/src/inline_macros/set.rs b/crates/dojo-lang/src/inline_macros/set.rs index ad1f3c269d..b027d22c58 100644 --- a/crates/dojo-lang/src/inline_macros/set.rs +++ b/crates/dojo-lang/src/inline_macros/set.rs @@ -106,7 +106,7 @@ impl InlineMacroExprPlugin for SetMacro { builder.add_str(&format!( " let __set_model_instance__ = {}; - dojo::model::Model::set(@__set_model_instance__, {}); + dojo::model::Model::set_model(@__set_model_instance__, {}); ", entity, world.as_syntax_node().get_text(db), diff --git a/crates/dojo-lang/src/model.rs b/crates/dojo-lang/src/model.rs index a5dcc99631..88e21fa69a 100644 --- a/crates/dojo-lang/src/model.rs +++ b/crates/dojo-lang/src/model.rs @@ -332,6 +332,14 @@ pub impl $type_name$EntityStoreImpl of $type_name$EntityStore { $type_name$ModelEntityImpl::get(world, entity_id) } + fn update(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { + dojo::model::ModelEntity::<$type_name$Entity>::update_entity(self, world); + } + + fn delete(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { + dojo::model::ModelEntity::<$type_name$Entity>::delete_entity(self, world); + } + $entity_field_accessors$ } @@ -368,6 +376,14 @@ pub impl $type_name$StoreImpl of $type_name$Store { dojo::model::Model::<$type_name$>::get(world, serialized.span()) } + fn set(self: @$type_name$, world: dojo::world::IWorldDispatcher) { + dojo::model::Model::<$type_name$>::set_model(self, world); + } + + fn delete(self: @$type_name$, world: dojo::world::IWorldDispatcher) { + dojo::model::Model::<$type_name$>::delete_model(self, world); + } + $field_accessors$ } @@ -406,7 +422,7 @@ pub impl $type_name$ModelEntityImpl of dojo::model::ModelEntity<$type_name$Entit Self::from_values(entity_id, ref values) } - fn update(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { + fn update_entity(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::<$type_name$>::selector(), @@ -416,7 +432,7 @@ pub impl $type_name$ModelEntityImpl of dojo::model::ModelEntity<$type_name$Entit ); } - fn delete(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { + fn delete_entity(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::<$type_name$>::selector(), @@ -507,7 +523,7 @@ pub impl $type_name$ModelImpl of dojo::model::Model<$type_name$> { $type_name$Store::from_values(ref _keys, ref values) } - fn set( + fn set_model( self: @$type_name$, world: dojo::world::IWorldDispatcher ) { @@ -520,7 +536,7 @@ pub impl $type_name$ModelImpl of dojo::model::Model<$type_name$> { ); } - fn delete( + fn delete_model( self: @$type_name$, world: dojo::world::IWorldDispatcher ) { diff --git a/crates/dojo-lang/src/semantics/test_data/set b/crates/dojo-lang/src/semantics/test_data/set index 2a9249f47c..ddbd0b8287 100644 --- a/crates/dojo-lang/src/semantics/test_data/set +++ b/crates/dojo-lang/src/semantics/test_data/set @@ -120,7 +120,7 @@ Block( StatementExpr { expr: FunctionCall( ExprFunctionCall { - function: ?6::set, + function: ?6::set_model, args: [ Value( Snapshot( diff --git a/spawn-and-move-db.tar.gz b/spawn-and-move-db.tar.gz index 7b811cc13a..9d912f3132 100644 Binary files a/spawn-and-move-db.tar.gz and b/spawn-and-move-db.tar.gz differ diff --git a/types-test-db.tar.gz b/types-test-db.tar.gz index c234d2b798..e6d5af4c67 100644 Binary files a/types-test-db.tar.gz and b/types-test-db.tar.gz differ