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

Propagate llvm::vfs::FileSystem from driver_env to Clang #4537

Merged
merged 12 commits into from
Nov 18, 2024

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Nov 15, 2024

As discussed in #4530 . This required switching to using llvm::IntrusiveRefCntPtr in a number of places.

@josh11b josh11b requested review from jonmeow and removed request for zygoloid November 15, 2024 18:06
@@ -77,7 +77,7 @@ class FileTestBase : public testing::Test {
// The return value should be an error if there was an abnormal error, and
// RunResult otherwise.
virtual auto Run(const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::vfs::InMemoryFileSystem& fs,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> fs,
Copy link
Contributor

@jonmeow jonmeow Nov 15, 2024

Choose a reason for hiding this comment

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

Can you elaborate why you're generally passing by value instead of by reference? That is, I understand a IntrusiveRefCntPtr is needed for ClangRunner. However, do we benefit from doing reference counting at each call boundary? (is incrementing the reference count for recursive calls the intended result?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not realize there was a performance concern here, and passing by value provides a simpler contract in general. I will make more of these references.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, these have complex construction/destruction so don't fall into the "trivial struct" case of copying.

Comment on lines +81 to +82
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> fs =
new llvm::vfs::InMemoryFileSystem;
Copy link
Contributor

@jonmeow jonmeow Nov 15, 2024

Choose a reason for hiding this comment

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

In some cases you use = initialization, in others you use () like:

  llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> fs(
      new llvm::vfs::InMemoryFileSystem);

What system are you using to choose which initialization style?

Copy link
Contributor Author

@josh11b josh11b Nov 15, 2024

Choose a reason for hiding this comment

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

Sorry, I was using () initialization for local variables, but that didn't work to default-initialize fields. I've now switched the () cases to =. There are a lot of choices for initialization in C++, have we settled on a convention?

Copy link
Contributor

@jonmeow jonmeow Nov 18, 2024

Choose a reason for hiding this comment

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

https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/cpp_style_guide.md#syntax-and-formatting, under "For initialization"

Note, I'm not sure there's a "best" choice here other than consistency.

@jonmeow jonmeow added this pull request to the merge queue Nov 18, 2024
Merged via the queue into carbon-language:trunk with commit 47bfa37 Nov 18, 2024
8 checks passed
@josh11b josh11b deleted the vfs branch November 18, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants