Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/bindings-csharp/BSATN.Codegen/BSATN.Codegen.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>SpacetimeDB.BSATN.Codegen</AssemblyName>
<Version>1.11.0</Version>
Expand Down Expand Up @@ -27,5 +26,4 @@
<!-- dev-dependency to add internal C# classes and attributes not included in .NET Standard -->
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions crates/bindings-csharp/BSATN.Codegen/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public abstract record TypeUse(string Name, string BSATNName)
/// </summary>
public static string BsatnFieldSuffix => $"{BSATN_FIELD_SUFFIX}";

/// <summary>
/// Indicates whether this type represents a void return.
/// </summary>
public virtual bool IsVoid => false;

/// <summary>
/// Parse a type use for a member.
/// </summary>
Expand All @@ -53,6 +58,11 @@ public abstract record TypeUse(string Name, string BSATNName)
/// <returns></returns>
public static TypeUse Parse(ISymbol member, ITypeSymbol typeSymbol, DiagReporter diag)
{
if (typeSymbol.SpecialType == SpecialType.System_Void)
{
return new VoidUse("void", "SpacetimeDB.BSATN.Unit");
}

var type = SymbolToName(typeSymbol);
string typeInfo;

Expand Down Expand Up @@ -194,6 +204,21 @@ public override string GetHashCodeStatement(string inVar, string outVar, int lev
$"var {outVar} = {inVar} == null ? 0 : {inVar}.GetHashCode();";
}

public sealed record VoidUse(string Type, string TypeInfo) : TypeUse(Type, TypeInfo)
{
public override bool IsVoid => true;

public override string EqualsStatement(
string inVar1,
string inVar2,
string outVar,
int level = 0
) => $"var {outVar} = true;";

public override string GetHashCodeStatement(string inVar, string outVar, int level = 0) =>
$"var {outVar} = 0;";
}

/// <summary>
/// A use of an array type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand All @@ -20,7 +19,10 @@

<ItemGroup>
<ProjectReference Include="../BSATN.Runtime/BSATN.Runtime.csproj" />
<ProjectReference Include="../BSATN.Codegen/BSATN.Codegen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference
Include="../BSATN.Codegen/BSATN.Codegen.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
/>
</ItemGroup>

</Project>
33 changes: 10 additions & 23 deletions crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,12 @@ public BasicDataClass((int x, string y, int? z, string? w) data)
}

[Type]
public partial struct BasicDataStruct
public partial struct BasicDataStruct((int x, string y, int? z, string? w) data)
{
public int X;
public string Y;
public int? Z;
public string? W;

public BasicDataStruct((int x, string y, int? z, string? w) data)
{
X = data.x;
Y = data.y;
Z = data.z;
W = data.w;
}
public int X = data.x;
public string Y = data.y;
public int? Z = data.z;
public string? W = data.w;
}

[Type]
Expand Down Expand Up @@ -315,12 +307,12 @@ public void Add(bool collides)
}
}

public double CollisionFraction
public readonly double CollisionFraction
{
get => (double)Collisions / (double)Comparisons;
}

