Skip to content

Commit

Permalink
Make all fbcode D code compatible with dmd 2.068.0
Browse files Browse the repository at this point in the history
Summary:
Upgrade internal code to dmd 2.068.0

Test Plan: fbconfig && fbmake dev && fbmake t every TARGETS file in the repo that contains a d_binary, d_library, or d_unittest build rule.

Reviewed By: david.soriaparra@oculus.com

Subscribers: trunkagent, exa, rhysparry, agallagher, fbcode-common-diffs@, net-systems-diffs@, alandau, bmatheny, louisk, darshan, yfeldblum, ttung, markisaa, yogeshwer, ldbrandy

FB internal diff: D2362521

Tasks: 8184731, 8069629

Signature: t1:2362521:1441129467:88fcdaca3a1779dd603bd429bb41568e7e97e9b4
  • Loading branch information
plapukhov authored and Haijun Zhu committed Nov 20, 2015
1 parent 77de741 commit aee392c
Show file tree
Hide file tree
Showing 28 changed files with 139 additions and 121 deletions.
12 changes: 6 additions & 6 deletions thrift/lib/d/thrift/async/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
* Defines the interface used for client-side handling of asynchronous
* I/O operations, based on coroutines.
*
* The main piece of the »client side« (e.g. for TAsyncClient users) of the
* The main piece of the >>client side<< (e.g. for TAsyncClient users) of the
* API is TFuture, which represents an asynchronously executed operation,
* which can have a return value, throw exceptions, and which can be waited
* upon.
*
* On the »implementation side«, the idea is that by using a TAsyncTransport
* On the >>implementation side<<, the idea is that by using a TAsyncTransport
* instead of a normal TTransport and executing the work through a
* TAsyncManager, the same code as for synchronous I/O can be used for
* asynchronous operation as well, for example:
*
* ---
* auto socket = new TAsyncSocket(someTAsyncSocketManager(), host, port);
* //
* // ...
* socket.asyncManager.execute(socket, {
* SomeThriftStruct s;
*
Expand Down Expand Up @@ -65,7 +65,7 @@ import thrift.util.cancellation;
* while waiting for time-consuming operations.
*
* The second important purpose of TAsyncManager is to serialize access to
* the transport resources without taking care of that, e.g. issuing multiple
* the transport resources - without taking care of that, e.g. issuing multiple
* RPC calls over the same connection in rapid succession would likely lead to
* more than one request being written at the same time, causing only garbage
* to arrive at the remote end.
Expand All @@ -76,7 +76,7 @@ interface TAsyncManager {
/**
* Submits a work item to be executed asynchronously.
*
* Access to asnyc transports is serialized if two work items associated
* Access to asnyc transports is serialized - if two work items associated
* with the same transport are submitted, the second delegate will not be
* invoked until the first has returned, even it the latter context-switches
* away (because it is waiting for I/O) and the async manager is idle
Expand Down Expand Up @@ -125,7 +125,7 @@ interface TAsyncManager {
*
* Example:
* ---
* // A very basic example usually, the actuall work item would enqueue
* // A very basic example - usually, the actuall work item would enqueue
* // some async transport operation.
* auto asyncMangager = someAsyncManager();
*
Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/d/thrift/async/libevent.d
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TLibeventAsyncManager : TAsyncSocketManager {

ensureWorkerThreadRunning();

// We should be able to send the control message as a whole we currently
// We should be able to send the control message as a whole - we currently
// assume to be able to receive it at once as well. If this proves to be
// unstable (e.g. send could possibly return early if the receiving buffer
// is full and the blocking call gets interrupted by a signal), it could
Expand Down
4 changes: 2 additions & 2 deletions thrift/lib/d/thrift/async/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class TAsyncSocket : TSocketBase, TAsyncTransport {
Address addr;
try {
// Currently, we just go with the first address returned, could be made
// more intelligent though IPv6?
// more intelligent though - IPv6?
addr = getAddress(host_, port_)[0];
} catch (Exception e) {
throw new TTransportException(`Unable to resolve host "` ~ host_ ~ `".`,
Expand Down Expand Up @@ -301,7 +301,7 @@ private:
}

auto fiber = Fiber.getThis();
assert(fiber, "Current fiber null not running in TAsyncManager?");
assert(fiber, "Current fiber null - not running in TAsyncManager?");
TAsyncEventReason eventReason = void;
asyncManager_.addOneshotListener(socket_, eventType, timeout,
scopedDelegate((TAsyncEventReason reason) {
Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/d/thrift/async/ssl.d
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private:
*
* Typically used with TAsyncClient. As an unfortunate consequence of the
* async client design, the passed transports cannot be statically verified to
* be of type TAsyncSocket. Instead, the type is verified at runtime if a
* be of type TAsyncSocket. Instead, the type is verified at runtime - if a
* transport of an unexpected type is passed to getTransport(), it fails,
* throwing a TTransportException.
*
Expand Down
9 changes: 5 additions & 4 deletions thrift/lib/d/thrift/codegen/async_client.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
module thrift.codegen.async_client;

import std.algorithm : join;
import std.algorithm : joiner;
import std.conv : text, to;
import std.traits : ParameterStorageClass, ParameterStorageClassTuple,
ParameterTypeTuple, ReturnType;
Expand Down Expand Up @@ -208,7 +208,7 @@ template TAsyncClient(Interface, InputProtocol = TProtocol, OutputProtocol = voi

immutable returnTypeCode = "ReturnType!(Interface." ~ methodName ~ ")";
code ~= "TFuture!(" ~ returnTypeCode ~ ") " ~ methodName ~ "(" ~
join(paramList, ",") ~ ") {\n";
joiner(paramList, ",").text ~ ") {\n";

// Create the future instance that will repesent the result.
code ~= "auto promise = new TPromise!(" ~ returnTypeCode ~ ");\n";
Expand All @@ -218,11 +218,12 @@ template TAsyncClient(Interface, InputProtocol = TProtocol, OutputProtocol = voi
code ~= "try {\n";
code ~= "static if (is(ReturnType!(Interface." ~ methodName ~
") == void)) {\n";
code ~= "client_." ~ methodName ~ "(" ~ join(paramNames, ",") ~ ");\n";
code ~= "client_." ~ methodName ~ "(" ~ joiner(paramNames, ",").text ~
");\n";
code ~= "promise.succeed();\n";
code ~= "} else {\n";
code ~= "auto result = client_." ~ methodName ~ "(" ~
join(paramNames, ",") ~ ");\n";
joiner(paramNames, ",").text ~ ");\n";
code ~= "promise.succeed(result);\n";
code ~= "}\n";
code ~= "} catch (Exception e) {\n";
Expand Down
12 changes: 6 additions & 6 deletions thrift/lib/d/thrift/codegen/async_client_pool.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* TAsyncClient.
*
* Terminology note: The names of the artifacts defined in this module are
* derived from »client pool«, because they operate on a pool of
* derived from >>client pool<<, because they operate on a pool of
* TAsyncClients. However, from a architectural point of view, they often
* represent a pool of hosts a Thrift client application communicates with
* using RPC calls.
Expand Down Expand Up @@ -110,7 +110,7 @@ static this() {
* A TAsyncClientPoolBase implementation which queries multiple servers in a
* row until a request succeeds, the result of which is then returned.
*
* The definition of »success« can be customized using the rpcFaultFilter()
* The definition of >>success<< can be customized using the rpcFaultFilter()
* delegate property. If it is non-null and calling it for an exception set by
* a failed method invocation returns true, the error is considered to be
* caused by the RPC layer rather than the application layer, and the next
Expand Down Expand Up @@ -332,7 +332,7 @@ private {
* A TAsyncClientPoolBase implementation which queries multiple servers at
* the same time and returns the first success response.
*
* The definition of »success« can be customized using the rpcFaultFilter()
* The definition of >>success<< can be customized using the rpcFaultFilter()
* delegate property. If it is non-null and calling it for an exception set by
* a failed method invocation returns true, the error is considered to be
* caused by the RPC layer rather than the application layer, and the next
Expand Down Expand Up @@ -599,7 +599,7 @@ private {
* byte[] bar();
* }
*
* // Create the aggregator pool client0, client1, client2 are some
* // Create the aggregator pool - client0, client1, client2 are some
* // TAsyncClient!Foo instances, but in theory could also be other
* // TFutureInterface!Foo implementations (e.g. some async client pool).
* auto pool = new TAsyncAggregator!Foo([client0, client1, client2]);
Expand Down Expand Up @@ -634,8 +634,8 @@ private {
* pragma(msg, typeof(pool.bar().accumulate().get())); // byte[].
* ---
*
* Note: For the accumulate!() interface, you might currently hit a »cannot use
* local '' as parameter to non-global template accumulate«-error, see
* Note: For the accumulate!() interface, you might currently hit a >>cannot use
* local '...' as parameter to non-global template accumulate<<-error, see
* $(DMDBUG 5710, DMD issue 5710). If your accumulator function does not need
* to access the surrounding scope, you might want to use a function literal
* instead of a delegate to avoid the issue.
Expand Down
55 changes: 32 additions & 23 deletions thrift/lib/d/thrift/codegen/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct TParamMeta {
* Compile-time metadata for a service method exception annotation.
*/
struct TExceptionMeta {
/// The name of the exception »return value«. Contrary to TFieldMeta, it
/// The name of the exception >>return value<<. Contrary to TFieldMeta, it
/// only serves decorative purposes here, as it is only used in code not
/// visible to processor implementations/service clients.
string name;
Expand Down Expand Up @@ -253,7 +253,7 @@ template BaseService(T) if (isDerivedService!T) {
/**
* Mixin template defining additional helper methods for using a struct with
* Thrift, and a member called isSetFlags if the struct contains any fields
* for which an »is set« flag is needed.
* for which an >>is set<< flag is needed.
*
* It can only be used inside structs or Exception classes.
*
Expand Down Expand Up @@ -399,7 +399,8 @@ mixin template TStructHelpers(alias fieldMetaData = cast(TFieldMeta[])null) if (
) {
static if (isNullable!(MemberType!(This, fieldName))) {
return __traits(getMember, this, fieldName) !is null;
} else static if (is(typeof(mixin("this.isSetFlags." ~ fieldName)) : bool)) {
} else static if
(is(typeof(mixin("this.isSetFlags." ~ fieldName)) : bool)) {
return __traits(getMember, this.isSetFlags, fieldName);
} else {
// This is a required field, which is always set.
Expand Down Expand Up @@ -442,7 +443,8 @@ mixin template TStructHelpers(alias fieldMetaData = cast(TFieldMeta[])null) if (
} else {
code ~= "result ~= `, `;\n";
}
code ~= "result ~= `" ~ name ~ ": ` ~ to!string(cast()this." ~ name ~ ");\n";
code ~= "result ~= `" ~ name ~ ": ` ~ to!string(cast()this." ~ name
~ ");\n";
code ~= "if (!isSet!q{" ~ name ~ "}) {\n";
code ~= "result ~= ` (unset)`;\n";
code ~= "}\n";
Expand All @@ -460,17 +462,20 @@ mixin template TStructHelpers(alias fieldMetaData = cast(TFieldMeta[])null) if (
return true;
}

static if (canFind!`!a.defaultValue.empty`(mergeFieldMeta!(This, fieldMetaData))) {
static if
(canFind!`!a.defaultValue.empty`(mergeFieldMeta!(This, fieldMetaData))) {
static if (is(This __ == class)) {
this() {
mixin(thriftFieldInitCode!(mergeFieldMeta!(This, fieldMetaData))("this"));
mixin(thriftFieldInitCode!(
mergeFieldMeta!(This, fieldMetaData))("this"));
}
} else {
// DMD @@BUG@@: Have to use auto here to avoid »no size yet for forward
// reference« errors.
// DMD @@BUG@@: Have to use auto here to avoid >>no size yet for forward
// reference<< errors.
static auto opCall() {
auto result = This.init;
mixin(thriftFieldInitCode!(mergeFieldMeta!(This, fieldMetaData))("result"));
mixin(thriftFieldInitCode!(
mergeFieldMeta!(This, fieldMetaData))("result"));
return result;
}
}
Expand Down Expand Up @@ -502,8 +507,8 @@ string thriftFieldInitCode(alias fieldMeta)(string thisName) {
}

version (unittest) {
// Cannot make this nested in the unittest block due to a »no size yet for
// forward reference« error.
// Cannot make this nested in the unittest block due to a >>no size yet for
// forward reference<< error.
struct Foo {
string a;
int b;
Expand Down Expand Up @@ -536,7 +541,7 @@ unittest {
* Generates an eponymous struct with boolean flags for the non-required
* non-nullable fields of T.
*
* Nullable fields are just set to null to signal »not set«, so no flag is
* Nullable fields are just set to null to signal >>not set<<, so no flag is
* emitted for them, even if they are optional.
*
* In most cases, you do not want to use this directly, but via TStructHelpers
Expand All @@ -549,11 +554,13 @@ template TIsSetFlags(T, alias fieldMetaData) {
code ~= "static if (!is(MemberType!(T, `" ~ meta.name ~ "`))) {\n";
code ~= q{
static assert(false, "Field '" ~ meta.name ~
"' referenced in metadata not present in struct '" ~ T.stringof ~ "'.");
"' referenced in metadata not present in struct '" ~ T.stringof ~
"'.");
};
code ~= "}";
if (meta.req == TReq.OPTIONAL || meta.req == TReq.OPT_IN_REQ_OUT) {
code ~= "else static if (!isNullable!(MemberType!(T, `" ~ meta.name ~ "`))) {\n";
code ~= "else static if (!isNullable!(MemberType!(T, `" ~ meta.name ~
"`))) {\n";
code ~= " bool " ~ meta.name ~ ";\n";
code ~= "}\n";
}
Expand Down Expand Up @@ -638,7 +645,8 @@ void readStruct(T, Protocol, alias fieldMetaData = cast(TFieldMeta[])null,
readValueCode!K(key, level + 1) ~ "\n" ~
"typeof(" ~ v ~ ".values[0]) " ~ value ~ ";\n" ~
readValueCode!V(value, level + 1) ~ "\n" ~
v ~ "[cast(typeof(" ~ v ~ ".keys[0]))" ~ key ~ "] = " ~ value ~ ";\n" ~
v ~ "[cast(typeof(" ~ v ~ ".keys[0]))" ~ key ~ "] = " ~ value ~
";\n" ~
"}\n" ~
"p.readMapEnd();" ~
"}";
Expand Down Expand Up @@ -705,7 +713,7 @@ void readStruct(T, Protocol, alias fieldMetaData = cast(TFieldMeta[])null,
/// Code for the case statements storing the fields to the result struct.
string readMembersCode = "";

// The last automatically assigned id fields with no meta information
// The last automatically assigned id - fields with no meta information
// are assigned (in lexical order) descending negative ids, starting with
// -1, just like the Thrift compiler does.
short lastId;
Expand Down Expand Up @@ -780,10 +788,11 @@ void writeStruct(T, Protocol, alias fieldMetaData = cast(TFieldMeta[])null,
}

// Check that required nullable members are non-null.
// WORKAROUND: To stop LDC from emitting the manifest constant »meta« below
// into the writeStruct function body this is inside the string mixin
// block – the code wouldn't depend on it (this is an LDC bug, and because
// of it a new array would be allocated on each method invocation at runtime).
// WORKAROUND: To stop LDC from emitting the manifest constant >>meta<<
// below into the writeStruct function body this is inside the string mixin
// block - the code wouldn't depend on it (this is an LDC bug, and because
// of it a new array would be allocated on each method invocation
// at runtime).
foreach (name; StaticFilter!(
Compose!(isNullable, PApply!(MemberType, T)),
FieldNames!T
Expand Down Expand Up @@ -880,7 +889,7 @@ void writeStruct(T, Protocol, alias fieldMetaData = cast(TFieldMeta[])null,
return code;
}

// The last automatically assigned id fields with no meta information
// The last automatically assigned id - fields with no meta information
// are assigned (in lexical order) descending negative ids, starting with
// -1, just like the Thrift compiler does.
short lastId;
Expand All @@ -893,8 +902,8 @@ void writeStruct(T, Protocol, alias fieldMetaData = cast(TFieldMeta[])null,
if (meta.empty) {
--lastId;
version (TVerboseCodegen) {
code ~= "pragma(msg, `[thrift.codegen.base.writeStruct] Warning: No " ~
"meta information for field '" ~ name ~ "' in struct '" ~
code ~= "pragma(msg, `[thrift.codegen.base.writeStruct] Warning: No "
~ "meta information for field '" ~ name ~ "' in struct '" ~
T.stringof ~ "'. Assigned id: " ~ to!string(lastId) ~ ".`);\n";
}
code ~= writeFieldCode!F(name, lastId, req);
Expand Down
20 changes: 10 additions & 10 deletions thrift/lib/d/thrift/codegen/client.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
module thrift.codegen.client;

import std.algorithm : find, join;
import std.algorithm : find, joiner;
import std.array : empty, front;
import std.conv : to;
import std.conv : to, text;
import std.traits : isSomeFunction, ParameterStorageClass,
ParameterStorageClassTuple, ParameterTypeTuple, ReturnType;
import thrift.codegen.base;
Expand Down Expand Up @@ -98,7 +98,7 @@ template TClient(Interface, InputProtocol = TProtocol, OutputProtocol = void) if
}

// DMD @@BUG@@: If these are not present in this class (would be)
// inherited anyway, »not implemented« errors are raised.
// inherited anyway, >>not implemented<< errors are raised.
override IProt inputProtocol() @property {
return super.inputProtocol;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ template TClient(Interface, InputProtocol = TProtocol, OutputProtocol = void) if
string[] paramList;
string paramAssignCode;
foreach (i, _; ParameterTypeTuple!(mixin("Interface." ~ methodName))) {
// Use the param name speficied in the meta information if any
// Use the param name specified in the meta information if any -
// just cosmetics in this case.
string paramName;
if (methodMetaFound && i < methodMeta.params.length) {
Expand All @@ -175,7 +175,7 @@ template TClient(Interface, InputProtocol = TProtocol, OutputProtocol = void) if
paramAssignCode ~= "args." ~ paramName ~ " = &" ~ paramName ~ ";\n";
}
code ~= "ReturnType!(Interface." ~ methodName ~ ") " ~ methodName ~
"(" ~ join(paramList, ", ") ~ ") {\n";
"(" ~ joiner(paramList, ", ").text ~ ") {\n";

code ~= "immutable methodName = `" ~ methodName ~ "`;\n";

Expand Down Expand Up @@ -321,7 +321,7 @@ template TPargsStruct(Interface, string methodName) {
string[] fieldMetaCodes;
foreach (i, _; ParameterTypeTuple!(mixin("Interface." ~ methodName))) {
// If we have no meta information, just use param1, param2, etc. as
// field names, it shouldn't really matter anyway. 1-based »indexing«
// field names, it shouldn't really matter anyway. 1-based >>indexing<<
// is used to match the common scheme in the Thrift world.
string memberId;
string memberName;
Expand Down Expand Up @@ -355,8 +355,8 @@ template TPargsStruct(Interface, string methodName) {
}
}
code ~= "void write(P)(P proto) const if (isTProtocol!P) {\n";
code ~= "writeStruct!(typeof(this), P, [" ~ join(fieldMetaCodes, ", ") ~
"], true)(this, proto);\n";
code ~= "writeStruct!(typeof(this), P, [" ~
joiner(fieldMetaCodes, ", ").text ~ "], true)(this, proto);\n";
code ~= "}\n";
code ~= "}\n";
return code;
Expand Down Expand Up @@ -474,8 +474,8 @@ template TPresultStruct(Interface, string methodName) {
};

code ~= "void read(P)(P proto) if (isTProtocol!P) {\n";
code ~= "readStruct!(typeof(this), P, [" ~ join(fieldMetaCodes, ", ") ~
"], true)(this, proto);\n";
code ~= "readStruct!(typeof(this), P, [" ~
joiner(fieldMetaCodes, ", ").text ~ "], true)(this, proto);\n";
code ~= "}\n";
code ~= "}\n";
return code;
Expand Down
Loading

0 comments on commit aee392c

Please sign in to comment.