Skip to content

Commit a0c53ee

Browse files
Merge branch 'master' into joshua/tokio-taskdump
2 parents 416804b + f9f1e19 commit a0c53ee

19 files changed

Lines changed: 163 additions & 205 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,8 @@ jobs:
10471047
run: dotnet restore --configfile ../../../NuGet.Config blackholio.csproj
10481048

10491049
- name: Build Godot project
1050-
run: godot --headless --verbose --path demo/Blackholio/client-godot --build-solutions --quit
1050+
working-directory: demo/Blackholio/client-godot
1051+
run: godot --headless --verbose --build-solutions --quit
10511052

10521053
- name: Start SpacetimeDB
10531054
run: |
@@ -1061,7 +1062,8 @@ jobs:
10611062
bash ./publish.sh
10621063
10631064
- name: Run Godot tests
1064-
run: godot --headless --path demo/Blackholio/client-godot --scene res://tests/GodotPlayModeTests.tscn
1065+
working-directory: demo/Blackholio/client-godot
1066+
run: godot --headless --scene res://tests/GodotPlayModeTests.tscn
10651067

10661068
csharp-testsuite:
10671069
needs: [merge_queue_noop, lints]

crates/bindings-csharp/BSATN.Codegen/Type.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,13 +740,13 @@ public override string ToString() =>
740740

741741
write = "value.WriteFields(writer);";
742742

743-
var declHashName = (MemberDeclaration decl) => $"___hash{decl.Name}";
743+
static string DeclHashName(MemberDeclaration decl) => $"___hash{decl.Name}";
744744

745745
getHashCode = $$"""
746-
{{string.Join("\n", bsatnDecls.Select(decl => decl.Type.GetHashCodeStatement(decl.Identifier, declHashName(decl))))}}
746+
{{string.Join("\n", bsatnDecls.Select(decl => decl.Type.GetHashCodeStatement(decl.Identifier, DeclHashName(decl))))}}
747747
return {{JoinOrValue(
748748
" ^\n ",
749-
bsatnDecls.Select(declHashName),
749+
bsatnDecls.Select(DeclHashName),
750750
"0" // if there are no members, the hash is 0.
751751
)}};
752752
""";
@@ -789,7 +789,7 @@ public override int GetHashCode()
789789
// If we are a reference type, various equality methods need to take nullable references.
790790
// If we are a value type, everything is pleasantly by-value.
791791
var fullNameMaybeRef = $"{FullName}{(Scope.IsStruct ? "" : "?")}";
792-
var declEqualsName = (MemberDeclaration decl) => $"___eq{decl.Name}";
792+
static string DeclEqualsName(MemberDeclaration decl) => $"___eq{decl.Name}";
793793

