New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue 10023 - Add rtInfo (or equivalent) to ModuleInfo. #2271
Conversation
Don't know if someone else can come up with a better name. |
dlang/druntime#534 is the runtime part needed to complete this. |
Why does it have to be RMInfo, can't RTInfo be used for both? The parameter passed into it is a module, not a type, should be pretty straightforward to overload, no? |
What I really don't like about these is that this is not user-data but runtime data, as you can only define RTInfo/RMInfo in object_.di.
Probably, there is also getMembers which does something similar. |
@schveiguy It was easy to do like this. It's straightforward in D but I have no idea how to implement that in the compiler. @dawgfoto I agree. There's a problem that it only works in object.di. I think we should have some mechanism that makes it possible for RTInfo/RMInfo to be used outside out object.di. |
I have an idea:
|
Any comments? |
I think a simpler approach would be to instantiate rtInfo/rmInfo from the scope of the type/module, thus allowing to define or import a different implementation. What about |
Sorry, I forgot about this. I think storing as an AA is making things overly complex. Why can't rtInfo simply have directly accessible fields? @dawgfoto's approach seems the most sane, give the power to the template to do whatever it wants in the correct context, including generating an AA.
The idea is that we can generate at runtime the information that we need for various runtime algorithms, such as precise GC, named unit tests, or better module cycle detection. These are the three I had in mind. The idea behind rtInfo is that it generates runtime accessible information, vs. getMembers which accesses compile-time accessible information. |
@dawgfoto
I don't think I understand. |
Currently Example, how it currently works: module object;
template RTInfo (T)
{
enum RTInfo = collectInfo!(T);
} module foo.bar;
struct Foo {}
auto info = typeid(Foo).rtInfo; Example of my approach: module foo.bar;
struct Foo {}
@rtInfo template RTInfo (T)
{
enum RTInfo = collectInfo!(T);
}
auto info = typeid(Foo).rtInfo["foo.bar"]; |
That would not really work with separate compilation, right?
Just instantiating the templates at the scope (location) of the Type definition. |
What would the difference be compared to now. What happens now with separate compilation?
Sorry, I still don't think I understand. Could you show an example? My approach does not have a single global definition. My approach can have a definition per module (I don't think any more is needed), that's why the AA is necessary. |
module a;
@rtInfo template RTInfo (T) { enum RTInfo = 0; }
struct Foo {}
assert(typeinfo(Foo).rtInfo["a"] == 0);
// This wouldn't work, because the compiler doesn't know about module b
assert(typeinfo(Foo).rtInfo["b"] == 1); module b;
@rtInfo template RTInfo (T) { enum RTInfo = 1; }
Basically it works like this. struct Foo {}
// compiler instantiates the unqualified `rtInfo` from the point of definition
TypeInfo_Struct.rtInfo = rtInfo!Foo;
// Would work with imports
import gc : rtInfo;
// Would work with definitions
template rtInfo(T) { enum rtInfo = 0; }
// Would work with AA's (if they were CTFEable)
template rtInfo(T) { enum rtInfo = buildAA!(gc.rtInfo, .rtInfo)(); } |
I'm still a bit confused.
Do you mean I have to define (or import) |
Of course, how would the compiler know about |
@@ -196,6 +203,7 @@ void Module::genmoduleinfo() | |||
void *sharedctor; | |||
void *shareddtor; | |||
uint index; | |||
void *rmInfo; | |||
void*[1] reserved; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keep around void*[1] reserved
if you're adding a new field that takes up that space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason. I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note that the reserved field brings the size of ModuleInfo is 64 bytes (128 on 64bit) - there's probably am reason why it was padded up to a power of 2. Though can't think why at this moment. :)
My idea was to have a UDA that the compiler recognizes. |
You would still have to import or define the template. |
Yes, but I can define it anywhere. I can inspect third party types. |
You mean something like this should work? module a;
struct Foo {} module b;
import a;
template rtInfo(T) { enum rtInfo = 0; }
assert(typeid(Foo).rtInfo["b"]); This is problematic because the TypeInfo for Foo is generated when |
Yes, that was the idea.
Ok, I see. The reason for the AA is to support multiple Is there some other way that we can support what I want to achieve? |
@MartinNowak bringing up this discussion again. I feel we couldn't really agree last time about the ModuleInfo stuff. How about I change the pull request to only implement the template part? That is still very useful. Then we can take care of the ModuleInfo some other time. |
Sorry, I don't really have time for this right now. I'd prefer if you discussed the details with @yglukhov about the nested rtinfo idea and this PR and come up with a combined solution.
You cannot inject arbitrary code/data into foreign modules without changing them. |
Ahhh, just noticed this PR, after i've done something related here. |
@MartinNowak fair enough. |
ping |
It seems @MartinNowak wants to solve the issue with custom |
Status of this? |
The status hasn't changed since my last post: #2271 (comment). The quest is, what is the status of dlang/druntime#775. It's mostly @MartinNowak that had objections to this and he doesn't have time. I can update the code and make sure it can be merged and passes the tests. But that seems pointless to me if there's objections to the concept. See also: dlang/druntime#775. |
I'll close this, as this is as pointless as RTInfo. |
No description provided.