From 4a596fb0805af64f9151cfbefa6331f4da0a1cfc Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 30 Sep 2024 22:26:27 +0200 Subject: [PATCH] excise AlgebraicType/Value::Map --- crates/bindings-csharp/BSATN.Codegen/Utils.cs | 2 - .../BSATN.Runtime/BSATN/AlgebraicType.cs | 8 -- .../BSATN.Runtime/BSATN/Runtime.cs | 35 ------- .../Codegen.Tests/fixtures/client/Lib.cs | 2 - .../snapshots/Type#PublicTable.verified.cs | 32 +------ .../Codegen.Tests/fixtures/server/Lib.cs | 2 - .../snapshots/Module#PublicTable.verified.cs | 40 +------- crates/cli/src/subcommands/call.rs | 7 -- crates/cli/src/subcommands/generate/csharp.rs | 18 +--- crates/cli/src/subcommands/generate/rust.rs | 1 - .../src/subcommands/generate/typescript.rs | 2 - crates/sats/src/algebraic_type.rs | 27 +----- crates/sats/src/algebraic_type/fmt.rs | 1 - .../sats/src/algebraic_type/map_notation.rs | 1 - crates/sats/src/algebraic_value.rs | 53 +---------- crates/sats/src/algebraic_value/de.rs | 92 ------------------- crates/sats/src/algebraic_value/ser.rs | 40 +------- crates/sats/src/algebraic_value_hash.rs | 19 +--- crates/sats/src/array_value.rs | 15 +-- crates/sats/src/bsatn/de.rs | 45 --------- crates/sats/src/bsatn/eq.rs | 11 +-- crates/sats/src/bsatn/ser.rs | 25 +---- crates/sats/src/convert.rs | 9 +- crates/sats/src/de.rs | 82 ----------------- crates/sats/src/de/impls.rs | 29 +----- crates/sats/src/de/serde.rs | 81 ---------------- crates/sats/src/lib.rs | 4 - crates/sats/src/map_type.rs | 24 ----- crates/sats/src/map_value.rs | 9 -- crates/sats/src/proptest.rs | 18 +--- crates/sats/src/resolve_refs.rs | 15 +-- crates/sats/src/satn.rs | 46 ---------- crates/sats/src/ser.rs | 34 ------- crates/sats/src/ser/impls.rs | 27 +----- crates/sats/src/ser/serde.rs | 31 ------- crates/sats/src/typespace.rs | 10 -- crates/schema/src/type_for_generate.rs | 37 +------- crates/sqltest/src/space.rs | 2 +- crates/table/src/bflatn_from.rs | 2 +- crates/table/src/bflatn_to.rs | 3 +- crates/table/src/bflatn_to_bsatn_fast_path.rs | 1 - crates/table/src/eq_to_pv.rs | 2 +- crates/table/src/layout.rs | 10 +- crates/table/src/read_column.rs | 3 +- crates/table/src/row_hash.rs | 2 +- 45 files changed, 34 insertions(+), 925 deletions(-) delete mode 100644 crates/sats/src/map_type.rs delete mode 100644 crates/sats/src/map_value.rs diff --git a/crates/bindings-csharp/BSATN.Codegen/Utils.cs b/crates/bindings-csharp/BSATN.Codegen/Utils.cs index 58764e8e62..5f7ee915af 100644 --- a/crates/bindings-csharp/BSATN.Codegen/Utils.cs +++ b/crates/bindings-csharp/BSATN.Codegen/Utils.cs @@ -145,8 +145,6 @@ static string GetTypeInfoForNamedType(INamedTypeSymbol type) "SpacetimeDB.I256" => "SpacetimeDB.BSATN.I256", "SpacetimeDB.U256" => "SpacetimeDB.BSATN.U256", "System.Collections.Generic.List" => $"SpacetimeDB.BSATN.List", - "System.Collections.Generic.Dictionary" => - $"SpacetimeDB.BSATN.Dictionary", // If we're here, then this is nullable *value* type like `int?`. "System.Nullable" => $"SpacetimeDB.BSATN.ValueOption", var name when name.StartsWith("System.") => throw new InvalidOperationException( diff --git a/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs b/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs index 70f331fec5..2c0a0f0f7a 100644 --- a/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs +++ b/crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs @@ -12,13 +12,6 @@ public partial struct AggregateElement(string? name, AlgebraicType algebraicType public AlgebraicType AlgebraicType = algebraicType; } -[SpacetimeDB.Type] -public partial struct MapElement(AlgebraicType key, AlgebraicType value) -{ - public AlgebraicType Key = key; - public AlgebraicType Value = value; -} - [SpacetimeDB.Type] public partial record AlgebraicType : SpacetimeDB.TaggedEnum<( @@ -26,7 +19,6 @@ public partial record AlgebraicType AggregateElement[] Sum, AggregateElement[] Product, AlgebraicType Array, - MapElement Map, Unit String, Unit Bool, Unit I8, diff --git a/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs b/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs index a31ae445ac..65dfa51913 100644 --- a/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs +++ b/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs @@ -438,38 +438,3 @@ public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => enumerable.GetAlgebraicType(registrar); } - -public readonly struct Dictionary : IReadWrite> - where Key : notnull - where KeyRW : IReadWrite, new() - where ValueRW : IReadWrite, new() -{ - private static readonly KeyRW keyRW = new(); - private static readonly ValueRW valueRW = new(); - - public Dictionary Read(BinaryReader reader) - { - var count = reader.ReadInt32(); - var result = new Dictionary(count); - for (var i = 0; i < count; i++) - { - result.Add(keyRW.Read(reader), valueRW.Read(reader)); - } - return result; - } - - public void Write(BinaryWriter writer, Dictionary value) - { - writer.Write(value.Count); - foreach (var (key, val) in value) - { - keyRW.Write(writer, key); - valueRW.Write(writer, val); - } - } - - public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => - new AlgebraicType.Map( - new(keyRW.GetAlgebraicType(registrar), valueRW.GetAlgebraicType(registrar)) - ); -} diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs index e9bc0c7218..e1a82bb3d3 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/client/Lib.cs @@ -71,8 +71,6 @@ public partial struct PublicTable public CustomEnum CustomEnumField; public CustomTaggedEnum CustomTaggedEnumField; public List ListField; - public Dictionary DictionaryField; public int? NullableValueField; public string? NullableReferenceField; - public Dictionary?>? ComplexNestedField; } diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs index 212c0b2fc5..3a47ce3009 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#PublicTable.verified.cs @@ -29,10 +29,8 @@ public void ReadFields(System.IO.BinaryReader reader) CustomEnumField = BSATN.CustomEnumField.Read(reader); CustomTaggedEnumField = BSATN.CustomTaggedEnumField.Read(reader); ListField = BSATN.ListField.Read(reader); - DictionaryField = BSATN.DictionaryField.Read(reader); NullableValueField = BSATN.NullableValueField.Read(reader); NullableReferenceField = BSATN.NullableReferenceField.Read(reader); - ComplexNestedField = BSATN.ComplexNestedField.Read(reader); } public void WriteFields(System.IO.BinaryWriter writer) @@ -60,10 +58,8 @@ public void WriteFields(System.IO.BinaryWriter writer) BSATN.CustomEnumField.Write(writer, CustomEnumField); BSATN.CustomTaggedEnumField.Write(writer, CustomTaggedEnumField); BSATN.ListField.Write(writer, ListField); - BSATN.DictionaryField.Write(writer, DictionaryField); BSATN.NullableValueField.Write(writer, NullableValueField); BSATN.NullableReferenceField.Write(writer, NullableReferenceField); - BSATN.ComplexNestedField.Write(writer, ComplexNestedField); } public readonly partial struct BSATN : SpacetimeDB.BSATN.IReadWrite @@ -92,12 +88,6 @@ public void WriteFields(System.IO.BinaryWriter writer) internal static readonly CustomTaggedEnum.BSATN CustomTaggedEnumField = new(); internal static readonly SpacetimeDB.BSATN.List ListField = new(); - internal static readonly SpacetimeDB.BSATN.Dictionary< - string, - int, - SpacetimeDB.BSATN.String, - SpacetimeDB.BSATN.I32 - > DictionaryField = new(); internal static readonly SpacetimeDB.BSATN.ValueOption< int, SpacetimeDB.BSATN.I32 @@ -106,24 +96,6 @@ internal static readonly SpacetimeDB.BSATN.RefOption< string, SpacetimeDB.BSATN.String > NullableReferenceField = new(); - internal static readonly SpacetimeDB.BSATN.RefOption< - System.Collections.Generic.Dictionary< - CustomEnum, - System.Collections.Generic.List? - >, - SpacetimeDB.BSATN.Dictionary< - CustomEnum, - System.Collections.Generic.List?, - SpacetimeDB.BSATN.Enum, - SpacetimeDB.BSATN.RefOption< - System.Collections.Generic.List, - SpacetimeDB.BSATN.List< - int?, - SpacetimeDB.BSATN.ValueOption - > - > - > - > ComplexNestedField = new(); public PublicTable Read(System.IO.BinaryReader reader) => SpacetimeDB.BSATN.IStructuralReadWrite.Read(reader); @@ -165,13 +137,11 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar CustomTaggedEnumField.GetAlgebraicType(registrar) ), new(nameof(ListField), ListField.GetAlgebraicType(registrar)), - new(nameof(DictionaryField), DictionaryField.GetAlgebraicType(registrar)), new(nameof(NullableValueField), NullableValueField.GetAlgebraicType(registrar)), new( nameof(NullableReferenceField), NullableReferenceField.GetAlgebraicType(registrar) - ), - new(nameof(ComplexNestedField), ComplexNestedField.GetAlgebraicType(registrar)) + ) } )); } diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs index 78f136f267..84b699424a 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs @@ -74,10 +74,8 @@ public partial struct PublicTable public CustomEnum CustomEnumField; public CustomTaggedEnum CustomTaggedEnumField; public List ListField; - public Dictionary DictionaryField; public int? NullableValueField; public string? NullableReferenceField; - public Dictionary?>? ComplexNestedField; } public static partial class Reducers diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs index 94ded4ff37..1e1882c7ea 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs @@ -32,10 +32,8 @@ public void ReadFields(System.IO.BinaryReader reader) CustomEnumField = BSATN.CustomEnumField.Read(reader); CustomTaggedEnumField = BSATN.CustomTaggedEnumField.Read(reader); ListField = BSATN.ListField.Read(reader); - DictionaryField = BSATN.DictionaryField.Read(reader); NullableValueField = BSATN.NullableValueField.Read(reader); NullableReferenceField = BSATN.NullableReferenceField.Read(reader); - ComplexNestedField = BSATN.ComplexNestedField.Read(reader); } public void WriteFields(System.IO.BinaryWriter writer) @@ -66,10 +64,8 @@ public void WriteFields(System.IO.BinaryWriter writer) BSATN.CustomEnumField.Write(writer, CustomEnumField); BSATN.CustomTaggedEnumField.Write(writer, CustomTaggedEnumField); BSATN.ListField.Write(writer, ListField); - BSATN.DictionaryField.Write(writer, DictionaryField); BSATN.NullableValueField.Write(writer, NullableValueField); BSATN.NullableReferenceField.Write(writer, NullableReferenceField); - BSATN.ComplexNestedField.Write(writer, ComplexNestedField); } public readonly partial struct BSATN : SpacetimeDB.BSATN.IReadWrite @@ -101,12 +97,6 @@ public void WriteFields(System.IO.BinaryWriter writer) internal static readonly CustomTaggedEnum.BSATN CustomTaggedEnumField = new(); internal static readonly SpacetimeDB.BSATN.List ListField = new(); - internal static readonly SpacetimeDB.BSATN.Dictionary< - string, - int, - SpacetimeDB.BSATN.String, - SpacetimeDB.BSATN.I32 - > DictionaryField = new(); internal static readonly SpacetimeDB.BSATN.ValueOption< int, SpacetimeDB.BSATN.I32 @@ -115,24 +105,6 @@ internal static readonly SpacetimeDB.BSATN.RefOption< string, SpacetimeDB.BSATN.String > NullableReferenceField = new(); - internal static readonly SpacetimeDB.BSATN.RefOption< - System.Collections.Generic.Dictionary< - CustomEnum, - System.Collections.Generic.List? - >, - SpacetimeDB.BSATN.Dictionary< - CustomEnum, - System.Collections.Generic.List?, - SpacetimeDB.BSATN.Enum, - SpacetimeDB.BSATN.RefOption< - System.Collections.Generic.List, - SpacetimeDB.BSATN.List< - int?, - SpacetimeDB.BSATN.ValueOption - > - > - > - > ComplexNestedField = new(); public PublicTable Read(System.IO.BinaryReader reader) => SpacetimeDB.BSATN.IStructuralReadWrite.Read(reader); @@ -177,13 +149,11 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar CustomTaggedEnumField.GetAlgebraicType(registrar) ), new(nameof(ListField), ListField.GetAlgebraicType(registrar)), - new(nameof(DictionaryField), DictionaryField.GetAlgebraicType(registrar)), new(nameof(NullableValueField), NullableValueField.GetAlgebraicType(registrar)), new( nameof(NullableReferenceField), NullableReferenceField.GetAlgebraicType(registrar) - ), - new(nameof(ComplexNestedField), ComplexNestedField.GetAlgebraicType(registrar)) + ) } )); } @@ -235,10 +205,6 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar BSATN.CustomTaggedEnumField.GetAlgebraicType(registrar) ), new(nameof(ListField), BSATN.ListField.GetAlgebraicType(registrar)), - new( - nameof(DictionaryField), - BSATN.DictionaryField.GetAlgebraicType(registrar) - ), new( nameof(NullableValueField), BSATN.NullableValueField.GetAlgebraicType(registrar) @@ -246,10 +212,6 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar new( nameof(NullableReferenceField), BSATN.NullableReferenceField.GetAlgebraicType(registrar) - ), - new( - nameof(ComplexNestedField), - BSATN.ComplexNestedField.GetAlgebraicType(registrar) ) ], Indexes: [], diff --git a/crates/cli/src/subcommands/call.rs b/crates/cli/src/subcommands/call.rs index 9d72c43035..fff18820ce 100644 --- a/crates/cli/src/subcommands/call.rs +++ b/crates/cli/src/subcommands/call.rs @@ -379,13 +379,6 @@ mod write_type { write_type(ctx, out, elem_ty)?; write!(out, ">")?; } - AlgebraicType::Map(ty) => { - write!(out, "Map<")?; - write_type(ctx, out, &ty.key_ty)?; - write!(out, ", ")?; - write_type(ctx, out, &ty.ty)?; - write!(out, ">")?; - } AlgebraicType::Ref(r) => { write!(out, "{}", ctx(*r))?; } diff --git a/crates/cli/src/subcommands/generate/csharp.rs b/crates/cli/src/subcommands/generate/csharp.rs index e19c7d9b0a..c53f4e7126 100644 --- a/crates/cli/src/subcommands/generate/csharp.rs +++ b/crates/cli/src/subcommands/generate/csharp.rs @@ -34,11 +34,9 @@ fn scalar_or_string_name(b: &AlgebraicType) -> Option<&str> { AlgebraicType::String => "string", AlgebraicType::F32 => "float", AlgebraicType::F64 => "double", - AlgebraicType::Ref(_) - | AlgebraicType::Sum(_) - | AlgebraicType::Product(_) - | AlgebraicType::Array(_) - | AlgebraicType::Map(_) => return None, + AlgebraicType::Ref(_) | AlgebraicType::Sum(_) | AlgebraicType::Product(_) | AlgebraicType::Array(_) => { + return None + } }) } @@ -64,14 +62,6 @@ fn ty_fmt<'a>(ctx: &'a GenCtx, ty: &'a AlgebraicType, namespace: &'a str) -> imp ty_fmt(ctx, elem_ty, namespace) ) } - AlgebraicType::Map(ty) => { - write!( - f, - "System.Collections.Generic.Dictionary<{}, {}>", - ty_fmt(ctx, &ty.ty, namespace), - ty_fmt(ctx, &ty.key_ty, namespace) - ) - } AlgebraicType::Ref(r) => { let name = csharp_typename(ctx, *r); match &ctx.typespace[*r] { @@ -105,7 +95,7 @@ fn default_init(ctx: &GenCtx, ty: &AlgebraicType) -> Option<&'static str> { // TODO: generate some proper default here (what would it be for tagged enums?). AlgebraicType::Sum(_) => Some("null!"), // For product types, arrays, and maps, we can use the default constructor. - AlgebraicType::Product(_) | AlgebraicType::Array(_) | AlgebraicType::Map(_) => Some("new()"), + AlgebraicType::Product(_) | AlgebraicType::Array(_) => Some("new()"), // Strings must have explicit default value of "". AlgebraicType::String => Some(r#""""#), AlgebraicType::Ref(r) => default_init(ctx, &ctx.typespace[*r]), diff --git a/crates/cli/src/subcommands/generate/rust.rs b/crates/cli/src/subcommands/generate/rust.rs index 7f4f4be9ae..459d6a97c6 100644 --- a/crates/cli/src/subcommands/generate/rust.rs +++ b/crates/cli/src/subcommands/generate/rust.rs @@ -515,7 +515,6 @@ pub fn write_type(module: &ModuleDef, out: &mut W, ty: &AlgebraicTypeU write_type(module, out, elem_ty)?; write!(out, ">")?; } - AlgebraicTypeUse::Map { .. } => unimplemented!("AlgebraicType::Map is unsupported and will be removed"), AlgebraicTypeUse::Ref(r) => { write!(out, "{}", type_ref_name(module, *r))?; } diff --git a/crates/cli/src/subcommands/generate/typescript.rs b/crates/cli/src/subcommands/generate/typescript.rs index 08ca49178a..efdfa09d7b 100644 --- a/crates/cli/src/subcommands/generate/typescript.rs +++ b/crates/cli/src/subcommands/generate/typescript.rs @@ -939,7 +939,6 @@ pub fn write_type( write_type(module, out, elem_ty, ref_prefix)?; write!(out, "[]")?; } - AlgebraicTypeUse::Map { .. } => unimplemented!("AlgebraicType::Map is unsupported and will be removed"), AlgebraicTypeUse::Ref(r) => { if let Some(prefix) = ref_prefix { write!(out, "{prefix}")?; @@ -978,7 +977,6 @@ fn convert_algebraic_type<'a>( AlgebraicTypeUse::Primitive(prim) => { write!(out, "AlgebraicType.create{prim:?}Type()"); } - AlgebraicTypeUse::Map { .. } => unimplemented!(), AlgebraicTypeUse::Unit => write!(out, "AlgebraicType.createProductType([])"), AlgebraicTypeUse::Never => unimplemented!(), AlgebraicTypeUse::String => write!(out, "AlgebraicType.createStringType()"), diff --git a/crates/sats/src/algebraic_type.rs b/crates/sats/src/algebraic_type.rs index 3ad0039173..fd672e8b01 100644 --- a/crates/sats/src/algebraic_type.rs +++ b/crates/sats/src/algebraic_type.rs @@ -8,9 +8,7 @@ use crate::meta_type::MetaType; use crate::product_type::{ADDRESS_TAG, IDENTITY_TAG}; use crate::sum_type::{OPTION_NONE_TAG, OPTION_SOME_TAG}; use crate::{i256, u256}; -use crate::{ - AlgebraicTypeRef, AlgebraicValue, ArrayType, MapType, ProductType, SpacetimeType, SumType, SumTypeVariant, -}; +use crate::{AlgebraicTypeRef, AlgebraicValue, ArrayType, ProductType, SpacetimeType, SumType, SumTypeVariant}; use derive_more::From; use enum_as_inner::EnumAsInner; @@ -81,10 +79,6 @@ pub enum AlgebraicType { /// The type of array values where elements are of a base type `elem_ty`. /// Values [`AlgebraicValue::Array(array)`](crate::AlgebraicValue::Array) will have this type. Array(ArrayType), - /// The type of map values consisting of a key type `key_ty` and value `ty`. - /// Values [`AlgebraicValue::Map(map)`](crate::AlgebraicValue::Map) will have this type. - /// The order of entries in a map value is observable. - Map(Box), /// The UTF-8 encoded `String` type. /// Values [`AlgebraicValue::String(s)`](crate::AlgebraicValue::String) will have this type. /// @@ -135,7 +129,6 @@ impl MetaType for AlgebraicType { ("sum", SumType::meta_type()), ("product", ProductType::meta_type()), ("array", ArrayType::meta_type()), - ("map", MapType::meta_type()), ("string", AlgebraicType::unit()), ("bool", AlgebraicType::unit()), ("i8", AlgebraicType::unit()), @@ -272,7 +265,6 @@ impl AlgebraicType { variants.iter().any(|variant| variant.algebraic_type.contains_refs()) } AlgebraicType::Array(array) => array.elem_ty.contains_refs(), - AlgebraicType::Map(map) => map.key_ty.contains_refs() || map.ty.contains_refs(), _ => false, } } @@ -297,11 +289,6 @@ impl AlgebraicType { ArrayType { elem_ty: Box::new(ty) }.into() } - /// Returns a map type from the type `key` to the type `value`. - pub fn map(key: Self, value: Self) -> Self { - MapType::new(key, value).into() - } - /// Construct a copy of the `Identity` type. pub fn identity() -> Self { AlgebraicType::product([(IDENTITY_TAG, AlgebraicType::bytes())]) @@ -428,9 +415,6 @@ impl AlgebraicType { } AlgebraicType::Product(product) => product.is_special() || product.is_unit(), AlgebraicType::Array(array) => array.elem_ty.is_valid_for_client_type_use(), - AlgebraicType::Map(map) => { - map.key_ty.is_valid_for_client_type_use() && map.ty.is_valid_for_client_type_use() - } AlgebraicType::Ref(_) => true, _ => true, } @@ -508,7 +492,6 @@ mod tests { algebraic_type: &0\ )>) \ | array: &0 \ - | map: (key_ty: &0, ty: &0) \ | string: () \ | bool: () \ | i8: () | u8: () \ @@ -553,7 +536,6 @@ mod tests { } \ }, \ array: { ty_: Ref, 0: 0 }, \ - map: { ty_: Product, key_ty: { ty_: Ref, 0: 0 }, ty: { ty_: Ref, 0: 0 } }, \ string: { ty_: Product }, \ bool: { ty_: Product }, \ i8: { ty_: Product }, u8: { ty_: Product }, \ @@ -641,13 +623,6 @@ mod tests { ]))\ ), \ (name = (some = \"array\"), {ref0}), \ - (\ - name = (some = \"map\"), \ - algebraic_type = (product = (elements = [\ - (name = (some = \"key_ty\"), {ref0}), \ - (name = (some = \"ty\"), {ref0})\ - ]))\ - ), \ (name = (some = \"string\"), {unit}), \ (name = (some = \"bool\"), {unit}), \ (name = (some = \"i8\"), {unit}), \ diff --git a/crates/sats/src/algebraic_type/fmt.rs b/crates/sats/src/algebraic_type/fmt.rs index ef767fdbc5..02a9e3274d 100644 --- a/crates/sats/src/algebraic_type/fmt.rs +++ b/crates/sats/src/algebraic_type/fmt.rs @@ -18,7 +18,6 @@ pub fn fmt_algebraic_type(ty: &AlgebraicType) -> impl '_ + Display { AlgebraicType::Sum(ty) => write!(f, "{}", fmt_sum_type(ty)), AlgebraicType::Product(ty) => write!(f, "{}", fmt_product_type(ty)), AlgebraicType::Array(a) => write!(f, "Array<{}>", fmt(&a.elem_ty)), - AlgebraicType::Map(m) => write!(f, "Map<{}, {}>", fmt(&m.key_ty), fmt(&m.ty)), AlgebraicType::Bool => write!(f, "Bool"), AlgebraicType::I8 => write!(f, "I8"), AlgebraicType::U8 => write!(f, "U8"), diff --git a/crates/sats/src/algebraic_type/map_notation.rs b/crates/sats/src/algebraic_type/map_notation.rs index d33ddb51c8..819dcf4f7c 100644 --- a/crates/sats/src/algebraic_type/map_notation.rs +++ b/crates/sats/src/algebraic_type/map_notation.rs @@ -30,7 +30,6 @@ pub fn fmt_algebraic_type(ty: &AlgebraicType) -> impl '_ + fmt::Display { write!(f, " }}") } AlgebraicType::Array(ty) => write!(f, "{{ ty_: Array, 0: {} }}", fmt(&ty.elem_ty)), - AlgebraicType::Map(map) => write!(f, "{{ ty_: Map, 0: {}, 1: {} }}", fmt(&map.key_ty), fmt(&map.ty)), AlgebraicType::Bool => write!(f, "{{ ty_: Bool }}"), AlgebraicType::I8 => write!(f, "{{ ty_: I8 }}"), AlgebraicType::U8 => write!(f, "{{ ty_: U8 }}"), diff --git a/crates/sats/src/algebraic_value.rs b/crates/sats/src/algebraic_value.rs index b9929e2556..3277c6092a 100644 --- a/crates/sats/src/algebraic_value.rs +++ b/crates/sats/src/algebraic_value.rs @@ -1,7 +1,7 @@ pub mod de; pub mod ser; -use crate::{AlgebraicType, ArrayValue, MapValue, ProductValue, SumValue}; +use crate::{AlgebraicType, ArrayValue, ProductValue, SumValue}; use core::mem; use core::ops::{Bound, RangeBounds}; use derive_more::From; @@ -53,25 +53,6 @@ pub enum AlgebraicValue { /// The contained values are stored packed in a representation appropriate for their type. /// See [`ArrayValue`] for details on the representation. Array(ArrayValue), - /// An ordered map value of `key: AlgebraicValue`s mapped to `value: AlgebraicValue`s. - /// Each `key` must be of the same [`AlgebraicType`] as all the others - /// and the same applies to each `value`. - /// A map as a whole has the type [`AlgebraicType::Map(key_ty, val_ty)`]. - /// - /// Maps are implemented internally as [`BTreeMap`]. - /// This implies that key/values are ordered first by key and then value - /// as if they were a sorted slice `[(key, value)]`. - /// This order is observable as maps are exposed both directly - /// and indirectly via `Ord for `[`AlgebraicValue`]. - /// The latter lets us observe that e.g., `{ a: 42 } < { b: 42 }`. - /// However, we cannot observe any difference between `{ a: 0, b: 0 }` and `{ b: 0, a: 0 }`, - /// as the natural order is used as opposed to insertion order. - /// Where insertion order is relevant, - /// a [`AlgebraicValue::Array`] with `(key, value)` pairs can be used instead. - /// - /// We box the `MapValue` to reduce size - /// and because we assume that map values will be uncommon. - Map(Box), /// A [`bool`] value of type [`AlgebraicType::Bool`]. Bool(bool), /// An [`i8`] value of type [`AlgebraicType::I8`]. @@ -213,11 +194,6 @@ impl AlgebraicValue { Self::Product(elements.into()) } - /// Returns an [`AlgebraicValue`] representing a map value defined by the given `map`. - pub fn map(map: MapValue) -> Self { - Self::Map(Box::new(map)) - } - /// Returns the [`AlgebraicType`] of the product value `x`. pub(crate) fn type_of_product(x: &ProductValue) -> Option { let mut elems = Vec::with_capacity(x.elements.len()); @@ -227,12 +203,6 @@ impl AlgebraicValue { Some(AlgebraicType::product(elems.into_boxed_slice())) } - /// Returns the [`AlgebraicType`] of the map with key type `k` and value type `v`. - pub(crate) fn type_of_map(val: &MapValue) -> Option { - let (k, v) = val.first_key_value().and_then(|(k, v)| k.type_of().zip(v.type_of()))?; - Some(AlgebraicType::product([k, v])) - } - /// Infer the [`AlgebraicType`] of an [`AlgebraicValue`]. /// /// This function is partial @@ -254,7 +224,6 @@ impl AlgebraicValue { Self::Sum(_) => None, Self::Product(x) => Self::type_of_product(x), Self::Array(x) => x.type_of().map(Into::into), - Self::Map(x) => Self::type_of_map(x), Self::Bool(_) => Some(AlgebraicType::Bool), Self::I8(_) => Some(AlgebraicType::I8), Self::U8(_) => Some(AlgebraicType::U8), @@ -352,8 +321,6 @@ impl RangeBounds for AlgebraicValue { #[cfg(test)] mod tests { - use std::collections::BTreeMap; - use crate::satn::Satn; use crate::{AlgebraicType, AlgebraicValue, ArrayValue, Typespace, ValueWithType, WithTypespace}; @@ -411,22 +378,4 @@ mod tests { let typespace = Typespace::new(vec![]); assert_eq!(in_space(&typespace, &array, &value).to_satn(), "0x03"); } - - #[test] - fn map() { - let map = AlgebraicType::map(AlgebraicType::U8, AlgebraicType::U8); - let value = AlgebraicValue::map(BTreeMap::new()); - let typespace = Typespace::new(vec![]); - assert_eq!(in_space(&typespace, &map, &value).to_satn(), "[:]"); - } - - #[test] - fn map_of_values() { - let map = AlgebraicType::map(AlgebraicType::U8, AlgebraicType::U8); - let mut val = BTreeMap::::new(); - val.insert(AlgebraicValue::U8(2), AlgebraicValue::U8(3)); - let value = AlgebraicValue::map(val); - let typespace = Typespace::new(vec![]); - assert_eq!(in_space(&typespace, &map, &value).to_satn(), "[2: 3]"); - } } diff --git a/crates/sats/src/algebraic_value/de.rs b/crates/sats/src/algebraic_value/de.rs index 70749ffaed..af4d064bbb 100644 --- a/crates/sats/src/algebraic_value/de.rs +++ b/crates/sats/src/algebraic_value/de.rs @@ -139,20 +139,6 @@ impl<'de> de::Deserializer<'de> for ValueDeserializer { let iter = map_err(self.val.into_array())?.into_iter(); visitor.visit(ArrayAccess { iter, seed }) } - - fn deserialize_map_seed< - Vi: de::MapVisitor<'de, K::Output, V::Output>, - K: de::DeserializeSeed<'de> + Clone, - V: de::DeserializeSeed<'de> + Clone, - >( - self, - visitor: Vi, - kseed: K, - vseed: V, - ) -> Result { - let iter = map_err(self.val.into_map())?.into_iter(); - visitor.visit(MapAccess { iter, kseed, vseed }) - } } /// Defines deserialization for [`ValueDeserializer`] where product elements are in the input. @@ -228,38 +214,6 @@ impl<'de, T: de::DeserializeSeed<'de> + Clone> de::ArrayAccess<'de> for ArrayAcc } } -/// Defines deserialization for [`ValueDeserializer`] where a map value is in the input. -struct MapAccess { - /// The elements of the map as an iterator of owned key/value entries. - iter: std::collections::btree_map::IntoIter, - /// A key seed value provided by the caller of - /// [`deserialize_map_seed`](de::Deserializer::deserialize_map_seed). - kseed: K, - /// A value seed value provided by the caller of - /// [`deserialize_map_seed`](de::Deserializer::deserialize_map_seed). - vseed: V, -} - -impl<'de, K: de::DeserializeSeed<'de> + Clone, V: de::DeserializeSeed<'de> + Clone> de::MapAccess<'de> - for MapAccess -{ - type Key = K::Output; - type Value = V::Output; - type Error = ValueDeserializeError; - - fn next_entry(&mut self) -> Result, Self::Error> { - self.iter - .next() - .map(|(key, val)| { - Ok(( - self.kseed.clone().deserialize(ValueDeserializer { val: key })?, - self.vseed.clone().deserialize(ValueDeserializer { val })?, - )) - }) - .transpose() - } -} - impl<'de> de::Deserializer<'de> for &'de ValueDeserializer { type Error = ValueDeserializeError; @@ -335,20 +289,6 @@ impl<'de> de::Deserializer<'de> for &'de ValueDeserializer { let iter = ok_or(self.val.as_array())?.iter_cloned(); visitor.visit(RefArrayAccess { iter, seed }) } - - fn deserialize_map_seed< - Vi: de::MapVisitor<'de, K::Output, V::Output>, - K: de::DeserializeSeed<'de> + Clone, - V: de::DeserializeSeed<'de> + Clone, - >( - self, - visitor: Vi, - kseed: K, - vseed: V, - ) -> Result { - let iter = ok_or(self.val.as_map())?.iter(); - visitor.visit(RefMapAccess { iter, kseed, vseed }) - } } /// Defines deserialization for [`&'de ValueDeserializer`] where product elements are in the input. @@ -408,35 +348,3 @@ impl<'de, T: de::DeserializeSeed<'de> + Clone> de::ArrayAccess<'de> for RefArray .transpose() } } - -/// Defines deserialization for [`&'de ValueDeserializer`] where an map value is in the input. -struct RefMapAccess<'a, K, V> { - /// The elements of the map as an iterator of borrowed key/value entries. - iter: std::collections::btree_map::Iter<'a, AlgebraicValue, AlgebraicValue>, - /// A key seed value provided by the caller of - /// [`deserialize_map_seed`](de::Deserializer::deserialize_map_seed). - kseed: K, - /// A value seed value provided by the caller of - /// [`deserialize_map_seed`](de::Deserializer::deserialize_map_seed). - vseed: V, -} - -impl<'de, K: de::DeserializeSeed<'de> + Clone, V: de::DeserializeSeed<'de> + Clone> de::MapAccess<'de> - for RefMapAccess<'de, K, V> -{ - type Key = K::Output; - type Value = V::Output; - type Error = ValueDeserializeError; - - fn next_entry(&mut self) -> Result, Self::Error> { - self.iter - .next() - .map(|(key, val)| { - Ok(( - self.kseed.clone().deserialize(ValueDeserializer::from_ref(key))?, - self.vseed.clone().deserialize(ValueDeserializer::from_ref(val))?, - )) - }) - .transpose() - } -} diff --git a/crates/sats/src/algebraic_value/ser.rs b/crates/sats/src/algebraic_value/ser.rs index 9b81cc0440..6b1870646f 100644 --- a/crates/sats/src/algebraic_value/ser.rs +++ b/crates/sats/src/algebraic_value/ser.rs @@ -1,6 +1,6 @@ use crate::ser::{self, ForwardNamedToSeqProduct, Serialize}; use crate::{i256, u256}; -use crate::{AlgebraicType, AlgebraicValue, ArrayValue, MapValue, F32, F64}; +use crate::{AlgebraicType, AlgebraicValue, ArrayValue, F32, F64}; use core::convert::Infallible; use core::mem::MaybeUninit; use core::ptr; @@ -29,7 +29,6 @@ impl ser::Serializer for ValueSerializer { type Error = Infallible; type SerializeArray = SerializeArrayValue; - type SerializeMap = SerializeMapValue; type SerializeSeqProduct = SerializeProductValue; type SerializeNamedProduct = ForwardNamedToSeqProduct; @@ -63,12 +62,6 @@ impl ser::Serializer for ValueSerializer { }) } - fn serialize_map(self, len: usize) -> Result { - Ok(SerializeMapValue { - entries: Vec::with_capacity(len), - }) - } - fn serialize_seq_product(self, len: usize) -> Result { Ok(SerializeProductValue { elements: Vec::with_capacity(len), @@ -293,8 +286,6 @@ enum ArrayValueBuilder { String(Vec>), /// An array of arrays. Array(Vec), - /// An array of maps. - Map(Vec), } impl ArrayValueBuilder { @@ -320,7 +311,6 @@ impl ArrayValueBuilder { Self::F64(v) => v.len(), Self::String(v) => v.len(), Self::Array(v) => v.len(), - Self::Map(v) => v.len(), } } @@ -343,7 +333,6 @@ impl ArrayValueBuilder { match val { AlgebraicValue::Sum(x) => vec(x, capacity).into(), AlgebraicValue::Product(x) => vec(x, capacity).into(), - AlgebraicValue::Map(x) => vec(*x, capacity).into(), AlgebraicValue::Bool(x) => vec(x, capacity).into(), AlgebraicValue::I8(x) => vec(x, capacity).into(), AlgebraicValue::U8(x) => vec(x, capacity).into(), @@ -374,7 +363,6 @@ impl ArrayValueBuilder { match (self, val) { (Self::Sum(v), AlgebraicValue::Sum(val)) => v.push(val), (Self::Product(v), AlgebraicValue::Product(val)) => v.push(val), - (Self::Map(v), AlgebraicValue::Map(val)) => v.push(*val), (Self::Bool(v), AlgebraicValue::Bool(val)) => v.push(val), (Self::I8(v), AlgebraicValue::I8(val)) => v.push(val), (Self::U8(v), AlgebraicValue::U8(val)) => v.push(val), @@ -422,7 +410,6 @@ impl From for ArrayValue { F64(v) => Self::F64(v.into()), String(v) => Self::String(v.into()), Array(v) => Self::Array(v.into()), - Map(v) => Self::Map(v.into()), } } } @@ -463,31 +450,6 @@ impl_from_array!(F32, F32); impl_from_array!(F64, F64); impl_from_array!(Box, String); impl_from_array!(ArrayValue, Array); -impl_from_array!(MapValue, Map); - -/// Continuation for serializing a map value. -pub struct SerializeMapValue { - /// The entry pairs to collect and convert into a map. - entries: Vec<(AlgebraicValue, AlgebraicValue)>, -} - -impl ser::SerializeMap for SerializeMapValue { - type Ok = AlgebraicValue; - type Error = ::Error; - - fn serialize_entry( - &mut self, - key: &K, - value: &V, - ) -> Result<(), Self::Error> { - self.entries.push((value_serialize(key), value_serialize(value))); - Ok(()) - } - - fn end(self) -> Result { - Ok(AlgebraicValue::map(self.entries.into_iter().collect())) - } -} /// Continuation for serializing a map value. pub struct SerializeProductValue { diff --git a/crates/sats/src/algebraic_value_hash.rs b/crates/sats/src/algebraic_value_hash.rs index f3f0c610b0..b327a5e1b9 100644 --- a/crates/sats/src/algebraic_value_hash.rs +++ b/crates/sats/src/algebraic_value_hash.rs @@ -4,7 +4,7 @@ use crate::{ bsatn::Deserializer, buffer::{BufReader, DecodeError}, de::{Deserialize, Deserializer as _}, - i256, u256, AlgebraicType, AlgebraicValue, ArrayValue, MapType, ProductType, ProductValue, SumType, F32, F64, + i256, u256, AlgebraicType, AlgebraicValue, ArrayValue, ProductType, ProductValue, SumType, F32, F64, }; use bytemuck::{must_cast_slice, NoUninit}; use core::hash::{Hash, Hasher}; @@ -37,7 +37,6 @@ impl Hash for AlgebraicValue { AlgebraicValue::Sum(x) => x.hash(state), AlgebraicValue::Product(x) => x.hash(state), AlgebraicValue::Array(x) => x.hash(state), - AlgebraicValue::Map(x) => x.hash(state), AlgebraicValue::Bool(x) => x.hash(state), AlgebraicValue::I8(x) => x.hash(state), AlgebraicValue::U8(x) => x.hash(state), @@ -117,7 +116,6 @@ impl Hash for ArrayValue { ArrayValue::F64(es) => es.hash(state), ArrayValue::String(es) => es.hash(state), ArrayValue::Array(es) => es.hash(state), - ArrayValue::Map(es) => es.hash(state), } } } @@ -130,7 +128,6 @@ pub fn hash_bsatn<'a>(state: &mut impl Hasher, ty: &AlgebraicType, de: Deseriali AlgebraicType::Sum(ty) => hash_bsatn_sum(state, ty, de), AlgebraicType::Product(ty) => hash_bsatn_prod(state, ty, de), AlgebraicType::Array(ty) => hash_bsatn_array(state, &ty.elem_ty, de), - AlgebraicType::Map(ty) => hash_bsatn_map(state, ty, de), AlgebraicType::Bool => hash_bsatn_de::(state, de), AlgebraicType::I8 => hash_bsatn_de::(state, de), AlgebraicType::U8 => hash_bsatn_de::(state, de), @@ -177,7 +174,6 @@ fn hash_bsatn_array<'a>(state: &mut impl Hasher, ty: &AlgebraicType, de: Deseria AlgebraicType::Sum(ty) => hash_bsatn_seq(state, de, |s, d| hash_bsatn_sum(s, ty, d)), AlgebraicType::Product(ty) => hash_bsatn_seq(state, de, |s, d| hash_bsatn_prod(s, ty, d)), AlgebraicType::Array(ty) => hash_bsatn_seq(state, de, |s, d| hash_bsatn_array(s, &ty.elem_ty, d)), - AlgebraicType::Map(ty) => hash_bsatn_seq(state, de, |s, d| hash_bsatn_map(s, ty, d)), AlgebraicType::Bool => hash_bsatn_seq(state, de, hash_bsatn_de::), AlgebraicType::I8 | AlgebraicType::U8 => hash_bsatn_int_seq(state, de, 1), AlgebraicType::I16 | AlgebraicType::U16 => hash_bsatn_int_seq(state, de, 2), @@ -191,19 +187,6 @@ fn hash_bsatn_array<'a>(state: &mut impl Hasher, ty: &AlgebraicType, de: Deseria } } -/// Hashes every (key, value) in the BSATN-encoded map value. -fn hash_bsatn_map<'a>(state: &mut impl Hasher, ty: &MapType, de: Deserializer<'_, impl BufReader<'a>>) -> HR { - // Hash each (key, value) pair but first length-prefix. - // This is OK as BSATN serializes the map in order - // and `BTreeMap` will hash the elements in order, - // so everything stays consistent. - hash_bsatn_seq(state, de, |state, mut de| { - hash_bsatn(state, &ty.key_ty, de.reborrow())?; - hash_bsatn(state, &ty.ty, de)?; - Ok(()) - }) -} - /// Hashes elements in the BSATN-encoded element sequence. /// The sequence is prefixed with its length and the hash will as well. fn hash_bsatn_seq<'a, H: Hasher, R: BufReader<'a>>( diff --git a/crates/sats/src/array_value.rs b/crates/sats/src/array_value.rs index 17edc512f3..b107a3619b 100644 --- a/crates/sats/src/array_value.rs +++ b/crates/sats/src/array_value.rs @@ -1,5 +1,5 @@ use crate::{i256, u256}; -use crate::{AlgebraicType, AlgebraicValue, ArrayType, MapValue, ProductValue, SumValue, F32, F64}; +use crate::{AlgebraicType, AlgebraicValue, ArrayType, ProductValue, SumValue, F32, F64}; use core::fmt; /// An array value in "monomorphized form". @@ -48,8 +48,6 @@ pub enum ArrayValue { String(Box<[Box]>), /// An array of arrays. Array(Box<[ArrayValue]>), - /// An array of maps. - Map(Box<[MapValue]>), } impl crate::Value for ArrayValue { @@ -79,7 +77,6 @@ impl ArrayValue { Self::F64(_) => Some(AlgebraicType::F64), Self::String(_) => Some(AlgebraicType::String), Self::Array(v) => Some(v.first()?.type_of()?.into()), - Self::Map(v) => AlgebraicValue::type_of_map(v.first()?), }?); Some(ArrayType { elem_ty }) } @@ -106,7 +103,6 @@ impl ArrayValue { Self::F64(v) => v.len(), Self::String(v) => v.len(), Self::Array(v) => v.len(), - Self::Map(v) => v.len(), } } @@ -138,7 +134,6 @@ impl ArrayValue { ArrayValue::F64(v) => ArrayValueIterCloned::F64(v.iter()), ArrayValue::String(v) => ArrayValueIterCloned::String(v.iter()), ArrayValue::Array(v) => ArrayValueIterCloned::Array(v.iter()), - ArrayValue::Map(v) => ArrayValueIterCloned::Map(v.iter()), } } } @@ -187,7 +182,6 @@ impl_from_array!(F32, F32); impl_from_array!(F64, F64); impl_from_array!(Box, String); impl_from_array!(ArrayValue, Array); -impl_from_array!(MapValue, Map); impl ArrayValue { /// Returns `self` as `&dyn Debug`. @@ -212,7 +206,6 @@ impl ArrayValue { Self::F64(v) => v, Self::String(v) => v, Self::Array(v) => v, - Self::Map(v) => v, } } } @@ -248,7 +241,6 @@ impl IntoIterator for ArrayValue { ArrayValue::F64(v) => ArrayValueIntoIter::F64(Vec::from(v).into_iter()), ArrayValue::String(v) => ArrayValueIntoIter::String(Vec::from(v).into_iter()), ArrayValue::Array(v) => ArrayValueIntoIter::Array(Vec::from(v).into_iter()), - ArrayValue::Map(v) => ArrayValueIntoIter::Map(Vec::from(v).into_iter()), } } } @@ -293,8 +285,6 @@ pub enum ArrayValueIntoIter { String(std::vec::IntoIter>), /// An iterator on an array of arrays. Array(std::vec::IntoIter), - /// An iterator on an array of maps. - Map(std::vec::IntoIter), } impl Iterator for ArrayValueIntoIter { @@ -321,7 +311,6 @@ impl Iterator for ArrayValueIntoIter { ArrayValueIntoIter::F64(it) => it.next().map(Into::into), ArrayValueIntoIter::String(it) => it.next().map(Into::into), ArrayValueIntoIter::Array(it) => it.next().map(Into::into), - ArrayValueIntoIter::Map(it) => it.next().map(Into::into), } } } @@ -346,7 +335,6 @@ pub enum ArrayValueIterCloned<'a> { F64(std::slice::Iter<'a, F64>), String(std::slice::Iter<'a, Box>), Array(std::slice::Iter<'a, ArrayValue>), - Map(std::slice::Iter<'a, MapValue>), } impl Iterator for ArrayValueIterCloned<'_> { @@ -373,7 +361,6 @@ impl Iterator for ArrayValueIterCloned<'_> { ArrayValueIterCloned::F64(it) => it.next().cloned().map(Into::into), ArrayValueIterCloned::String(it) => it.next().cloned().map(Into::into), ArrayValueIterCloned::Array(it) => it.next().cloned().map(Into::into), - ArrayValueIterCloned::Map(it) => it.next().cloned().map(Into::into), } } } diff --git a/crates/sats/src/bsatn/de.rs b/crates/sats/src/bsatn/de.rs index 249594a272..2d4cb123f4 100644 --- a/crates/sats/src/bsatn/de.rs +++ b/crates/sats/src/bsatn/de.rs @@ -125,21 +125,6 @@ impl<'de, 'a, R: BufReader<'de>> de::Deserializer<'de> for Deserializer<'a, R> { let seeds = itertools::repeat_n(seed, len); visitor.visit(ArrayAccess { de: self, seeds }) } - - fn deserialize_map_seed< - Vi: de::MapVisitor<'de, K::Output, V::Output>, - K: de::DeserializeSeed<'de> + Clone, - V: de::DeserializeSeed<'de> + Clone, - >( - mut self, - visitor: Vi, - kseed: K, - vseed: V, - ) -> Result { - let len = self.reborrow().deserialize_len()?; - let seeds = itertools::repeat_n((kseed, vseed), len); - visitor.visit(MapAccess { de: self, seeds }) - } } impl<'de, 'a, R: BufReader<'de>> SeqProductAccess<'de> for Deserializer<'a, R> { @@ -188,33 +173,3 @@ impl<'de, 'a, R: BufReader<'de>, T: de::DeserializeSeed<'de> + Clone> de::ArrayA Some(self.seeds.len()) } } - -/// Deserializer for map elements. -pub struct MapAccess<'a, R, K, V> { - de: Deserializer<'a, R>, - seeds: itertools::RepeatN<(K, V)>, -} - -impl<'de, 'a, R: BufReader<'de>, K: de::DeserializeSeed<'de> + Clone, V: de::DeserializeSeed<'de> + Clone> - de::MapAccess<'de> for MapAccess<'a, R, K, V> -{ - type Key = K::Output; - type Value = V::Output; - type Error = DecodeError; - - fn next_entry(&mut self) -> Result, Self::Error> { - self.seeds - .next() - .map(|(kseed, vseed)| { - Ok(( - kseed.deserialize(self.de.reborrow())?, - vseed.deserialize(self.de.reborrow())?, - )) - }) - .transpose() - } - - fn size_hint(&self) -> Option { - Some(self.seeds.len()) - } -} diff --git a/crates/sats/src/bsatn/eq.rs b/crates/sats/src/bsatn/eq.rs index 67675e66a2..e54ad60426 100644 --- a/crates/sats/src/bsatn/eq.rs +++ b/crates/sats/src/bsatn/eq.rs @@ -3,7 +3,7 @@ //! The lifetime `'r` in `eq_bsatn` is the lifetime of `rhs`'s backing data, i.e., the BSATN itself. use super::Deserializer; -use crate::{buffer::BufReader, de::Deserialize, AlgebraicValue, ArrayValue, MapValue, ProductValue, SumValue}; +use crate::{buffer::BufReader, de::Deserialize, AlgebraicValue, ArrayValue, ProductValue, SumValue}; use core::{mem, slice}; /// Equates `lhs` to a BSATN-encoded `AlgebraicValue` of the same type. @@ -12,7 +12,6 @@ pub fn eq_bsatn<'r>(lhs: &AlgebraicValue, rhs: Deserializer<'_, impl BufReader<' AlgebraicValue::Sum(lhs) => eq_bsatn_sum(lhs, rhs), AlgebraicValue::Product(lhs) => eq_bsatn_prod(lhs, rhs), AlgebraicValue::Array(lhs) => eq_bsatn_array(lhs, rhs), - AlgebraicValue::Map(lhs) => eq_bsatn_map(lhs, rhs), AlgebraicValue::Bool(lhs) => eq_bsatn_de(lhs, rhs), AlgebraicValue::I8(lhs) => eq_bsatn_de(lhs, rhs), AlgebraicValue::U8(lhs) => eq_bsatn_de(lhs, rhs), @@ -43,13 +42,6 @@ fn eq_bsatn_prod<'r>(lhs: &ProductValue, mut rhs: Deserializer<'_, impl BufReade lhs.elements.iter().all(|f| eq_bsatn(f, rhs.reborrow())) } -/// Equates `lhs` to the `(key, value)`s in the BSATN-encoded map value. -fn eq_bsatn_map<'r>(lhs: &MapValue, rhs: Deserializer<'_, impl BufReader<'r>>) -> bool { - eq_bsatn_seq(lhs, rhs, |(key, value), mut rhs| { - eq_bsatn(key, rhs.reborrow()) && eq_bsatn(value, rhs) - }) -} - /// Equates every elem in `lhs` to those in the BSATN-encoded array value. fn eq_bsatn_array<'r>(lhs: &ArrayValue, rhs: Deserializer<'_, impl BufReader<'r>>) -> bool { match lhs { @@ -60,7 +52,6 @@ fn eq_bsatn_array<'r>(lhs: &ArrayValue, rhs: Deserializer<'_, impl BufReader<'r> ArrayValue::F64(lhs) => eq_bsatn_seq(&**lhs, rhs, eq_bsatn_de), ArrayValue::String(lhs) => eq_bsatn_seq(&**lhs, rhs, eq_bsatn_str), ArrayValue::Array(lhs) => eq_bsatn_seq(&**lhs, rhs, eq_bsatn_array), - ArrayValue::Map(lhs) => eq_bsatn_seq(&**lhs, rhs, eq_bsatn_map), // SAFETY: For all of the below, the element types are integer types, as required. ArrayValue::I8(lhs) => unsafe { eq_bsatn_int_seq(lhs, rhs) }, ArrayValue::U8(lhs) => unsafe { eq_bsatn_int_seq(lhs, rhs) }, diff --git a/crates/sats/src/bsatn/ser.rs b/crates/sats/src/bsatn/ser.rs index df7b47bb85..40070e037d 100644 --- a/crates/sats/src/bsatn/ser.rs +++ b/crates/sats/src/bsatn/ser.rs @@ -1,5 +1,5 @@ use crate::buffer::BufWriter; -use crate::ser::{self, Error, ForwardNamedToSeqProduct, Serialize, SerializeArray, SerializeMap, SerializeSeqProduct}; +use crate::ser::{self, Error, ForwardNamedToSeqProduct, SerializeArray, SerializeSeqProduct}; use crate::AlgebraicValue; use crate::{i256, u256}; use core::fmt; @@ -57,7 +57,6 @@ impl ser::Serializer for Serializer<'_, W> { type Ok = (); type Error = BsatnError; type SerializeArray = Self; - type SerializeMap = Self; type SerializeSeqProduct = Self; type SerializeNamedProduct = ForwardNamedToSeqProduct; @@ -133,10 +132,6 @@ impl ser::Serializer for Serializer<'_, W> { put_len(self.writer, len)?; // N.B. `len > u32::MAX` isn't allowed. Ok(self) } - fn serialize_map(self, len: usize) -> Result { - put_len(self.writer, len)?; // N.B. `len > u32::MAX` isn't allowed. - Ok(self) - } fn serialize_seq_product(self, _len: usize) -> Result { Ok(self) } @@ -216,24 +211,6 @@ impl SerializeArray for Serializer<'_, W> { } } -impl SerializeMap for Serializer<'_, W> { - type Ok = (); - type Error = BsatnError; - - fn serialize_entry( - &mut self, - key: &K, - value: &V, - ) -> Result<(), Self::Error> { - key.serialize(self.reborrow())?; - value.serialize(self.reborrow()) - } - - fn end(self) -> Result { - Ok(()) - } -} - impl SerializeSeqProduct for Serializer<'_, W> { type Ok = (); type Error = BsatnError; diff --git a/crates/sats/src/convert.rs b/crates/sats/src/convert.rs index 3a0c1f45e4..c43647ba35 100644 --- a/crates/sats/src/convert.rs +++ b/crates/sats/src/convert.rs @@ -1,5 +1,5 @@ use crate::{i256, u256}; -use crate::{AlgebraicType, AlgebraicValue, MapType, MapValue, ProductType, ProductValue}; +use crate::{AlgebraicType, AlgebraicValue, ProductType, ProductValue}; use spacetimedb_primitives::{ColId, ConstraintId, IndexId, ScheduleId, SequenceId, TableId}; impl crate::Value for AlgebraicValue { @@ -25,12 +25,6 @@ impl From for ProductType { } } -impl From for AlgebraicType { - fn from(x: MapType) -> Self { - Box::new(x).into() - } -} - macro_rules! built_in_into { ($native:ty, $kind:ident) => { impl From<$native> for AlgebraicValue { @@ -41,7 +35,6 @@ macro_rules! built_in_into { }; } -built_in_into!(MapValue, Map); built_in_into!(u128, U128); built_in_into!(i128, I128); built_in_into!(u256, U256); diff --git a/crates/sats/src/de.rs b/crates/sats/src/de.rs index 9af45fd9a5..974c959812 100644 --- a/crates/sats/src/de.rs +++ b/crates/sats/src/de.rs @@ -13,7 +13,6 @@ use core::fmt; use core::marker::PhantomData; use smallvec::SmallVec; use std::borrow::Borrow; -use std::collections::BTreeMap; /// A **data format** that can deserialize any data structure supported by SATS. /// @@ -145,31 +144,6 @@ pub trait Deserializer<'de>: Sized { visitor: V, seed: T, ) -> Result; - - /// Deserializes a map value. - /// - /// This is typically the same as [`deserialize_map_seed`](Deserializer::deserialize_map_seed) - /// with an uninteresting `seed` value. - fn deserialize_map, K: Deserialize<'de>, V: Deserialize<'de>>( - self, - visitor: Vi, - ) -> Result { - self.deserialize_map_seed(visitor, PhantomData, PhantomData) - } - - /// Deserializes a map value. - /// - /// The deserialization is provided with `kseed` and `vseed` for keys and values respectively. - fn deserialize_map_seed< - Vi: MapVisitor<'de, K::Output, V::Output>, - K: DeserializeSeed<'de> + Clone, - V: DeserializeSeed<'de> + Clone, - >( - self, - visitor: Vi, - kseed: K, - vseed: V, - ) -> Result; } /// The `Error` trait allows [`Deserialize`] implementations to create descriptive error messages @@ -555,51 +529,6 @@ pub trait ArrayAccess<'de> { } } -/// A visitor walking through a [`Deserializer`] for maps. -pub trait MapVisitor<'de, K, V> { - /// The output produced by this visitor. - type Output; - - /// The input contains a key-value map. - fn visit>(self, map: A) -> Result; -} - -/// Provides a [`MapVisitor`] with access to each element of the array in the input. -/// -/// This is a trait that a [`Deserializer`] passes to a [`MapVisitor`] implementation. -pub trait MapAccess<'de> { - /// The key type of the map. - type Key; - - /// The value type of the map. - type Value; - - /// The error type that can be returned if some error occurs during deserialization. - type Error: Error; - - /// This returns `Ok(Some((key, value)))` for the next (key-value) pair in the map, - /// or `Ok(None)` if there are no more remaining items. - #[allow(clippy::type_complexity)] - fn next_entry(&mut self) -> Result, Self::Error>; - - /// Returns the number of elements remaining in the map, if known. - fn size_hint(&self) -> Option { - None - } -} - -impl<'de, A: MapAccess<'de>> ArrayAccess<'de> for A { - type Element = (A::Key, A::Value); - type Error = A::Error; - - fn next_element(&mut self) -> Result, Self::Error> { - self.next_entry() - } - fn size_hint(&self) -> Option { - self.size_hint() - } -} - /// `DeserializeSeed` is the stateful form of the [`Deserialize`] trait. pub trait DeserializeSeed<'de> { /// The type produced by using this seed. @@ -713,17 +642,6 @@ impl<'de, T, const N: usize> ArrayVisitor<'de, T> for BasicSmallVecVisitor { } } -/// An implementation of [`MapVisitor<'de, K, V>`] where the output is a `BTreeMap`. -pub struct BasicMapVisitor; - -impl<'de, K: Ord, V> MapVisitor<'de, K, V> for BasicMapVisitor { - type Output = BTreeMap; - - fn visit>(self, map: A) -> Result { - Ok(array_visit::<_, Vec<_>>(map)?.into_iter().collect()) - } -} - /// An implementation of [`ArrayVisitor<'de, T>`] where the output is a `[T; N]`. struct BasicArrayVisitor; diff --git a/crates/sats/src/de/impls.rs b/crates/sats/src/de/impls.rs index 022e27637d..eb7432ebfd 100644 --- a/crates/sats/src/de/impls.rs +++ b/crates/sats/src/de/impls.rs @@ -1,18 +1,16 @@ use super::{ - BasicMapVisitor, BasicSmallVecVisitor, BasicVecVisitor, Deserialize, DeserializeSeed, Deserializer, Error, - FieldNameVisitor, ProductKind, ProductVisitor, SeqProductAccess, SliceVisitor, SumAccess, SumVisitor, - VariantAccess, VariantVisitor, + BasicSmallVecVisitor, BasicVecVisitor, Deserialize, DeserializeSeed, Deserializer, Error, FieldNameVisitor, + ProductKind, ProductVisitor, SeqProductAccess, SliceVisitor, SumAccess, SumVisitor, VariantAccess, VariantVisitor, }; use crate::{ de::{array_visit, ArrayAccess, ArrayVisitor, GrowingVec}, - AlgebraicType, AlgebraicValue, ArrayType, ArrayValue, MapType, MapValue, ProductType, ProductTypeElement, - ProductValue, SumType, SumValue, WithTypespace, F32, F64, + AlgebraicType, AlgebraicValue, ArrayType, ArrayValue, ProductType, ProductTypeElement, ProductValue, SumType, + SumValue, WithTypespace, F32, F64, }; use crate::{i256, u256}; use core::{marker::PhantomData, ops::Bound}; use smallvec::SmallVec; use spacetimedb_primitives::{ColId, ColList}; -use std::collections::BTreeMap; use std::{borrow::Cow, rc::Rc, sync::Arc}; /// Implements [`Deserialize`] for a type in a simplified manner. @@ -182,11 +180,6 @@ impl<'de, T: ToOwned + ?Sized + 'de> SliceVisitor<'de, T> for CowSliceVisitor { } } -impl_deserialize!( - [K: Deserialize<'de> + Ord, V: Deserialize<'de>] BTreeMap, - de => de.deserialize_map(BasicMapVisitor) -); - impl_deserialize!([T: Deserialize<'de>] Box, de => T::deserialize(de).map(Box::new)); impl_deserialize!([T: Deserialize<'de>] Option, de => de.deserialize_sum(OptionVisitor(PhantomData))); @@ -378,7 +371,6 @@ impl<'de> DeserializeSeed<'de> for WithTypespace<'_, AlgebraicType> { AlgebraicType::Sum(sum) => self.with(sum).deserialize(de).map(Into::into), AlgebraicType::Product(prod) => self.with(prod).deserialize(de).map(Into::into), AlgebraicType::Array(ty) => self.with(ty).deserialize(de).map(Into::into), - AlgebraicType::Map(ty) => self.with(&**ty).deserialize(de).map(Into::into), AlgebraicType::Bool => bool::deserialize(de).map(Into::into), AlgebraicType::I8 => i8::deserialize(de).map(Into::into), AlgebraicType::U8 => u8::deserialize(de).map(Into::into), @@ -526,10 +518,6 @@ impl<'de> DeserializeSeed<'de> for WithTypespace<'_, ArrayType> { .deserialize_array_seed(BasicVecVisitor, self.with(ty)) .map(>::from) .map(ArrayValue::Array), - AlgebraicType::Map(ty) => deserializer - .deserialize_array_seed(BasicVecVisitor, self.with(&**ty)) - .map(>::from) - .map(ArrayValue::Map), &AlgebraicType::Bool => de_array(deserializer, ArrayValue::Bool), &AlgebraicType::I8 => de_array(deserializer, ArrayValue::I8), &AlgebraicType::U8 => deserializer @@ -554,15 +542,6 @@ impl<'de> DeserializeSeed<'de> for WithTypespace<'_, ArrayType> { } } -impl<'de> DeserializeSeed<'de> for WithTypespace<'_, MapType> { - type Output = MapValue; - - fn deserialize>(self, deserializer: D) -> Result { - let MapType { key_ty, ty } = self.ty(); - deserializer.deserialize_map_seed(BasicMapVisitor, self.with(key_ty), self.with(ty)) - } -} - // impl<'de> DeserializeSeed<'de> for &ReducerDef { // type Output = ProductValue; diff --git a/crates/sats/src/de/serde.rs b/crates/sats/src/de/serde.rs index e56ed8bcfe..de7bcd0278 100644 --- a/crates/sats/src/de/serde.rs +++ b/crates/sats/src/de/serde.rs @@ -124,21 +124,6 @@ impl<'de, D: serde::Deserializer<'de>> Deserializer<'de> for SerdeDeserializer, - K: super::DeserializeSeed<'de> + Clone, - V: super::DeserializeSeed<'de> + Clone, - >( - self, - visitor: Vi, - kseed: K, - vseed: V, - ) -> Result { - self.de - .deserialize_map(MapVisitor { visitor, kseed, vseed }) - .map_err(SerdeError) - } } /// Converts `DeserializeSeed<'de>` in SATS to the one in Serde. @@ -582,72 +567,6 @@ impl<'de, A: serde::SeqAccess<'de>, T: super::DeserializeSeed<'de> + Clone> supe } } -/// Translates SATS's `MapVisior<'de>` (the trait) to `serde::Visitor<'de>` -/// for implementing deserialization of maps. -struct MapVisitor { - /// The SATS visitor to translate to a Serde visitor. - visitor: Vi, - /// The seed value to provide to `DeserializeSeed` for deserializing keys. - /// As this is reused for every entry element, it will be `.cloned()`. - kseed: K, - /// The seed value to provide to `DeserializeSeed` for deserializing values. - /// As this is reused for every entry element, it will be `.cloned()`. - vseed: V, -} - -impl< - 'de, - K: super::DeserializeSeed<'de> + Clone, - V: super::DeserializeSeed<'de> + Clone, - Vi: super::MapVisitor<'de, K::Output, V::Output>, - > serde::Visitor<'de> for MapVisitor -{ - type Value = Vi::Output; - - fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("a vec") - } - - fn visit_map>(self, map: A) -> Result { - self.visitor - .visit(MapAccess { - map, - kseed: self.kseed, - vseed: self.vseed, - }) - .map_err(unwrap_error) - } -} - -struct MapAccess { - /// An implementation of `serde::MapAccess<'de>`. - map: A, - /// The seed value to provide to `DeserializeSeed` for deserializing keys. - /// As this is reused for every entry element, it will be `.cloned()`. - kseed: K, - /// The seed value to provide to `DeserializeSeed` for deserializing values. - /// As this is reused for every entry element, it will be `.cloned()`. - vseed: V, -} - -impl<'de, A: serde::MapAccess<'de>, K: super::DeserializeSeed<'de> + Clone, V: super::DeserializeSeed<'de> + Clone> - super::MapAccess<'de> for MapAccess -{ - type Key = K::Output; - type Value = V::Output; - type Error = SerdeError; - - fn next_entry(&mut self) -> Result, Self::Error> { - self.map - .next_entry_seed(SeedWrapper(self.kseed.clone()), SeedWrapper(self.vseed.clone())) - .map_err(SerdeError) - } - - fn size_hint(&self) -> Option { - self.map.size_hint() - } -} - impl fmt::Result> serde::Expected for super::FDisplay { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (self.0)(f) diff --git a/crates/sats/src/lib.rs b/crates/sats/src/lib.rs index d64228b22e..948992ef74 100644 --- a/crates/sats/src/lib.rs +++ b/crates/sats/src/lib.rs @@ -10,8 +10,6 @@ pub mod convert; pub mod de; pub mod hash; pub mod hex; -pub mod map_type; -pub mod map_value; pub mod meta_type; pub mod primitives; pub mod product_type; @@ -39,8 +37,6 @@ pub use algebraic_value::{i256, u256, AlgebraicValue, F32, F64}; pub use algebraic_value_hash::hash_bsatn; pub use array_type::ArrayType; pub use array_value::ArrayValue; -pub use map_type::MapType; -pub use map_value::MapValue; pub use product_type::ProductType; pub use product_type_element::ProductTypeElement; pub use product_value::ProductValue; diff --git a/crates/sats/src/map_type.rs b/crates/sats/src/map_type.rs deleted file mode 100644 index 45665ab8d0..0000000000 --- a/crates/sats/src/map_type.rs +++ /dev/null @@ -1,24 +0,0 @@ -use crate::{meta_type::MetaType, AlgebraicType, SpacetimeType}; - -/// A map type from keys of type `key_ty` to values of type `ty`. -#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, SpacetimeType)] -#[sats(crate = crate)] -pub struct MapType { - /// The key type of the map. - pub key_ty: AlgebraicType, - /// The value type of the map. - pub ty: AlgebraicType, -} - -impl MapType { - /// Returns a map type with keys of type `key` and values of type `value`. - pub fn new(key: AlgebraicType, value: AlgebraicType) -> Self { - Self { key_ty: key, ty: value } - } -} - -impl MetaType for MapType { - fn meta_type() -> AlgebraicType { - AlgebraicType::product([("key_ty", AlgebraicType::ZERO_REF), ("ty", AlgebraicType::ZERO_REF)]) - } -} diff --git a/crates/sats/src/map_value.rs b/crates/sats/src/map_value.rs deleted file mode 100644 index b7cc8076c9..0000000000 --- a/crates/sats/src/map_value.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::AlgebraicValue; -use std::collections::BTreeMap; - -/// A map value `AlgebraicValue` → `AlgebraicValue`. -pub type MapValue = BTreeMap; - -impl crate::Value for MapValue { - type Type = crate::MapType; -} diff --git a/crates/sats/src/proptest.rs b/crates/sats/src/proptest.rs index 6d9558c00d..2b0c883b92 100644 --- a/crates/sats/src/proptest.rs +++ b/crates/sats/src/proptest.rs @@ -4,8 +4,8 @@ use crate::{i256, u256, ProductTypeElement, SumTypeVariant}; use crate::{ - AlgebraicType, AlgebraicTypeRef, AlgebraicValue, ArrayValue, MapType, MapValue, ProductType, ProductValue, SumType, - SumValue, Typespace, F32, F64, + AlgebraicType, AlgebraicTypeRef, AlgebraicValue, ArrayValue, ProductType, ProductValue, SumType, SumValue, + Typespace, F32, F64, }; use proptest::{ collection::{vec, SizeRange}, @@ -53,7 +53,6 @@ fn generate_algebraic_type_from_leaves( leaves.prop_recursive(depth, SIZE as u32, SIZE as u32, |gen_element| { prop_oneof![ gen_element.clone().prop_map(AlgebraicType::array), - (gen_element.clone(), gen_element.clone()).prop_map(|(key, val)| AlgebraicType::map(key, val)), // No need to generate units here; // we already generate them in `generate_non_compound_algebraic_type`. vec(gen_element.clone().prop_map_into(), 1..=SIZE) @@ -134,8 +133,6 @@ pub fn generate_algebraic_value(ty: AlgebraicType) -> impl Strategy generate_array_value(*ty.elem_ty).prop_map_into().boxed(), - AlgebraicType::Map(ty) => generate_map_value(*ty).prop_map_into().boxed(), - AlgebraicType::Product(ty) => generate_product_value(ty).prop_map_into().boxed(), AlgebraicType::Sum(ty) => generate_sum_value(ty).prop_map_into().boxed(), @@ -167,15 +164,6 @@ fn generate_sum_value(ty: SumType) -> impl Strategy { }) } -/// Generates a `MapValue` typed at `ty`. -fn generate_map_value(ty: MapType) -> impl Strategy { - vec( - (generate_algebraic_value(ty.key_ty), generate_algebraic_value(ty.ty)), - 0..=SIZE, - ) - .prop_map(|entries| entries.into_iter().collect()) -} - /// Generates an array value given an element generator `gen_elem`. fn generate_array_of(gen_elem: S) -> BoxedStrategy where @@ -210,7 +198,6 @@ fn generate_array_value(ty: AlgebraicType) -> BoxedStrategy { AlgebraicType::Product(ty) => generate_array_of(generate_product_value(ty)), AlgebraicType::Sum(ty) => generate_array_of(generate_sum_value(ty)), AlgebraicType::Array(ty) => generate_array_of(generate_array_value(*ty.elem_ty)), - AlgebraicType::Map(ty) => generate_array_of(generate_map_value(*ty)), AlgebraicType::Ref(_) => unreachable!(), } } @@ -244,7 +231,6 @@ fn generate_type_valid_for_client_use() -> impl Strategy leaf.prop_recursive(size, size, size, |gen_element| { prop_oneof![ gen_element.clone().prop_map(AlgebraicType::array), - (gen_element.clone(), gen_element.clone()).prop_map(|(key, val)| AlgebraicType::map(key, val)), gen_element.clone().prop_map(AlgebraicType::option), ] }) diff --git a/crates/sats/src/resolve_refs.rs b/crates/sats/src/resolve_refs.rs index df2bf014d8..cfab164b64 100644 --- a/crates/sats/src/resolve_refs.rs +++ b/crates/sats/src/resolve_refs.rs @@ -1,6 +1,6 @@ use crate::{ - typespace::TypeRefError, AlgebraicType, AlgebraicTypeRef, ArrayType, MapType, ProductType, ProductTypeElement, - SumType, SumTypeVariant, WithTypespace, + typespace::TypeRefError, AlgebraicType, AlgebraicTypeRef, ArrayType, ProductType, ProductTypeElement, SumType, + SumTypeVariant, WithTypespace, }; /// Resolver for [`AlgebraicTypeRef`]s within a structure. @@ -70,7 +70,6 @@ impl ResolveRefs for AlgebraicType { Self::Sum(sum) => this.with(sum)._resolve_refs(state).map(Into::into), Self::Product(prod) => this.with(prod)._resolve_refs(state).map(Into::into), Self::Array(ty) => this.with(ty)._resolve_refs(state).map(Into::into), - Self::Map(m) => this.with(&**m)._resolve_refs(state).map(Into::into), // These types are plain and cannot have refs in them. x => Ok(x.clone()), } @@ -86,16 +85,6 @@ impl ResolveRefs for ArrayType { } } -impl ResolveRefs for MapType { - type Output = Self; - fn resolve_refs(this: WithTypespace<'_, Self>, state: &mut ResolveRefState) -> Result { - Ok(Self { - key_ty: this.map(|m| &m.key_ty)._resolve_refs(state)?, - ty: this.map(|m| &m.ty)._resolve_refs(state)?, - }) - } -} - impl ResolveRefs for ProductType { type Output = Self; fn resolve_refs(this: WithTypespace<'_, Self>, state: &mut ResolveRefState) -> Result { diff --git a/crates/sats/src/satn.rs b/crates/sats/src/satn.rs index 9e9605e5a1..e753696164 100644 --- a/crates/sats/src/satn.rs +++ b/crates/sats/src/satn.rs @@ -253,7 +253,6 @@ impl<'a, 'b> ser::Serializer for SatnFormatter<'a, 'b> { type Ok = (); type Error = SatnError; type SerializeArray = ArrayFormatter<'a, 'b>; - type SerializeMap = MapFormatter<'a, 'b>; type SerializeSeqProduct = SeqFormatter<'a, 'b>; type SerializeNamedProduct = NamedFormatter<'a, 'b>; @@ -318,16 +317,6 @@ impl<'a, 'b> ser::Serializer for SatnFormatter<'a, 'b> { }) } - fn serialize_map(mut self, len: usize) -> Result { - write!(self, "[")?; // Closed via `.end()`. - if len == 0 { - write!(self, ":")?; - } - Ok(MapFormatter { - f: EntryWrapper::new(self.f), - }) - } - fn serialize_seq_product(self, len: usize) -> Result { // Delegate to named products handling of element formatting. self.serialize_named_product(len).map(|inner| SeqFormatter { inner }) @@ -428,36 +417,6 @@ impl<'a, 'b> ser::SerializeArray for ArrayFormatter<'a, 'b> { } } -/// Provides the data format for maps for SATN. -struct MapFormatter<'a, 'b> { - /// The formatter for each element separating elements by a `,`. - f: EntryWrapper<'a, 'b, ','>, -} - -impl<'a, 'b> ser::SerializeMap for MapFormatter<'a, 'b> { - type Ok = (); - type Error = SatnError; - - fn serialize_entry( - &mut self, - key: &K, - value: &V, - ) -> Result<(), Self::Error> { - self.f.entry(|mut f| { - key.serialize(SatnFormatter { f: f.as_mut() })?; - f.write_str(": ")?; - value.serialize(SatnFormatter { f })?; - Ok(()) - })?; - Ok(()) - } - - fn end(mut self) -> Result { - write!(self.f.fmt, "]")?; - Ok(()) - } -} - /// Provides the data format for unnamed products for SATN. struct SeqFormatter<'a, 'b> { /// Delegates to the named format. @@ -607,7 +566,6 @@ impl<'a, 'b> ser::Serializer for PsqlFormatter<'a, 'b> { type Ok = (); type Error = SatnError; type SerializeArray = ArrayFormatter<'a, 'b>; - type SerializeMap = MapFormatter<'a, 'b>; type SerializeSeqProduct = PsqlSeqFormatter<'a, 'b>; type SerializeNamedProduct = PsqlNamedFormatter<'a, 'b>; @@ -669,10 +627,6 @@ impl<'a, 'b> ser::Serializer for PsqlFormatter<'a, 'b> { self.fmt.serialize_array(len) } - fn serialize_map(self, len: usize) -> Result { - self.fmt.serialize_map(len) - } - fn serialize_seq_product(self, len: usize) -> Result { Ok(PsqlSeqFormatter { inner: self.serialize_named_product(len)?, diff --git a/crates/sats/src/ser.rs b/crates/sats/src/ser.rs index a7c16b7eab..e3a89ae0ab 100644 --- a/crates/sats/src/ser.rs +++ b/crates/sats/src/ser.rs @@ -32,10 +32,6 @@ pub trait Serializer: Sized { /// for serializing the contents of the array. type SerializeArray: SerializeArray; - /// Type returned from [`serialize_map`](Serializer::serialize_map) - /// for serializing the contents of the map. - type SerializeMap: SerializeMap; - /// Type returned from [`serialize_seq_product`](Serializer::serialize_seq_product) /// for serializing the contents of the *unnamed* product. type SerializeSeqProduct: SerializeSeqProduct; @@ -102,13 +98,6 @@ pub trait Serializer: Sized { /// The argument is the number of elements in the sequence. fn serialize_array(self, len: usize) -> Result; - /// Begin to serialize a variably sized map. - /// This call must be followed by zero or more calls to [`SerializeMap::serialize_element`], - /// then a call to [`SerializeMap::end`]. - /// - /// The argument is the number of elements in the map. - fn serialize_map(self, len: usize) -> Result; - /// Begin to serialize a product with unnamed fields. /// This call must be followed by zero or more calls to [`SerializeSeqProduct::serialize_element`], /// then a call to [`SerializeSeqProduct::end`]. @@ -280,29 +269,6 @@ pub trait SerializeArray { fn end(self) -> Result; } -/// Returned from [`Serializer::serialize_map`]. -/// -/// This provides a continuation of sorts -/// where you can call [`serialize_entry`](SerializeMap::serialize_entry) however many times -/// and then finally the [`end`](SerializeMap::end) is reached. -pub trait SerializeMap { - /// Must match the `Ok` type of any `Serializer` that uses this type. - type Ok; - - /// Must match the `Error` type of any `Serializer` that uses this type. - type Error: Error; - - /// Serialize a map entry given by its `key` and `value`. - fn serialize_entry( - &mut self, - key: &K, - value: &V, - ) -> Result<(), Self::Error>; - - /// Consumes and finalizes the map serializer returning the `Self::Ok` data. - fn end(self) -> Result; -} - /// Returned from [`Serializer::serialize_seq_product`]. /// /// This provides a continuation of sorts diff --git a/crates/sats/src/ser/impls.rs b/crates/sats/src/ser/impls.rs index 2ab6b12521..909b5fd2de 100644 --- a/crates/sats/src/ser/impls.rs +++ b/crates/sats/src/ser/impls.rs @@ -1,12 +1,9 @@ -use super::{Serialize, SerializeArray, SerializeMap, SerializeNamedProduct, SerializeSeqProduct, Serializer}; +use super::{Serialize, SerializeArray, SerializeNamedProduct, SerializeSeqProduct, Serializer}; use crate::{i256, u256}; -use crate::{ - AlgebraicType, AlgebraicValue, ArrayValue, MapType, MapValue, ProductValue, SumValue, ValueWithType, F32, F64, -}; +use crate::{AlgebraicType, AlgebraicValue, ArrayValue, ProductValue, SumValue, ValueWithType, F32, F64}; use core::ops::Bound; use smallvec::SmallVec; use spacetimedb_primitives::{ColList, ColSet}; -use std::collections::BTreeMap; use std::rc::Rc; use std::sync::Arc; @@ -98,18 +95,10 @@ impl_serialize!([T: Serialize] Bound, (self, ser) => match self { Bound::Excluded(x) => ser.serialize_variant(1, Some("excluded"), x), Bound::Unbounded => ser.serialize_variant(2, Some("unbounded"), &()), }); -impl_serialize!([K: Serialize, V: Serialize] BTreeMap, (self, ser) => { - let mut map = ser.serialize_map(self.len())?; - for (k, v) in self { - map.serialize_entry(k, v)?; - } - map.end() -}); impl_serialize!([] AlgebraicValue, (self, ser) => match self { Self::Sum(sum) => sum.serialize(ser), Self::Product(prod) => prod.serialize(ser), Self::Array(arr) => arr.serialize(ser), - Self::Map(map) => map.serialize(ser), Self::Bool(v) => ser.serialize_bool(*v), Self::I8(v) => ser.serialize_i8(*v), Self::U8(v) => ser.serialize_u8(*v), @@ -157,7 +146,6 @@ impl_serialize!([] ArrayValue, (self, ser) => match self { Self::F64(v) => v.serialize(ser), Self::String(v) => v.serialize(ser), Self::Array(v) => v.serialize(ser), - Self::Map(v) => v.serialize(ser), }); impl_serialize!([] ValueWithType<'_, AlgebraicValue>, (self, ser) => { let mut ty = self.ty(); @@ -170,7 +158,6 @@ impl_serialize!([] ValueWithType<'_, AlgebraicValue>, (self, ser) => { (AlgebraicValue::Sum(val), AlgebraicType::Sum(ty)) => self.with(ty, val).serialize(ser), (AlgebraicValue::Product(val), AlgebraicType::Product(ty)) => self.with(ty, val).serialize(ser), (AlgebraicValue::Array(val), AlgebraicType::Array(ty)) => self.with(ty, val).serialize(ser), - (AlgebraicValue::Map(val), AlgebraicType::Map(ty)) => self.with(&**ty, &**val).serialize(ser), (AlgebraicValue::Bool(v), AlgebraicType::Bool) => ser.serialize_bool(*v), (AlgebraicValue::I8(v), AlgebraicType::I8) => ser.serialize_i8(*v), (AlgebraicValue::U8(v), AlgebraicType::U8) => ser.serialize_u8(*v), @@ -220,7 +207,6 @@ impl_serialize!([] ValueWithType<'_, ProductValue>, (self, ser) => { impl_serialize!([] ValueWithType<'_, ArrayValue>, (self, ser) => match (self.value(), &*self.ty().elem_ty) { (ArrayValue::Sum(v), AlgebraicType::Sum(ty)) => self.with(ty, v).serialize(ser), (ArrayValue::Product(v), AlgebraicType::Product(ty)) => self.with(ty, v).serialize(ser), - (ArrayValue::Map(v), AlgebraicType::Map(m)) => self.with(&**m, v).serialize(ser), (ArrayValue::Bool(v), AlgebraicType::Bool) => v.serialize(ser), (ArrayValue::I8(v), AlgebraicType::I8) => v.serialize(ser), (ArrayValue::U8(v), AlgebraicType::U8) => v.serialize(ser), @@ -241,15 +227,6 @@ impl_serialize!([] ValueWithType<'_, ArrayValue>, (self, ser) => match (self.val (val, _) if val.is_empty() => ser.serialize_array(0)?.end(), (val, ty) => panic!("mismatched value and schema: {val:?} {ty:?}"), }); -impl_serialize!([] ValueWithType<'_, MapValue>, (self, ser) => { - let val = self.value(); - let MapType { key_ty, ty } = self.ty(); - let mut map = ser.serialize_map(val.len())?; - for (key, val) in val { - map.serialize_entry(&self.with(key_ty, key), &self.with(ty, val))?; - } - map.end() -}); impl_serialize!([] spacetimedb_primitives::TableId, (self, ser) => ser.serialize_u32(self.0)); impl_serialize!([] spacetimedb_primitives::SequenceId, (self, ser) => ser.serialize_u32(self.0)); diff --git a/crates/sats/src/ser/serde.rs b/crates/sats/src/ser/serde.rs index 7a7e4b3039..075082c82d 100644 --- a/crates/sats/src/ser/serde.rs +++ b/crates/sats/src/ser/serde.rs @@ -34,7 +34,6 @@ impl Serializer for SerdeSerializer { type Ok = S::Ok; type Error = SerdeError; type SerializeArray = SerializeArray; - type SerializeMap = SerializeMap; type SerializeSeqProduct = SerializeSeqProduct; type SerializeNamedProduct = SerializeNamedProduct; @@ -96,11 +95,6 @@ impl Serializer for SerdeSerializer { Ok(SerializeArray { seq }) } - fn serialize_map(self, len: usize) -> Result { - let map = self.ser.serialize_map(Some(len)).map_err(SerdeError)?; - Ok(SerializeMap { map }) - } - fn serialize_seq_product(self, len: usize) -> Result { let tup = self.ser.serialize_tuple(len).map_err(SerdeError)?; Ok(SerializeSeqProduct { tup }) @@ -201,31 +195,6 @@ impl ser::SerializeArray for SerializeArray { } } -/// Serializes map entries by forwarding to `S: serde::SerializeMap`. -pub struct SerializeMap { - /// An implementation of `serde::SerializeMap`. - map: S, -} - -impl ser::SerializeMap for SerializeMap { - type Ok = S::Ok; - type Error = SerdeError; - - fn serialize_entry( - &mut self, - key: &K, - value: &V, - ) -> Result<(), Self::Error> { - self.map - .serialize_entry(SerializeWrapper::from_ref(key), SerializeWrapper::from_ref(value)) - .map_err(SerdeError) - } - - fn end(self) -> Result { - self.map.end().map_err(SerdeError) - } -} - /// Serializes unnamed product elements by forwarding to `S: serde::SerializeTuple`. pub struct SerializeSeqProduct { /// An implementation of `serde::SerializeTuple`. diff --git a/crates/sats/src/typespace.rs b/crates/sats/src/typespace.rs index 6579643c7b..5c721a244d 100644 --- a/crates/sats/src/typespace.rs +++ b/crates/sats/src/typespace.rs @@ -129,10 +129,6 @@ impl Typespace { AlgebraicType::Array(array_ty) => { self.inline_typerefs_in_type(&mut array_ty.elem_ty)?; } - AlgebraicType::Map(map_type) => { - self.inline_typerefs_in_type(&mut map_type.key_ty)?; - self.inline_typerefs_in_type(&mut map_type.ty)?; - } AlgebraicType::Ref(r) => { // Lazily resolve any nested references first. let resolved_ty = self.inline_typerefs_in_ref(*r)?; @@ -385,12 +381,6 @@ mod tests { assert_not_valid(AlgebraicType::option(bad_inner_1.clone())); assert_not_valid(AlgebraicType::option(bad_inner_2.clone())); - assert_not_valid(AlgebraicType::map(AlgebraicType::U8, bad_inner_1.clone())); - assert_not_valid(AlgebraicType::map(AlgebraicType::U8, bad_inner_2.clone())); - - assert_not_valid(AlgebraicType::map(bad_inner_1.clone(), AlgebraicType::U8)); - assert_not_valid(AlgebraicType::map(bad_inner_2.clone(), AlgebraicType::U8)); - assert_not_valid(AlgebraicType::option(AlgebraicType::array(AlgebraicType::option( bad_inner_1.clone(), )))); diff --git a/crates/schema/src/type_for_generate.rs b/crates/schema/src/type_for_generate.rs index 706be6e554..41454670b5 100644 --- a/crates/schema/src/type_for_generate.rs +++ b/crates/schema/src/type_for_generate.rs @@ -308,14 +308,6 @@ pub enum AlgebraicTypeUse { /// Values [`AlgebraicValue::Array(array)`](crate::AlgebraicValue::Array) will have this type. Array(Arc), - /// The type of map values consisting of a key type `key_ty` and value `ty`. - /// Values [`AlgebraicValue::Map(map)`](crate::AlgebraicValue::Map) will have this type. - /// The order of entries in a map value is observable. - Map { - key: Arc, - value: Arc, - }, - /// A standard structural option type. Option(Arc), @@ -360,10 +352,6 @@ impl AlgebraicTypeUse { match self { AlgebraicTypeUse::Ref(ref_) => f(*ref_), AlgebraicTypeUse::Array(elem_ty) => elem_ty._for_each_ref(f), - AlgebraicTypeUse::Map { key, value } => { - key._for_each_ref(f); - value._for_each_ref(f); - } AlgebraicTypeUse::Option(elem_ty) => elem_ty._for_each_ref(f), _ => {} } @@ -443,18 +431,6 @@ impl TypespaceForGenerateBuilder<'_> { let interned = self.intern_use(elem_ty); Ok(AlgebraicTypeUse::Array(interned)) } - AlgebraicType::Map(map) => { - let key_ty = self.parse_use(&map.key_ty); - let value_ty = self.parse_use(&map.ty); - let (key_ty, value_ty) = (key_ty, value_ty).combine_errors()?; - let interned_key = self.intern_use(key_ty); - let interned_value = self.intern_use(value_ty); - Ok(AlgebraicTypeUse::Map { - key: interned_key, - value: interned_value, - }) - } - AlgebraicType::String => Ok(AlgebraicTypeUse::String), AlgebraicType::Bool => Ok(AlgebraicTypeUse::Primitive(PrimitiveType::Bool)), AlgebraicType::I8 => Ok(AlgebraicTypeUse::Primitive(PrimitiveType::I8)), @@ -751,17 +727,12 @@ mod tests { let ref0 = t.add(AlgebraicType::Ref(def)); let ref1 = t.add(AlgebraicType::array(AlgebraicType::Ref(def))); let ref2 = t.add(AlgebraicType::option(AlgebraicType::Ref(ref1))); - let ref3 = t.add(AlgebraicType::map(AlgebraicType::U64, AlgebraicType::Ref(ref2))); - let ref4 = t.add(AlgebraicType::Ref(ref3)); + let ref3 = t.add(AlgebraicType::Ref(ref2)); let expected_0 = AlgebraicTypeUse::Ref(def); let expected_1 = AlgebraicTypeUse::Array(Arc::new(expected_0.clone())); let expected_2 = AlgebraicTypeUse::Option(Arc::new(expected_1.clone())); - let expected_3 = AlgebraicTypeUse::Map { - key: Arc::new(AlgebraicTypeUse::Primitive(PrimitiveType::U64)), - value: Arc::new(expected_2.clone()), - }; - let expected_4 = expected_3.clone(); + let expected_3 = expected_2.clone(); let mut for_generate_forward = TypespaceForGenerate::builder(&t, [def]); for_generate_forward.add_definition(def).unwrap(); @@ -769,16 +740,13 @@ mod tests { let use1 = for_generate_forward.parse_use(&ref1.into()).unwrap(); let use2 = for_generate_forward.parse_use(&ref2.into()).unwrap(); let use3 = for_generate_forward.parse_use(&ref3.into()).unwrap(); - let use4 = for_generate_forward.parse_use(&ref4.into()).unwrap(); assert_eq!(use0, expected_0); assert_eq!(use1, expected_1); assert_eq!(use2, expected_2); assert_eq!(use3, expected_3); - assert_eq!(use4, expected_4); let mut for_generate_backward = TypespaceForGenerate::builder(&t, [def]); - let use4 = for_generate_backward.parse_use(&ref4.into()).unwrap(); let use3 = for_generate_forward.parse_use(&ref3.into()).unwrap(); let use2 = for_generate_forward.parse_use(&ref2.into()).unwrap(); let use1 = for_generate_forward.parse_use(&ref1.into()).unwrap(); @@ -789,7 +757,6 @@ mod tests { assert_eq!(use1, expected_1); assert_eq!(use2, expected_2); assert_eq!(use3, expected_3); - assert_eq!(use4, expected_4); } #[test] diff --git a/crates/sqltest/src/space.rs b/crates/sqltest/src/space.rs index c2cc3fa973..f52bd25c87 100644 --- a/crates/sqltest/src/space.rs +++ b/crates/sqltest/src/space.rs @@ -34,7 +34,7 @@ impl ColumnType for Kind { fn to_char(&self) -> char { match &self.0 { - AlgebraicType::Map(_) | AlgebraicType::Array(_) => '?', + AlgebraicType::Array(_) => '?', ty if ty.is_integer() => 'I', ty if ty.is_float() => 'R', AlgebraicType::String => 'T', diff --git a/crates/table/src/bflatn_from.rs b/crates/table/src/bflatn_from.rs index bd6abc6a67..3ec31fcf00 100644 --- a/crates/table/src/bflatn_from.rs +++ b/crates/table/src/bflatn_from.rs @@ -241,7 +241,7 @@ pub(crate) unsafe fn serialize_value( // SAFETY: `value` was valid at `::String` and `VarLenRef`s won't be dangling. unsafe { serialize_string(ser, bytes, page, blob_store, curr_offset) } } - AlgebraicTypeLayout::VarLen(VarLenType::Array(ty) | VarLenType::Map(ty)) => { + AlgebraicTypeLayout::VarLen(VarLenType::Array(ty)) => { // SAFETY: `value` was valid at `ty` and `VarLenRef`s won't be dangling. unsafe { serialize_bsatn(ser, bytes, page, blob_store, curr_offset, ty) } } diff --git a/crates/table/src/bflatn_to.rs b/crates/table/src/bflatn_to.rs index bb576052cd..5299656777 100644 --- a/crates/table/src/bflatn_to.rs +++ b/crates/table/src/bflatn_to.rs @@ -223,8 +223,7 @@ impl BflatnSerializedRowBuffer<'_> { // For array and maps, we reserve space for a `VarLenRef` // and push the bytes, after BSATN encoding, as a var-len object. - (AlgebraicTypeLayout::VarLen(VarLenType::Array(_)), val @ AlgebraicValue::Array(_)) - | (AlgebraicTypeLayout::VarLen(VarLenType::Map(_)), val @ AlgebraicValue::Map(_)) => { + (AlgebraicTypeLayout::VarLen(VarLenType::Array(_)), val @ AlgebraicValue::Array(_)) => { self.write_av_bsatn(val)? } diff --git a/crates/table/src/bflatn_to_bsatn_fast_path.rs b/crates/table/src/bflatn_to_bsatn_fast_path.rs index 023ec2c6a0..21c12b2373 100644 --- a/crates/table/src/bflatn_to_bsatn_fast_path.rs +++ b/crates/table/src/bflatn_to_bsatn_fast_path.rs @@ -533,7 +533,6 @@ mod test { AlgebraicType::bytes(), AlgebraicType::never(), AlgebraicType::array(AlgebraicType::U16), - AlgebraicType::map(AlgebraicType::U8, AlgebraicType::I8), AlgebraicType::sum([AlgebraicType::U8, AlgebraicType::U16]), ] { let layout = RowTypeLayout::from(ProductType::from([ty])); diff --git a/crates/table/src/eq_to_pv.rs b/crates/table/src/eq_to_pv.rs index 8e703c98b9..fad23607b2 100644 --- a/crates/table/src/eq_to_pv.rs +++ b/crates/table/src/eq_to_pv.rs @@ -158,7 +158,7 @@ unsafe fn eq_value(ctx: &mut EqCtx<'_>, ty: &AlgebraicTypeLayout, rhs: &Algebrai // to either be `NULL` or point to a valid granule in `ctx.lhs.page`. unsafe { eq_str(ctx, rhs) } } - (AlgebraicTypeLayout::VarLen(_), AlgebraicValue::Array(_) | AlgebraicValue::Map(_)) => { + (AlgebraicTypeLayout::VarLen(_), AlgebraicValue::Array(_)) => { // SAFETY: `lhs` was valid at and aligned for `ty`. // This kind of `ty` stores a `vlr: VarLenRef` as its value, // so the range is valid and properly aligned for `VarLenRef`. diff --git a/crates/table/src/layout.rs b/crates/table/src/layout.rs index 08cde9aa1d..4db7103e36 100644 --- a/crates/table/src/layout.rs +++ b/crates/table/src/layout.rs @@ -350,11 +350,6 @@ pub enum VarLenType { /// Storing the whole `AlgebraicType` here allows us to directly call BSATN ser/de, /// and to report type errors. Array(Box), - /// A map type. The whole outer `AlgebraicType` is stored here. - /// - /// Storing the whole `AlgebraicType` here allows us to directly call BSATN ser/de, - /// and to report type errors. - Map(Box), } impl MemoryUsage for VarLenType { @@ -388,7 +383,7 @@ impl From for AlgebraicTypeLayout { AlgebraicType::String => AlgebraicTypeLayout::VarLen(VarLenType::String), AlgebraicType::Array(_) => AlgebraicTypeLayout::VarLen(VarLenType::Array(Box::new(ty))), - AlgebraicType::Map(_) => AlgebraicTypeLayout::VarLen(VarLenType::Map(Box::new(ty))), + AlgebraicType::Bool => AlgebraicTypeLayout::Bool, AlgebraicType::I8 => AlgebraicTypeLayout::I8, AlgebraicType::U8 => AlgebraicTypeLayout::U8, @@ -518,7 +513,6 @@ impl VarLenType { match self { VarLenType::String => AlgebraicType::String, VarLenType::Array(ty) => ty.as_ref().clone(), - VarLenType::Map(ty) => ty.as_ref().clone(), } } } @@ -613,7 +607,7 @@ pub fn required_var_len_granules_for_row(val: &ProductValue) -> usize { match val { AlgebraicValue::Product(val) => traverse_product(val, count), AlgebraicValue::Sum(val) => traverse_av(&val.value, count), - AlgebraicValue::Array(_) | AlgebraicValue::Map(_) => add_for_bytestring(bsatn_len(val), count), + AlgebraicValue::Array(_) => add_for_bytestring(bsatn_len(val), count), AlgebraicValue::String(val) => add_for_bytestring(val.len(), count), _ => (), } diff --git a/crates/table/src/read_column.rs b/crates/table/src/read_column.rs index c406dee11d..f1ad4825cc 100644 --- a/crates/table/src/read_column.rs +++ b/crates/table/src/read_column.rs @@ -11,7 +11,7 @@ use crate::{ }; use spacetimedb_sats::{ algebraic_value::{ser::ValueSerializer, Packed}, - i256, u256, AlgebraicType, AlgebraicValue, ArrayValue, MapValue, ProductType, ProductValue, SumValue, + i256, u256, AlgebraicType, AlgebraicValue, ArrayValue, ProductType, ProductValue, SumValue, }; use std::{cell::Cell, mem}; use thiserror::Error; @@ -305,7 +305,6 @@ macro_rules! impl_read_column_via_av { impl_read_column_via_av! { AlgebraicTypeLayout::VarLen(VarLenType::String) => into_string => Box; AlgebraicTypeLayout::VarLen(VarLenType::Array(_)) => into_array => ArrayValue; - AlgebraicTypeLayout::VarLen(VarLenType::Map(_)) => into_map => Box; AlgebraicTypeLayout::Sum(_) => into_sum => SumValue; AlgebraicTypeLayout::Product(_) => into_product => ProductValue; } diff --git a/crates/table/src/row_hash.rs b/crates/table/src/row_hash.rs index 978ae2444a..6e50be0375 100644 --- a/crates/table/src/row_hash.rs +++ b/crates/table/src/row_hash.rs @@ -157,7 +157,7 @@ unsafe fn hash_value( }); } } - AlgebraicTypeLayout::VarLen(VarLenType::Array(ty) | VarLenType::Map(ty)) => { + AlgebraicTypeLayout::VarLen(VarLenType::Array(ty)) => { // SAFETY: `value` was valid at and aligned for `ty`. // These `ty` store a `vlr: VarLenRef` as their value, // so the range is valid and properly aligned for `VarLenRef`.