D needs to be honest
Jonathan Marler
johnnymarler at gmail.com
Mon Oct 29 04:58:09 UTC 2018
I filed this issue
(https://issues.dlang.org/show_bug.cgi?id=18517) about 8 months
ago. It provides a couple test cases that show that import order
changes the semantics of D programs and the order in which
modules are passed to the compiler also changes semantics. This
behavior has existed long enough that it's probably time for D to
remove and/or qualify some of its claims. Statements like:
https://dlang.org/spec/module.html
> The order in which ImportDeclarations occur has no significance.
> The order in which modules are imported does not affect the
> semantics.
The bugzilla issue above shows cases where these statements are
demonstrated to be false, and I wouldn't characterize the issue
as a bug, rather, a fundamental problem with the way D handles
module imports. The language definition as it exists does not
allow import order to be invariant. Note there are a number of
ways to fix this issue (see PRs below) but note that they do
require changes to the way D handles imports.
> The semantics of a module are not affected by what imports it.
The module name and or the namespace it exists in will change
depending on how the module is imported. It can change depending
on if it was passed in on the command line, or loaded from an
import by another module, and the path from which it was loaded
can change depending on which module loaded it first.
Based on the response of my pull requests to fix these issues,
its clear that these issues are low on the priority list. This is
fine and maybe it's better that the maintainers focus on other
things rather than this problem, however, I think it's been long
enough that keeping these claims on the website and in the
documentation is bordering on being deceptive and unethical.
Everyone will have an opinion on where you draw the line, but in
my opinion, it's time to come clean.
I've included my pull requests related to these issues. Feel
free to look into them if you want more information.
Relevant Pull Requests:
Fix module/import order invariance:
https://github.com/dlang/dmd/pull/7900
Interpret imports the same regardless of other modules passed on
the command line: https://github.com/dlang/dmd/pull/7878
Add broken import order invariance tests:
https://github.com/dlang/dmd/pull/8165
Deprecate import/module name mismatch (ALL CASES):
https://github.com/dlang/dmd/pull/7778
More information about the Digitalmars-d
mailing list