Skip to content

Commit ebf00ec

Browse files
[clang-repl] Refactor locking of runtime PTU stack (NFC)
The previous implementation seemed hacky, because it required the reader to be familiar with the internal workings of the PTU stack. The concept itself is a pragmatic solution and not very surprising. Keeping it behind a finalization call seems reasonable.
1 parent 2a4a852 commit ebf00ec

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class Interpreter {
142142

143143
private:
144144
size_t getEffectivePTUSize() const;
145+
void markUserCodeStart();
145146

146147
bool FindRuntimeInterface();
147148

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,14 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
280280
if (Err)
281281
return std::move(Err);
282282

283+
// Add runtime code and set a marker to hide it from user code. Undo will not
284+
// go through that.
283285
auto PTU = Interp->Parse(Runtimes);
284286
if (!PTU)
285287
return PTU.takeError();
288+
Interp->markUserCodeStart();
286289

287290
Interp->ValuePrintingInfo.resize(4);
288-
// FIXME: This is a ugly hack. Undo command checks its availability by looking
289-
// at the size of the PTU list. However we have parsed something in the
290-
// beginning of the REPL so we have to mark them as 'Irrevocable'.
291-
Interp->InitPTUSize = Interp->IncrParser->getPTUs().size();
292291
return std::move(Interp);
293292
}
294293

@@ -345,6 +344,11 @@ const ASTContext &Interpreter::getASTContext() const {
345344
return getCompilerInstance()->getASTContext();
346345
}
347346

347+
void Interpreter::markUserCodeStart() {
348+
assert(!InitPTUSize && "We only do this once");
349+
InitPTUSize = IncrParser->getPTUs().size();
350+
}
351+
348352
size_t Interpreter::getEffectivePTUSize() const {
349353
std::list<PartialTranslationUnit> &PTUs = IncrParser->getPTUs();
350354
assert(PTUs.size() >= InitPTUSize && "empty PTU list?");

0 commit comments

Comments
 (0)