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
base: master
Are you sure you want to change the base?
Conversation
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 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 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#16003" |
e738b6a
to
19aab34
Compare
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
Invalid C++ was already generated, this PR does not fix those existing bugs
There was a problem hiding this 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.
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 |
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. |
@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. |
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. |
There are some dtoh tests under
indeed.
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. |
19aab34
to
b3b914e
Compare
No description provided.