-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
[Batch Mode] Move supplementary output paths into a dedicated structure in FrontendInputsAndOutputs (3) #14402
Conversation
@swift-ci please smoke test |
e4c5934
to
c145b55
Compare
@swift-ci please smoke test os x platform |
c145b55
to
b4852f9
Compare
@swift-ci please smoke test |
There’s a new diagnostic in this PR. I’ll try to write a test for it tomorrow. |
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 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>> |
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.
Opinion: This is too complicated now, better to use out parameters.
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.
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.
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.
I guess another alternative would be to use a one-off struct.
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.
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. |
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.
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.
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.
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; |
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.
Nitpicks: No need for swift::
, pathID
instead of path_id
.
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.
Fixed, thanks.
const SupplementaryOutputPaths &pathsFromFilelists, | ||
const InputFile &) const; | ||
|
||
StringRef deriveImplicitBasis(StringRef outputFilename, |
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.
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.
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.
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) |
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.
I think it'd be more declarative to set these individually rather than as a long list of undifferentiated arguments.
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.
If only C++ had C's named member initializer syntax. (It does in C++17.)
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.
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)) |
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.
This should probably just be too many %0 arguments
or perhaps too many %0 arguments (expected %1, got %2)
.
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.
Very nice! Fixed.
const unsigned N = | ||
InputsAndOutputs.countOfFilesProducingSupplementaryOutput(); | ||
if (paths.size() > N) { | ||
std::unique_ptr<llvm::opt::OptTable> Table = createSwiftOptTable(); |
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.
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.
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.
Thanks. Figured out a way to do it without generating a new table.
return None; | ||
} | ||
while (paths.size() < N) | ||
paths.push_back(std::string()); |
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.
This doesn't make sense; like with -o
, there should always be exactly the right number of paths, or 0 paths.
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.
(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.)
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.
Do you mean that the code should emit a diagnostic and bail out if there are paths, but not the right number?
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.
I think so, yes.
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.
OK, done, I think.
if (!serializedDiagnosticsPath) | ||
return None; | ||
|
||
auto objCHeaderOutputPath = determineSupplementaryOutputFilename( |
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.
Super nitpick: "ObjC" is one word when abbreviated as such, so its lowercase form is "objc".
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.
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 |
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.
Comment needs updating.
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.
Good catch, thanks! Much of the comments in that function were redundant, so I streamlined them.
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. |
b4852f9
to
1714740
Compare
@swift-ci please smoke test |
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. |
@swift-ci please smoke test |
1714740
to
c98189b
Compare
@swift-ci please smoke test os x platform |
c98189b
to
6672d5a
Compare
@swift-ci please smoke test os x platform |
6672d5a
to
987cc1f
Compare
@swift-ci please smoke test os x platform |
987cc1f
to
a5fdb7f
Compare
@swift-ci please smoke test os x platform |
a5fdb7f
to
0d290a3
Compare
@swift-ci please smoke test os x platform |
0d290a3
to
b2b052e
Compare
@swift-ci please smoke test os x platform |
@swift-ci please test |
Build failed |
Build failed |
return None; | ||
} | ||
while (paths.size() < N) | ||
paths.push_back(std::string()); |
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.
…which means this can become, unconditionally, paths.rezise(N)
.
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.
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. |
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.
Another specific-rather-than-generic comment.
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.
Thank you for the catch! Fixed.
return pathFromArguments; | ||
|
||
if (!Args.hasArg(emitOpt)) | ||
return std::string(); |
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.
Shouldn't this be None
?
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.
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()) | ||
; |
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.
Does this need to be handled explicitly at all? When is the assertion from before no longer valid?
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.
I just pushed a new commit that cleans up these corner cases. Check it out!
lib/FrontendTool/FrontendTool.cpp
Outdated
static bool serializeSIB(FrontendOptions &opts, SILModule *SM, | ||
ASTContext &Context, ModuleOrSourceFile MSF) { | ||
const std::string &moduleOutputPath = opts.ModuleOutputPath; | ||
static bool serializeSIBIfNeeded(FrontendOptions &opts, SILModule *SM, |
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.
Looks like the wrong name snuck back into this version.
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.
Thanks. Fixed.
b2b052e
to
526441c
Compare
@swift-ci please smoke test os x platform |
526441c
to
1096388
Compare
@swift-ci please smoke test os x platform |
1096388
to
e32afe8
Compare
@swift-ci please smoke test |
521f102
to
93daabb
Compare
@swift-ci please smoke test |
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.
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; |
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.
Nice, I like the way this came out!
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.
:)
options::ID emitOpt, std::string pathFromArguments, StringRef extension, | ||
StringRef mainOutputIfUsable, | ||
StringRef defaultSupplementaryOutputPathExcludingExtension) const { | ||
using namespace options; |
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.
Nitpick: this is no longer necessary.
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.
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, |
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.
getPrefixedName()
produces a slightly prettier diagnostic (it says "-emit-module-path" instead of "emit-module-path").
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.
Great! Done.
Good catches! I'll make the fixes, retest, and merge. Thank you. |
93daabb
to
fda0bf3
Compare
@swift-ci please smoke test |
…ere are no inputs.
fda0bf3
to
ef02d0b
Compare
@swift-ci please smoke test |
In preparation for many sets of supplementary outputs, reify the set, and move it into FrontendInputsAndOutputs. Also move the computation of those.