Skip to content

Add support for parseable-output straight from the frontend #34417

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 11 commits into from
Dec 16, 2020

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Oct 23, 2020

This PR adds initial support for emitting parseable-output JSON directly from swift-frontend.
"began" and "finished" messages are currently supported.

  • The existing parseable-output library used by the Driver is sunk into Basic and extended with entry-points that accept a CompilerInvocation of a swift-frontend, in addition to existing entry-points used by the Driver that accept a Job.
  • A new diagnostic consumer is added in order to capture all produced diagnostics during the frontend's execution, mirroring what the printing consumer would do, except simply accumulating diagnostics, on a per-primary-input basis.
  • For batch jobs, "began" and "finished" messages are emitted on a per-primary-input basis, with quasi-PIDs assigned to the messages of jobs we are "faking". The same scheme as used by the driver is employed to generate quasi-PIDs: start at -1000 and decrement for each next primary input. Non-batch jobs get a real OS PID.

Note: The code in ParseableOutput.h and ParseableOutput.cpp with a Job-based interface is not new. I tried moving these files carefully to preserve history, but enough stuff seems to have changed to not get nice diffs here.

@artemcm
Copy link
Contributor Author

artemcm commented Oct 29, 2020

@swift-ci Please Test Source Compatibility

@artemcm
Copy link
Contributor Author

artemcm commented Oct 30, 2020

@swift-ci Please Smoke Test

2 similar comments
@artemcm
Copy link
Contributor Author

artemcm commented Oct 30, 2020

@swift-ci Please Smoke Test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 2, 2020

@swift-ci Please Smoke Test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 2, 2020

@swift-ci Please Smoke Test Windows platform

2 similar comments
@artemcm
Copy link
Contributor Author

artemcm commented Nov 2, 2020

@swift-ci Please Smoke Test Windows platform

@artemcm
Copy link
Contributor Author

artemcm commented Nov 2, 2020

@swift-ci Please Smoke Test Windows platform

@artemcm artemcm force-pushed the FrontendParseableOutput branch from b6a53c7 to 63c51dd Compare November 3, 2020 17:30
@artemcm
Copy link
Contributor Author

artemcm commented Nov 3, 2020

@swift-ci Please Smoke Test

@artemcm artemcm force-pushed the FrontendParseableOutput branch from 63c51dd to 24ca496 Compare November 3, 2020 19:24
@artemcm
Copy link
Contributor Author

artemcm commented Nov 3, 2020

@swift-ci Please Smoke Test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 4, 2020

@swift-ci Please Smoke Test Linux Platform

@artemcm artemcm force-pushed the FrontendParseableOutput branch from 24ca496 to e9a5203 Compare November 4, 2020 16:17
@artemcm
Copy link
Contributor Author

artemcm commented Nov 4, 2020

@swift-ci Please Smoke Test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 4, 2020

@swift-ci Please smoke Test

@artemcm artemcm force-pushed the FrontendParseableOutput branch from e9a5203 to 477c0a8 Compare November 4, 2020 20:52
@artemcm
Copy link
Contributor Author

artemcm commented Nov 4, 2020

@swift-ci Please Test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 4, 2020

@swift-ci Please Test Source Compatibility

#include "swift/Basic/LLVM.h"
#include "swift/Basic/TaskQueue.h"
#include "swift/Driver/Job.h"
#include "swift/Frontend/Frontend.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Including Driver and Frontend headers from Basic is a layering violation. When we have to violate layering, we usually try to use forward declarations in the header and only import in the implementation, but it'd be better to avoid it entirely.

It looks like what's happening here is that you're trying to create equivalent entry points that take a driver::Job and a CompilerInvocation and share their implementation behind the scenes. Instead, I would create a common-currency type that captures the information about a job that parseable_output cares about, and then write conversion functions in Driver and Frontend respectively to construct this type from driver::Job and CompilerInvocation. (Alternatively, have a superclass in Basic that both of these classes subclass.) That will separate the components in Basic more cleanly from the details of the driver and frontend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing this out.
The implementation's Message types already lended themselves pretty nicely to being separated in this fashion with some core basics being kept in a Basic library. The specific portions have now been split into their new homes in Driver and Frontend.

