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

[dtoh] ensure class return types are fwd declared #16003

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thewilsonator
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @thewilsonator! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your 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 locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#16003"

@thewilsonator thewilsonator marked this pull request as ready for review January 6, 2024 01:22
@thewilsonator
Copy link
Contributor Author

+5,406 −5,490

Looks like it did something, exactly what Im not quite sure.

void accept(Visitor* v) override;
};

class SymOffExp final : public SymbolExp
class Expression : public ASTNode
Copy link
Member

@ibuclaw ibuclaw Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like now all definitions of classes referenced by this class via pointer are emitted before its own definition...

UshrExp* isUshrExp();
AndExp* isAndExp();
OrExp* isOrExp();
XorExp* isXorExp();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... in the order as they appear here...

PrettyFuncInitExp* isPrettyFuncInitExp();
ObjcClassReferenceExp* isObjcClassReferenceExp();
ClassReferenceExp* isClassReferenceExp();
ThrownExceptionExp* isThrownExceptionExp();
Copy link
Member

@ibuclaw ibuclaw Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... so now you have for example

class Expression
{
   const(char)* toChars() const;
   final ThrownExceptionExp isThrownExceptionExp();
} 

class ThrownExceptionExp : Expression
{
    override const(char) * toChars() const;
}

Will generate the following

class ThrownExceptionExp;
class Expression;

class ThrownExceptionExp : public Expression
{
public:
    const char* toChars() const override;
}; 

class Expression
{
public:
   virtual const char* toChars() const;
   ThrownExceptionExp* isThrownExceptionExp();
};

Are you expecting the C++ compiler to not complain about override as it's not seen virtual yet when parsing?

Likewise that it'll be okay with ThrownExceptionExp inheriting an opaque class at that particular point in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the fact that base classes are emitted after sub classes in some cases is an existing bug in dtoh.
Note that includeSymbol emits a fwd decl, not a complete complete declaration.
Note also that this PR removes more lines than it adds

ibuclaw
ibuclaw previously requested changes Jan 6, 2024
Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judging from what I can see, this only generates invalid C++ code.

@thewilsonator thewilsonator dismissed ibuclaw’s stale review January 6, 2024 10:08

Invalid C++ was already generated, this PR does not fix those existing bugs

ibuclaw
ibuclaw previously requested changes Jan 6, 2024
Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direction should be to have less invalid headers than before, not more.

@thewilsonator
Copy link
Contributor Author

thewilsonator commented Jan 6, 2024

Again, the header was invalid before, this is not "more invalid", it is less invalid than before. To be sure, it is definitely still very invalid, but this is an improvement as now:

extern(C++):
Class foo() { return new Class(); }

class Class {}

works as it will now correctly generate a forward declaration

class Class;

Class* foo();

class Class {}

previously it would not

@WalterBright
Copy link
Member

This is really only a 2 line change, the rest is the changed frontend.h.

Since I'm not a user of frontend.h, but @ibuclaw is, I will defer to him.

@RazvanN7
Copy link
Contributor

@thewilsonator Is there any way we can, at least, partially test the output of dtoh with some real life tests? The entire point of dtoh was to replace the C++ headers present in the dmd tree, but now we're stuck with both the headers and a semi-working dtoh.

@RazvanN7
Copy link
Contributor

Also, you mention about existing bugs. Are these documented anywhere? We should probably work in a more systematic way so that we eventually get rid of the manually maintained headers.

@thewilsonator
Copy link
Contributor Author

Is there any way we can, at least, partially test the output of dtoh with some real life tests?

There are some dtoh tests under compilable/ but they are... not comprehensive.

The entire point of dtoh was to replace the C++ headers present in the dmd tree, but now we're stuck with both the headers and a semi-working dtoh.

indeed.

Are these [bugs] documented anywhere?

Not that I'm aware of. But if you want to find them just do

#include "frontend.h"

By far the largest source of errors is failing to emit a full declaration of base class before emitting a subclass such that a class tries to inherit from something that is not (yet) defined. Wouldn't be surprised if (sub)classes + namespaces in combination also don't work, but thankfully we don't need to worry about those for DMD.

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