-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
@swift-ci Please smoke test |
@swift-ci Please smoke test |
Seems reasonable to me. I haven't looked through all of the details though. |
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 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?
include/swift/Frontend/Types.def
Outdated
@@ -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, |
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.
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", "") |
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.
Did you mean to change "ir" to "ll"?
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.
Yep, as commented above "ir" was a mistake but we weren't relying on it for anything until now.
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.
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"; |
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.
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.)
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 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.
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 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); |
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.
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.
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.
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)); |
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.
Hooray!
@@ -117,11 +117,14 @@ OutputFilesComputer::create(const llvm::opt::ArgList &args, | |||
return None; | |||
} | |||
|
|||
file_types::ID outputType = |
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.
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( |
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 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.
@swift-ci Please test |
Build failed |
Build failed |
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.
@swift-ci Please test |
Build failed |
Build failed |
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! Love the symmetry. Would still want the consts, but it's not a big deal.
...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.