This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Improve FileSpec internal APIs and usage in preparation for adding caching of resolved/absolute.
ClosedPublic

Authored by clayborg on Jul 25 2022, 11:33 PM.

Details

Summary

Resubmission of https://reviews.llvm.org/D130309 with the 2 patches that fixed the linux buildbot, and new windows fixes.

The FileSpec APIs allow users to modify instance variables directly by getting a non const reference to the directory and filename instance variables. This makes it impossible to control all of the times the FileSpec object is modified so we can clear cached member variables like m_resolved and with an upcoming patch caching if the file is relative or absolute. This patch modifies the APIs of FileSpec so no one can modify the directory or filename instance variables directly by adding set accessors and by removing the get accessors that are non const.

Many clients were using FileSpec::GetCString(...) which returned a unique C string from a ConstString'ified version of the result of GetPath() which returned a std::string. This caused many locations to use this convenient function incorrectly and could cause many strings to be added to the constant string pool that didn't need to. Most clients were converted to using FileSpec::GetPath().c_str() when possible. Other clients were modified to use the newly renamed version of this function which returns an actualy ConstString:

ConstString FileSpec::GetPathAsConstString(bool denormalize = true) const;

This avoids the issue where people were getting an already uniqued "const char *" that came from a ConstString only to put the "const char *" back into a "ConstString" object. By returning the ConstString instead of a "const char *" clients can be more efficient with the result.

The patch:

  • Removes the non const GetDirectory() and GetFilename() get accessors
  • Adds set accessors to replace the above functions: SetDirectory() and SetFilename().
  • Adds ClearDirectory() and ClearFilename() to replace usage of the FileSpec::GetDirectory().Clear()/FileSpec::GetFilename().Clear() call sites
  • Fixed all incorrect usage of FileSpec::GetCString() to use FileSpec::GetPath().c_str() where appropriate, and updated other call sites that wanted a ConstString to use the newly returned ConstString appropriately and efficiently.

Diff Detail

Event Timeline

clayborg created this revision.Jul 25 2022, 11:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2022, 11:33 PM
clayborg requested review of this revision.Jul 25 2022, 11:33 PM
Herald added a project: Restricted Project. · View Herald Transcript

Can anyone with windows access try applying this patch and seeing if things build? Any help to avoid having Buildbot issues would be great

Ping. This was accepted before but I had Buildbot issues. Those should all be resolved in this updated patch after a revert.

Ping. This was accepted before but I had Buildbot issues. Those should all be resolved in this updated patch after a revert.

Sorry for the delay. I can confirm this builds correctly for Windows now.

Ping. This was accepted before but I had Buildbot issues. Those should all be resolved in this updated patch after a revert.

Sorry for the delay. I can confirm this builds correctly for Windows now.

Great! Can someone accept the patch?

FYI: I have built this on mac and on my linux machine, so I know both mac and linux build, and we know windows builds now too

smeenai accepted this revision.Jul 28 2022, 12:21 PM

FWIW, I've usually seen people just recommit directly instead of going through another review. Accepting this since it was already reviewed last time and the only changes are buildbot fixes.

This revision is now accepted and ready to land.Jul 28 2022, 12:21 PM