Skip to content

Replace C++ syntax check with dummy frontend#7520

Merged
MartinNowak merged 6 commits intodlang:stablefrom
ibuclaw:cxxtest
Dec 29, 2017
Merged

Replace C++ syntax check with dummy frontend#7520
MartinNowak merged 6 commits intodlang:stablefrom
ibuclaw:cxxtest

Conversation

@ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Dec 25, 2017

On closer inspection the Visitor interface broken by #7397 still wasn't fixed by #7438.

The entire C++ Visitor class has been re-layed out to match the order of virtuals in the D implementation.

Have exported Id::initialize to C++ as fundamental components don't work if you can't call it.

Replaced cxxcheckheaders with cxx-unittest, a small program that links against the front-end in the same way that LDC or GDC would to test that interaction works.

I anticipate to build on this test file later.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ibuclaw!

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.

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 25, 2017

@MartinNowak - this should go in stable + 2.078, as the C++<->D visitor interface is utterly unusable without this, and breaks all downstream.

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 26, 2017

Looks like I should partially revert #7005 also, as the fix is just lazy.

@wilzbach
Copy link
Contributor

@MartinNowak - this should go in stable + 2.078, as the C++<->D visitor interface is utterly unusable without this, and breaks all downstream.

Simple target stable, then it will be part of 2.078 (you can change the targeted branch directly via the GitHub UI, but you will need to do the git rebase too).
Once merge we can easily merge stable back into master.

@wilzbach wilzbach added this to the 2.078.0 milestone Dec 26, 2017
@ibuclaw ibuclaw changed the base branch from master to stable December 26, 2017 00:48
@ibuclaw ibuclaw force-pushed the cxxtest branch 2 times, most recently from d9ed729 to 6ba0644 Compare December 26, 2017 00:52
@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 26, 2017

Rebased against stable. I think the tests should pass now once I fixed up ForwardingStatement visit methods - @tgehr.

@tgehr
Copy link
Contributor

tgehr commented Dec 26, 2017

I'm not sure why #7005 needs to be reverted. (Or why it is at all virtuous to not be "lazy" -- there is exactly one sensible default implementation, therefore #7005 prevents all further bugs like the one it fixed.)

