Skip to content

Commit

Permalink
Migrate C# ModuleDef to V9 (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser authored Dec 16, 2024
1 parent 9211708 commit 08a3f32
Show file tree
Hide file tree
Showing 79 changed files with 2,049 additions and 1,569 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bindings-csharp/BSATN.Codegen/BSATN.Codegen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<AssemblyName>SpacetimeDB.BSATN.Codegen</AssemblyName>
<Version>1.0.0-rc1-hotfix1</Version>
<Version>1.0.0-rc2</Version>
<Title>SpacetimeDB BSATN Codegen</Title>
<Description>The SpacetimeDB BSATN Codegen implements the Roslyn incremental generators for BSATN serialization/deserialization in C#.</Description>
</PropertyGroup>
Expand Down
31 changes: 31 additions & 0 deletions crates/bindings-csharp/BSATN.Codegen/Diag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,41 @@ Func<TContext, ISymbol> toLocation
)
: this(group, title, interpolate, ctx => toLocation(ctx).Locations.FirstOrDefault()) { }

public ErrorDescriptor(
ErrorDescriptorGroup group,
string title,
Expression<Func<TContext, FormattableString>> interpolate,
Func<TContext, AttributeData> toLocation
)
: this(
group,
title,
interpolate,
ctx =>
toLocation(ctx).ApplicationSyntaxReference is { } r
? r.SyntaxTree.GetLocation(r.Span)
: null
) { }

public Diagnostic ToDiag(TContext ctx) =>
Diagnostic.Create(descriptor, toLocation(ctx), makeFormatArgs(ctx));
}

/// <summary>
/// No-op error descriptor placeholder.
///
/// <para>Error descriptors must have strong ID to avoid breaking semver, since they are used for diagnostic suppression by users.</para>
/// <para>To ensure this, we cannot reorder to delete unused diagnostics - instead, we need to put some placeholders where they used to be.</para>
/// <para>This class serves that purpose - it's a no-op error descriptor that you can instantiate just to reserve said ID.</para>
/// </summary>
public sealed class UnusedErrorDescriptor
{
public UnusedErrorDescriptor(ErrorDescriptorGroup group)
{
group.NextId();
}
}

