From d8a9a3f1ef9d923edef5e812a344f66a1855386b Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Thu, 23 Nov 2023 09:08:03 -0800 Subject: [PATCH] Support deriving Introspect for generics (#1082) --- crates/dojo-core/src/database.cairo | 4 +- .../{schema.cairo => introspect.cairo} | 2 +- .../src/database/introspect_test.cairo | 17 + crates/dojo-core/src/model.cairo | 2 +- crates/dojo-core/src/packing_test.cairo | 2 +- crates/dojo-core/src/world_test.cairo | 6 +- crates/dojo-lang/src/inline_macros/get.rs | 3 +- crates/dojo-lang/src/introspect.rs | 144 ++- .../dojo-lang/src/manifest_test_data/manifest | 28 +- crates/dojo-lang/src/model.rs | 12 +- .../dojo-lang/src/plugin_test_data/introspect | 1065 ++++------------- crates/dojo-lang/src/plugin_test_data/model | 431 ++++--- crates/dojo-lang/src/semantics/test_data/get | 2 +- crates/dojo-world/src/contracts/model_test.rs | 2 +- .../graphql/src/tests/types-test/Scarb.lock | 5 +- 15 files changed, 547 insertions(+), 1178 deletions(-) rename crates/dojo-core/src/database/{schema.cairo => introspect.cairo} (97%) create mode 100644 crates/dojo-core/src/database/introspect_test.cairo diff --git a/crates/dojo-core/src/database.cairo b/crates/dojo-core/src/database.cairo index 925b02cacf..86b6ec6136 100644 --- a/crates/dojo-core/src/database.cairo +++ b/crates/dojo-core/src/database.cairo @@ -7,7 +7,9 @@ use poseidon::poseidon_hash_span; mod index; #[cfg(test)] mod index_test; -mod schema; +mod introspect; +#[cfg(test)] +mod introspect_test; mod storage; #[cfg(test)] mod storage_test; diff --git a/crates/dojo-core/src/database/schema.cairo b/crates/dojo-core/src/database/introspect.cairo similarity index 97% rename from crates/dojo-core/src/database/schema.cairo rename to crates/dojo-core/src/database/introspect.cairo index 2aa0541f05..3d0af0d90b 100644 --- a/crates/dojo-core/src/database/schema.cairo +++ b/crates/dojo-core/src/database/introspect.cairo @@ -41,7 +41,7 @@ fn serialize_member_type(m: @Ty) -> Span { serialized.span() } -trait SchemaIntrospection { +trait Introspect { fn size() -> usize; fn layout(ref layout: Array); fn ty() -> Ty; diff --git a/crates/dojo-core/src/database/introspect_test.cairo b/crates/dojo-core/src/database/introspect_test.cairo new file mode 100644 index 0000000000..e366f8acd3 --- /dev/null +++ b/crates/dojo-core/src/database/introspect_test.cairo @@ -0,0 +1,17 @@ +use dojo::database::introspect::Introspect; + +#[derive(Drop, Introspect)] +struct Base { + value: u32, +} + +#[derive(Drop, Introspect)] +struct Generic { + value: T, +} + +#[test] +#[available_gas(2000000)] +fn test_generic_introspect() { + let generic = Generic { value: Base { value: 123 } }; +} diff --git a/crates/dojo-core/src/model.cairo b/crates/dojo-core/src/model.cairo index 2547a9275a..f8657cc666 100644 --- a/crates/dojo-core/src/model.cairo +++ b/crates/dojo-core/src/model.cairo @@ -10,5 +10,5 @@ trait Model { trait IModel { fn name(self: @T) -> felt252; fn layout(self: @T) -> Span; - fn schema(self: @T) -> Span; + fn schema(self: @T) -> Span; } diff --git a/crates/dojo-core/src/packing_test.cairo b/crates/dojo-core/src/packing_test.cairo index 38dfde0015..d4ffa6f380 100644 --- a/crates/dojo-core/src/packing_test.cairo +++ b/crates/dojo-core/src/packing_test.cairo @@ -5,7 +5,7 @@ use integer::U256BitAnd; use option::OptionTrait; use debug::PrintTrait; use traits::{Into, TryInto}; -use dojo::database::schema::SchemaIntrospection; +use dojo::database::introspect::Introspect; #[test] #[available_gas(9000000)] diff --git a/crates/dojo-core/src/world_test.cairo b/crates/dojo-core/src/world_test.cairo index 8612168548..de6ced047f 100644 --- a/crates/dojo-core/src/world_test.cairo +++ b/crates/dojo-core/src/world_test.cairo @@ -10,7 +10,7 @@ use starknet::syscalls::deploy_syscall; use dojo::benchmarks; use dojo::executor::executor; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, world}; -use dojo::database::schema::SchemaIntrospection; +use dojo::database::introspect::Introspect; use dojo::test_utils::{spawn_test_world, deploy_with_world_address}; use dojo::benchmarks::{Character, end}; @@ -38,7 +38,7 @@ trait Ibar { #[starknet::contract] mod bar { - use super::{Foo, IWorldDispatcher, IWorldDispatcherTrait, SchemaIntrospection}; + use super::{Foo, IWorldDispatcher, IWorldDispatcherTrait, Introspect}; use super::benchmarks::{Character, Abilities, Stats, Weapon, Sword}; use traits::Into; use starknet::{get_caller_address, ContractAddress}; @@ -60,7 +60,7 @@ mod bar { fn delete_foo(self: @ContractState) { let mut layout = array![]; - SchemaIntrospection::::layout(ref layout); + Introspect::::layout(ref layout); self .world .read() diff --git a/crates/dojo-lang/src/inline_macros/get.rs b/crates/dojo-lang/src/inline_macros/get.rs index 2717d01013..ecb3aec87a 100644 --- a/crates/dojo-lang/src/inline_macros/get.rs +++ b/crates/dojo-lang/src/inline_macros/get.rs @@ -106,8 +106,7 @@ impl InlineMacroExprPlugin for GetMacro { builder.add_str(&format!( "\n let mut __{model}_layout__ = array::ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::<{model}>::layout(ref \ - __{model}_layout__); + dojo::database::introspect::Introspect::<{model}>::layout(ref __{model}_layout__); let mut __{model}_layout_clone__ = __{model}_layout__.clone(); let mut __{model}_layout_span__ = array::ArrayTrait::span(@__{model}_layout__); let mut __{model}_layout_clone_span__ = \ diff --git a/crates/dojo-lang/src/introspect.rs b/crates/dojo-lang/src/introspect.rs index 8cd46e1967..662d8d4fbc 100644 --- a/crates/dojo-lang/src/introspect.rs +++ b/crates/dojo-lang/src/introspect.rs @@ -2,7 +2,9 @@ use std::collections::HashMap; use cairo_lang_defs::patcher::RewriteNode; use cairo_lang_defs::plugin::PluginDiagnostic; -use cairo_lang_syntax::node::ast::{Expr, ItemEnum, ItemStruct, OptionTypeClause}; +use cairo_lang_syntax::node::ast::{ + Expr, GenericParam, ItemEnum, ItemStruct, OptionTypeClause, OptionWrappedGenericParamList, +}; use cairo_lang_syntax::node::db::SyntaxGroup; use cairo_lang_syntax::node::helpers::QueryAttrs; use cairo_lang_syntax::node::{Terminal, TypedSyntaxNode}; @@ -57,23 +59,23 @@ pub fn handle_introspect_struct(db: &dyn SyntaxGroup, struct_ast: ItemStruct) -> if primitive_sizes.get(&ty).is_some() { // It's a primitive type member_types.push(format!( - " - dojo::database::schema::serialize_member(@dojo::database::schema::Member {{ - name: '{name}', - ty: dojo::database::schema::Ty::Primitive('{ty}'), - attrs: array![{}].span() - }})\n", + "dojo::database::introspect::serialize_member(@\ + dojo::database::introspect::Member {{ + name: '{name}', + ty: dojo::database::introspect::Ty::Primitive('{ty}'), + attrs: array![{}].span() + }})", attrs.join(","), )); } else { // It's a custom struct/enum member_types.push(format!( - " - dojo::database::schema::serialize_member(@dojo::database::schema::Member {{ - name: '{name}', - ty: dojo::database::schema::SchemaIntrospection::<{ty}>::ty(), - attrs: array![{}].span() - }})\n", + "dojo::database::introspect::serialize_member(@\ + dojo::database::introspect::Member {{ + name: '{name}', + ty: dojo::database::introspect::Introspect::<{ty}>::ty(), + attrs: array![{}].span() + }})", attrs.join(","), )); } @@ -81,19 +83,17 @@ pub fn handle_introspect_struct(db: &dyn SyntaxGroup, struct_ast: ItemStruct) -> Member { name, ty, key } }) .collect::<_>(); - drop(primitive_sizes); let type_ty = format!( - " - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct {{ + "dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct {{ name: '{name}', attrs: array![].span(), children: array![{}].span() }})", - member_types.join(",\n") + member_types.join(", ") ); - handle_introspect_internal(db, name, vec![], 0, type_ty, members) + handle_introspect_internal(db, name, struct_ast.generic_params(db), vec![], 0, type_ty, members) } /// A handler for Dojo code derives Introspect for an enum @@ -108,6 +108,7 @@ pub fn handle_introspect_enum( enum_ast: ItemEnum, ) -> RewriteNode { let name = enum_ast.name(db).text(db).into(); + let variant_type = enum_ast.variants(db).elements(db).first().unwrap().type_clause(db); let variant_type_text = variant_type.as_syntax_node().get_text(db); let variant_type_text = variant_type_text.trim(); @@ -121,8 +122,8 @@ pub fn handle_introspect_enum( variant_type_arr.push(( // Not using Ty right now, but still keeping it for later. format!( - "dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('{}') + "dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Primitive('{}') )", ty_name ), @@ -134,8 +135,8 @@ pub fn handle_introspect_enum( variant_type_arr.push(( // Not using Ty right now, but still keeping it for later. format!( - "dojo::database::schema::serialize_member_type( - @dojo::database::schema::SchemaIntrospection::<{}>::ty() + "dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Introspect::<{}>::ty() )", ty_name ), @@ -170,17 +171,15 @@ pub fn handle_introspect_enum( // @TODO: Prepare type struct arms_ty.push(format!( - " - ( - '{member_name}', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![{}].span())) - )", + "( + '{member_name}', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![{}].span())) + )", if !variant_type_arr.is_empty() { let ty_cairo: Vec<_> = variant_type_arr.iter().map(|(ty_cairo, _)| ty_cairo.to_string()).collect(); - // format!("'{}'", &ty_cairo.join("', '")) - ty_cairo.join(",\n") + ty_cairo.join(", ") } else { "".to_string() } @@ -188,14 +187,11 @@ pub fn handle_introspect_enum( }); let type_ty = format!( - " - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum {{ + "dojo::database::introspect::Ty::Enum( + dojo::database::introspect::Enum {{ name: '{name}', attrs: array![].span(), - children: array![ - {} - ].span() + children: array![{}].span() }} )", arms_ty.join(",\n") @@ -204,12 +200,21 @@ pub fn handle_introspect_enum( // Enums have 1 size and 8 bit layout by default let layout = vec![RewriteNode::Text("layout.append(8);\n".into())]; let size_precompute = 1; - handle_introspect_internal(db, name, layout, size_precompute, type_ty, members) + handle_introspect_internal( + db, + name, + enum_ast.generic_params(db), + layout, + size_precompute, + type_ty, + members, + ) } fn handle_introspect_internal( - _db: &dyn SyntaxGroup, + db: &dyn SyntaxGroup, name: String, + generics: OptionWrappedGenericParamList, mut layout: Vec, mut size_precompute: usize, type_ty: String, @@ -218,6 +223,30 @@ fn handle_introspect_internal( let mut size = vec![]; let primitive_sizes = primitive_type_introspection(); + let generics = if let OptionWrappedGenericParamList::WrappedGenericParamList(params) = generics + { + params + .generic_params(db) + .elements(db) + .iter() + .filter_map(|el| { + if let GenericParam::Type(typ) = el { + Some(typ.name(db).text(db).to_string()) + } else { + None + } + }) + .collect::>() + } else { + vec![] + }; + + let generic_impls = generics + .iter() + .map(|g| format!("{g}, impl {g}Introspect: dojo::database::introspect::Introspect<{g}>")) + .collect::>() + .join(", "); + members.iter().for_each(|m| { let primitive_intro = primitive_sizes.get(&m.ty); let mut attrs = vec![]; @@ -237,12 +266,9 @@ fn handle_introspect_internal( if m.key { attrs.push("'key'"); } else { - size.push(format!( - "dojo::database::schema::SchemaIntrospection::<{}>::size()", - m.ty, - )); + size.push(format!("dojo::database::introspect::Introspect::<{}>::size()", m.ty,)); layout.push(RewriteNode::Text(format!( - "dojo::database::schema::SchemaIntrospection::<{}>::layout(ref layout);\n", + "dojo::database::introspect::Introspect::<{}>::layout(ref layout);\n", m.ty ))); } @@ -255,26 +281,28 @@ fn handle_introspect_internal( RewriteNode::interpolate_patched( " - impl $name$SchemaIntrospection of dojo::database::schema::SchemaIntrospection<$name$> { - - #[inline(always)] - fn size() -> usize { - $size$ - } +impl $name$Introspect<$generics$> of \ + dojo::database::introspect::Introspect<$name$<$generics_types$>> { + #[inline(always)] + fn size() -> usize { + $size$ + } - #[inline(always)] - fn layout(ref layout: Array) { - $layout$ - } + #[inline(always)] + fn layout(ref layout: Array) { + $layout$ + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - $ty$ - } - } + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + $ty$ + } +} ", &UnorderedHashMap::from([ ("name".to_string(), RewriteNode::Text(name)), + ("generics".to_string(), RewriteNode::Text(generic_impls)), + ("generics_types".to_string(), RewriteNode::Text(generics.join(", "))), ("size".to_string(), RewriteNode::Text(size.join(" + "))), ("layout".to_string(), RewriteNode::new_modified(layout)), ("ty".to_string(), RewriteNode::Text(type_ty)), diff --git a/crates/dojo-lang/src/manifest_test_data/manifest b/crates/dojo-lang/src/manifest_test_data/manifest index 5a491c57f8..393e808895 100644 --- a/crates/dojo-lang/src/manifest_test_data/manifest +++ b/crates/dojo-lang/src/manifest_test_data/manifest @@ -1200,7 +1200,7 @@ test_manifest_file "key": false } ], - "class_hash": "0x2e5174b54aef0b99d4685827ffa51488447e1f5607908293d5c715d6bd22433", + "class_hash": "0x509a65bd8cc5516176a694a3b3c809011f1f0680959c567b3189e60ddab7ce1", "abi": [ { "type": "function", @@ -1278,7 +1278,7 @@ test_manifest_file }, { "type": "struct", - "name": "dojo::database::schema::Struct", + "name": "dojo::database::introspect::Struct", "members": [ { "name": "name", @@ -1306,7 +1306,7 @@ test_manifest_file }, { "type": "struct", - "name": "dojo::database::schema::Enum", + "name": "dojo::database::introspect::Enum", "members": [ { "name": "name", @@ -1324,7 +1324,7 @@ test_manifest_file }, { "type": "enum", - "name": "dojo::database::schema::Ty", + "name": "dojo::database::introspect::Ty", "variants": [ { "name": "Primitive", @@ -1332,11 +1332,11 @@ test_manifest_file }, { "name": "Struct", - "type": "dojo::database::schema::Struct" + "type": "dojo::database::introspect::Struct" }, { "name": "Enum", - "type": "dojo::database::schema::Enum" + "type": "dojo::database::introspect::Enum" }, { "name": "Tuple", @@ -1350,7 +1350,7 @@ test_manifest_file "inputs": [], "outputs": [ { - "type": "dojo::database::schema::Ty" + "type": "dojo::database::introspect::Ty" } ], "state_mutability": "view" @@ -1377,7 +1377,7 @@ test_manifest_file "key": false } ], - "class_hash": "0x6a11b5b3003a3aa0ae7f8f443e48314cc0bc51eaea7c3ed1c19beb909f5dda3", + "class_hash": "0x52a1da1853c194683ca5d6d154452d0654d23f2eacd4267c555ff2338e144d6", "abi": [ { "type": "function", @@ -1455,7 +1455,7 @@ test_manifest_file }, { "type": "struct", - "name": "dojo::database::schema::Struct", + "name": "dojo::database::introspect::Struct", "members": [ { "name": "name", @@ -1483,7 +1483,7 @@ test_manifest_file }, { "type": "struct", - "name": "dojo::database::schema::Enum", + "name": "dojo::database::introspect::Enum", "members": [ { "name": "name", @@ -1501,7 +1501,7 @@ test_manifest_file }, { "type": "enum", - "name": "dojo::database::schema::Ty", + "name": "dojo::database::introspect::Ty", "variants": [ { "name": "Primitive", @@ -1509,11 +1509,11 @@ test_manifest_file }, { "name": "Struct", - "type": "dojo::database::schema::Struct" + "type": "dojo::database::introspect::Struct" }, { "name": "Enum", - "type": "dojo::database::schema::Enum" + "type": "dojo::database::introspect::Enum" }, { "name": "Tuple", @@ -1527,7 +1527,7 @@ test_manifest_file "inputs": [], "outputs": [ { - "type": "dojo::database::schema::Ty" + "type": "dojo::database::introspect::Ty" } ], "state_mutability": "view" diff --git a/crates/dojo-lang/src/model.rs b/crates/dojo-lang/src/model.rs index 65a016b48e..2250db615e 100644 --- a/crates/dojo-lang/src/model.rs +++ b/crates/dojo-lang/src/model.rs @@ -96,7 +96,7 @@ pub fn handle_model_struct( #[inline(always)] fn layout(self: @$type_name$) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::<$type_name$>::layout(ref layout); + dojo::database::introspect::Introspect::<$type_name$>::layout(ref layout); array::ArrayTrait::span(@layout) } @@ -128,13 +128,13 @@ pub fn handle_model_struct( #[external(v0)] fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::<$type_name$>::size() + dojo::database::introspect::Introspect::<$type_name$>::size() } #[external(v0)] fn packed_size(self: @ContractState) -> usize { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::<$type_name$>::layout(ref layout); + dojo::database::introspect::Introspect::<$type_name$>::layout(ref layout); let mut layout_span = layout.span(); dojo::packing::calculate_packed_size(ref layout_span) } @@ -142,13 +142,13 @@ pub fn handle_model_struct( #[external(v0)] fn layout(self: @ContractState) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::<$type_name$>::layout(ref layout); + dojo::database::introspect::Introspect::<$type_name$>::layout(ref layout); array::ArrayTrait::span(@layout) } #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::<$type_name$>::ty() + fn schema(self: @ContractState) -> dojo::database::introspect::Ty { + dojo::database::introspect::Introspect::<$type_name$>::ty() } } ", diff --git a/crates/dojo-lang/src/plugin_test_data/introspect b/crates/dojo-lang/src/plugin_test_data/introspect index f24bd429ed..7ee8be69f3 100644 --- a/crates/dojo-lang/src/plugin_test_data/introspect +++ b/crates/dojo-lang/src/plugin_test_data/introspect @@ -36,7 +36,7 @@ enum EnumCustom { Right: Vec2, } -#[derive(Model, Copy, Drop, Introspect)] +#[derive(Copy, Drop, Introspect)] struct Position { #[key] player: ContractAddress, @@ -45,525 +45,11 @@ struct Position { after: u16, } -//! > generated_cairo_code -use serde::Serde; - - #[derive(Copy, Drop, Serde, Introspect)] -struct Vec2 { - x: u32, - y: u32 -} - -impl Vec2SchemaIntrospection of dojo::database::schema::SchemaIntrospection { - #[inline(always)] - fn size() -> usize { - 2 - } - - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(32); - layout.append(32); - } - - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Struct( - dojo::database::schema::Struct { - name: 'Vec2', - attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'x', - ty: dojo::database::schema::Ty::Primitive('u32'), - attrs: array![].span() - } - ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'y', - ty: dojo::database::schema::Ty::Primitive('u32'), - attrs: array![].span() - } - ) - ] - .span() - } - ) - } -} - - - -#[derive(Serde, Copy, Drop, Introspect)] -enum PlainEnum { - Left: (), - Right: (), -} - -impl PlainEnumSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - #[inline(always)] - fn size() -> usize { - 1 - } - - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); - } - - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { - name: 'PlainEnum', - attrs: array![].span(), - children: array![ - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![].span()) - ) - ), - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![].span()) - ) - ) - ] - .span() - } - ) - } -} - - - -#[derive(Serde, Copy, Drop, Introspect)] -enum EnumPrimitive { - Left: (u16,), - Right: (u16,), -} - -impl EnumPrimitiveSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - #[inline(always)] - fn size() -> usize { - 2 - } - - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); - layout.append(16); - } - - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { - name: 'EnumPrimitive', - attrs: array![].span(), - children: array![ - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple( - array![ - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u16') - ) - ] - .span() - ) - ) - ), - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple( - array![ - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u16') - ) - ] - .span() - ) - ) - ) - ] - .span() - } - ) - } -} - - - -#[derive(Serde, Copy, Drop, Introspect)] -enum EnumTuple { - Left: (u8, u8), - Right: (u8, u8), +struct GenericStruct { + t: T, } -impl EnumTupleSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - #[inline(always)] - fn size() -> usize { - 3 - } - - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); - layout.append(8); - layout.append(8); - } - - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { - name: 'EnumTuple', - attrs: array![].span(), - children: array![ - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple( - array![ - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') - ), - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') - ) - ] - .span() - ) - ) - ), - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple( - array![ - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') - ), - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') - ) - ] - .span() - ) - ) - ) - ] - .span() - } - ) - } -} - - - -#[derive(Serde, Copy, Drop, Introspect)] -enum EnumCustom { - Left: Vec2, - Right: Vec2, -} - -impl EnumCustomSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() + 1 - } - - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - } - - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { - name: 'EnumCustom', - attrs: array![].span(), - children: array![ - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple( - array![ - dojo::database::schema::serialize_member_type( - @dojo::database::schema::SchemaIntrospection::::ty() - ) - ] - .span() - ) - ) - ), - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple( - array![ - dojo::database::schema::serialize_member_type( - @dojo::database::schema::SchemaIntrospection::::ty() - ) - ] - .span() - ) - ) - ) - ] - .span() - } - ) - } -} - - - -#[derive(Model, Copy, Drop, Introspect)] -struct Position { - #[key] - player: ContractAddress, - before: u8, - vec: Vec2, - after: u16, -} -impl PositionModel of dojo::model::Model { - #[inline(always)] - fn name(self: @Position) -> felt252 { - 'Position' - } - - #[inline(always)] - fn keys(self: @Position) -> Span { - let mut serialized = ArrayTrait::new(); - serde::Serde::serialize(self.player, ref serialized); - array::ArrayTrait::span(@serialized) - } - - #[inline(always)] - fn values(self: @Position) -> Span { - let mut serialized = ArrayTrait::new(); - serde::Serde::serialize(self.before, ref serialized); - serde::Serde::serialize(self.vec, ref serialized); - serde::Serde::serialize(self.after, ref serialized); - array::ArrayTrait::span(@serialized) - } - - #[inline(always)] - fn layout(self: @Position) -> Span { - let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - array::ArrayTrait::span(@layout) - } - - #[inline(always)] - fn packed_size(self: @Position) -> usize { - let mut layout = self.layout(); - dojo::packing::calculate_packed_size(ref layout) - } -} - - -impl PositionSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() + 2 - } - - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - layout.append(16); - } - - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Struct( - dojo::database::schema::Struct { - name: 'Position', - attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'player', - ty: dojo::database::schema::Ty::Primitive('ContractAddress'), - attrs: array!['key'].span() - } - ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'before', - ty: dojo::database::schema::Ty::Primitive('u8'), - attrs: array![].span() - } - ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'vec', - ty: dojo::database::schema::SchemaIntrospection::::ty(), - attrs: array![].span() - } - ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'after', - ty: dojo::database::schema::Ty::Primitive('u16'), - attrs: array![].span() - } - ) - ] - .span() - } - ) - } -} - - -#[starknet::interface] -trait IPosition { - fn name(self: @T) -> felt252; -} - -#[starknet::contract] -mod position { - use super::Position; - - #[storage] - struct Storage {} - - #[external(v0)] - fn name(self: @ContractState) -> felt252 { - 'Position' - } - - #[external(v0)] - fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() - } - - #[external(v0)] - fn packed_size(self: @ContractState) -> usize { - let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - let mut layout_span = layout.span(); - dojo::packing::calculate_packed_size(ref layout_span) - } - - #[external(v0)] - fn layout(self: @ContractState) -> Span { - let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - array::ArrayTrait::span(@layout) - } - - #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() - } -} - -impl PositionSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() + 2 - } - - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - layout.append(16); - } - - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Struct( - dojo::database::schema::Struct { - name: 'Position', - attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'player', - ty: dojo::database::schema::Ty::Primitive('ContractAddress'), - attrs: array!['key'].span() - } - ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'before', - ty: dojo::database::schema::Ty::Primitive('u8'), - attrs: array![].span() - } - ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'vec', - ty: dojo::database::schema::SchemaIntrospection::::ty(), - attrs: array![].span() - } - ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { - name: 'after', - ty: dojo::database::schema::Ty::Primitive('u16'), - attrs: array![].span() - } - ) - ] - .span() - } - ) - } -} - -//! > expected_diagnostics -error: Unsupported attribute. - --> test_src/lib.cairo[Position]:96:13 - #[starknet::contract] - ^*******************^ - -error: Unsupported attribute. - --> test_src/lib.cairo[Position]:100:17 - #[storage] - ^********^ - -error: Unsupported attribute. - --> test_src/lib.cairo[Position]:103:17 - #[external(v0)] - ^*************^ - -error: Unsupported attribute. - --> test_src/lib.cairo[Position]:108:17 - #[external(v0)] - ^*************^ - -error: Unsupported attribute. - --> test_src/lib.cairo[Position]:113:17 - #[external(v0)] - ^*************^ - -error: Unsupported attribute. - --> test_src/lib.cairo[Position]:121:17 - #[external(v0)] - ^*************^ - -error: Unsupported attribute. - --> test_src/lib.cairo[Position]:128:17 - #[external(v0)] - ^*************^ - //! > expanded_cairo_code use serde::Serde; @@ -597,7 +83,7 @@ enum EnumCustom { Right: Vec2, } -#[derive(Model, Copy, Drop, Introspect)] +#[derive(Copy, Drop, Introspect)] struct Position { #[key] player: ContractAddress, @@ -605,6 +91,11 @@ struct Position { vec: Vec2, after: u16, } + +#[derive(Copy, Drop, Serde, Introspect)] +struct GenericStruct { + t: T, +} impl Vec2Copy of Copy::; impl Vec2Drop of Drop::; impl Vec2Serde of Serde:: { @@ -620,43 +111,36 @@ impl Vec2Serde of Serde:: { } } - impl Vec2SchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - 2 - } +impl Vec2Introspect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + 2 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(32); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(32); layout.append(32); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct { name: 'Vec2', attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'x', - ty: dojo::database::schema::Ty::Primitive('u32'), - attrs: array![].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'y', - ty: dojo::database::schema::Ty::Primitive('u32'), - attrs: array![].span() - }) -].span() + children: array![dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'x', + ty: dojo::database::introspect::Ty::Primitive('u32'), + attrs: array![].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'y', + ty: dojo::database::introspect::Ty::Primitive('u32'), + attrs: array![].span() + })].span() }) - } - } + } +} impl PlainEnumSerde of Serde:: { fn serialize(self: @PlainEnum, ref output: array::Array) { match self { @@ -676,44 +160,38 @@ impl PlainEnumSerde of Serde:: { impl PlainEnumCopy of Copy::; impl PlainEnumDrop of Drop::; - impl PlainEnumSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - 1 - } +impl PlainEnumIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + 1 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(8); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Enum( + dojo::database::introspect::Enum { name: 'PlainEnum', attrs: array![].span(), - children: array![ - - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![].span())) - ), - - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![].span())) - ) - ].span() + children: array![( + 'Left', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![].span())) + ), +( + 'Right', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![].span())) + )].span() } ) - } - } + } +} impl EnumPrimitiveSerde of Serde:: { fn serialize(self: @EnumPrimitive, ref output: array::Array) { match self { @@ -733,49 +211,43 @@ impl EnumPrimitiveSerde of Serde:: { impl EnumPrimitiveCopy of Copy::; impl EnumPrimitiveDrop of Drop::; - impl EnumPrimitiveSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - 2 - } +impl EnumPrimitiveIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + 2 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(8); layout.append(16); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Enum( + dojo::database::introspect::Enum { name: 'EnumPrimitive', attrs: array![].span(), - children: array![ - - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u16') + children: array![( + 'Left', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Primitive('u16') )].span())) - ), - - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u16') + ), +( + 'Right', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Primitive('u16') )].span())) - ) - ].span() + )].span() } ) - } - } + } +} impl EnumTupleSerde of Serde:: { fn serialize(self: @EnumTuple, ref output: array::Array) { match self { @@ -795,56 +267,48 @@ impl EnumTupleSerde of Serde:: { impl EnumTupleCopy of Copy::; impl EnumTupleDrop of Drop::; - impl EnumTupleSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - 3 - } +impl EnumTupleIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + 3 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(8); layout.append(8); layout.append(8); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Enum( + dojo::database::introspect::Enum { name: 'EnumTuple', attrs: array![].span(), - children: array![ - - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') - ), -dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') + children: array![( + 'Left', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Primitive('u8') + ), dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Primitive('u8') )].span())) - ), - - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') - ), -dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Primitive('u8') + ), +( + 'Right', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Primitive('u8') + ), dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Primitive('u8') )].span())) - ) - ].span() + )].span() } ) - } - } + } +} impl EnumCustomSerde of Serde:: { fn serialize(self: @EnumCustom, ref output: array::Array) { match self { @@ -864,233 +328,122 @@ impl EnumCustomSerde of Serde:: { impl EnumCustomCopy of Copy::; impl EnumCustomDrop of Drop::; - impl EnumCustomSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() + 1 - } +impl EnumCustomIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + dojo::database::introspect::Introspect::::size() + 1 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); -dojo::database::schema::SchemaIntrospection::::layout(ref layout); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(8); +dojo::database::introspect::Introspect::::layout(ref layout); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Enum( - dojo::database::schema::Enum { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Enum( + dojo::database::introspect::Enum { name: 'EnumCustom', attrs: array![].span(), - children: array![ - - ( - 'Left', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![dojo::database::schema::serialize_member_type( - @dojo::database::schema::SchemaIntrospection::::ty() + children: array![( + 'Left', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Introspect::::ty() )].span())) - ), - - ( - 'Right', - dojo::database::schema::serialize_member_type( - @dojo::database::schema::Ty::Tuple(array![dojo::database::schema::serialize_member_type( - @dojo::database::schema::SchemaIntrospection::::ty() + ), +( + 'Right', + dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Ty::Tuple(array![dojo::database::introspect::serialize_member_type( + @dojo::database::introspect::Introspect::::ty() )].span())) - ) - ].span() + )].span() } ) - } - } + } +} impl PositionCopy of Copy::; impl PositionDrop of Drop::; - impl PositionModel of dojo::model::Model { - #[inline(always)] - fn name(self: @Position) -> felt252 { - 'Position' - } - - #[inline(always)] - fn keys(self: @Position) -> Span { - let mut serialized = ArrayTrait::new(); - serde::Serde::serialize(self.player, ref serialized); - array::ArrayTrait::span(@serialized) - } - - #[inline(always)] - fn values(self: @Position) -> Span { - let mut serialized = ArrayTrait::new(); - serde::Serde::serialize(self.before, ref serialized);serde::Serde::serialize(self.vec, ref serialized);serde::Serde::serialize(self.after, ref serialized); - array::ArrayTrait::span(@serialized) - } - - #[inline(always)] - fn layout(self: @Position) -> Span { - let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - array::ArrayTrait::span(@layout) - } - - #[inline(always)] - fn packed_size(self: @Position) -> usize { - let mut layout = self.layout(); - dojo::packing::calculate_packed_size(ref layout) - } - } - - - impl PositionSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() + 2 - } +impl PositionIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + dojo::database::introspect::Introspect::::size() + 2 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); -dojo::database::schema::SchemaIntrospection::::layout(ref layout); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(8); +dojo::database::introspect::Introspect::::layout(ref layout); layout.append(16); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct { name: 'Position', attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'player', - ty: dojo::database::schema::Ty::Primitive('ContractAddress'), - attrs: array!['key'].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'before', - ty: dojo::database::schema::Ty::Primitive('u8'), - attrs: array![].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'vec', - ty: dojo::database::schema::SchemaIntrospection::::ty(), - attrs: array![].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'after', - ty: dojo::database::schema::Ty::Primitive('u16'), - attrs: array![].span() - }) -].span() + children: array![dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'player', + ty: dojo::database::introspect::Ty::Primitive('ContractAddress'), + attrs: array!['key'].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'before', + ty: dojo::database::introspect::Ty::Primitive('u8'), + attrs: array![].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'vec', + ty: dojo::database::introspect::Introspect::::ty(), + attrs: array![].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'after', + ty: dojo::database::introspect::Ty::Primitive('u16'), + attrs: array![].span() + })].span() }) - } - } - - - #[starknet::interface] - trait IPosition { - fn name(self: @T) -> felt252; - } - - #[starknet::contract] - mod position { - use super::Position; - - #[storage] - struct Storage {} - - #[external(v0)] - fn name(self: @ContractState) -> felt252 { - 'Position' - } - - #[external(v0)] - fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() - } - - #[external(v0)] - fn packed_size(self: @ContractState) -> usize { - let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - let mut layout_span = layout.span(); - dojo::packing::calculate_packed_size(ref layout_span) - } - - #[external(v0)] - fn layout(self: @ContractState) -> Span { - let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); - array::ArrayTrait::span(@layout) - } + } +} +impl GenericStructCopy> of Copy::>; +impl GenericStructDrop> of Drop::>; +impl GenericStructSerde, impl TDestruct: Destruct> of Serde::> { + fn serialize(self: @GenericStruct, ref output: array::Array) { + serde::Serde::serialize(self.t, ref output) + } + fn deserialize(ref serialized: array::Span) -> Option> { + Option::Some(GenericStruct { + t: serde::Serde::deserialize(ref serialized)?, + }) + } +} - #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() - } - } - - impl PositionSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() + 2 - } +impl GenericStructIntrospect> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + dojo::database::introspect::Introspect::::size() + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(8); -dojo::database::schema::SchemaIntrospection::::layout(ref layout); -layout.append(16); + #[inline(always)] + fn layout(ref layout: Array) { + dojo::database::introspect::Introspect::::layout(ref layout); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct { - name: 'Position', + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct { + name: 'GenericStruct', attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'player', - ty: dojo::database::schema::Ty::Primitive('ContractAddress'), - attrs: array!['key'].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'before', - ty: dojo::database::schema::Ty::Primitive('u8'), - attrs: array![].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'vec', - ty: dojo::database::schema::SchemaIntrospection::::ty(), - attrs: array![].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'after', - ty: dojo::database::schema::Ty::Primitive('u16'), - attrs: array![].span() - }) -].span() + children: array![dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 't', + ty: dojo::database::introspect::Introspect::::ty(), + attrs: array![].span() + })].span() }) - } - } + } +} + +//! > expected_diagnostics diff --git a/crates/dojo-lang/src/plugin_test_data/model b/crates/dojo-lang/src/plugin_test_data/model index c6fdecdb4f..00a549b83f 100644 --- a/crates/dojo-lang/src/plugin_test_data/model +++ b/crates/dojo-lang/src/plugin_test_data/model @@ -66,7 +66,7 @@ struct Vec3 { z: u8, } -impl Vec3SchemaIntrospection of dojo::database::schema::SchemaIntrospection { +impl Vec3Introspect of dojo::database::introspect::Introspect { #[inline(always)] fn size() -> usize { 3 @@ -80,30 +80,30 @@ impl Vec3SchemaIntrospection of dojo::database::schema::SchemaIntrospection dojo::database::schema::Ty { - dojo::database::schema::Ty::Struct( - dojo::database::schema::Struct { + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct( + dojo::database::introspect::Struct { name: 'Vec3', attrs: array![].span(), children: array![ - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'x', - ty: dojo::database::schema::Ty::Primitive('u32'), + ty: dojo::database::introspect::Ty::Primitive('u32'), attrs: array![].span() } ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'y', - ty: dojo::database::schema::Ty::Primitive('u32'), + ty: dojo::database::introspect::Ty::Primitive('u32'), attrs: array![].span() } ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'z', - ty: dojo::database::schema::Ty::Primitive('u8'), + ty: dojo::database::introspect::Ty::Primitive('u8'), attrs: array![].span() } ) @@ -146,7 +146,7 @@ impl PositionModel of dojo::model::Model { #[inline(always)] fn layout(self: @Position) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } @@ -158,35 +158,35 @@ impl PositionModel of dojo::model::Model { } -impl PositionSchemaIntrospection of dojo::database::schema::SchemaIntrospection { +impl PositionIntrospect of dojo::database::introspect::Introspect { #[inline(always)] fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() + dojo::database::introspect::Introspect::::size() } #[inline(always)] fn layout(ref layout: Array) { - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); } #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Struct( - dojo::database::schema::Struct { + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct( + dojo::database::introspect::Struct { name: 'Position', attrs: array![].span(), children: array![ - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'id', - ty: dojo::database::schema::Ty::Primitive('felt252'), + ty: dojo::database::introspect::Ty::Primitive('felt252'), attrs: array!['key'].span() } ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'v', - ty: dojo::database::schema::SchemaIntrospection::::ty(), + ty: dojo::database::introspect::Introspect::::ty(), attrs: array![].span() } ) @@ -217,13 +217,13 @@ mod position { #[external(v0)] fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() + dojo::database::introspect::Introspect::::size() } #[external(v0)] fn packed_size(self: @ContractState) -> usize { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); let mut layout_span = layout.span(); dojo::packing::calculate_packed_size(ref layout_span) } @@ -231,13 +231,13 @@ mod position { #[external(v0)] fn layout(self: @ContractState) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() + fn schema(self: @ContractState) -> dojo::database::introspect::Ty { + dojo::database::introspect::Introspect::::ty() } } @@ -291,7 +291,7 @@ impl RolesModel of dojo::model::Model { #[inline(always)] fn layout(self: @Roles) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } @@ -303,28 +303,28 @@ impl RolesModel of dojo::model::Model { } -impl RolesSchemaIntrospection of dojo::database::schema::SchemaIntrospection { +impl RolesIntrospect of dojo::database::introspect::Introspect { #[inline(always)] fn size() -> usize { - dojo::database::schema::SchemaIntrospection::>::size() + dojo::database::introspect::Introspect::>::size() } #[inline(always)] fn layout(ref layout: Array) { - dojo::database::schema::SchemaIntrospection::>::layout(ref layout); + dojo::database::introspect::Introspect::>::layout(ref layout); } #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - dojo::database::schema::Ty::Struct( - dojo::database::schema::Struct { + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct( + dojo::database::introspect::Struct { name: 'Roles', attrs: array![].span(), children: array![ - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'role_ids', - ty: dojo::database::schema::SchemaIntrospection::>::ty(), + ty: dojo::database::introspect::Introspect::>::ty(), attrs: array![].span() } ) @@ -355,13 +355,13 @@ mod roles { #[external(v0)] fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() + dojo::database::introspect::Introspect::::size() } #[external(v0)] fn packed_size(self: @ContractState) -> usize { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); let mut layout_span = layout.span(); dojo::packing::calculate_packed_size(ref layout_span) } @@ -369,13 +369,13 @@ mod roles { #[external(v0)] fn layout(self: @ContractState) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() + fn schema(self: @ContractState) -> dojo::database::introspect::Ty { + dojo::database::introspect::Introspect::::ty() } } @@ -417,7 +417,7 @@ impl PlayerModel of dojo::model::Model { #[inline(always)] fn layout(self: @Player) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } @@ -429,7 +429,7 @@ impl PlayerModel of dojo::model::Model { } -impl PlayerSchemaIntrospection of dojo::database::schema::SchemaIntrospection { +impl PlayerIntrospect of dojo::database::introspect::Introspect { #[inline(always)] fn size() -> usize { 1 @@ -441,30 +441,30 @@ impl PlayerSchemaIntrospection of dojo::database::schema::SchemaIntrospection dojo::database::schema::Ty { - dojo::database::schema::Ty::Struct( - dojo::database::schema::Struct { + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct( + dojo::database::introspect::Struct { name: 'Player', attrs: array![].span(), children: array![ - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'game', - ty: dojo::database::schema::Ty::Primitive('felt252'), + ty: dojo::database::introspect::Ty::Primitive('felt252'), attrs: array!['key'].span() } ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'player', - ty: dojo::database::schema::Ty::Primitive('ContractAddress'), + ty: dojo::database::introspect::Ty::Primitive('ContractAddress'), attrs: array!['key'].span() } ), - dojo::database::schema::serialize_member( - @dojo::database::schema::Member { + dojo::database::introspect::serialize_member( + @dojo::database::introspect::Member { name: 'name', - ty: dojo::database::schema::Ty::Primitive('felt252'), + ty: dojo::database::introspect::Ty::Primitive('felt252'), attrs: array![].span() } ) @@ -495,13 +495,13 @@ mod player { #[external(v0)] fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() + dojo::database::introspect::Introspect::::size() } #[external(v0)] fn packed_size(self: @ContractState) -> usize { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); let mut layout_span = layout.span(); dojo::packing::calculate_packed_size(ref layout_span) } @@ -509,13 +509,13 @@ mod player { #[external(v0)] fn layout(self: @ContractState) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() + fn schema(self: @ContractState) -> dojo::database::introspect::Ty { + dojo::database::introspect::Introspect::::ty() } } @@ -526,107 +526,107 @@ struct Roles { ^***^ error: Unsupported attribute. - --> test_src/lib.cairo[Position]:80:13 + --> test_src/lib.cairo[Position]:73:13 #[starknet::contract] ^*******************^ error: Unsupported attribute. - --> test_src/lib.cairo[Roles]:73:13 + --> test_src/lib.cairo[Roles]:69:13 #[starknet::contract] ^*******************^ error: Unsupported attribute. - --> test_src/lib.cairo[Player]:87:13 + --> test_src/lib.cairo[Player]:77:13 #[starknet::contract] ^*******************^ error: Unsupported attribute. - --> test_src/lib.cairo[Position]:84:17 + --> test_src/lib.cairo[Position]:77:17 #[storage] ^********^ error: Unsupported attribute. - --> test_src/lib.cairo[Position]:87:17 + --> test_src/lib.cairo[Position]:80:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Position]:92:17 + --> test_src/lib.cairo[Position]:85:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Position]:97:17 + --> test_src/lib.cairo[Position]:90:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Position]:105:17 + --> test_src/lib.cairo[Position]:98:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Position]:112:17 + --> test_src/lib.cairo[Position]:105:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Roles]:77:17 + --> test_src/lib.cairo[Roles]:73:17 #[storage] ^********^ error: Unsupported attribute. - --> test_src/lib.cairo[Roles]:80:17 + --> test_src/lib.cairo[Roles]:76:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Roles]:85:17 + --> test_src/lib.cairo[Roles]:81:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Roles]:90:17 + --> test_src/lib.cairo[Roles]:86:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Roles]:98:17 + --> test_src/lib.cairo[Roles]:94:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Roles]:105:17 + --> test_src/lib.cairo[Roles]:101:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Player]:91:17 + --> test_src/lib.cairo[Player]:81:17 #[storage] ^********^ error: Unsupported attribute. - --> test_src/lib.cairo[Player]:94:17 + --> test_src/lib.cairo[Player]:84:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Player]:99:17 + --> test_src/lib.cairo[Player]:89:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Player]:104:17 + --> test_src/lib.cairo[Player]:94:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Player]:112:17 + --> test_src/lib.cairo[Player]:102:17 #[external(v0)] ^*************^ error: Unsupported attribute. - --> test_src/lib.cairo[Player]:119:17 + --> test_src/lib.cairo[Player]:109:17 #[external(v0)] ^*************^ @@ -698,51 +698,41 @@ impl Vec3Serde of Serde:: { } } - impl Vec3SchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - 3 - } +impl Vec3Introspect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + 3 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(32); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(32); layout.append(32); layout.append(8); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct { name: 'Vec3', attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'x', - ty: dojo::database::schema::Ty::Primitive('u32'), - attrs: array![].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'y', - ty: dojo::database::schema::Ty::Primitive('u32'), - attrs: array![].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'z', - ty: dojo::database::schema::Ty::Primitive('u8'), - attrs: array![].span() - }) -].span() + children: array![dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'x', + ty: dojo::database::introspect::Ty::Primitive('u32'), + attrs: array![].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'y', + ty: dojo::database::introspect::Ty::Primitive('u32'), + attrs: array![].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'z', + ty: dojo::database::introspect::Ty::Primitive('u8'), + attrs: array![].span() + })].span() }) - } - } + } +} impl PositionCopy of Copy::; impl PositionDrop of Drop::; impl PositionSerde of Serde:: { @@ -781,7 +771,7 @@ impl PositionSerde of Serde:: { #[inline(always)] fn layout(self: @Position) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } @@ -793,42 +783,35 @@ impl PositionSerde of Serde:: { } - impl PositionSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::::size() - } +impl PositionIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + dojo::database::introspect::Introspect::::size() + } - #[inline(always)] - fn layout(ref layout: Array) { - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + #[inline(always)] + fn layout(ref layout: Array) { + dojo::database::introspect::Introspect::::layout(ref layout); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct { name: 'Position', attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'id', - ty: dojo::database::schema::Ty::Primitive('felt252'), - attrs: array!['key'].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'v', - ty: dojo::database::schema::SchemaIntrospection::::ty(), - attrs: array![].span() - }) -].span() + children: array![dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'id', + ty: dojo::database::introspect::Ty::Primitive('felt252'), + attrs: array!['key'].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'v', + ty: dojo::database::introspect::Introspect::::ty(), + attrs: array![].span() + })].span() }) - } - } + } +} #[starknet::interface] @@ -850,13 +833,13 @@ impl PositionSerde of Serde:: { #[external(v0)] fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() + dojo::database::introspect::Introspect::::size() } #[external(v0)] fn packed_size(self: @ContractState) -> usize { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); let mut layout_span = layout.span(); dojo::packing::calculate_packed_size(ref layout_span) } @@ -864,13 +847,13 @@ impl PositionSerde of Serde:: { #[external(v0)] fn layout(self: @ContractState) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() + fn schema(self: @ContractState) -> dojo::database::introspect::Ty { + dojo::database::introspect::Introspect::::ty() } } impl RolesSerde of Serde:: { @@ -907,7 +890,7 @@ impl RolesSerde of Serde:: { #[inline(always)] fn layout(self: @Roles) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } @@ -919,35 +902,31 @@ impl RolesSerde of Serde:: { } - impl RolesSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - dojo::database::schema::SchemaIntrospection::>::size() - } +impl RolesIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + dojo::database::introspect::Introspect::>::size() + } - #[inline(always)] - fn layout(ref layout: Array) { - dojo::database::schema::SchemaIntrospection::>::layout(ref layout); + #[inline(always)] + fn layout(ref layout: Array) { + dojo::database::introspect::Introspect::>::layout(ref layout); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct { name: 'Roles', attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'role_ids', - ty: dojo::database::schema::SchemaIntrospection::>::ty(), - attrs: array![].span() - }) -].span() + children: array![dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'role_ids', + ty: dojo::database::introspect::Introspect::>::ty(), + attrs: array![].span() + })].span() }) - } - } + } +} #[starknet::interface] @@ -969,13 +948,13 @@ impl RolesSerde of Serde:: { #[external(v0)] fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() + dojo::database::introspect::Introspect::::size() } #[external(v0)] fn packed_size(self: @ContractState) -> usize { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); let mut layout_span = layout.span(); dojo::packing::calculate_packed_size(ref layout_span) } @@ -983,13 +962,13 @@ impl RolesSerde of Serde:: { #[external(v0)] fn layout(self: @ContractState) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() + fn schema(self: @ContractState) -> dojo::database::introspect::Ty { + dojo::database::introspect::Introspect::::ty() } } impl PlayerCopy of Copy::; @@ -1032,7 +1011,7 @@ impl PlayerSerde of Serde:: { #[inline(always)] fn layout(self: @Player) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } @@ -1044,49 +1023,39 @@ impl PlayerSerde of Serde:: { } - impl PlayerSchemaIntrospection of dojo::database::schema::SchemaIntrospection { - - #[inline(always)] - fn size() -> usize { - 1 - } +impl PlayerIntrospect<> of dojo::database::introspect::Introspect> { + #[inline(always)] + fn size() -> usize { + 1 + } - #[inline(always)] - fn layout(ref layout: Array) { - layout.append(251); + #[inline(always)] + fn layout(ref layout: Array) { + layout.append(251); - } + } - #[inline(always)] - fn ty() -> dojo::database::schema::Ty { - - dojo::database::schema::Ty::Struct(dojo::database::schema::Struct { + #[inline(always)] + fn ty() -> dojo::database::introspect::Ty { + dojo::database::introspect::Ty::Struct(dojo::database::introspect::Struct { name: 'Player', attrs: array![].span(), - children: array![ - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'game', - ty: dojo::database::schema::Ty::Primitive('felt252'), - attrs: array!['key'].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'player', - ty: dojo::database::schema::Ty::Primitive('ContractAddress'), - attrs: array!['key'].span() - }) -, - - dojo::database::schema::serialize_member(@dojo::database::schema::Member { - name: 'name', - ty: dojo::database::schema::Ty::Primitive('felt252'), - attrs: array![].span() - }) -].span() + children: array![dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'game', + ty: dojo::database::introspect::Ty::Primitive('felt252'), + attrs: array!['key'].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'player', + ty: dojo::database::introspect::Ty::Primitive('ContractAddress'), + attrs: array!['key'].span() + }), dojo::database::introspect::serialize_member(@dojo::database::introspect::Member { + name: 'name', + ty: dojo::database::introspect::Ty::Primitive('felt252'), + attrs: array![].span() + })].span() }) - } - } + } +} #[starknet::interface] @@ -1108,13 +1077,13 @@ impl PlayerSerde of Serde:: { #[external(v0)] fn unpacked_size(self: @ContractState) -> usize { - dojo::database::schema::SchemaIntrospection::::size() + dojo::database::introspect::Introspect::::size() } #[external(v0)] fn packed_size(self: @ContractState) -> usize { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); let mut layout_span = layout.span(); dojo::packing::calculate_packed_size(ref layout_span) } @@ -1122,12 +1091,12 @@ impl PlayerSerde of Serde:: { #[external(v0)] fn layout(self: @ContractState) -> Span { let mut layout = ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::::layout(ref layout); + dojo::database::introspect::Introspect::::layout(ref layout); array::ArrayTrait::span(@layout) } #[external(v0)] - fn schema(self: @ContractState) -> dojo::database::schema::Ty { - dojo::database::schema::SchemaIntrospection::::ty() + fn schema(self: @ContractState) -> dojo::database::introspect::Ty { + dojo::database::introspect::Introspect::::ty() } } diff --git a/crates/dojo-lang/src/semantics/test_data/get b/crates/dojo-lang/src/semantics/test_data/get index d46f8f8659..da5f04e60e 100644 --- a/crates/dojo-lang/src/semantics/test_data/get +++ b/crates/dojo-lang/src/semantics/test_data/get @@ -199,7 +199,7 @@ Block( StatementExpr { expr: FunctionCall( ExprFunctionCall { - function: test::HealthSchemaIntrospection::layout, + function: test::HealthIntrospect::layout, args: [ Reference( LocalVarId(test::__Health_layout__), diff --git a/crates/dojo-world/src/contracts/model_test.rs b/crates/dojo-world/src/contracts/model_test.rs index 6b4b5e1981..887310faf0 100644 --- a/crates/dojo-world/src/contracts/model_test.rs +++ b/crates/dojo-world/src/contracts/model_test.rs @@ -63,7 +63,7 @@ async fn test_model() { assert_eq!( position.class_hash(), FieldElement::from_hex_be( - "0x06a11b5b3003a3aa0ae7f8f443e48314cc0bc51eaea7c3ed1c19beb909f5dda3" + "0x052a1da1853c194683ca5d6d154452d0654d23f2eacd4267c555ff2338e144d6" ) .unwrap() ); diff --git a/crates/torii/graphql/src/tests/types-test/Scarb.lock b/crates/torii/graphql/src/tests/types-test/Scarb.lock index 59ad92bcaa..a1c39e0280 100644 --- a/crates/torii/graphql/src/tests/types-test/Scarb.lock +++ b/crates/torii/graphql/src/tests/types-test/Scarb.lock @@ -3,14 +3,15 @@ version = 1 [[package]] name = "dojo" -version = "0.3.11" +version = "0.3.12" dependencies = [ "dojo_plugin", ] [[package]] name = "dojo_plugin" -version = "0.3.11" +version = "0.3.12" +source = "git+https://github.com/dojoengine/dojo?tag=v0.3.12#12d58f29ec53454317f1f6d265007a053d279288" [[package]] name = "types_test"