794794
extensions.Contents.Append(
795795
$$"""
@@ -798,10 +798,10 @@ public override int GetHashCode()
798798
public bool Equals({{fullNameMaybeRef}} that)
799799
{
800800
{{(Scope.IsStruct ? "" : "if (((object?)that) == null) { return false; }\n ")}}
801-
{{string.Join("\n", bsatnDecls.Select(decl => decl.Type.EqualsStatement($"this.{decl.Identifier}", $"that.{decl.Identifier}", declEqualsName(decl))))}}
801+
{{string.Join("\n", bsatnDecls.Select(decl => decl.Type.EqualsStatement($"this.{decl.Identifier}", $"that.{decl.Identifier}", DeclEqualsName(decl))))}}
802802
return {{JoinOrValue(
803803
" &&\n ",
804-
bsatnDecls.Select(declEqualsName),
804+
bsatnDecls.Select(DeclEqualsName),
805805
"true" // if there are no elements, the structs are equal :)
806806
)}};
807807
}

crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ public interface IReadWrite<T>
129129
/// Note: the [Type] macro rejects enums with explicitly set values (see Codegen.Tests),
130130
/// so this array is guaranteed to be continuous and indexed starting from 0.
131131
/// </summary>
132+
#pragma warning disable CA2263, IDE0305 // netstandard2.1 lacks the generic Enum overloads.
132133
private static readonly T[] TagToValue = Enum.GetValues(typeof(T)).Cast<T>().ToArray();
134+
#pragma warning restore CA2263, IDE0305
133135

134136
public T Read(BinaryReader reader)
135137
{
@@ -177,9 +179,12 @@ public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>
177179
registrar.RegisterType<T>(
178180
(_) =>
179181
new AlgebraicType.Sum(
180-
Enum.GetNames(typeof(T))
181-
.Select(name => new AggregateElement(name, AlgebraicType.Unit))
182-
.ToArray()
182+
#pragma warning disable CA2263 // netstandard2.1 lacks the generic Enum overloads.
183+
[
184+
.. Enum.GetNames(typeof(T))
185+
.Select(name => new AggregateElement(name, AlgebraicType.Unit)),
186+
]
187+
#pragma warning restore CA2263
183188
)
184189
);
185190
}

crates/bindings-csharp/BSATN.Runtime/BSATN/U128.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static U128 FromBytesBigEndian(ReadOnlySpan<byte> bytes)
4545
);
4646
}
4747

48-
var upper = BinaryPrimitives.ReadUInt64BigEndian(bytes.Slice(0, 8));
49-
var lower = BinaryPrimitives.ReadUInt64BigEndian(bytes.Slice(8, 8));
48+
var upper = BinaryPrimitives.ReadUInt64BigEndian(bytes[..8]);
49+
var lower = BinaryPrimitives.ReadUInt64BigEndian(bytes[8..16]);
5050

5151
return new U128(upper, lower);
5252
}

crates/bindings-csharp/BSATN.Runtime/Builtins.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public static implicit operator DateTimeOffset(Timestamp t) =>
357357
DateTimeOffset.UnixEpoch.AddTicks(t.MicrosecondsSinceUnixEpoch * Util.TicksPerMicrosecond);
358358

359359
public static implicit operator Timestamp(DateTimeOffset offset) =>
360-
new Timestamp(offset.Subtract(DateTimeOffset.UnixEpoch).Ticks / Util.TicksPerMicrosecond);
360+
new(offset.Subtract(DateTimeOffset.UnixEpoch).Ticks / Util.TicksPerMicrosecond);
361361

362362
// For backwards-compatibility.
363363
public readonly DateTimeOffset ToStd() => this;
@@ -373,7 +373,7 @@ public override readonly string ToString()
373373
public static readonly Timestamp UNIX_EPOCH = new(0);
374374

375375
public static Timestamp FromTimeDurationSinceUnixEpoch(TimeDuration timeDuration) =>
376-
new Timestamp(timeDuration.Microseconds);
376+
new(timeDuration.Microseconds);
377377

378378
public readonly TimeDuration ToTimeDurationSinceUnixEpoch() => TimeDurationSince(UNIX_EPOCH);
379379

@@ -383,13 +383,13 @@ public static Timestamp FromTimeSpanSinceUnixEpoch(TimeSpan timeSpan) =>
383383
public readonly TimeSpan ToTimeSpanSinceUnixEpoch() => (TimeSpan)ToTimeDurationSinceUnixEpoch();
384384

385385
public readonly TimeDuration TimeDurationSince(Timestamp earlier) =>
386-
new TimeDuration(checked(MicrosecondsSinceUnixEpoch - earlier.MicrosecondsSinceUnixEpoch));
386+
new(checked(MicrosecondsSinceUnixEpoch - earlier.MicrosecondsSinceUnixEpoch));
387387

388388
public static Timestamp operator +(Timestamp point, TimeDuration interval) =>
389-
new Timestamp(checked(point.MicrosecondsSinceUnixEpoch + interval.Microseconds));
389+
new(checked(point.MicrosecondsSinceUnixEpoch + interval.Microseconds));
390390

391391
public static Timestamp operator -(Timestamp point, TimeDuration interval) =>
392-
new Timestamp(checked(point.MicrosecondsSinceUnixEpoch - interval.Microseconds));
392+
new(checked(point.MicrosecondsSinceUnixEpoch - interval.Microseconds));
393393

394394
public readonly int CompareTo(Timestamp that)
395395
{
@@ -492,10 +492,10 @@ public static implicit operator TimeDuration(TimeSpan timeSpan) =>
492492
new(timeSpan.Ticks / Util.TicksPerMicrosecond);
493493

494494
public static TimeDuration operator +(TimeDuration lhs, TimeDuration rhs) =>
495-
new TimeDuration(checked(lhs.Microseconds + rhs.Microseconds));
495+
new(checked(lhs.Microseconds + rhs.Microseconds));
496496

497497
public static TimeDuration operator -(TimeDuration lhs, TimeDuration rhs) =>
498-
new TimeDuration(checked(lhs.Microseconds + rhs.Microseconds));
498+
new(checked(lhs.Microseconds + rhs.Microseconds));
499499

500500
// For backwards-compatibility.
501501
public readonly TimeSpan ToStd() => this;
@@ -574,7 +574,7 @@ long microsSinceUnixEpoch
574574
// --- auto-generated ---
575575
private ScheduleAt() { }
576576

577-
internal enum @enum : byte
577+
internal enum ScheduleAtVariant : byte
578578
{
579579
Interval,
580580
Time,
@@ -586,15 +586,15 @@ public sealed record Time(Timestamp Time_) : ScheduleAt;
586586

587587
public readonly partial struct BSATN : IReadWrite<ScheduleAt>
588588
{
589-
internal static readonly SpacetimeDB.BSATN.Enum<@enum> __enumTag = new();
589+
internal static readonly SpacetimeDB.BSATN.Enum<ScheduleAtVariant> __enumTag = new();
590590
internal static readonly TimeDuration.BSATN Interval = new();
591591
internal static readonly Timestamp.BSATN Time = new();
592592

593593
public ScheduleAt Read(BinaryReader reader) =>
594594
__enumTag.Read(reader) switch
595595
{
596-
@enum.Interval => new Interval(Interval.Read(reader)),
597-
@enum.Time => new Time(Time.Read(reader)),
596+
ScheduleAtVariant.Interval => new Interval(Interval.Read(reader)),
597+
ScheduleAtVariant.Time => new Time(Time.Read(reader)),
598598
_ => throw new InvalidOperationException(
599599
"Invalid tag value, this state should be unreachable."
600600
),
@@ -605,12 +605,12 @@ public void Write(BinaryWriter writer, ScheduleAt value)
605605
switch (value)
606606
{
607607
case Interval(var inner):
608-
__enumTag.Write(writer, @enum.Interval);
608+
__enumTag.Write(writer, ScheduleAtVariant.Interval);
609609
Interval.Write(writer, inner);
610610
break;
611611

612612
case Time(var inner):
613-
__enumTag.Write(writer, @enum.Time);
613+
__enumTag.Write(writer, ScheduleAtVariant.Time);
614614
Time.Write(writer, inner);
615615
break;
616616
}
@@ -682,7 +682,7 @@ public T UnwrapOrElse(Func<E, T> f) =>
682682

683683
private Result() { }
684684

685-
internal enum @enum : byte
685+
internal enum ResultVariant : byte
686686
{
687687
Ok,
688688
Err,
@@ -702,15 +702,15 @@ private enum Variant : byte
702702
where OkRW : struct, IReadWrite<T>
703703
where ErrRW : struct, IReadWrite<E>
704704
{
705-
private static readonly SpacetimeDB.BSATN.Enum<@enum> __enumTag = new();
705+
private static readonly SpacetimeDB.BSATN.Enum<ResultVariant> __enumTag = new();
706706
private static readonly OkRW okRW = new();
707707
private static readonly ErrRW errRW = new();
708708

709709
public Result<T, E> Read(BinaryReader reader) =>
710710
__enumTag.Read(reader) switch
711711
{
712-
@enum.Ok => new OkR(okRW.Read(reader)),
713-
@enum.Err => new ErrR(errRW.Read(reader)),
712+
ResultVariant.Ok => new OkR(okRW.Read(reader)),
713+
ResultVariant.Err => new ErrR(errRW.Read(reader)),
714714
_ => throw new InvalidOperationException(),
715715
};
716716

@@ -719,12 +719,12 @@ public void Write(BinaryWriter writer, Result<T, E> value)
719719
switch (value)
720720
{
721721
case OkR(var v):
722-
__enumTag.Write(writer, @enum.Ok);
722+
__enumTag.Write(writer, ResultVariant.Ok);
723723
okRW.Write(writer, v);
724724
break;
725725

726726
case ErrR(var e):
727-
__enumTag.Write(writer, @enum.Err);
727+
__enumTag.Write(writer, ResultVariant.Err);
728728
errRW.Write(writer, e);
729729
break;
730730
}

crates/bindings-csharp/BSATN.Runtime/QueryBuilder.cs

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable enable
2-
31
namespace SpacetimeDB;
42

53
using System;
@@ -68,14 +66,9 @@ public interface IQuery<TRow>
6866
string ToSql();
6967
}
7068

71-
public readonly struct BoolExpr<TRow>
69+
public readonly struct BoolExpr<TRow>(string sql)
7270
{
73-
public string Sql { get; }
74-
75-
public BoolExpr(string sql)
76-
{
77-
Sql = sql;
78-
}
71+
public string Sql { get; } = sql;
7972

8073
public BoolExpr<TRow> And(BoolExpr<TRow> other) => new($"({Sql} AND {other.Sql})");
8174

@@ -120,18 +113,9 @@ internal IxJoinEq(string leftRefSql, string rightRefSql)
120113
}
121114
}
122115

123-
public readonly struct Col<TRow, TValue>
116+
public readonly struct Col<TRow, TValue>(string tableName, string columnName)
124117
where TValue : notnull
125118
{
126-
private readonly string tableName;
127-
private readonly string columnName;
128-
129-
public Col(string tableName, string columnName)
130-
{
131-
this.tableName = tableName;
132-
this.columnName = columnName;
133-
}
134-
135119
internal string RefSql =>
136120
$"{SqlFormat.QuoteIdent(tableName)}.{SqlFormat.QuoteIdent(columnName)}";
137121

@@ -162,18 +146,9 @@ public Col(string tableName, string columnName)
162146
public override string ToString() => RefSql;
163147
}
164148

165-
public readonly struct IxCol<TRow, TValue>
149+
public readonly struct IxCol<TRow, TValue>(string tableName, string columnName)
166150
where TValue : notnull
167151
{
168-
private readonly string tableName;
169-
private readonly string columnName;
170-
171-
public IxCol(string tableName, string columnName)
172-
{
173-
this.tableName = tableName;
174-
this.columnName = columnName;
175-
}
176-
177152
internal string RefSql =>
178153
$"{SqlFormat.QuoteIdent(tableName)}.{SqlFormat.QuoteIdent(columnName)}";
179154

@@ -187,19 +162,9 @@ public IxJoinEq<TRow, TOtherRow> Eq<TOtherRow>(IxCol<TOtherRow, TValue> other) =
187162
public override string ToString() => RefSql;
188163
}
189164

190-
public sealed class Table<TRow, TCols, TIxCols> : IQuery<TRow>
165+
public sealed class Table<TRow, TCols, TIxCols>(string tableName, TCols cols, TIxCols ixCols)
166+
: IQuery<TRow>
191167
{
192-
private readonly string tableName;
193-
private readonly TCols cols;
194-
private readonly TIxCols ixCols;
195-
196-
public Table(string tableName, TCols cols, TIxCols ixCols)
197-
{
198-
this.tableName = tableName;
199-
this.cols = cols;
200-
this.ixCols = ixCols;
201-
}
202-
203168
internal string TableRefSql => SqlFormat.QuoteIdent(tableName);
204169

205170
internal TCols Cols => cols;
@@ -229,7 +194,7 @@ public LeftSemiJoin<TRow, TCols, TIxCols, TRightRow, TRightCols, TRightIxCols> L
229194
>(
230195
Table<TRightRow, TRightCols, TRightIxCols> right,
231196
Func<TIxCols, TRightIxCols, IxJoinEq<TRow, TRightRow>> on
232-
) => new(this, right, on(ixCols, right.ixCols), whereExpr: null);
197+
) => new(this, right, on(ixCols, right.IxCols), whereExpr: null);
233198

234199
public RightSemiJoin<TRow, TCols, TIxCols, TRightRow, TRightCols, TRightIxCols> RightSemijoin<
235200
TRightRow,
@@ -238,7 +203,7 @@ public RightSemiJoin<TRow, TCols, TIxCols, TRightRow, TRightCols, TRightIxCols>
238203
>(
239204
Table<TRightRow, TRightCols, TRightIxCols> right,
240205
Func<TIxCols, TRightIxCols, IxJoinEq<TRow, TRightRow>> on
241-
) => new(this, right, on(ixCols, right.ixCols), leftWhereExpr: null);
206+
) => new(this, right, on(ixCols, right.IxCols), leftWhereExpr: null);
242207
}
243208

244209
public sealed class FromWhere<TRow, TCols, TIxCols> : IQuery<TRow>
@@ -889,7 +854,7 @@ public static string FormatHexLiteral(string hex)
889854
var s = hex;
890855
if (s.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
891856
{
892-
s = s.Substring(2);
857+
s = s[2..];
893858
}
894859

895860
s = s.Replace("-", string.Empty);

crates/bindings-csharp/Codegen.Tests/Tests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@ public static class GeneratorSnapshotTests
2626

2727
record struct StepOutput(string Key, IncrementalStepRunReason Reason, object Value);
2828

29-
private class Fixture
29+
private class Fixture(string projectDir, CSharpCompilation sampleCompilation)
3030
{
31-
private readonly string projectDir;
32-
public CSharpCompilation SampleCompilation { get; }
33-
public CSharpParseOptions ParseOptions { get; }
34-
35-
public Fixture(string projectDir, CSharpCompilation sampleCompilation)
36-
{
37-
this.projectDir = projectDir;
38-
SampleCompilation = sampleCompilation;
39-
ParseOptions = (CSharpParseOptions)sampleCompilation.SyntaxTrees.First().Options;
40-
}
31+
public CSharpCompilation SampleCompilation { get; } = sampleCompilation;
32+
public CSharpParseOptions ParseOptions { get; } =
33+
(CSharpParseOptions)sampleCompilation.SyntaxTrees.First().Options;
4134

4235
public static async Task<Fixture> Compile(string name)
4336
{

0 commit comments

Comments
 (0)