Skip to content

Frontend: use preferred path spellings for paths #81103

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

compnerd
Copy link
Member

Convert paths to the preferred spelling before passing it to the SourceManager to ensure that we have the canonical spelling. This is important as a path with a non-canonical path separator would otherwise fail to be looked up in the source manager buffer.

@compnerd
Copy link
Member Author

@swift-ci please smoke test

@compnerd
Copy link
Member Author

@swift-ci please smoke test macOS platform

@compnerd
Copy link
Member Author

CC: @j-hui

Copy link
Contributor

@j-hui j-hui left a comment

Choose a reason for hiding this comment

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

Thanks for getting around to this. I think this is the right thing to do here (and avoids the lifetime issues I encountered in #80564).

However, I'm not convinced that this will close #81012 just yet because it only canonicalizes the path separators from -verify-additional-file. My logging showed that the paths from -verify-additional-file and from the capture error both have inconsistent path separators:

# .---command stderr------------
# | Got additional file: [[42]]::C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\foreign-reference/Inputs/inheritance.h
# | Captured error in [[2]]::C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\foreign-reference/Inputs\inheritance.h: 125
…

So, this patch should fix the problem for bufID [[42]] here, but not bufID [[2]].

@compnerd
Copy link
Member Author

@swift-ci please smoke test

@compnerd
Copy link
Member Author

I think that fixing [2] is going to require more work and we should do this incrementally. Fixing the first half gets us to a better place as we work towards improving this.

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented May 3, 2025

@swift-ci please test Windows platform

@compnerd
Copy link
Member Author

compnerd commented May 5, 2025

@swift-ci please smoke test

@@ -934,7 +934,9 @@ importer::addCommonInvocationArguments(
invocationArgStrs.push_back("-isystem");
invocationArgStrs.push_back(path.Path);
} else {
invocationArgStrs.push_back("-I" + path.Path);
llvm::SmallString<261> Path{path.Path};
llvm::sys::path::make_preferred(Path);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need to do this for the path strings above too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I missed that in this revision, but I didn't want to interrupt the build itself.

auto bufferID = SM.getIDForBufferIdentifier(path);
llvm::SmallString<261> buffer{path};
llvm::sys::path::make_preferred(buffer);
auto bufferID = SM.getIDForBufferIdentifier(buffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be assertions in central locations like getIDForBufferIdentifier() to catch code that uses non-preferred paths? Or maybe a new type or something? I honestly find it a little difficult to believe that there are only four places where we need to do this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what that central location is, this has been a long standing issue. This fixes the issues that are being uncovered here by enabling some of the tests that you added a long time ago.

@compnerd
Copy link
Member Author

compnerd commented May 7, 2025

@swift-ci please smoke test

@compnerd
Copy link
Member Author

compnerd commented May 7, 2025

@swift-ci please test Windows platform

@compnerd
Copy link
Member Author

compnerd commented May 8, 2025

@swift-ci please test Windows platform

Convert paths to the preferred spelling before passing it to the
SourceManager to ensure that we have the canonical spelling. This is
important as a path with a non-canonical path separator would otherwise
fail to be looked up in the source manager buffer.
@compnerd
Copy link
Member Author

compnerd commented May 8, 2025

@swift-ci please test Windows platform

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