src/dmd/sapply.d Outdated
override void visit(ForwardingStatement s)
{
if (s.statement)
doCond(s.statement) || applyTo(s.statement);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the exact purpose of the walkPostorder visitor, but this seems fishy to me as ForwardingStatement is not supposed to have behaviour different from the wrapped statement.

Copy link
Member Author

@ibuclaw ibuclaw Dec 26, 2017

Choose a reason for hiding this comment

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

This is correct, as you want to walk over the underlying wrapped statement, not the wrapper itself.

Copy link
Contributor

@tgehr tgehr Dec 26, 2017

Choose a reason for hiding this comment

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

If I have a ForwardingStatement wrapping a LabelStatement, doCond is called with different arguments than if I have only a LabelStatement. Before your changes, the behaviour was identical for both cases. Is this change in behaviour intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have code example that changes behaviour? Or is that just hypothetical?

The order that it walks the AST should be the same as the original.

Should probably add applyTo(s) if the underlying statement is null, but that does not happen in the current.

Copy link
Contributor

Choose a reason for hiding this comment

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

Running the visitor on a semantically-analyzed version of the following code will result in changed behaviour:

static foreach(i;0..1) L: writeln(i);

L: writeln(i) will be visited by the StoppableVisitor v twice now, even though before it was visited only once.

I don't think applyTo(s) should be called if s.statement is null.

Copy link
Contributor

Choose a reason for hiding this comment

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

Only if it makes sense to Visit the ForwardingStatement by default. (I don't see why it would.)
Is this Visitor used for anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used by comeFrom and/or blockExit for determining reachable statements.

Copy link
Contributor

@tgehr tgehr Dec 26, 2017

Choose a reason for hiding this comment

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

Visiting the ForwardingStatement will break the hasCode method in statement.d. (I.e., I think the implementation should stay the same as before.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, that sounds like what I saw last night when seeing unreachable warnings.

So just the one applyTo(s.statement then to elide double visiting.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should just be

if(s.statement)
    s.statement.accept(this);

(Otherwise, e.g. bodies of while loops inside static foreach will not be visited.)

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 26, 2017

there is exactly one sensible default implementation, therefore #7005 prevents all further bugs like the one it fixed.

The base visitor should just forward onto the next method in the inheritance chain. Any special logic above that should go in overriding visitors.

@tgehr
Copy link
Contributor

tgehr commented Dec 26, 2017

Well, then the best fix might be to add a DefaultVisitor in-between Visitor and all its subclasses. To forward to visit(Statement) by default is to do the wrong thing by default. Everybody who wants to introduce a new subclass of Visitor now needs to be aware of ForwardingStatement. This is a trap that can lead to bugs.

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 26, 2017

To forward to visit(Statement) by default is to do the wrong thing by default. Everybody who wants to introduce a new subclass of Visitor now needs to be aware of ForwardingStatement. This is a trap that can lead to bugs.

Having it in visitor just hid bugs. As it wasn't forwarding onto Statement in the event that the underlying wrapped statement was null.

If your writing a visitor, that you should be aware of all classes is a given. If the entire point of ForwardingStatement is to not exist outside semantic then that needs to be looked at and fixed. If we can do away with ForwardingStatement in any way (I don't know what it's used for, so I'll arbitrarily suggest adding a Scope flag) then all the better.

@tgehr
Copy link
Contributor

tgehr commented Dec 26, 2017

Which bugs? If it is sensible to ignore a null Statement, it is sensible to ignore a ForwardingStatement wrapping null.

ForwardingStatement is used to insert wrapped symbols into a different scope than the current one.
It could probably be removed during semantic analysis, if that is a useful thing to do.

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 26, 2017

It could probably be removed during semantic analysis, if that is a useful thing to do.

It seems to me that this is something that should not be leaked outside of the static foreach semantic, so yes.

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 26, 2017

Which bugs? If it is sensible to ignore a null Statement, it is sensible to ignore a ForwardingStatement wrapping null.

If I have a visitor with the following method.

class MV : public Visitor
{
  void visit(Statement *) { puts("have statement"); }
}

Passing this a ForwardingStatement with interior null would print nothing, which is an unexpected behaviour.

@tgehr
Copy link
Contributor

tgehr commented Dec 26, 2017

I'll try to create a pull request that removes ForwardingStatements after they are no longer required.
Knowing the semantics of ForwardingStatement, that behaviour is expected, but point taken.

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 27, 2017

I moved the ForwardingStatement fix to #7526

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 27, 2017

Cherry-picked other PR into this one.

@PetarKirov
Copy link
Member

@ibuclaw #7526 has been merged. Rebase?

@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 28, 2017

@ZombineDev already rebased.

@PetarKirov
Copy link
Member

@ZombineDev already rebased.

Hmm, I missed that #7526 was targeting master instead of stable, unlike this PR.

DMD_FLAGS := -I$(ROOT) -Wuninitialized
GLUE_FLAGS := -I$(ROOT) -I$(TK) -I$(C)
DMD_FLAGS := -I$(D) -I$(ROOT) -Wuninitialized
GLUE_FLAGS := -I$(D) -I$(ROOT) -I$(TK) -I$(C)
Copy link
Contributor

Choose a reason for hiding this comment

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

The common style of this Makefile is to skip the parentheses for one letter variables, i.e. $D

Copy link
Member Author

Choose a reason for hiding this comment

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

All I have to say is $(C).

@@ -0,0 +1,199 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Creating the folder src/tests might lead to confusions for newcomers.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure the best place for this, as the main source folder doesn't seem right.

@MartinNowak
Copy link
Member

Cherry-picked other PR into this one.

Please avoid cherry-picking if possible to not unnecessary merge conflicts.

@MartinNowak MartinNowak merged commit 9180f36 into dlang:stable Dec 29, 2017
@ibuclaw ibuclaw deleted the cxxtest branch December 30, 2017 01:02
@ibuclaw
Copy link
Member Author

ibuclaw commented Dec 30, 2017

@MartinNowak so having the source in tests is fine?

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

Successfully merging this pull request may close these issues.

6 participants