Issue 24830 - separate compilation + circular deps + templated opCmp = missing symbols
Summary: separate compilation + circular deps + templated opCmp = missing symbols
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Mac OS X
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2024-10-23 14:15 UTC by ilya.yanok
Modified: 2024-10-23 22:40 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ilya.yanok 2024-10-23 14:15:00 UTC
It's probably a rare case, but if I try to compile separately two modules that are part of a dependency cycle, and both of them are instantiating a templated struct that has a templated `opCmp` implementation (I think `opEquals` and `toHash` are also affected), none of the resulting object files will contains the code for the `opCmp` instantiation.

Example:
```d
// option.d
import util;
struct Option(T) {
        private T _x;
        int opCmp()(const(Option) rhs) const {
            return 1;
        }
}
Option!string p;
```
```d
// util.d
import option;
Option!string x;
```

This is happening because while compiling `option.d` the compiler thinks `Option!string.opCmp!()` is instantiated in `util.d` and vice versa, so we end up not having it at all.
Comment 1 ilya.yanok 2024-10-23 14:18:30 UTC
This happens since even though while processing the second `Option!string` instantiation we try to update the `minst` of all children to the root module, it fails to update the automatically generated `__xopCmp` method (and friends). I have a fix and currently am working on the test case. I'll send a PR soon.
Comment 2 Dlang Bot 2024-10-23 15:44:09 UTC
@yanok updated dlang/dmd pull request #17022 "dsymbolsem/InstMemberWalker: also visit generated structs' members" fixing this issue:

- dsymbolsem/InstMemberWalker: also visit generated structs' members
  
  While updating children's `minst` only going over `members` is not
  enough: structs may also have generated methods that are not in
  `members`.
  
  As a result, if a generated method instantiates a template, it gets a
  poentially wrong `minst`, so can be omitted from the compilation result.
  
  Fixes Bugzilla Issue 24830.

https://github.com/dlang/dmd/pull/17022
Comment 3 Dlang Bot 2024-10-23 22:40:23 UTC
dlang/dmd pull request #17022 "dsymbolsem/InstMemberWalker: also visit generated structs' members" was merged into master:

- 1f98c6b69854348a271b9cd1314f77822f875f77 by Ilya Yanok:
  dsymbolsem/InstMemberWalker: also visit generated structs' members
  
  While updating children's `minst` only going over `members` is not
  enough: structs may also have generated methods that are not in
  `members`.
  
  As a result, if a generated method instantiates a template, it gets a
  poentially wrong `minst`, so can be omitted from the compilation result.
  
  Fixes Bugzilla Issue 24830.

https://github.com/dlang/dmd/pull/17022