Skip to content

Commit

Permalink
Enable the fancy version of -preview=in
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 committed Oct 4, 2020
1 parent e61fc7b commit a524198
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 108 deletions.
1 change: 0 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"buildRequirements": [ "allowWarnings" ],

"toolchainRequirements": {
"dmd": "no",
"gdc": "no",
"ldc": "~>1.19"
},
Expand Down
2 changes: 1 addition & 1 deletion source/agora/common/BitField.d
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public struct BitField (T = uint)
}

/// Compare BitField of same length
public bool opEquals (OtherT) (const auto ref BitField!OtherT other) const
public bool opEquals (OtherT) (in BitField!OtherT other) const
{
// Always do the comparison from the PoV of the BitField with
// the largest data type
Expand Down
23 changes: 11 additions & 12 deletions source/agora/common/Config.d
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public GetoptResult parseCommandLine (ref CommandLine cmdline, string[] args)
*******************************************************************************/

public Config parseConfigFile (ref const CommandLine cmdln)
public Config parseConfigFile (in CommandLine cmdln)
{
Node root = Loader.fromFile(cmdln.config_path).load();
return parseConfigImpl(cmdln, root);
Expand Down Expand Up @@ -277,7 +277,7 @@ network:
}

/// ditto
private Config parseConfigImpl (ref const CommandLine cmdln, Node root)
private Config parseConfigImpl (in CommandLine cmdln, Node root)
{
const(string)[] parseSequence (string section, bool optional = false)
{
Expand Down Expand Up @@ -325,7 +325,7 @@ private Config parseConfigImpl (ref const CommandLine cmdln, Node root)
}

/// Parse the node config section
private NodeConfig parseNodeConfig (Node* node, const ref CommandLine cmdln)
private NodeConfig parseNodeConfig (Node* node, in CommandLine cmdln)
{
auto min_listeners = get!(size_t, "node", "min_listeners")(cmdln, node);
auto max_listeners = get!(size_t, "node", "max_listeners")(cmdln, node);
Expand Down Expand Up @@ -444,7 +444,7 @@ validator:
}

/// Parse the banman config section
private BanManager.Config parseBanManagerConfig (Node* node, const ref CommandLine cmdln)
private BanManager.Config parseBanManagerConfig (Node* node, in CommandLine cmdln)
{
BanManager.Config conf;
conf.max_failed_requests = get!(size_t, "banman", "max_failed_requests")(cmdln, node);
Expand All @@ -465,7 +465,7 @@ private BanManager.Config parseBanManagerConfig (Node* node, const ref CommandLi
*******************************************************************************/

private LoggingConfig parseLoggingSection (Node* ptr, const ref CommandLine c)
private LoggingConfig parseLoggingSection (Node* ptr, in CommandLine c)
{
LoggingConfig ret;
ret.level = get!(LogLevel, "logging", "level")(c, ptr);
Expand Down Expand Up @@ -512,7 +512,7 @@ logging:

/// Optionally get a value
private T opt (T, string section, string name) (
const ref CommandLine cmdln, Node* node, lazy T def = T.init)
in CommandLine cmdln, Node* node, lazy T def = T.init)
{
try
return get!(T, section, name)(cmdln, node);
Expand All @@ -521,15 +521,14 @@ private T opt (T, string section, string name) (
}

/// Helper function to get a config parameter
private T get (T, string section, string name) (
const ref CommandLine cmdln, Node* node)
private T get (T, string section, string name) (in CommandLine cmdln, Node* node)
{
return get!(T, section, name, (string val) => val.to!T)(cmdln, node);
}

/// Helper function to get a config parameter with a conversion routine
private T get (T, string section, string name, alias conv)
(const ref CommandLine cmdl, Node* node)
(in CommandLine cmdl, Node* node)
{
static immutable QualifiedName = (section ~ "." ~ name);

Expand All @@ -556,7 +555,7 @@ private T get (T, string section, string name, alias conv)

/// Helper function to get a config parameter with a converter
private auto get (string section, string name, Converter) (
const ref CommandLine cmdl, Node* node, scope Converter converter)
in CommandLine cmdl, Node* node, scope Converter converter)
{
return converter(get!(ParameterType!convert, section, name)(cmdl, node));
}
Expand Down Expand Up @@ -608,7 +607,7 @@ public SCPQuorumSet toSCPQuorumSet ( in QuorumConfig quorum_conf ) @safe nothrow
*******************************************************************************/

public QuorumConfig toQuorumConfig (const ref SCPQuorumSet scp_quorum)
public QuorumConfig toQuorumConfig (in SCPQuorumSet scp_quorum)
@safe nothrow
{
import std.conv;
Expand Down Expand Up @@ -664,7 +663,7 @@ unittest
*******************************************************************************/

private EventHandlerConfig parserEventHandlers (Node* node, const ref CommandLine c)
private EventHandlerConfig parserEventHandlers (Node* node, in CommandLine c)
{
if (node is null)
return EventHandlerConfig.init;
Expand Down
16 changes: 7 additions & 9 deletions source/agora/common/Hash.d
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public alias Hash = agora.common.Types.Hash;
public alias Signature = agora.common.Types.Signature;

/// Type of delegate passed to `hash` function when there's a state
public alias HashDg = void delegate(scope const(ubyte)[]) /*pure*/ nothrow @safe @nogc;
public alias HashDg = void delegate(in ubyte[]) /*pure*/ nothrow @safe @nogc;


/*******************************************************************************
Expand All @@ -109,8 +109,7 @@ public alias HashDg = void delegate(scope const(ubyte)[]) /*pure*/ nothrow @safe
*******************************************************************************/

public Hash hashFull (T) (scope const auto ref T record)
nothrow @nogc @trusted
public Hash hashFull (T) (in T record) nothrow @nogc @trusted
{
Hash hash = void;
crypto_generichash_state state;
Expand All @@ -123,8 +122,7 @@ public Hash hashFull (T) (scope const auto ref T record)
}

/// Ditto
public void hashPart (T) (scope const auto ref T record, scope HashDg state)
/*pure*/ nothrow @nogc
public void hashPart (T) (in T record, scope HashDg state) /*pure*/ nothrow @nogc
if (is(T == struct))
{
static if (is(typeof(T.init.computeHash(HashDg.init))))
Expand Down Expand Up @@ -161,20 +159,20 @@ public void hashPart (ulong record, scope HashDg state) /*pure*/ nothrow @nogc @
}

/// Ditto
public void hashPart (scope const(char)[] record, scope HashDg state) /*pure*/ nothrow @nogc @trusted
public void hashPart (in char[] record, scope HashDg state) /*pure*/ nothrow @nogc @trusted
{
state(cast(const ubyte[])record);
}

/// Ditto
public void hashPart (scope const(ubyte)[] record, scope HashDg state)
public void hashPart (in ubyte[] record, scope HashDg state)
/*pure*/ nothrow @nogc @safe
{
state(record);
}

/// Ditto
public void hashPart (T) (scope const auto ref T[] records, scope HashDg state)
public void hashPart (T) (in T[] records, scope HashDg state)
/*pure*/ nothrow @nogc @safe
{
foreach (ref record; records)
Expand Down Expand Up @@ -236,7 +234,7 @@ nothrow @nogc @safe unittest
*******************************************************************************/

public Hash hashMulti (T...)(auto ref T args) nothrow @nogc @safe
public Hash hashMulti (T...)(in T args) nothrow @nogc @safe
{
Hash hash = void;
crypto_generichash_state state;
Expand Down
18 changes: 8 additions & 10 deletions source/agora/common/Serializer.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
struct Foo
{
static T fromBinary (T) (scope DeserializeDg data,
scope const ref DeserializerOptions) @safe;
in DeserializerOptions) @safe;
}
---
The deserializer might request an instance of a `const` or `immutable`
Expand Down Expand Up @@ -156,7 +156,7 @@ unittest
}

static QT fromBinary (QT) (
scope DeserializeDg dg, const ref DeserializerOptions opts)
scope DeserializeDg dg, in DeserializerOptions opts)
@safe
{
// One need to use temporary values for this,
Expand Down Expand Up @@ -218,7 +218,7 @@ unittest
ubyte[] data;

public static QT fromBinary (QT) (
scope DeserializeDg dg, const ref DeserializerOptions opts) @safe
scope DeserializeDg dg, in DeserializerOptions opts) @safe
{
// The following is incorrect because it doesn't account for
// type constructors (e.g. `immutable`).
Expand Down Expand Up @@ -298,8 +298,7 @@ private enum hasFromBinaryFunction (T) = is(T == struct)
*******************************************************************************/

public ubyte[] serializeToBuffer (T) (scope const auto ref T record,
scope return ref ubyte[] buffer)
public ubyte[] serializeToBuffer (T) (in T record, scope return ref ubyte[] buffer)
@safe
{
buffer.length = 0;
Expand Down Expand Up @@ -360,8 +359,7 @@ unittest
*******************************************************************************/

public ubyte[] serializeFull (T) (scope const auto ref T record)
@safe
public ubyte[] serializeFull (T) (in T record) @safe
{
ubyte[] buffer;
return serializeToBuffer(record, buffer);
Expand Down Expand Up @@ -403,7 +401,7 @@ unittest
}

/// Ditto
public void serializePart (T) (scope const auto ref T record, scope SerializeDg dg,
public void serializePart (T) (in T record, scope SerializeDg dg,
CompactMode compact = CompactMode.Yes)
@safe
{
Expand Down Expand Up @@ -593,7 +591,7 @@ public T deserializeFull (T) (scope const(ubyte)[] data) @safe

/// Ditto
public T deserializeFull (T) (scope DeserializeDg dg,
const ref DeserializerOptions opts = DeserializerOptions.Default) @safe
in DeserializerOptions opts = DeserializerOptions.Default) @safe
{
// Custom deserialization trumps everything
static if (hasFromBinaryFunction!T)
Expand Down Expand Up @@ -1029,7 +1027,7 @@ public void testSymmetry (T) (auto ref T value = T.init)
}

/// Ditto
private void testSymmetryImpl (T) (const auto ref T value, string typename)
private void testSymmetryImpl (T) (in T value, string typename)
{
import std.stdio;

Expand Down
24 changes: 9 additions & 15 deletions source/agora/common/crypto/ECC.d
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public struct Scalar
***************************************************************************/

public void toString (scope void delegate(const(char)[]) @safe sink,
public void toString (scope void delegate(in char[]) @safe sink,
PrintMode mode = PrintMode.Obfuscated) const @safe
{
final switch (mode)
Expand Down Expand Up @@ -147,13 +147,13 @@ public struct Scalar
}

/// Vibe.d deserialization
public static Scalar fromString (scope const(char)[] str) @safe
public static Scalar fromString (in char[] str) @safe
{
return Scalar(typeof(this.data).fromString(str));
}

/// Operator overloads for `+`, `-`, `*`
public Scalar opBinary (string op)(const scope auto ref Scalar rhs)
public Scalar opBinary (string op)(in Scalar rhs)
const nothrow @nogc @trusted
{
Scalar result = void;
Expand Down Expand Up @@ -307,7 +307,7 @@ public struct Point
}

/// Expose `toString`
public void toString (scope void delegate(const(char)[]) @safe dg)
public void toString (scope void delegate(in char[]) @safe dg)
const @safe
{
this.data.toString(dg);
Expand All @@ -320,13 +320,13 @@ public struct Point
}

/// Vibe.d deserialization
public static Point fromString (scope const(char)[] str) @safe
public static Point fromString (in char[] str) @safe
{
return Point(typeof(this.data).fromString(str));
}

/// Operator overloads for points additions
public Point opBinary (string op)(const scope auto ref Point rhs)
public Point opBinary (string op)(in Point rhs)
const nothrow @nogc @trusted
if (op == "+" || op == "-")
{
Expand All @@ -348,7 +348,7 @@ public struct Point
}

/// Operator overloads for scalar multiplication
public Point opBinary (string op)(const scope auto ref Scalar rhs)
public Point opBinary (string op)(in Scalar rhs)
const nothrow @nogc @trusted
if (op == "*")
{
Expand All @@ -360,7 +360,7 @@ public struct Point
}

/// Ditto
public Point opBinaryRight (string op)(const scope auto ref Scalar lhs)
public Point opBinaryRight (string op)(in Scalar lhs)
const nothrow @nogc @trusted
if (op == "*")
{
Expand All @@ -378,13 +378,7 @@ public struct Point
}

/// Support for comparison
public int opCmp (ref const typeof(this) s) const
{
return this.data.opCmp(s.data);
}

/// Support for comparison (rvalue overload)
public int opCmp (const typeof(this) s) const
public int opCmp (in typeof(this) s) const
{
return this.data.opCmp(s.data);
}
Expand Down
13 changes: 5 additions & 8 deletions source/agora/common/crypto/Schnorr.d
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,29 @@ unittest
}

/// Single-signer trivial API
public Signature sign (T) (const ref Pair kp, auto ref T data)
public Signature sign (T) (const ref Pair kp, in T data)
nothrow @nogc @safe
{
const R = Pair.random();
return sign!T(kp.v, kp.V, R.V, R.v, data);
}

/// Single-signer privkey API
public Signature sign (T) (const ref Scalar privateKey, T data)
public Signature sign (T) (in Scalar privateKey, T data)
nothrow @nogc @safe
{
const R = Pair.random();
return sign!T(privateKey, privateKey.toPoint(), R.V, R.v, data);
}

/// Sign with a given `r` (warning: `r` should never be reused with `x`)
public Signature sign (T) (const ref Pair kp, const ref Pair r, auto ref T data)
public Signature sign (T) (in Pair kp, in Pair r, in T data)
{
return sign!T(kp.v, kp.V, r.V, r.v, data);
}

/// Complex API, allow multisig
public Signature sign (T) (
const ref Scalar x, const ref Point X,
const ref Point R, const ref Scalar r,
auto ref T data)
public Signature sign (T) (in Scalar x, in Point X, in Point R, in Scalar r, in T data)
nothrow @nogc @trusted
{
/*
Expand Down Expand Up @@ -238,7 +235,7 @@ public Signature sign (T) (
*******************************************************************************/

public bool verify (T) (const ref Point X, const ref Signature sig, auto ref T data)
public bool verify (T) (in Point X, in Signature sig, in T data)
nothrow @nogc @trusted
{
Sig s = Sig.fromBlob(sig);
Expand Down
Loading

0 comments on commit a524198

Please sign in to comment.