generate TypeInfo for structs only on demand#6561
generate TypeInfo for structs only on demand#6561WalterBright wants to merge 1 commit intodlang:masterfrom
Conversation
|
The good thing about emitting it with the struct is that it is more likely to contain correct RTInfo. (See #2480 for an old attempt at fixing this). You might want to add a warning/error at https://github.com/dlang/dmd/blob/master/src/todt.d#L1374 checking for unevaluated RTInfo to see if the number increases. |
508dbdc to
6deb979
Compare
|
@rainers I thought that was the point behind the various calls to |
Yes, but you have to perfectly (and sometimes pessimistically) predict what the glue layer will do. Just building phobos fails the suggested check for core.stdc.stdio._iobuf (I haven't analyzed where it is invoked from). |
|
Please be exact about what you suggest as the check, and I'll add it to this PR. |
|
Also, I see the rtinfo is calculated in semantic3() of structs. Is there any reason it cannot be done in semantic2() ? |
When the struct is used, or when the typeinfo is used? I hope it's the latter. |
Sorry, the link above got invalid due to file moves. Here's a diff for the suggested check:
I suspect it very much depends on what happens during RTInfo evaluation. Right now, it's very simplistic (always null), dlang/druntime#1603 will make it a little more complicated, but doesn't need a lot of more introspection than the trait |
The latter, but with some pessimistic guesses regarding glue layer lowerings. |
|
BTW: Kenji once proposed the opposite than this PR: only generate the type info with the struct. #3958. This requires that all files with struct declarations are actually compiled, not merely imported. |
|
It turns out that TypeInfo for structs is rarely needed, but always generated and put in the executable. D is slowly evolving towards needing it even less. My goal here is to generate it only when actually required. However, it could be computed eagerly, just not written to the object file. @rainers I added the check you proposed. Thanks! |
5392704 to
229d953
Compare
|
I moved the computation of getRTInfo into semantic2(). |
d01d15b to
1c071bb
Compare
I tried this PR with dlang/druntime#1603 and it seemed to compile ok (though I've disabled the precise GC). With RTInfo as in https://github.com/rainers/druntime/blob/gcx_precise/src/gc/gctemplates.d, the linker complains about undefined symbols on every test file (on symbols used during CTFE). That only happens for some with master (everything until inner.d compiles). |
|
@rainers Can you please be more specific? Hopefully with a small test case? |
|
Try this branch of druntime: https://github.com/rainers/druntime/tree/gctemplates with RTInfo from the precise GC presented at DConf2013. |
|
It seems the additional |
|
Can you please go a bit further and have a minimal RTInfo template that produces the error? |
fda77bc to
3ccef0a
Compare
|
Sorry for the late reply, I've been busy with non-D stuff. Most errors are again inner.d still fails with RTInfo defined by and gc/gctemplates.d as inner.d is reduced to: to produce I see tests link11931.d, link2500.d and a couple more understandable failures too. |
|
Thanks! In investigating this, I've found some mass confusion in the front end about when semantic processing is done. Unfortunately, this PR needs that to be straightened out. In particular, attempting to run |
3ccef0a to
fe6b710
Compare
fe6b710 to
deaf3a5
Compare
|
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#6561" |
deaf3a5 to
a9e1b57
Compare
|
@WalterBright this seems to be in good shape now, good to go? |
src/ddmd/todt.d
Outdated
|
|
||
| // xgetRTInfo | ||
| if (!sd.getRTInfo) | ||
| error(sd.loc, "ICE: RTInfo not evaluated for %s", sd.toChars()); |
There was a problem hiding this comment.
"ICE:"? Is this just a test?
|
@WalterBright What's the state of this PR? Was it just an experiment? |
a9e1b57 to
a043621
Compare
a043621 to
995552a
Compare
995552a to
a1bb373
Compare
|
(rebased to master to see what's failing now) |
a1bb373 to
ebb57de
Compare
|
@WalterBright status? |
ebb57de to
fcfa327
Compare
|
with the current work on making TypeInfo templates hooks I think this can be closed. Do you agree ? |
The original code always generates them when a struct declaration was found. But they were also generated again by other object modules whenever the typeinfo was needed. This relied on COMDATs to cull the duplicates. But with such, the typeinfo does not need to be generated just because the struct is declared - only when it is actually used.