Skip to content

Commit a570dbf

Browse files
author
Moritz Scherer
committed
Revert "[circt-lsp-server] Make time source injectable"
This reverts commit 7eb08b1.
1 parent 3585069 commit a570dbf

File tree

3 files changed

+44
-133
lines changed

3 files changed

+44
-133
lines changed

lib/Tools/circt-verilog-lsp-server/Utils/PendingChanges.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ void PendingChangesMap::debounceAndUpdate(
4848

4949
void PendingChangesMap::enqueueChange(
5050
const llvm::lsp::DidChangeTextDocumentParams &params) {
51-
const auto now = nowFn();
51+
// Key by normalized LSP file path. If your pipeline allows multiple
52+
// spellings (symlinks/case), normalize upstream or canonicalize here.
53+
const auto now = std::chrono::steady_clock::now();
5254
const std::string key = params.textDocument.uri.file().str();
5355

5456
std::scoped_lock lock(mu);
@@ -69,7 +71,7 @@ void PendingChangesMap::debounceAndThen(
6971
DebounceOptions options,
7072
std::function<void(std::unique_ptr<PendingChanges>)> cb) {
7173
const std::string key = params.textDocument.uri.file().str();
72-
const auto scheduleTime = nowFn();
74+
const auto scheduleTime = std::chrono::steady_clock::now();
7375

7476
// If debounce is disabled, run on main thread
7577
if (options.disableDebounce) {
@@ -85,7 +87,8 @@ void PendingChangesMap::debounceAndThen(
8587
// Simple timer: sleep min-quiet before checking. We rely on the fact
8688
// that newer edits can arrive while we sleep, updating lastChangeTime.
8789
if (options.debounceMinMs > 0)
88-
waitForMinMs(options.debounceMinMs, scheduleTime);
90+
std::this_thread::sleep_for(
91+
std::chrono::milliseconds(options.debounceMinMs));
8992

9093
std::unique_ptr<PendingChanges>
9194
result; // decided under lock, callback after
@@ -95,7 +98,7 @@ void PendingChangesMap::debounceAndThen(
9598
auto it = pending.find(key);
9699
if (it != pending.end()) {
97100
PendingChanges &pc = it->second;
98-
const auto now = nowFn();
101+
const auto now = std::chrono::steady_clock::now();
99102

100103
// quietSinceSchedule: if no newer edits arrived after we scheduled
101104
// this task, then we consider the burst "quiet" and flush now.
@@ -139,20 +142,5 @@ PendingChangesMap::takeAndErase(llvm::StringMap<PendingChanges>::iterator it) {
139142
return out;
140143
}
141144

142-
void PendingChangesMap::waitForMinMs(uint64_t ms,
143-
SteadyClock::time_point start) {
144-
if (!ms)
145-
return;
146-
if (!useManualClock) {
147-
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
148-
return;
149-
}
150-
// Manual clock: busy-wait with yields until now() reaches start + ms.
151-
const auto target = start + std::chrono::milliseconds(ms);
152-
while (nowFn() < target) {
153-
std::this_thread::yield();
154-
}
155-
}
156-
157145
} // namespace lsp
158146
} // namespace circt

lib/Tools/circt-verilog-lsp-server/Utils/PendingChanges.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717

1818
#include <chrono>
1919
#include <cstdint>
20-
#include <functional>
2120
#include <mutex>
2221
#include <thread>
2322
#include <vector>
2423

2524
namespace circt {
2625
namespace lsp {
2726

28-
using SteadyClock = std::chrono::steady_clock;
29-
using NowFn = std::function<SteadyClock::time_point()>;
30-
3127
/// Build a pool strategy with a sensible minimum.
3228
static llvm::ThreadPoolStrategy makeStrategy(unsigned maxThreads) {
3329
llvm::ThreadPoolStrategy s = llvm::hardware_concurrency();
@@ -60,16 +56,7 @@ class PendingChangesMap {
6056
public:
6157
explicit PendingChangesMap(
6258
unsigned maxThreads = std::thread::hardware_concurrency())
63-
: pool(makeStrategy(maxThreads)), tasks(pool),
64-
nowFn([] { return SteadyClock::now(); }), useManualClock(false) {}
65-
66-
// Test-only path: provide a manual clock source.
67-
explicit PendingChangesMap(unsigned maxThreads, NowFn now)
68-
: pool(makeStrategy(maxThreads)), tasks(pool), nowFn(std::move(now)),
69-
useManualClock(true) {}
70-
71-
/// Destructor ensures all pending work is cleared.
72-
~PendingChangesMap() { abort(); }
59+
: pool(makeStrategy(maxThreads)), tasks(pool) {}
7360

7461
/// Call during server shutdown; Erase all file changes, then clear file map.
7562
/// Thread-safe.
@@ -119,13 +106,6 @@ class PendingChangesMap {
119106
/// Internal concurrency used for sleeps + checks.
120107
llvm::StdThreadPool pool;
121108
llvm::ThreadPoolTaskGroup tasks;
122-
123-
/// Injectable time source for unit testing
124-
NowFn nowFn;
125-
bool useManualClock;
126-
127-
/// Test wrapper around a thread timeout
128-
void waitForMinMs(uint64_t ms, SteadyClock::time_point start);
129109
};
130110

131111
} // namespace lsp

0 commit comments

Comments
 (0)