mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
refactor(rust): index compiler paths by first observation (#16768)
This commit is contained in:
1 parent
1d22bd0580
commit
25def6f31f
1 file changed
+16
-26
+16
-26
@@ -157,16 +157,15 @@ const rustcCommitFromReader = async (
|
||||
pause: ZstandardFramePause,
|
||||
): Promise<RustBinaryImage["rustc_commit"]> => {
|
||||
const retention: RustcPathRetention = {
|
||||
hashes: [],
|
||||
seen: new Set(),
|
||||
hashes: new Map(),
|
||||
maxHashes,
|
||||
maxBytes: maxOutputBytes,
|
||||
bytes: 2,
|
||||
reason: undefined,
|
||||
limit: undefined,
|
||||
};
|
||||
for (const range of mergedFileRanges(spans)) {
|
||||
let cursor = range.offset;
|
||||
while (cursor < range.end && retention.reason === undefined) {
|
||||
while (cursor < range.end && retention.limit === undefined) {
|
||||
if (cursor > range.offset) await pause();
|
||||
const length = Math.min(RUSTC_SCAN_WINDOW_BYTES, range.end - cursor);
|
||||
const chunk = await readByteSourceSlice(source, cursor, length);
|
||||
@@ -174,23 +173,16 @@ const rustcCommitFromReader = async (
|
||||
if (cursor + length >= range.end) break;
|
||||
cursor += length - RUSTC_SCAN_OVERLAP_BYTES;
|
||||
}
|
||||
if (retention.reason !== undefined) break;
|
||||
if (retention.limit !== undefined) break;
|
||||
}
|
||||
return retention.hashes.length === 0
|
||||
return retention.hashes.size === 0
|
||||
? null
|
||||
: {
|
||||
evidence_kind: "inferred",
|
||||
hashes: retention.hashes,
|
||||
...(retention.reason !== undefined
|
||||
? {
|
||||
coverage: rustcPartialCoverage(
|
||||
retention.reason,
|
||||
retention.reason === "report_bytes"
|
||||
? maxOutputBytes
|
||||
: maxHashes,
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
hashes: [...retention.hashes.values()],
|
||||
...(retention.limit === undefined
|
||||
? {}
|
||||
: { coverage: rustcPartialCoverage(...retention.limit) }),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -267,12 +259,11 @@ const dependencySection = (
|
||||
|
||||
/** One owner for compiler-path uniqueness, retained output and exhaustion. */
|
||||
interface RustcPathRetention {
|
||||
readonly hashes: { hash: string; file_offset: number }[];
|
||||
readonly seen: Set<string>;
|
||||
readonly hashes: Map<string, { hash: string; file_offset: number }>;
|
||||
readonly maxHashes: number;
|
||||
readonly maxBytes: number;
|
||||
bytes: number;
|
||||
reason: "max_rustc_hashes" | "report_bytes" | undefined;
|
||||
limit: Parameters<typeof rustcPartialCoverage> | undefined;
|
||||
}
|
||||
|
||||
const mergedFileRanges = (
|
||||
@@ -303,20 +294,19 @@ const collectHashesInChunk = (
|
||||
if (at < 0) return;
|
||||
const start = at + RUSTC_PREFIX.length;
|
||||
const hash = hashAt(region, start);
|
||||
if (hash !== null && !retention.seen.has(hash)) {
|
||||
if (retention.seen.size >= retention.maxHashes) {
|
||||
retention.reason = "max_rustc_hashes";
|
||||
if (hash !== null && !retention.hashes.has(hash)) {
|
||||
if (retention.hashes.size >= retention.maxHashes) {
|
||||
retention.limit = ["max_rustc_hashes", retention.maxHashes];
|
||||
return;
|
||||
}
|
||||
const entry = { hash, file_offset: baseOffset + at };
|
||||
const entryBytes = Buffer.byteLength(JSON.stringify(entry)) + 1;
|
||||
if (entryBytes > retention.maxBytes - retention.bytes) {
|
||||
retention.reason = "report_bytes";
|
||||
retention.limit = ["report_bytes", retention.maxBytes];
|
||||
return;
|
||||
}
|
||||
retention.bytes += entryBytes;
|
||||
retention.seen.add(hash);
|
||||
retention.hashes.push(entry);
|
||||
retention.hashes.set(hash, entry);
|
||||
}
|
||||
cursor = at + 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user