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

Check unnecessary vtbl emissions #662

Closed
redstar opened this issue Jul 1, 2014 · 6 comments
Closed

Check unnecessary vtbl emissions #662

redstar opened this issue Jul 1, 2014 · 6 comments

Comments

@redstar
Copy link
Member

redstar commented Jul 1, 2014

Reported by temtaine in news group (http://forum.dlang.org/post/yephpwnmvkcpyjnpbzti@forum.dlang.org). Look at the following modules:

A.d

import B;

B.d

import C;
import D;

import std.range;

class Font {
public:
    mixin RCounted;

    auto makeTextData(string s) {
        // split text by spaces
        auto arr = s.splitter.array;
    }    
}

class Engine {
    RC!Font font;
}

C.d

import A;

D.d

template RCounted() {
        void release() { this.destroy; }
}

struct RC(T) {
    ~this() {  _rc_ptr.release; }
    T _rc_ptr;
}

ldc2 -c A.d B.d C.d D.d works but ldc2 -c A.d produces an error message.

@ckamm
Copy link
Member

ckamm commented Jul 3, 2014

Notes so far: The failure happens in DtoDefineFunction() for std.array.Appender!(string[]).Appender.Data.__xopEquals because semantic3 is never run for it (not even while gagged).

DMD does not call toObjFile on this FuncDeclaration at all and doesn't semantic3 it either. It does not even call toObjFile on the TemplateInstance Appender!(string[]). For that TemplateInstance not even semantic() is run.

The next step would be to figure out why we run TemplateInstance::semantic() for Appender!(string[]).

@redstar
Copy link
Member Author

redstar commented Jul 3, 2014

I played a bit with the error message. DtoDefineFunction() is called for every method of std.array.Appender - with no semantic3 run.

@ckamm
Copy link
Member

ckamm commented Jul 5, 2014

When we codegen object.destroy!(Font) (dmd does this too), we call IrTypeClass:get() for B.Font and that generates the vtbl for that class (I don't think dmd does that). To get the vtbl we call semantic3 on all members (makeTextData in the test case) and that generates the Appender!(string[]) template instance but doesn't semantic3 it.

We either need to ensure we semantic3 the template instances generated during our calls back into the frontend for vtbl generation - or make sure we don't emit it in the first place.

@dnadlinger
Copy link
Member

I think we should just try to not emit the vtbl at all, unless there is a compelling use case as to why not doing so is a bug in DMD. Even then, we should probably try to fix this upstream.

dnadlinger added a commit to ldc-developers/dmd-testsuite that referenced this issue Oct 11, 2014
dnadlinger added a commit to ldc-developers/dmd-testsuite that referenced this issue Oct 12, 2014
dnadlinger added a commit that referenced this issue Oct 12, 2014
Added test cases for GitHub issues #662 and #739.
@kinke
Copy link
Member

kinke commented Aug 21, 2016

The original symptoms should be worked around by #1709.

When we codegen object.destroy!(Font) (dmd does this too), we call IrTypeClass:get() for B.Font and that generates the vtbl for that class (I don't think dmd does that).

Still needs to be looked into.

@kinke kinke changed the title Collection of modules does not compile because of not analyzed code Check unnecessary vtbl emissions Aug 21, 2016
@kinke kinke mentioned this issue Nov 19, 2016
@kinke
Copy link
Member

kinke commented Jun 27, 2021

Vtables are emitted once into the CU owning the class declaration. They are needed for the class init symbol, which is also emitted in that CU, so definitely not superfluous.

The testcase (nowadays requiring import std.algorithm, std.array;) works with LDC v1.27.

@kinke kinke closed this as completed Jun 27, 2021
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

4 participants