Skip to content
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

[SE-0274] Update concise #file implementation in response to first round of review #29412

Merged
merged 6 commits into from
Mar 6, 2020

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Jan 24, 2020

This PR addresses several issues that came up in the first review of SE-0274:

  • The format of the #file string is now <module>/<filename>. (Technically, the proposal will also allow it to be <module>/<other-stuff>/<filename> instead, but that's for future expansion.)

  • If a #sourceLocation(file:line:) directive maps to the same #file string as a real file or another #sourceLocation directive, but the paths don't match exactly, the compiler now emits a warning.

  • -emit-sil and related textual SIL outputs now include a comment with a table mapping #file strings to #filePath strings. This is a proof-of-concept demonstrating that we can expose this information in e.g. SourceKit later on.

The proposal will be updated to include these changes shortly.

@beccadax beccadax requested a review from CodaFi January 24, 2020 02:08
@beccadax
Copy link
Contributor Author

@CodaFi This set of changes works, but I'm not very happy with where this code lives in the compiler or how it ends up being called. Do you have any suggestions to improve it?

@beccadax
Copy link
Contributor Author

@swift-ci test

@beccadax
Copy link
Contributor Author

@swift-ci test Windows platform

@beccadax beccadax force-pushed the two-revisions-for-slashing branch from 81a9927 to 54b93a8 Compare March 6, 2020 01:21
beccadax added 2 commits March 5, 2020 17:23
A proof of concept for tools providing this information in more useful forms.
@beccadax beccadax force-pushed the two-revisions-for-slashing branch from 54b93a8 to 8c01e59 Compare March 6, 2020 01:23
@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax beccadax requested review from hamishknight and removed request for CodaFi March 6, 2020 01:52
@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

8 similar comments
@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test Windows platform

beccadax added 3 commits March 5, 2020 23:30
GYB opens its inputs and outputs in text mode. This is a problem because the recommendation in Windows is to check everything out in LF mode to avoid breaking tests, so gybbing a file ends up converting LFs to CRLFs. That broke test/SILGen/magic_identifier_file_conflicting.swift.gyb.

Modify GYB to open its files in binary mode instead of text mode. This is a no-op everywhere but Windows.

Note that this change is incomplete: it’s somewhat difficult to switch stdin and stdout to binary mode in Python 2. I’ve added FIXME comments about this.
@beccadax beccadax force-pushed the two-revisions-for-slashing branch from 84b1ef7 to 62ab3df Compare March 6, 2020 07:31
@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test windows platform

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test

@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test windows platform

1 similar comment
@beccadax
Copy link
Contributor Author

beccadax commented Mar 6, 2020

@swift-ci please test windows platform

@beccadax beccadax merged commit 2cc9446 into swiftlang:master Mar 6, 2020
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Looks great! Just a couple of nits

/// file.
llvm::SmallVector<Located<StringRef>, 0> VirtualFilenames;

llvm::StringMap<SourceFilePathInfo> getInfoForUsedFilePaths() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a brief doc comment explaining that this returns info for the physical and virtual file paths introduced by this file?

@@ -321,6 +321,12 @@ class SourceFile final : public FileUnit {
/// forwarded on to IRGen.
ASTStage_t ASTStage = Unprocessed;

/// Virtual filenames declared by #sourceLocation(file:) directives in this
/// file.
llvm::SmallVector<Located<StringRef>, 0> VirtualFilenames;
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth renaming this to VirtualFilePaths to clarify that it deals with the whole path passed to #sourceLocation, and cannot be used in general to subscript e.g getInfoForUsedFileNames.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, unrelated to this PR, but I think we should also consider renaming SourceFile::getFilename.

@@ -131,6 +131,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {

ASTContext &getASTContext() { return M.getASTContext(); }

llvm::StringMap<std::pair<std::string, /*isWinner=*/bool>>
MagicFileStringsByFilePath;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I believe MagicFileStringsByFilePath should be indented

beccadax added a commit that referenced this pull request Mar 9, 2020
beccadax added a commit to beccadax/swift that referenced this pull request Mar 13, 2020
This addresses some late-breaking review comments left by @hamishknight on swiftlang#29412.
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.

2 participants