Skip to content

Commit

Permalink
Move types that don't depend on template args our of spawn
Browse files Browse the repository at this point in the history
This was reported by the LDC developers as being the source of an ICE
we are seeing on Windows.
  • Loading branch information
Geod24 committed Jul 23, 2020
1 parent 5196f35 commit 1fe5ba1
Showing 1 changed file with 53 additions and 42 deletions.
95 changes: 53 additions & 42 deletions source/geod24/LocalRest.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module geod24.LocalRest;

static import C = geod24.concurrency;
import geod24.Serialization;
import std.datetime.systime : Clock, SysTime;
import std.format;
import std.meta : AliasSeq;
import std.traits : fullyQualifiedName, Parameters, ReturnType;
Expand Down Expand Up @@ -198,6 +199,58 @@ public class ClientException : Exception
}
}

/// Simple exception unwind the stack when we need to terminate/restart,
/// used by `spawn` but kept here as it doesn't depend on template parameters.
private final class ExitException : Exception
{
public bool restart;

this () @safe pure nothrow @nogc
{
super("You should never see this exception - please report a bug");
}
}

/// Wrapper for data inside of `spawn`, kept here as it doesn't
/// depend on template parameters
private struct Variant
{
pure nothrow @nogc:

public this (Response res) @trusted
{
this.res = res;
this.tag = 0;
}
public this (Command cmd) @trusted
{
this.cmd = cmd;
this.tag = 1;
}

union
{
Response res;
Command cmd;
}

public ubyte tag;
}

/// Used by `spawn` for recording current filtering / sleeping setting
private struct Control
{
public FilterAPI filter; // filter specific messages
public SysTime sleep_until; // sleep until this time
public bool drop; // drop messages if sleeping

public bool isSleeping() const @safe /* nothrow: Not on Windows (currTime) */
{
return this.sleep_until != SysTime.init
&& Clock.currTime < this.sleep_until;
}
}

/// Simple wrapper to deal with tuples
/// Vibe.d might emit a pragma(msg) when T.length == 0
private struct ArgWrapper (T...)
Expand Down Expand Up @@ -521,51 +574,9 @@ public final class RemoteAPI (API, alias S = VibeJSONSerializer!()) : API
C.Tid self, string file, int line, CtorParams!Implementation cargs)
nothrow
{
import std.datetime.systime : Clock, SysTime;
import std.algorithm : each;
import std.range;

/// Simple exception unwind the stack when we need to terminate/restart
static final class ExitException : Exception
{
bool restart;

this () @safe pure nothrow @nogc
{
super("You should never see this exception - please report a bug");
}
}

// very simple & limited variant, to keep it performant.
// should be replaced by a real Variant later
static struct Variant
{
this (Response res) { this.res = res; this.tag = 0; }
this (Command cmd) { this.cmd = cmd; this.tag = 1; }

union
{
Response res;
Command cmd;
}

ubyte tag;
}

// used for controling filtering / sleep
static struct Control
{
FilterAPI filter; // filter specific messages
SysTime sleep_until; // sleep until this time
bool drop; // drop messages if sleeping

bool isSleeping() const
{
return this.sleep_until != SysTime.init
&& Clock.currTime < this.sleep_until;
}
}

scope exc = new ExitException();

void runNode ()
Expand Down

0 comments on commit 1fe5ba1

Please sign in to comment.