Skip to content

Consistently get extensions from FileTypes.h #18203

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 5 commits into from
Jul 26, 2018

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Jul 25, 2018

...instead of sometimes hardcoding them and sometimes using Strings.h. The exceptions are the libraries that sit below Frontend; these can continue using strings.

There's one semantic change here, which is that LLVM IR files mistakenly had the extension "ir" instead of "ll" before. Nothing was actually depending on this until now, though.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@gottesmm
Copy link
Contributor

Seems reasonable to me. I haven't looked through all of the details though.

Copy link
Contributor

@davidungar davidungar left a comment

Choose a reason for hiding this comment

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

This is great stuff! Of all my comments, it's the ones about symmetry that strike me hardest. If it has to be this way, how about a comment somewhere explaining why all the type extensions can't be in one place?

@@ -46,13 +46,15 @@ TYPE("object", Object, "o", "")
TYPE("dSYM", dSYM, "dSYM", "")
TYPE("dependencies", Dependencies, "d", "")
TYPE("autolink", AutolinkFile, "autolink", "")
TYPE("swiftmodule", SwiftModuleFile, "swiftmodule", "")
TYPE("swiftdoc", SwiftModuleDocFile, "swiftdoc", "")
TYPE("swiftmodule", SwiftModuleFile,
Copy link
Contributor

Choose a reason for hiding this comment

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

As I read this, I'm wondering why some of the extension strings are here but others are macros. Why the asymmetry?

TYPE("swiftinterface", SwiftModuleInterfaceFile, "swiftinterface", "")
TYPE("assembly", Assembly, "s", "")
TYPE("raw-sil", RawSIL, "sil", "")
TYPE("raw-sib", RawSIB, "sib", "")
TYPE("llvm-ir", LLVM_IR, "ir", "")
TYPE("llvm-ir", LLVM_IR, "ll", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to change "ir" to "ll"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, as commented above "ir" was a mistake but we weren't relying on it for anything until now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry-missed that comment.

constexpr static const char SIB_EXTENSION[] = "sib";
/// The extension for LLVM IR files.
constexpr static const char LLVM_BC_EXTENSION[] = "bc";
constexpr static const char LLVM_IR_EXTENSION[] = "ll";
Copy link
Contributor

Choose a reason for hiding this comment

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

W.r.t. the asymmetry comment above, another option would be to keep these here and use all of these consts in the TYPE definitions. Why one vs the other? (I'll bet you have a good reason.)

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 have an okay reason. :-/ The remaining constants here are ones that are used in libraries below Frontend (in layering terms). I'd prefer not to put them all here because I think the file_types abstractions are better, but it does make an ugly asymmetry here.

Another option would be to go a step further and sink the information in file_types down to Basic, which means they could be included from anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like that option: sinking the info down to Basic! It's a nice unification which I suspect will pay off in the future!

@@ -718,7 +718,7 @@ createStatsReporter(const llvm::opt::InputArgList *ArgList,
if (Inputs.size() == 1) {
InputName = Inputs[0].second->getSpelling();
}
StringRef OutputType = file_types::getTypeTempSuffix(OI.CompilerOutputType);
StringRef OutputType = file_types::getExtension(OI.CompilerOutputType);
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, @graydon has reminded me that it can be better to separate renaming changes from other changes, for instance in separate commits. I like what you're doing here--just passing this on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough.

@@ -2718,7 +2718,8 @@ void Driver::chooseRemappingOutputPath(Compilation &C,
} else {
llvm::SmallString<128> Path(Output->getPrimaryOutputFilenames()[0]);
bool isTempFile = C.isTemporaryFile(Path);
llvm::sys::path::replace_extension(Path, "remap");
llvm::sys::path::replace_extension(Path,
file_types::getExtension(file_types::ID::TY_Remapping));
Copy link
Contributor

Choose a reason for hiding this comment

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

Hooray!

@@ -117,11 +117,14 @@ OutputFilesComputer::create(const llvm::opt::ArgList &args,
return None;
}

file_types::ID outputType =
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be const

}
// If we have one primary input and it's a filename with extension "sil",
// treat the input as SIL.
unsigned silPrimaryCount = numberOfPrimaryInputsEndingWith(SIL_EXTENSION);
unsigned silPrimaryCount = numberOfPrimaryInputsEndingWith(
Copy link
Contributor

Choose a reason for hiding this comment

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

I should have made this a const if/when I wrote it.

Let's be honest: this isn't just for temporary files. Also, it's not
really a "suffix" if it doesn't include the leading dot.

No functionality change.
...instead of sometimes hardcoding them and sometimes using Strings.h.
The exceptions are the libraries that sit below Frontend; these can
continue using strings.
@jrose-apple jrose-apple changed the title Consistently get extensions from swift/Frontend/FileTypes.h Consistently get extensions from FileTypes.h Jul 26, 2018
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6631399969aa38e22146f5b082039dcec4e8b5b0

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6631399969aa38e22146f5b082039dcec4e8b5b0

The next commit will take advantage of this, but this is just a
mechanical change.
Remove the last few literal extension strings from Strings.h in favor
of the file_types APIs, and use those APIs in a few more places.
No intended functionality change.
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 457130fdf7441ed77b8585d8fea625853d264bd1

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 457130fdf7441ed77b8585d8fea625853d264bd1

Copy link
Contributor

@davidungar davidungar left a comment

Choose a reason for hiding this comment

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

Very nice! Love the symmetry. Would still want the consts, but it's not a big deal.

@jrose-apple jrose-apple merged commit ca5eacf into swiftlang:master Jul 26, 2018
@jrose-apple jrose-apple deleted the strung-out branch July 26, 2018 21:30
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.

4 participants