Comment #0 by default_357-line — 2019-01-16T06:33:52Z
Repro:
module foo;
import std.stdio;
import std.string;
// This will indicate the existence of a package "std".
pragma(msg, __traits(allMembers, foo).stringof);
// This, however, will not indicate two modules "stdio" and "string", but rather some other symbols, whose source is unclear.
pragma(msg, __traits(allMembers, std).stringof);
Furthermore, even if this worked it would not give an avenue to explore imports by *other* packages, since, for instance, "std.stdio.std" is not a legitimate symbol even if std.stdio was imported.
For this reason, I believe that allMembers should never return packages, only complete modules. In other words, __traits(allMembers, foo) should return "std.stdio" and "std.string".
Complication: what about renamed imports, such as import std.stdio : print = writefln;? They don't show up either, and it's not clear how they *should* show up. Make them appear as a member "print" of the current module, and it becomes difficult to determine their source module.
A possible solution may be traits such as isImport and getDeclaredIdentifier.
Comment #1 by dlang-bot — 2020-08-25T16:40:10Z
@NilsLankila created dlang/dmd pull request #11627 "fix issue 19590 - `__traits allMembers` should put fully qualified names for imports" fixing this issue:
- fix issue 19590 - `__traits allMembers` should put fully qualified names for imports
a next step to make `allMembers` + import the more correct possible.
- put imports FQN
- exclude import if it is selective
- displace fix for 17057 in the added code, virtual `sds.isModule()` call was executed in a loop that didn't mutate `sds` BTW
https://github.com/dlang/dmd/pull/11627
Comment #2 by dlang-bot — 2020-08-31T21:46:26Z
dlang/dmd pull request #11627 "fix issue 19590 - `__traits allMembers` should put fully qualified names for imports" was merged into master:
- 0c6f0309c7dc52b55094cb3335582e02e528c499 by Nils Lankila:
fix issue 19590 - `__traits allMembers` should put fully qualified names for imports
a next step to make `allMembers` + import the more correct possible.
- put imports FQN
- exclude import if it is selective
- displace fix for 17057 in the added code, virtual `sds.isModule()` call was executed in a loop that didn't mutate `sds` BTW
https://github.com/dlang/dmd/pull/11627
Comment #3 by dlang-bot — 2020-09-17T14:22:59Z
dlang/dmd pull request #11739 "Revert "fix issue 19590 - `__traits allMembers` should put fully qual…" was merged into stable:
- 8b1520df59f2d0d503bf412bfec8ddf6e64f9e63 by Steven Schveighoffer:
Revert "fix issue 19590 - `__traits allMembers` should put fully qualified names for imports"
This reverts commit 801e841e7dc1cef01c17ee0df5adca29b8c1e1bf.
https://github.com/dlang/dmd/pull/11739
Comment #4 by schveiguy — 2020-10-02T14:14:41Z
Fix was reverted.
I've reopened for now. But I strongly believe you shouldn't see imports at all in the __traits(allMembers) result. Perhaps if they are renamed imports, because now you have a local alias for it.
Is there a use case to being able to get the imports? If so, perhaps a new __traits is needed.
Comment #5 by b2.temp — 2020-10-05T01:52:49Z
After thinking more about the problem, I have concluded that what should be done is to add to the AST a new Dsymbol derived class called "ImportWrapper". It would solve the problem that the information that your in the "import domain" is lost and without using the FQN trick, which did not respect the fact that a sym has a single ident.
class ImportWrapper : Dsymbol
{
this(Ident id, ImportWrapper iw, Module m)
{
super(id);
module_ = m;
next = iw;
}
ImportWrapper next;
Module module_;
override Dsymbol search(const ref Loc loc, Identifier ident, int flags = IgnoreNone)
{
// if .next is assigned than return whether (next.identifier == ident)
// if .module_ is assisgned then forward result of module_.search()
}
}
so that for `import std.algorithm;` `allMembers` can include "std", just as now but `getMember` on this "std" gives an ImportWrapper instance that has no `.module_` but a `.next`. `allMember` on "std" can return "algorithm".
This way partial import in the chain is not lost and sub modules that are not imported by the ImportStatement are not visible.
Comment #6 by destructionator — 2020-10-09T13:21:07Z
I'm of the opinion that modules are not members of anything and should thus NEVER appear in __traits(allMembers). A new trait should be added for imports.
A module name should also ALWAYS be given as its proper, full name, NEVER truncated.
Comment #7 by bugzilla — 2020-10-09T13:23:56Z
This was reverted because it broke existing code. The solution can be leaving allMembers alone and come up with a new name, allMembers2 for the new behavior.
Comment #8 by bugzilla — 2020-12-01T07:50:40Z
Reading over the PR and these comments leaves me rather confused over just what is desired here.
But surely, whatever is done, it should be a new trait, and not break existing code by altering allmembers.
Comment #9 by robert.schadek — 2024-12-13T19:02:02Z