Skip to content

Commit 940d0a3

Browse files
committed
Revert "FileManager: Improve the FileEntryRef API and customize its OptionalStorage" and follow-ups
This reverts commit 5530fb5. This reverts commit 010238a. This reverts commit 84e8257. Having trouble getting the bots compiling. Will try again later.
1 parent 5530fb5 commit 940d0a3

File tree

4 files changed

+15
-369
lines changed

4 files changed

+15
-369
lines changed

clang/include/clang/Basic/FileEntry.h

Lines changed: 15 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,16 @@ class File;
3131

3232
namespace clang {
3333

34-
class FileEntryRef;
35-
36-
} // namespace clang
37-
38-
namespace llvm {
39-
namespace optional_detail {
40-
41-
/// Forward declare a template specialization for OptionalStorage.
42-
template <>
43-
class OptionalStorage<clang::FileEntryRef, /*is_trivially_copyable*/ true>;
44-
45-
} // namespace optional_detail
46-
} // namespace llvm
47-
48-
namespace clang {
49-
5034
class DirectoryEntry;
5135
class FileEntry;
5236

5337
/// A reference to a \c FileEntry that includes the name of the file as it was
5438
/// accessed by the FileManager's client.
5539
class FileEntryRef {
5640
public:
57-
StringRef getName() const { return ME->first(); }
41+
const StringRef getName() const { return Entry->first(); }
5842
const FileEntry &getFileEntry() const {
59-
return *ME->second->V.get<FileEntry *>();
43+
return *Entry->second->V.get<FileEntry *>();
6044
}
6145

6246
inline bool isValid() const;
@@ -65,26 +49,12 @@ class FileEntryRef {
6549
inline const llvm::sys::fs::UniqueID &getUniqueID() const;
6650
inline time_t getModificationTime() const;
6751

68-
/// Check if the underlying FileEntry is the same, intentially ignoring
69-
/// whether the file was referenced with the same spelling of the filename.
7052
friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) {
71-
return &LHS.getFileEntry() == &RHS.getFileEntry();
72-
}
73-
friend bool operator==(const FileEntry *LHS, const FileEntryRef &RHS) {
74-
return LHS == &RHS.getFileEntry();
75-
}
76-
friend bool operator==(const FileEntryRef &LHS, const FileEntry *RHS) {
77-
return &LHS.getFileEntry() == RHS;
53+
return LHS.Entry == RHS.Entry;
7854
}
7955
friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) {
8056
return !(LHS == RHS);
8157
}
82-
friend bool operator!=(const FileEntry *LHS, const FileEntryRef &RHS) {
83-
return !(LHS == RHS);
84-
}
85-
friend bool operator!=(const FileEntryRef &LHS, const FileEntry *RHS) {
86-
return !(LHS == RHS);
87-
}
8858

8959
struct MapValue;
9060

@@ -108,191 +78,20 @@ class FileEntryRef {
10878
MapValue(MapEntry &ME) : V(&ME) {}
10979
};
11080

111-
/// Check if RHS referenced the file in exactly the same way.
112-
bool isSameRef(const FileEntryRef &RHS) const { return ME == RHS.ME; }
113-
114-
/// Allow FileEntryRef to degrade into 'const FileEntry*' to facilitate
115-
/// incremental adoption.
116-
///
117-
/// The goal is to avoid code churn due to dances like the following:
118-
/// \code
119-
/// // Old code.
120-
/// lvalue = rvalue;
121-
///
122-
/// // Temporary code from an incremental patch.
123-
/// lvalue = &rvalue.getFileEntry();
124-
///
125-
/// // Final code.
126-
/// lvalue = rvalue;
127-
/// \endcode
128-
///
129-
/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
130-
/// FileEntry::getName have been deleted, delete this implicit conversion.
131-
operator const FileEntry *() const { return &getFileEntry(); }
132-
133-
FileEntryRef() = delete;
134-
explicit FileEntryRef(const MapEntry &ME) : ME(&ME) {
135-
assert(ME.second && "Expected payload");
136-
assert(ME.second->V && "Expected non-null");
137-
assert(ME.second->V.is<FileEntry *>() && "Expected FileEntry");
138-
}
139-
140-
/// Expose the underlying MapEntry to simplify packing in a PointerIntPair or
141-
/// PointerUnion and allow construction in Optional.
142-
const clang::FileEntryRef::MapEntry &getMapEntry() const { return *ME; }
143-
14481
private:
145-
friend class llvm::optional_detail::OptionalStorage<
146-
FileEntryRef, /*is_trivially_copyable*/ true>;
147-
struct optional_none_tag {};
148-
149-
// Private constructor for use by OptionalStorage.
150-
FileEntryRef(optional_none_tag) : ME(nullptr) {}
151-
constexpr bool hasOptionalValue() const { return ME; }
152-
153-
const MapEntry *ME;
154-
};
155-
156-
static_assert(sizeof(FileEntryRef) == sizeof(const FileEntry *),
157-
"FileEntryRef must avoid size overhead");
158-
159-
static_assert(std::is_trivially_copyable<FileEntryRef>::value,
160-
"FileEntryRef must be trivially copyable");
161-
162-
} // end namespace clang
163-
164-
namespace llvm {
165-
namespace optional_detail {
166-
167-
/// Customize OptionalStorage<FileEntryRef> to use FileEntryRef and its
168-
/// optional_none_tag to keep it the size of a single pointer.
169-
template <> class OptionalStorage<clang::FileEntryRef> {
170-
clang::FileEntryRef MaybeRef;
171-
172-
public:
173-
~OptionalStorage() = default;
174-
constexpr OptionalStorage() noexcept
175-
: MaybeRef(clang::FileEntryRef::optional_none_tag) {}
176-
constexpr OptionalStorage(OptionalStorage const &Other) = default;
177-
constexpr OptionalStorage(OptionalStorage &&Other) = default;
178-
OptionalStorage &operator=(OptionalStorage const &Other) = default;
179-
OptionalStorage &operator=(OptionalStorage &&Other) = default;
180-
181-
template <class... ArgTypes>
182-
constexpr explicit OptionalStorage(in_place_t, ArgTypes &&...Args)
183-
: MaybeRef(std::forward<ArgTypes>(Args)...) {}
184-
185-
void reset() noexcept { MaybeRef = clang::FileEntryRef::optional_none_tag(); }
186-
187-
constexpr bool hasValue() const noexcept {
188-
return MaybeRef.hasOptionalValue();
189-
}
190-
191-
clang::FileEntryRef &getValue() LLVM_LVALUE_FUNCTION noexcept {
192-
assert(hasValue());
193-
return MaybeRef;
194-
}
195-
constexpr clang::FileEntryRef const &
196-
getValue() const LLVM_LVALUE_FUNCTION noexcept {
197-
assert(hasValue());
198-
return MaybeRef;
199-
}
200-
#if LLVM_HAS_RVALUE_REFERENCE_THIS
201-
clang::FileEntryRef &&getValue() &&noexcept {
202-
assert(hasValue());
203-
return std::move(MaybeRef);
204-
}
205-
#endif
206-
207-
template <class... Args> void emplace(Args &&...args) {
208-
MaybeRef = clang::FileEntryRef(std::forward<Args>(args)...);
209-
}
210-
211-
OptionalStorage &operator=(clang::FileEntryRef Ref) {
212-
MaybeRef = Ref;
213-
return *this;
214-
}
215-
};
216-
217-
static_assert(sizeof(Optional<clang::FileEntryRef>) ==
218-
sizeof(clang::FileEntryRef),
219-
"Optional<FileEntryRef> must avoid size overhead");
220-
221-
static_assert(std::is_trivially_copyable<Optional<clang::FileEntryRef>>::value,
222-
"Optional<FileEntryRef> should be trivially copyable");
223-
224-
} // end namespace optional_detail
225-
} // end namespace llvm
226-
227-
namespace clang {
82+
friend class FileManager;
22883

229-
/// Wrapper around Optional<FileEntryRef> that degrades to 'const FileEntry*',
230-
/// facilitating incremental patches to propagate FileEntryRef.
231-
///
232-
/// This class can be used as return value or field where it's convenient for
233-
/// an Optional<FileEntryRef> to degrade to a 'const FileEntry*'. The purpose
234-
/// is to avoid code churn due to dances like the following:
235-
/// \code
236-
/// // Old code.
237-
/// lvalue = rvalue;
238-
///
239-
/// // Temporary code from an incremental patch.
240-
/// Optional<FileEntryRef> MaybeF = rvalue;
241-
/// lvalue = MaybeF ? &MaybeF.getFileEntry() : nullptr;
242-
///
243-
/// // Final code.
244-
/// lvalue = rvalue;
245-
/// \endcode
246-
///
247-
/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
248-
/// FileEntry::getName have been deleted, delete this class and replace
249-
/// instances with Optional<FileEntryRef>.
250-
class OptionalFileEntryRefDegradesToFileEntryPtr
251-
: public Optional<FileEntryRef> {
252-
public:
253-
constexpr OptionalFileEntryRefDegradesToFileEntryPtr() noexcept = default;
254-
constexpr OptionalFileEntryRefDegradesToFileEntryPtr(
255-
OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
256-
constexpr OptionalFileEntryRefDegradesToFileEntryPtr(
257-
const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
258-
OptionalFileEntryRefDegradesToFileEntryPtr &
259-
operator=(OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
260-
OptionalFileEntryRefDegradesToFileEntryPtr &
261-
operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
262-
263-
OptionalFileEntryRefDegradesToFileEntryPtr(llvm::NoneType) {}
264-
OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
265-
: Optional<FileEntryRef>(Ref) {}
266-
OptionalFileEntryRefDegradesToFileEntryPtr(Optional<FileEntryRef> MaybeRef)
267-
: Optional<FileEntryRef>(MaybeRef) {}
268-
269-
OptionalFileEntryRefDegradesToFileEntryPtr &operator=(llvm::NoneType) {
270-
Optional<FileEntryRef>::operator=(None);
271-
return *this;
272-
}
273-
OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) {
274-
Optional<FileEntryRef>::operator=(Ref);
275-
return *this;
276-
}
277-
OptionalFileEntryRefDegradesToFileEntryPtr &
278-
operator=(Optional<FileEntryRef> MaybeRef) {
279-
Optional<FileEntryRef>::operator=(MaybeRef);
280-
return *this;
84+
FileEntryRef() = delete;
85+
explicit FileEntryRef(const MapEntry &Entry)
86+
: Entry(&Entry) {
87+
assert(Entry.second && "Expected payload");
88+
assert(Entry.second->V && "Expected non-null");
89+
assert(Entry.second->V.is<FileEntry *>() && "Expected FileEntry");
28190
}
28291

283-
/// Degrade to 'const FileEntry *' to allow FileEntry::LastRef and
284-
/// FileEntry::getName have been deleted, delete this class and replace
285-
/// instances with Optional<FileEntryRef>
286-
operator const FileEntry *() const {
287-
return hasValue() ? &getValue().getFileEntry() : nullptr;
288-
}
92+
const MapEntry *Entry;
28993
};
29094

291-
static_assert(
292-
std::is_trivially_copyable<
293-
OptionalFileEntryRefDegradesToFileEntryPtr>::value,
294-
"OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable");
295-
29695
/// Cached information about one file (either on disk
29796
/// or in the virtual file system).
29897
///
@@ -348,6 +147,10 @@ class FileEntry {
348147
bool isNamedPipe() const { return IsNamedPipe; }
349148

350149
void closeFile() const;
150+
151+
// Only for use in tests to see if deferred opens are happening, rather than
152+
// relying on RealPathName being empty.
153+
bool isOpenForTests() const { return File != nullptr; }
351154
};
352155

353156
bool FileEntryRef::isValid() const { return getFileEntry().isValid(); }

clang/unittests/Basic/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set(LLVM_LINK_COMPONENTS
55
add_clang_unittest(BasicTests
66
CharInfoTest.cpp
77
DiagnosticTest.cpp
8-
FileEntryTest.cpp
98
FileManagerTest.cpp
109
LineOffsetMappingTest.cpp
1110
SourceManagerTest.cpp

clang/unittests/Basic/FileEntryTest.cpp

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)