Skip to content

Ast dump ignore wmo #20596

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

Merged
merged 7 commits into from
Dec 19, 2019
Merged

Ast dump ignore wmo #20596

merged 7 commits into from
Dec 19, 2019

Conversation

vinivendra
Copy link
Contributor

The current Dump AST methods dump the AST for primary files or, if there are no primary files, the main file. This behavior is weird on WMO builds, which don't have the concept of primary files. In that case, the compiler currently dumps the main file and ignores all other files.

Since it's uncommon to have the -dump-ast argument in an invocation, it is assumed to be a priority over -wmo. Therefore, the decision is to ignore -wmo when -dump-ast is also present, printing a warning for the user and dumping all files normally.

This was briefly discussed on PR-20392, where it was decided that a FIXME would be added to lib/FrontendTool/FrontendTool.cpp and the change would be delayed to a separate pull request.

This pull request executes the necessary changes on Driver.cpp and DiagnosticsDriver.def and removes the FIXME from FrontendTool.cpp. It also fixes a bit of the code style in DiagnosticsDriver.def.

@vinivendra
Copy link
Contributor Author

Cc @jrose-apple, who's been following these changes.

@@ -42,91 +42,92 @@
DIAG(REMARK,ID,Options,Text,Signature)
#endif

WARNING(warning_parallel_execution_not_supported,none,
WARNING(warning_parallel_execution_not_supported, none,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't include formatting changes for code you're not touching.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, ok. I thought it'd be useful to do this as I was adding a new warning, but yeah, maybe not.

// AST dump doesn't work in WMO. Since it's not common want to dump the AST,
// we assume that's the priority and ignore `-wmo`, but we warn the user about
// this decision.
if (Args.hasArg(options::OPT_whole_module_optimization) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

You're ignoring OPT_index_file here, compared to the logic above. If that's intentional, it deserves a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about ignoring OPT_index_file too, but that seems to be a bit more complicated than just adding it in this check, and it's probably not as important (no one seems to have complained about it or tried to fix it so far).

I'll add a FIXME saying OPT_index_file should probably also be ignored in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh never mind, adding -index-file to the check seems to have worked after all.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just reuse the boolean from above, so that it's always consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'm reusing the boolean, but I think a separate if statement makes the code easier to understand... do you agree?

@@ -1653,6 +1653,15 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
if (!ArgRequiringSingleCompile)
return OutputInfo::Mode::StandardCompile;

// AST dump doesn't work in WMO. Since it's not common want to dump the AST,
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "not common want to".

@vinivendra
Copy link
Contributor Author

Should I do a rebase on master every time I update the pull request? It seems like the right thing to do, but at the same time it seems to make github act a little weird.

@jrose-apple
Copy link
Contributor

Should I do a rebase on master every time I update the pull request? It seems like the right thing to do, but at the same time it seems to make github act a little weird.

I think most of us do do force pushes, which is 90% of GitHub's weirdness, but you don't need to rebase every time if there's not actually a conflict.

@jrose-apple
Copy link
Contributor

Thanks, this looks good. Can you add a test case for it in test/Driver/ somewhere?

@vinivendra
Copy link
Contributor Author

Heheh, adding tests reminded me why I hadn't ignored -index-file in the first place: if I ignore it the same way as -wmo in the code but then pass -index-file after -dump-ast in the command line, my option gets overwritten and un-ignored (inDriver.cpp, around line 1410).

This seems to happen because the compiler checks for the last argument (Args.getLastArg(options::OPT_modes_Group)), and I didn't find a good way to fix this yet. So I'm just gonna revert it back to only ignoring -wmo, add a FIXME for -index-file, write the tests, and leave that for a future PR.

WARNING(warn_ignoring_single_compile, none,
"ignoring '%0' because '-dump-ast' was also specified", (StringRef))
WARNING(warn_ignoring_wmo, none,
"ignoring '-wmo' because '-dump-ast' was also specified", ())
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 this was better the way it was before, since there are several ways to spell the flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The place from which I copied this code (Driver.cpp at line 1672, just below my changes) used ArgRequiringSingleCompile->getOption().getPrefixedName(). As far as I can tell, this will always print "-whole-module-optimization", even if you pass the shortened -wmo version.

The snippet I copied uses this method to distinguish between printing -whole-module-optimization or -index-file, but I don't think it'll have the desired effect here unless we change the way we get the flag name too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, then we should probably be using ArgRequiringSingleCompile->getSpelling() instead, probably in both places.

@CodaFi
Copy link
Contributor

CodaFi commented Nov 18, 2019

@vinivendra Are you still interested in pursuing this change?

@vinivendra
Copy link
Contributor Author

@CodaFi Yes!
I’ve been busy with other things and unfortunately this got left behind. I suppose by now it’d be better to start again from scratch since the code is probably very different.
That said, I’m more interested in using this feature than implementing it myself, so if anyone else wants to take a crack at it they’re welcome.

@CodaFi
Copy link
Contributor

CodaFi commented Nov 21, 2019

It looks like this diff still applies just fine. You should probably rebase and retest to make sure, but we don't have to start over if you don't want to. Jordan still has unaddressed feedback, though, which is the most important thing.

If you would like, I can close this and file an SR to let somebody else try their hand at this.

@CodaFi
Copy link
Contributor

CodaFi commented Nov 22, 2019

I spoke too soon. This needs a quick rebase.

@vinivendra
Copy link
Contributor Author

You're right, these changes still apply well. I just performed a rebase and everything looks OK.

As for Jordan's feedback (where he suggested using ArgRequiringSingleCompile->getSpelling()), I just tried it but it prints '-whole-module-optimization' even when I pass '-wmo'. I also tried this (to make sure I'm printing the wmo argument and not the index-file argument), but the same thing happens:

const Arg *ArgWMO = Args.getLastArg(options::OPT_whole_module_optimization);
Diags.diagnose(SourceLoc(), diag::warn_ignoring_wmo, ArgWMO->getSpelling());

And I tried this, but the program crashes:

const Arg *ArgWMO = Args.getLastArg(options::OPT_wmo);
Diags.diagnose(SourceLoc(), diag::warn_ignoring_wmo, ArgWMO->getSpelling());

Any ideas?

@jrose-apple
Copy link
Contributor

Weird. I thought that was the point of getSpelling(). There's also getAsString but that seems like overkill.

I'm no longer at Apple at this point, but there's not too much here, and this diagnostic bit shouldn't hold up the rest of the patch if it's not coming together easily. If you rebase, @CodaFi or @brentdax can do the final bit of shepherding it in.

Ignoring both `-wmo` and `-index-file` will be harder than just `-wmo`. This is because when calling the compiler and passing `-index-file` after `-dump-ast`, the option gets un-ignored by `Driver::buildOutputInfo`. Therefore, we will just ignore `-wmo` for now.
@vinivendra
Copy link
Contributor Author

Ok then! It's rebased and should be ready to merge.

@CodaFi
Copy link
Contributor

CodaFi commented Dec 7, 2019

Will manually squash this down when it passes

@swift-ci please smoke test

@vinivendra
Copy link
Contributor Author

I don't mean to pressure anyone, but it seems the tests have passed - and I'm afraid if we wait much longer we'll need a new rebase and new tests. Is this still OK to merge?

@CodaFi
Copy link
Contributor

CodaFi commented Dec 19, 2019

⛵️

@CodaFi CodaFi merged commit aebfb53 into swiftlang:master Dec 19, 2019
@vinivendra vinivendra deleted the ast-dump-ignore-wmo branch December 20, 2019 18:19
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.

3 participants