[Issue 3122] New: [patch] Adding support for fast and reliable build tools to the frontend

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 1 10:28:12 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3122

           Summary: [patch] Adding support for fast and reliable build
                    tools to the frontend
           Product: D
           Version: 1.045
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch
          Severity: enhancement
          Priority: P3
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: h3r3tic at mat.uni.torun.pl


Created an attachment (id=410)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=410)
DMD frontend patch

Creating a reliable and fast build tool for D is a tricky business currently.
Bu[il]d gets away with partial parsing of D files and is reasonably fast, but
may miss some imports and doesn't guarantee proper incremental builds. ReBuild
parses the project's modules by using the DMD frontend on them, then figures
out which files to pass to the compiler. This approach may provide proper full
and partial builds, but is slow because of duplicating a lot of work.

Leonard Dahlmann and myself have been working on a build tool that achieves
both of these merits through a reasonable compromise. It requires a special
patch to the compiler so it emits dependencies between modules to a file during
the semantic analysis. This way it can track module dependencies and build
projects by usually only running the compiler once (twice in special cases).

Tracking module dependencies is critical, because when A imports B and its code
is conditionally generated upon some declarations in B, they both have to be
recompiled whenever B is changed.

The patch has already been included in LDC 0.9.1 and works great with the first
tool that can exploit the extra info the compiler provides thanks to it -
xfBuild ( http://wiki.team0xf.com/index.php?n=Tools.XfBuild ). Several people
have been testing it for more than a month with DMD as well on Linux and
Windows, using a custom-patched version of DMD. It's proving to be consistently
faster and more reliable than other build tools.

Summary of the diff:
The mars.c file is modified as to accept an additional switch "-deps=filename".
This is to specify the file to which module dependencies are written in the
following format ( the real work is done in import.c ):

----

ImportDeclaration
    ::= BasicImportDeclaration [ " : " ImportBindList ] [ " -> "
ModuleAliasIdentifier ] "\n"

BasicImportDeclaration
    ::= ModuleFullyQualifiedName " (" FilePath ") : " Protection " [ " static"
] : " ModuleFullyQualifiedName " (" FilePath ")"

FilePath
    - any string with '(', ')' and '\' escaped with the '\' character

The ImportBindList, ModuleAliasIdentifier, ModuleFullyQualifiedName
non-terminals are borrowed from
http://digitalmars.com/d/1.0/module.html#ImportDeclaration with the exception
of not allowing whitespace between substitution symbols

----

For example:

mod.ModA (mod\\ModA.d) : public : object
(c:\\prog\\dmd\\bin\\..\\import\\object.di)
mod.ModCommon (mod\\ModCommon.d) : public : object
(c:\\prog\\dmd\\bin\\..\\import\\object.di)
mod.ModA (mod\\ModA.d) : public : mod.ModCommon (mod\\ModCommon.d)
aliasedSelectiveImport (aliasedSelectiveImport.d) : public :
tango.text.convert.Integer
(c:\\prog\\dmd\\bin\\..\\import\\tango\\text\\convert\\Integer.d) :
parse,toString32 -> Integer

----

The patch I've attached is Public Domain. It can be applied to DMD's source by
running:
> patch -p0 -ui dmdDiff.patch
in the dmd/src directory, assuming DMD sources are in dmd/src/dmd. It's created
against DMD 1.045. It might be necessary to run 'dos2unix' on the files to be
patched (import.c, mars.c, mars.h) if doing it on a *nix.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list