internal static class ErrorDescriptor
{
private static readonly ErrorDescriptorGroup group = new("BSATN", "SpacetimeDB.BSATN");
Expand Down
5 changes: 4 additions & 1 deletion crates/bindings-csharp/BSATN.Codegen/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,13 @@ public void Write(System.IO.BinaryWriter writer, {{FullName}} value) {
{{write}}
}
public SpacetimeDB.BSATN.AlgebraicType GetAlgebraicType(SpacetimeDB.BSATN.ITypeRegistrar registrar) =>
public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType(SpacetimeDB.BSATN.ITypeRegistrar registrar) =>
registrar.RegisterType<{{FullName}}>(_ => new SpacetimeDB.BSATN.AlgebraicType.{{Kind}}(new SpacetimeDB.BSATN.AggregateElement[] {
{{MemberDeclaration.GenerateDefs(Members)}}
}));
SpacetimeDB.BSATN.AlgebraicType SpacetimeDB.BSATN.IReadWrite<{{FullName}}>.GetAlgebraicType(SpacetimeDB.BSATN.ITypeRegistrar registrar) =>
GetAlgebraicType(registrar);
}
"""
);
Expand Down
6 changes: 5 additions & 1 deletion crates/bindings-csharp/BSATN.Codegen/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ public override string ToString()
sb.Append(" : ").AppendJoin(", ", BaseTypes);
}

sb.Append(typeScope.Constraints).AppendLine(" {");
if (typeScope.Constraints.Length > 0)
{
sb.Append(' ').Append(typeScope.Constraints);
}
sb.AppendLine(" {");
}

sb.AppendLine();
Expand Down
2 changes: 1 addition & 1 deletion crates/bindings-csharp/BSATN.Runtime/BSATN.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<AssemblyName>SpacetimeDB.BSATN.Runtime</AssemblyName>
<Version>1.0.0-rc1-hotfix1</Version>
<Version>1.0.0-rc2</Version>
<Title>SpacetimeDB BSATN Runtime</Title>
<Description>The SpacetimeDB BSATN Runtime implements APIs for BSATN serialization/deserialization in C#.</Description>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Write(System.IO.BinaryWriter writer, CustomClass value)
value.WriteFields(writer);
}

public SpacetimeDB.BSATN.AlgebraicType GetAlgebraicType(
public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) =>
registrar.RegisterType<CustomClass>(_ => new SpacetimeDB.BSATN.AlgebraicType.Product(
Expand All @@ -39,5 +39,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
new(nameof(StringField), StringField.GetAlgebraicType(registrar))
}
));

SpacetimeDB.BSATN.AlgebraicType SpacetimeDB.BSATN.IReadWrite<CustomClass>.GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) => GetAlgebraicType(registrar);
}
} // CustomClass
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Write(System.IO.BinaryWriter writer, CustomStruct value)
value.WriteFields(writer);
}

public SpacetimeDB.BSATN.AlgebraicType GetAlgebraicType(
public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) =>
registrar.RegisterType<CustomStruct>(_ => new SpacetimeDB.BSATN.AlgebraicType.Product(
Expand All @@ -39,5 +39,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
new(nameof(StringField), StringField.GetAlgebraicType(registrar))
}
));

SpacetimeDB.BSATN.AlgebraicType SpacetimeDB.BSATN.IReadWrite<CustomStruct>.GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) => GetAlgebraicType(registrar);
}
} // CustomStruct
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Write(System.IO.BinaryWriter writer, CustomTaggedEnum value)
}
}

public SpacetimeDB.BSATN.AlgebraicType GetAlgebraicType(
public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) =>
registrar.RegisterType<CustomTaggedEnum>(_ => new SpacetimeDB.BSATN.AlgebraicType.Sum(
Expand All @@ -58,5 +58,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
new(nameof(StringVariant), StringVariant.GetAlgebraicType(registrar))
}
));

SpacetimeDB.BSATN.AlgebraicType SpacetimeDB.BSATN.IReadWrite<CustomTaggedEnum>.GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) => GetAlgebraicType(registrar);
}
} // CustomTaggedEnum
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void Write(System.IO.BinaryWriter writer, PublicTable value)
value.WriteFields(writer);
}

public SpacetimeDB.BSATN.AlgebraicType GetAlgebraicType(
public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) =>
registrar.RegisterType<PublicTable>(_ => new SpacetimeDB.BSATN.AlgebraicType.Product(
Expand Down Expand Up @@ -144,5 +144,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
)
}
));

SpacetimeDB.BSATN.AlgebraicType SpacetimeDB.BSATN.IReadWrite<PublicTable>.GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) => GetAlgebraicType(registrar);
}
} // PublicTable
46 changes: 32 additions & 14 deletions crates/bindings-csharp/Codegen.Tests/fixtures/diag/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,24 +361,42 @@ public static partial class InAnotherNamespace
public partial struct TestDuplicateTableName { }
}

[SpacetimeDB.Table(
Name = "TestIncompatibleSchedule1",
Scheduled = nameof(TestIncompatibleScheduleReducer)
)]
[SpacetimeDB.Table(Name = "TestIncompatibleSchedule2")]
public partial struct TestIncompatibleSchedule
{
[SpacetimeDB.Reducer]
public static void TestIncompatibleScheduleReducer(
ReducerContext ctx,
TestIncompatibleSchedule table
) { }
}

[SpacetimeDB.Table]
[SpacetimeDB.Index]
public partial struct TestIndexWithoutColumns { }

[SpacetimeDB.Table]
[SpacetimeDB.Index(BTree = [])]
public partial struct TestIndexWithEmptyColumns { }

[SpacetimeDB.Table(
Name = "TestScheduleWithoutPrimaryKey",
Scheduled = "DummyScheduledReducer",
ScheduledAt = nameof(ScheduleAtCorrectType)
)]
[SpacetimeDB.Table(
Name = "TestScheduleWithWrongPrimaryKeyType",
Scheduled = "DummyScheduledReducer",
ScheduledAt = nameof(ScheduleAtCorrectType)
)]
[SpacetimeDB.Table(Name = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
[SpacetimeDB.Table(
Name = "TestScheduleWithWrongScheduleAtType",
Scheduled = "DummyScheduledReducer",
ScheduledAt = nameof(ScheduleAtWrongType)
)]
public partial struct TestScheduleIssues
{
[SpacetimeDB.PrimaryKey(Table = "TestScheduleWithWrongPrimaryKeyType")]
public string IdWrongType;

[SpacetimeDB.PrimaryKey(Table = "TestScheduleWithoutScheduleAt")]
[SpacetimeDB.PrimaryKey(Table = "TestScheduleWithWrongScheduleAtType")]
public int IdCorrectType;

public int ScheduleAtWrongType;
public ScheduleAt ScheduleAtCorrectType;

[SpacetimeDB.Reducer]
public static void DummyScheduledReducer(ReducerContext ctx, TestScheduleIssues table) { }
}
Loading

1 comment on commit 08a3f32

@github-actions
Copy link

@github-actions github-actions bot commented on 08a3f32 Dec 16, 2024

Choose a reason for hiding this comment

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

Criterion benchmark results

Please sign in to comment.