Last update September 8, 2012

Language Devel / DIPs /

DIP13: Import path binding

Title:Import path binding
Last Modified:2011-10-18
Author:Martin Nowak
Links:Split off from DIP11


Allow to use specific import paths for selected modules or packages.


The proposal increases the flexibility of directory layouts w.r.t. the package system. It decouples the package hierarchy from a fixed directory layout. It is a requirement to do virtual imports based on URLs.


The feature is implemented by augmenting the syntax for imports. Currently, the D import path is specified either via command line through the -I switch, or via the dmd.conf (dmd.ini) file.

The path given via the command line or configuration file will now be of the form:


When the ("module.or.package=") part is given this is referred to as a qualified import path.


A qualified import path specifies that the given path will ONLY be used if the module being imported begins with or is exactly the given module. The 'path' takes the place of the module or package path when finding a physical resource. The package qualifier must be exact, for example, if a path given is

and someone imports a.bc, this does not match.

If a modules matches a qualified import path and the given import cannot be found using that path, the compiler generates an error. This is to prevent cases where the module is found in an alternative path.

If path is a symlink it will be resolved as is done for unqualified import paths.


module a;


void main()

dmd a.d -Ifoo=/path/D/foo           => /path/D/foo/bar.{d|di} is read as module
dmd a.d  => /path/D/foobar.d is read as module
dmd a.d -Ifoo.baz=/path/foo/baz     => bar.{d|di} is not being searched in /path/foo/baz
dmd a.d     => error src.ext is not a d source file
dmd a.d  => error source file does not exist
dmd a.d -Ifoo=/path/foo             => error if /path/foo/bar.{d|di} is not a file

Hijack Prevention

The compiler will produce an error if you specify two package qualifiers where one is the prefix of another. For example:


This is to prevent ambiguity of where a certain module exists. It is still possible to define multiple import paths for a module if the package qualifier is not used. In this case, the behavior is the same as the current compiler.


This does not conflict with the current import path spec. It will break assumptions on having a corresponding directory layout for the package hierarchy.


This document has been placed in the Public Domain.

FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: September 8, 2012 2:28 (diff))