Skip to content

[Batch Mode] Move supplementary output paths into a dedicated structure in FrontendInputsAndOutputs (3) #14402

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

Conversation

davidungar
Copy link
Contributor

In preparation for many sets of supplementary outputs, reify the set, and move it into FrontendInputsAndOutputs. Also move the computation of those.

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from e4c5934 to c145b55 Compare February 6, 2018 03:37
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from c145b55 to b4852f9 Compare February 6, 2018 04:05
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar
Copy link
Contributor Author

There’s a new diagnostic in this PR. I’ll try to write a test for it tomorrow.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

The next step is to sink this into the individual inputs, then?

@@ -41,7 +42,8 @@ class ArgsToFrontendOutputsConverter {
: Args(args), ModuleName(moduleName), InputsAndOutputs(inputsAndOutputs),
Diags(diags) {}

Optional<std::vector<std::string>> convert();
Optional<std::pair<std::vector<std::string>, SupplementaryOutputPaths>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Opinion: This is too complicated now, better to use out parameters.

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 love the functional style, but since this will get even more complicated when a vector of SupplementaryPaths is returned, I'm changing it as suggested.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess another alternative would be to use a one-off struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that would work, too. I just went with out-parameters.


/// \return None if error
/// Otherwise return a vector with one entry per file producing supplementary
/// 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 gets collected into a single section in Doxygen, so you'll want a period after the word "error". But I also don't understand what this function does from its name or its 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.

Expanded the comment and tweaked the name. If it is still unclear, would you like to suggest something?

/// Otherwise return a vector with one entry per file producing supplementary
/// outputs.
Optional<std::vector<std::string>>
readSupplementaryOutputArguments(swift::options::ID path_id) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicks: No need for swift::, pathID instead of path_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks.

const SupplementaryOutputPaths &pathsFromFilelists,
const InputFile &) const;

StringRef deriveImplicitBasis(StringRef outputFilename,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: I don't think "basis" is a standard term. I happen to know what you mean (directory + basename but not extension), but if you want to call it this please leave a doc 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.

Renamed function to: deriveDefaultSupplementaryOutputPathExcludingExtension and renamed implicitBasis to defaultSupplementaryOutputPathExcludingExtension. May be long, but at least it's clear.

std::string referenceDependenciesFilePath,
std::string serializedDiagnosticsPath,
std::string loadedModuleTracePath,
std::string tbdPath)
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'd be more declarative to set these individually rather than as a long list of undifferentiated arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

If only C++ had C's named member initializer syntax. (It does in C++17.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, a problematic tradeoff. I've made the change.

