Official compiler
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 25 17:27:01 PST 2016
On Fri, 26 Feb 2016 00:48:15 +0100, Xavier Bigand wrote:
> Is dmd multi-threaded?
Not at present.
It should be relatively easy to parallelize IO and parsing, at least in
theory. I think IO parallelism was removed with the ddmd switch, maybe?
But you'd have to identify the files you need to read in advance, so
that's not as straightforward.
D's metaprogramming is too complex for a 100% solution for parallelizing
semantic analysis on a module level. But you could create a partial
solution:
* After parsing, look for unconditional imports. Skip static if/else
blocks, skip template bodies, but grab everything else.
* Make a module dependency graph from that.
* Map each module to a task.
* Merge dependency cycles into single tasks. You now have a DAG.
* While there are any tasks in the graph:
- Find all leaf tasks in the graph.
- Run semantic analysis on them in parallel.
When you encounter a conditional or mixed in import, you can insert it
into the DAG if it's not already there, but it would be simpler just to
run analysis right then and there.
Alternatively, you can find regular and conditional imports and try to
use them all. But this requires you to hold errors until you're certain
that the module is used, and you end up doing more work overall. And that
could be *tons* more work. Consider:
module a;
enum data = import("ten_million_records.csv");
mixin(createClassesFromData(data));
module b;
enum shouldUseModuleA = false;
module c;
import b;
static if (shouldUseModuleA) import a;
And even if you ignored that, you'd still have to deal with mixed in
imports, which can be the result of arbitrarily complex CTFE expressions.
While all of this is straightforward in theory, it probably isn't so
simple in practice.
More information about the Digitalmars-d
mailing list