Skip to content
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

C++ classes need TypeInfo #4779

Open
rikkimax opened this issue Nov 12, 2024 · 4 comments
Open

C++ classes need TypeInfo #4779

rikkimax opened this issue Nov 12, 2024 · 4 comments

Comments

@rikkimax
Copy link
Contributor

I've finally got around to using C++ classes in -betterC cross the shared library boundary.

As of ldc 1.38.0, what I've found is that the TypeInfo/Interface do not get emitted (expected) from within the shared library.
However, on the executable side that is full D, it'll error given that it doesn't exist.
I have not had this as an issue for any other TypeInfo.

I was not able to use my usual tricks via inline assembly to emit the data due to LLVM's type checking (I really wish I had a way to disable that for a symbol).
In the end, the workaround I came up with was to template the entire class hierarchy (not good).

On that note, wouldn't the external path switch have helped here? Since if it was external, it may not have been compiled by the D compiler.

@kinke
Copy link
Member

kinke commented Nov 12, 2024

Class TypeInfos are emitted into their owning module/object file only, not on-demand in every referencing object file as other TypeInfos (and later uniqued during linking). So if the owning module is compiled with -betterC, they aren't available.

We could change this behavior, although the -betterC reason is IMO meh. ;) - I think the main reason for that decision is that class TypeInfos aren't optional/elidable as other TypeInfos, as the vtable refs it - at least for extern(D) classes. And they are added to the owning module's ModuleInfo.localClasses, for that Object.factory() abomination.

You'd need duplicates in every referencing object file.

@rikkimax
Copy link
Contributor Author

I was thinking that for C++ classes/interfaces they'll just nullify out since they may not be needed or appropriate to have.

@kinke
Copy link
Member

kinke commented Nov 12, 2024

Oh, druntime does need those D TypeInfos for extern(C++) classes too, GC etc.

@rikkimax
Copy link
Contributor Author

AA's, down casting and destructor calling by GC.

All things I don't need. If it is a binding which never gets compiled in it wouldn't need that either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants