Skip to content

Commit

Permalink
reduce error message from Roslyn analyser (lunditoph-siago#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieluna committed Mar 17, 2024
1 parent c71a9bc commit 5fd3343
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 7 deletions.
9 changes: 9 additions & 0 deletions Sia.CodeGenerators/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"DebugRoslynSourceGenerator": {
"commandName": "DebugRoslynComponent",
"targetProject": "../Sia.Examples/Sia.Examples.csproj"
}
}
}
8 changes: 2 additions & 6 deletions Sia.CodeGenerators/Sia.CodeGenerators.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>12.0</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>

Expand All @@ -15,10 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
</Project>
106 changes: 106 additions & 0 deletions Sia.Examples/Fail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Diagnostics;
using Sia;

namespace Sia_Examples;

public partial record struct Component1(int Value);

public partial record struct Component2(int Value);

public partial record struct Padding1();

public partial record struct Padding2();

public partial record struct Padding3();

public partial record struct Padding4();

public class Fail
{
private static TimeSpan _monoThreadElapsed;
private static TimeSpan _multiThreadElapsed;

[AfterSystem<MultiThreadUpdateSystem>]
public class DebugLogSystem()
: SystemBase(matcher: Matchers.Of<Component1, Component2>())
{
public override void Execute(World world, Scheduler scheduler, IEntityQuery query)
{
foreach (var entity in query) {
Console.WriteLine("Result: " + entity.Get<Component1>().Value);
}
}
}

public sealed class MonoThreadUpdateSystem()
: SystemBase(matcher: Matchers.Of<Component1, Component2>())
{
public override void Execute(World world, Scheduler scheduler, IEntityQuery query)
{
var watch = new Stopwatch();
watch.Start();

query.ForSlice((ref Component1 c1, ref Component2 c2) => {
c1.Value += c2.Value;
});

watch.Stop();
_monoThreadElapsed = watch.Elapsed;
}
}

public sealed class MultiThreadUpdateSystem()
: SystemBase(matcher: Matchers.Of<Component1, Component2>())
{
public override void Execute(World world, Scheduler scheduler, IEntityQuery query)
{
var watch = new Stopwatch();
watch.Start();

Console.WriteLine("taskCount: " + query.Count + ", Processor: " + Environment.ProcessorCount);

query.ForSliceOnParallel((ref Component1 c1, ref Component2 c2) => {
c1.Value += c2.Value;
});

watch.Stop();
_multiThreadElapsed = watch.Elapsed;
}
}

public static void Run(World world)
{
int entityCount = 100;
for (int i = 0; i < entityCount; ++i) {
switch (i % 4)
{
case 0:
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding1()));
break;

case 1:
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding2()));
break;

case 2:
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding3()));
break;

case 3:
world.CreateInArrayHost(Bundle.Create(new Component1(), new Component2 { Value = 1 }, new Padding4()));
break;
}
}

var schduler = new Scheduler();

SystemChain.Empty
.Add<MultiThreadUpdateSystem>()
.Add<DebugLogSystem>()
.RegisterTo(world, schduler);

schduler.Tick();

Console.WriteLine("MultiThread: " + _multiThreadElapsed);
}
}
1 change: 0 additions & 1 deletion Sia.Examples/Sia.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<PublishAot>true</PublishAot>
</PropertyGroup>

Expand Down
9 changes: 9 additions & 0 deletions Sia/Entities/Extensions/EntityQueryExtensions.Handle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,20 @@ static void Action(in HandleData<TData> data, (int, int) range)

while (true) {
var slotCount = host.Count;
<<<<<<< Updated upstream
if (remainingCount < slotCount) {
handler(host, data.UserData, slotIndex, slotIndex + remainingCount);
=======

var endIndex = slotIndex + remainingCount;
if (endIndex < slotCount) {
Console.WriteLine($"[{from}-{to}]A remainingCount: {remainingCount}, slotCount: {slotCount}, hostIndex: {hostIndex}, slotIndex: ({slotIndex}, {endIndex})");
handler(host, data.UserData, slotIndex, endIndex);
>>>>>>> Stashed changes
return;
}

Console.WriteLine($"[{from}-{to}]B remainingCount: {remainingCount}, slotCount: {slotCount}, hostIndex: {hostIndex}, slotIndex: ({slotIndex}, {slotCount - 1})");
handler(host, data.UserData, slotIndex, slotCount);
remainingCount -= slotCount;

Expand Down

0 comments on commit 5fd3343

Please sign in to comment.