This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Handle case insensitive file systems in header/source switch
ClosedPublic

Authored by kadircet on Mar 9 2022, 5:55 AM.

Diff Detail

Event Timeline

kadircet created this revision.Mar 9 2022, 5:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2022, 5:55 AM
kadircet requested review of this revision.Mar 9 2022, 5:55 AM
kadircet edited the summary of this revision. (Show Details)
sammccall added inline comments.Mar 9 2022, 7:09 AM
clang-tools-extra/clangd/unittests/TestFS.cpp
88

This is clever, but I don't think it's a good idea.

It's very surprising given the contract and historical behavior of this function, and can lead to spurious test failures in some legitimate uses, e.g in IncludeCleanerTests:

// Note we deduped the names as _number_ of <built-in>s is uninteresting.
EXPECT_THAT(ReferencedFileNames.keys(),
            UnorderedElementsAre("<built-in>", "<scratch space>",
                                 testPath("macros.h")));

(Not sure why this isn't failing, luck? Maybe you'll get more failures by adding more possible case variations?)
I don't think the extra verbosity to make such tests resilient to case changes is an improvement.

The paths coming from testRoot get propagated around a lot, so lots of strings start having unpredictable case (which is the point!). Nevertheless I'm not confident many of them will be effectively tested, because the paths compared need to originate through independent calls to testRoot() rather than e.g. both resulting from relative paths resolved against a CWD set to testRoot() called once.

kadircet updated this revision to Diff 414301.Mar 10 2022, 1:20 AM

Add tests specifically and postpone change in testRoot

kadircet updated this revision to Diff 414324.Mar 10 2022, 2:55 AM
  • Adjust after tests on windows
kadircet updated this revision to Diff 414325.Mar 10 2022, 2:57 AM
kadircet retitled this revision from [clangd] Test against path insensitivity to [clangd] Handle case insensitive file systems in header/source switch.
  • rename patch
kadircet updated this revision to Diff 414326.Mar 10 2022, 2:59 AM
  • Match path ignoring case.
sammccall accepted this revision.Mar 21 2022, 3:19 AM
sammccall added inline comments.
clang-tools-extra/clangd/support/Path.h
50 ↗(On Diff #414326)

This function is a bit of a trap.

c.f. pathStartsWith which understands path semantics: pathStartsWith("a/b", "a/bc") is false.

This function returns true/false based on paths semantics, but the stripping is lexical:

  • pathConsumeFront("a/b/c", "a/b/") is "c"
  • pathConsumeFront("a/b/c", "a/b") is "/c", a very different path.

It's safe where called here because we know testRoot() ends in a slash, but I'd probably inline it for that reason - it's not as reusable as it looks.

Up to you, though.

clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
277

mac is the same as windows here I think.

This should probably be #ifdef CLANGD_PATH_CASE_INSENSITIVE if possible?

If you want to be really clever, you could keep the test on all platforms and just #ifdef the assertions to give opposite results. We don't want tests to pass if we are case insensitive everywhere, right?

281

are the inline functions essential to this test?
Even with context I was struggling a bit to understand what this is testing, so it'd be nice to cut down a few elements

294

either a comment or a variable name explaining what we're doing here?

// Providing the "wrong"-case drive letter in the query should still find the file.

Why uppercase the drive letter only and not the whole filename? Then we could run the test on mac too

295

May be nice to have an assertion that HeaderAbsPath != testPath(TU.HeaderFilename), so that we're not spuriously passing because testRoot() is "C:\" or "\\something"

This revision is now accepted and ready to land.Mar 21 2022, 3:19 AM
kadircet updated this revision to Diff 416984.Mar 21 2022, 9:23 AM
kadircet marked 2 inline comments as done.
  • Address comments
kadircet marked 3 inline comments as done.Mar 21 2022, 9:26 AM
kadircet added inline comments.
clang-tools-extra/clangd/support/Path.h
50 ↗(On Diff #414326)

fair point, moved into TestFS.cpp.

clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
281

yes, we need majority of the symbols to be defined in the header, so that the heuristic picks the header as the implementation file (if the header isn't ignored due to case-sensitive check of filepaths). adding a comment though.

kadircet updated this revision to Diff 416988.Mar 21 2022, 9:26 AM
  • Address comments for real
This revision was landed with ongoing or failed builds.Mar 21 2022, 9:33 AM
This revision was automatically updated to reflect the committed changes.