Comment on lines 245 to 252
Outputs.push_back(OutputPair(file_types::lookupTypeForExtension(
llvm::sys::path::extension(output)),
output));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it's a good idea to use lookupTypeForExtension() like this. A build system could pass filenames with no extension or the wrong extension; if they do, we should still treat these correctly, using a file type based on which field in the supplementary output path field we found the path in. (This probably means forEachSetOutput would pass the file type to the lambda.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great observation, thank you. We do indeed have all the information we need to determines this based on action and known file type instead of inferring it. I modified forAllOutputPaths to pass along the filetype.

// If we got this far, we need to suppress the output of the
// PrintingDiagnosticConsumer to ensure that only the parseable-output
// is emitted
PDC.setSuppressOutput(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking: We're disabling the PrintingDiagnosticConsumer instead of never adding it in the first place because we need the PDC while we're parsing arguments, including the argument that sets this option?

Copy link
Contributor Author

@artemcm artemcm Nov 5, 2020

Choose a reason for hiding this comment

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

Exactly. In fact, it seems that this is why setSuppressOutput exists in the first place.

@artemcm artemcm force-pushed the FrontendParseableOutput branch from 5d34735 to c9d21e0 Compare November 5, 2020 19:49
@artemcm
Copy link
Contributor Author

artemcm commented Nov 6, 2020

@brentdax Thank you for such thorough and insightful feedback.

@artemcm
Copy link
Contributor Author

artemcm commented Nov 6, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2020

Build failed
Swift Test Linux Platform
Git Sha - ba2f677daed0578ad9dd2efda70199f21294cfdf

@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - ba2f677daed0578ad9dd2efda70199f21294cfdf

@artemcm artemcm force-pushed the FrontendParseableOutput branch from ba2f677 to 789504e Compare November 6, 2020 19:25
@artemcm
Copy link
Contributor Author

artemcm commented Nov 30, 2020

@swift-ci please test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 30, 2020

@swift-ci please test Windows platform

@artemcm
Copy link
Contributor Author

artemcm commented Dec 1, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 94e56953b3ccf3c5c9fc52a33706ec5291bfad81

@artemcm
Copy link
Contributor Author

artemcm commented Dec 2, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 2, 2020

Build failed
Swift Test Linux Platform
Git Sha - ed242439584a6ecd6f1f3be2839024e43fbab437

@artemcm artemcm force-pushed the FrontendParseableOutput branch from ed24243 to 709b55c Compare December 2, 2020 19:31
@artemcm
Copy link
Contributor Author

artemcm commented Dec 2, 2020

@swift-ci please test

@artemcm
Copy link
Contributor Author

artemcm commented Dec 2, 2020

@brentdax ping. The feedback above has been addressed, I believe.

@artemcm artemcm force-pushed the FrontendParseableOutput branch from 709b55c to 234c49c Compare December 12, 2020 00:01
@artemcm
Copy link
Contributor Author

artemcm commented Dec 12, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 234c49ce0d3a86f1d4042b0c8f6374268bedb81c

@artemcm
Copy link
Contributor Author

artemcm commented Dec 14, 2020

@swift-ci please test macOS platform

Copy link
Contributor

@beccadax beccadax left a comment

Choose a reason for hiding this comment

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

Much better! I have a couple nits to pick, but this has the right shape now.

Comment on lines 46 to 54
struct DetailedMessagePayload {
std::string Executable;
SmallVector<std::string, 16> Arguments;
std::string CommandLine;
SmallVector<CommandInput, 4> Inputs;
SmallVector<OutputPair, 8> Outputs;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This type ought to have a doc comment.

I'd also like you to think carefully about its name. Yes, from the perspective of the emit*Message() functions, this is the payload of the DetailedMessage you're emitting. But that's an implementation detail of this subsystem.

A better type name would come from asking, "what is this type to the clients of this header"? I might call it something like a "job description" or "process info" or maybe a "quasi-invocation" or something. I'll leave the exact decision to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the insight, I fully agree.
I have renamed the type and it now has a doc to describe its purpose.

…tend

Introducing new entry-points that can be used from both Driver and Frontend clients, using an intermediary new type: `DetailedMessagePayload`, when needed.
@artemcm artemcm force-pushed the FrontendParseableOutput branch from 234c49c to 915186a Compare December 14, 2020 19:36
@artemcm
Copy link
Contributor Author

artemcm commented Dec 14, 2020

@swift-ci please test

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented Dec 16, 2020

@swift-ci please test

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