On Friday, 9 December 2022 at 22:20:28 UTC, Walter Bright wrote:
>- Could we just remove it entirely?
In replacement, is something like __traits(allModules)
not possible at that phase of compilation?
December 12, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | Some good ideas in this thread! P.S. ModuleInfo doesn't list structs, only classes. |
December 12, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 12/12/2022 12:57 PM, Steven Schveighoffer wrote:
> But it would be better to do that anyway, since the compiler isn't completely consistent with which classes it inserts into `ModuleInfo`.
Also, ModuleInfo can't know what to *exclude*.
|
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 12/12/22 11:34 PM, Walter Bright wrote:
> On 12/12/2022 12:57 PM, Steven Schveighoffer wrote:
>> But it would be better to do that anyway, since the compiler isn't completely consistent with which classes it inserts into `ModuleInfo`.
>
> Also, ModuleInfo can't know what to *exclude*.
If Object.factory is to be a supported feature (I don't think it should be), then it has to include *all* classes. Otherwise, you have odd unrelated conditions that break the feature, and something that brittle really shouldn't be used.
-Steve
|
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 9 December 2022 at 22:20:28 UTC, Walter Bright wrote: >
In replacement, is something like |
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to cc | On 13/12/2022 6:32 PM, cc wrote:
> On Friday, 9 December 2022 at 22:20:28 UTC, Walter Bright wrote:
>> 4. Could we just remove it entirely?
>
> In replacement, is something like `__traits(allModules)` not possible at that phase of compilation?
No unfortunately.
But there is something we can do, which has been on my todo list for a while now for dub:
When building a binary (executable/shared library) produce a module which contains all modules that has or is compiled into the binary.
We already kinda have this, but its only for unittesting. Just gotta make it more generic.
I intended this to go with injectSourceFiles for registering stuff like web routes.
|
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On 13/12/22 4:17, Adam D Ruppe wrote: > Yes, separate compilation is a thing, but you still have to `import` your dependencies. There's dynamic loading of shared libraries, where you don't even know at compilation time what classes there might be coming. For instance, if you implement a plugin system, and want the classes to add themselves automagically to some central registry. In my view, the best solution for this would be to fix / extend the `this` template parameter [1] to every part of the class, in this case including static constructors: ```d struct MyClassInfo { /* ... */ } MyClassInfo[string] myClassRegistry; class MyRoot { static this(this C) { import std.traits : fullyQualifiedName; // Gather C's metadata and store it myClassRegistry[fullyQualifiedName] = MyClassInfo(/*...*/); } } ``` This way, you could create a hierarchy where everything inheriting from `MyRoot` would register automatically. In an ideal world the current ClassInfo (or even an improved version of it) would be part of Object, but not of ProtoObject (what's the status of DIP1042, btw?). [1]: https://issues.dlang.org/show_bug.cgi?id=10488 |
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arafel | On 13/12/22 9:52, Arafel wrote:
> static this(this C)
This should obviously be `static this(this C)()`
|
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 9 December 2022 at 22:20:28 UTC, Walter Bright wrote:
> This adds a lot of extra size.
>
> 1. Does anybody use Object.localClasses() or Object.find() ?
>
> 2. Does anybody need them?
I don't.
|
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Tuesday, 13 December 2022 at 05:49:49 UTC, rikki cattermole wrote: >But there is something we can do, which has been on my todo list for a while now for dub: When building a binary (executable/shared library) produce a module which contains all modules that has or is compiled into the binary. Sounds good to me. |
December 13, 2022 Re: ModuleInfo, Object.localClasses(), and Object.find() - any users? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 9 December 2022 at 22:20:28 UTC, Walter Bright wrote: >
I use those in this way:
My use case here is to enumerate all the classes that can initialize a backend that are currently loaded in the runtime. But I only need to iterate through all types. If there was a way to make templates that are automatically instatiated into all child classes, it would probably allow the right classes to automatically register to a list on Runtime initialization, and thus optimizing this code. |