@@ -190,6 +190,9 @@ ERROR(error_index_failed_status_check,none,
ERROR(error_index_inputs_more_than_outputs,none,
"index output filenames do not match input source files", ())

ERROR(error_too_many_supplementary_outputs,none,
"too many supplementary outputs '%0'", (StringRef))
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably just be too many %0 arguments or perhaps too many %0 arguments (expected %1, got %2).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very nice! Fixed.

const unsigned N =
InputsAndOutputs.countOfFilesProducingSupplementaryOutput();
if (paths.size() > N) {
std::unique_ptr<llvm::opt::OptTable> Table = createSwiftOptTable();
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't have to greate a new OptTable for this; each Arg already has a reference to the full Option info in the existing table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Figured out a way to do it without generating a new table.

return None;
}
while (paths.size() < N)
paths.push_back(std::string());
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't make sense; like with -o, there should always be exactly the right number of paths, or 0 paths.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Honestly it is useful to be able to override previous options by having the last argument win, but that's still not what's going on here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean that the code should emit a diagnostic and bail out if there are paths, but not the right number?

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 so, yes.

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, done, I think.

if (!serializedDiagnosticsPath)
return None;

auto objCHeaderOutputPath = determineSupplementaryOutputFilename(
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nitpick: "ObjC" is one word when abbreviated as such, so its lowercase form is "objc".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

return outputFilename;

// If we have a primary input, so use that as the basis for the name of the
// serialized diagnostics file, otherwise fall back on the
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment needs updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks! Much of the comments in that function were redundant, so I streamlined them.

@davidungar
Copy link
Contributor Author

Thanks for getting on this so quickly! You are keeping me energized. I have a midday commitment, but otherwise will be working on these comments to get you a revision ASAP, including a test for the new diagnostic.

The next step will be the introduction of the PrimarySpecificPaths structure, which can be passed around in the compiler and holds both main and supp outputs. Then, putting that in the inputs.

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from b4852f9 to 1714740 Compare February 7, 2018 00:30
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar
Copy link
Contributor Author

At this point, I've taken a whack at addressing all of the suggestions. Feel free to let me know what ought to be done next. I'll also be writing a test for the new diagnostic.

@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 1714740 to c98189b Compare February 7, 2018 02:44
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from c98189b to 6672d5a Compare February 7, 2018 03:15
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 6672d5a to 987cc1f Compare February 7, 2018 04:08
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 987cc1f to a5fdb7f Compare February 7, 2018 04:49
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from a5fdb7f to 0d290a3 Compare February 7, 2018 05:14
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 0d290a3 to b2b052e Compare February 7, 2018 05:44
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2018

Build failed
Swift Test OS X Platform
Git Sha - e4c59343b54f86bb9cf089e6839be8820135bccd

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2018

Build failed
Swift Test Linux Platform
Git Sha - e4c59343b54f86bb9cf089e6839be8820135bccd

return None;
}
while (paths.size() < N)
paths.push_back(std::string());
Copy link
Contributor

Choose a reason for hiding this comment

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

…which means this can become, unconditionally, paths.rezise(N).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing so quickly! I went down a rathole last night and had to back up.
Maybe have backed up too far. I have rewritten this routine and directly constructs a vector with N blanks if needed.

StringRef SupplementaryOutputPathsComputer::
deriveDefaultSupplementaryOutputPathExcludingExtension(
StringRef outputFilename, const InputFile &input) const {
// Put the serialized diagnostics file next to the output file if possible.
Copy link
Contributor

Choose a reason for hiding this comment

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

Another specific-rather-than-generic 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.

Thank you for the catch! Fixed.

return pathFromArguments;

if (!Args.hasArg(emitOpt))
return std::string();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be None?

Copy link
Contributor Author

@davidungar davidungar Feb 7, 2018

Choose a reason for hiding this comment

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

std::string() is correct, but the code was unclear because it was using None for error. However,
there is no error condition in this version. So, I modified this function and its caller to just return a string, instead of an optional. And, I added a Doxygen comment. (The optional may come back in a future PR, but I'll comment it if so.) Thanks for catching this.

ArrayRef<std::string> outputFiles,
SupplementaryOutputPaths supplementaryOutputs) {
if (outputFiles.empty())
;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be handled explicitly at all? When is the assertion from before no longer valid?

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 just pushed a new commit that cleans up these corner cases. Check it out!

static bool serializeSIB(FrontendOptions &opts, SILModule *SM,
ASTContext &Context, ModuleOrSourceFile MSF) {
const std::string &moduleOutputPath = opts.ModuleOutputPath;
static bool serializeSIBIfNeeded(FrontendOptions &opts, SILModule *SM,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the wrong name snuck back into this version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from b2b052e to 526441c Compare February 7, 2018 18:23
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 526441c to 1096388 Compare February 7, 2018 18:28
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test os x platform

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 1096388 to e32afe8 Compare February 7, 2018 18:44
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 521f102 to 93daabb Compare February 7, 2018 21:59
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Last few comments, but no need for another round of review after that!

Diags.diagnose(SourceLoc(), diag::error_wrong_number_of_arguments,
Args.getLastArg(pathID)->getOption().getName(), N,
paths.size());
return None;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I like the way this came out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

options::ID emitOpt, std::string pathFromArguments, StringRef extension,
StringRef mainOutputIfUsable,
StringRef defaultSupplementaryOutputPathExcludingExtension) const {
using namespace options;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: this is no longer necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Removed.

return std::vector<std::string>(N, std::string());

Diags.diagnose(SourceLoc(), diag::error_wrong_number_of_arguments,
Args.getLastArg(pathID)->getOption().getName(), N,
Copy link
Contributor

Choose a reason for hiding this comment

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

getPrefixedName() produces a slightly prettier diagnostic (it says "-emit-module-path" instead of "emit-module-path").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! Done.

@davidungar
Copy link
Contributor Author

Good catches! I'll make the fixes, retest, and merge. Thank you.

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from 93daabb to fda0bf3 Compare February 8, 2018 20:35
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar davidungar force-pushed the PR-18-5a-SupplementaryOutputs branch from fda0bf3 to ef02d0b Compare February 8, 2018 21:23
@davidungar
Copy link
Contributor Author

@swift-ci please smoke test

@davidungar davidungar merged commit 95f70f7 into swiftlang:master Feb 8, 2018
@davidungar davidungar deleted the PR-18-5a-SupplementaryOutputs branch May 16, 2018 16:59
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