public void AssertCollisionsLessThan(double fraction)
public readonly void AssertCollisionsLessThan(double fraction)
{
Assert.True(
CollisionFraction < fraction,
Expand Down Expand Up @@ -626,18 +618,13 @@ public static void GeneratedNestedListRoundTrip()
.Select(list => new ContainsNestedList(list));
#pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.


static readonly Gen<(ContainsNestedList e1, ContainsNestedList e2)> GenTwoContainsNestedList =
Gen.Select(GenContainsNestedList, GenContainsNestedList, (e1, e2) => (e1, e2));

class EnumerableEqualityComparer<T> : EqualityComparer<IEnumerable<T>>
class EnumerableEqualityComparer<T>(EqualityComparer<T> equalityComparer)
: EqualityComparer<IEnumerable<T>>
{
private readonly EqualityComparer<T> EqualityComparer;

public EnumerableEqualityComparer(EqualityComparer<T> equalityComparer)
{
EqualityComparer = equalityComparer;
}
private readonly EqualityComparer<T> EqualityComparer = equalityComparer;

public override bool Equals(IEnumerable<T>? x, IEnumerable<T>? y) =>
x == null ? y == null : (y == null ? false : x.SequenceEqual(y, EqualityComparer));
Expand Down
14 changes: 10 additions & 4 deletions crates/bindings-csharp/BSATN.Runtime/BSATN.Runtime.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>SpacetimeDB.BSATN.Runtime</AssemblyName>
<Version>1.11.0</Version>
Expand All @@ -18,18 +17,25 @@

<ItemGroup>
<!-- We want to build BSATN.Codegen both to include it in our NuGet package but also we want it to transform [SpacetimeDB.Type] usages in BSATN.Runtime code itself. -->
<ProjectReference Include="../BSATN.Codegen/BSATN.Codegen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference
Include="../BSATN.Codegen/BSATN.Codegen.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
/>
</ItemGroup>

<ItemGroup>
<None Include="../Runtime/README.md" Pack="true" PackagePath="" />
<!-- We want all users who depends on BSATN.Runtime to automatically get the Roslyn codegen component as well. -->
<None Include="../BSATN.Codegen/bin/$(Configuration)/netstandard2.0/SpacetimeDB.BSATN.Codegen.dll" Pack="true" PackagePath="analyzers/dotnet/cs" />
<None
Include="../BSATN.Codegen/bin/$(Configuration)/netstandard2.0/SpacetimeDB.BSATN.Codegen.dll"
Pack="true"
PackagePath="analyzers/dotnet/cs"
/>
</ItemGroup>

<ItemGroup>
<!-- dev-dependency to add internal C# classes and attributes not included in .NET Standard -->
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" />
</ItemGroup>

</Project>
12 changes: 3 additions & 9 deletions crates/bindings-csharp/BSATN.Runtime/BSATN/AlgebraicType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ public interface ITypeRegistrar
}

[SpacetimeDB.Type]
public partial struct AggregateElement
public partial struct AggregateElement(string name, AlgebraicType algebraicType)
{
public string? Name;
public string? Name = name;

public AlgebraicType AlgebraicType;

public AggregateElement(string name, AlgebraicType algebraicType)
{
Name = name;
AlgebraicType = algebraicType;
}
public AlgebraicType AlgebraicType = algebraicType;
}

[SpacetimeDB.Type]
Expand Down
1 change: 0 additions & 1 deletion crates/bindings-csharp/BSATN.Runtime/BSATN/I256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public int CompareTo(I256 value)
}

/// <inheritdoc cref="INumberBase{TSelf}.IsNegative(TSelf)" />

public static bool IsNegative(I256 value) => (long)value._upper.Upper < 0;

private BigInteger AsBigInt() =>
Expand Down
2 changes: 1 addition & 1 deletion crates/bindings-csharp/BSATN.Runtime/Builtins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public readonly TimeDuration TimeDurationSince(Timestamp earlier) =>
public static Timestamp operator -(Timestamp point, TimeDuration interval) =>
new Timestamp(checked(point.MicrosecondsSinceUnixEpoch - interval.Microseconds));

public int CompareTo(Timestamp that)
public readonly int CompareTo(Timestamp that)
{
return this.MicrosecondsSinceUnixEpoch.CompareTo(that.MicrosecondsSinceUnixEpoch);
}
Expand Down
2 changes: 0 additions & 2 deletions crates/bindings-csharp/Codegen.Tests/Codegen.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand Down Expand Up @@ -32,5 +31,4 @@
<ItemGroup>
<ProjectReference Include="../Codegen/Codegen.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- We want to ensure that BSATN.Codegen on its own produces code compatible with Unity. -->
<!-- This means limiting project to .NET Standard 2.1 and C# 9. -->
Expand All @@ -10,5 +9,4 @@
<ItemGroup>
<ProjectReference Include="../../../BSATN.Runtime/BSATN.Runtime.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -9,5 +8,4 @@
<ProjectReference Include="../../../BSATN.Runtime/BSATN.Runtime.csproj" />
<ProjectReference Include="../../../Runtime/Runtime.csproj" />
</ItemGroup>

</Project>
Loading
Loading