8000 A C++ full run claims ctor_calls although its constructor scan skipped a document · Issue #2001 · ClickHouse/loom · GitHub
[go: up one dir, main page]

Skip to content

A C++ full run claims ctor_calls although its constructor scan skipped a document #2001

Backlog

Description

@KaloyanNaumov

TL;DR: On #1704's head, DeltaStream.tail claims the ctor_calls feature whenever the window's skipped_files is empty, and ignores _run.ctors_complete. A C++ --full run passes --changed-files, so a document the constructor scan skipped outside that list never reaches skipped_files, and the apply records the namespace as carrying constructor calls. I found no input where this makes an answer wrong; the claim is wider than the scan behind it, and the recorded bit is never withdrawn.

Company

Independent

Component

Code index

Describe the situation

This is a follow-up to #1704, which adds the code it concerns. Cursor Bugbot raised the first part on that pull request (thread r4765529741). All line numbers are on #1704's head 226a92c4a638f6f0a985950d33bdeafd6e5163b1; upstream/main at 82dc31216fd252db028fa57eca570fe87258e64a has neither _Skips nor ctors_complete.

  1. _prepare runs the constructor scan _ctor_overloads over every document in the index and sets ctors_complete to false when that scan skipped one (scip_to_delta.py:1054-1058).
  2. DeltaStream.tail lists as skipped_files only the skipped documents inside the window (:1339-1343), then claims ctor_calls when self._claims_ctor_calls and not skipped (:1354). It never reads self._run.ctors_complete.
  3. The C++ --full harness runs --full together with --changed-files set to every tracked src/*, base/* and programs/* file (run_delta.sh:100-105, :178-183), so changed is not None and _Skips is not in whole mode (:1302). A document outside those paths that fails to decode, a header under contrib/ for example, is counted in skipped_failed and warned on stderr, but is not in skipped_files, and delta_version stays 1.
  4. apply_delta records scip_ctor_calls whenever the feature is present (server/code/app/index/scip_delta.py:293-302). _ctor_edge_coverage then reads the compiler tier as carrying constructor calls unless a compiler-tier file is marked stale (server/code/app/symbol/coverage.py:183-199), and _ctor_edges_absent is false for a compiler-covered seed (:231-243), so an empty code.callers answer for a constructor has no ctor_edges_absent cause.

What I could not show is a wrong answer. A factory call in a window file whose type's constructors the scan missed is itself skipped and listed (_OverloadsIncomplete, :732 and :1194-1197; test_a_factory_caller_keeps_its_rows_when_the_overload_scan_misses_a_document), and in a C++ --full run every tracked source file is in the window. So the constructor answer rests on a scan that is known to be incomplete, but I have no input where an edge is missing from a converted file because of it.

A second part is open: scip_ctor_calls has one write site on the server (scip_delta.py:298) and nothing clears it. A later run that withholds the claim, with this change or because a window file was skipped and marked, leaves the bit an earlier clean run set. Only a stale mark in the window lowers the answer again (coverage.py:195-199); a scan that misses a document outside the window does not.

Does it reproduce on the latest release or main?

Yes, on #1704's head. The code does not exist on main yet.

How to reproduce

From a checkout of #1704's head, with the server's virtualenv. An index of two C++ documents, one inside the window and one outside it whose text field is not valid UTF-8:

mkdir -p root/src && echo 'int x;' > root/src/a.cpp
python3 - "$PWD/root" t.scip <<'PY'
import importlib.util, sys
spec = importlib.util.spec_from_file_location("scip_pb2", "scripts/scip_harness/vendor/scip_pb2.py")
pb = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pb)
index = pb.Index()
index.metadata.project_root = "file://" + sys.argv[1]
for path, text in (("src/a.cpp", "ok"), ("contrib/bad.h", "ZZBADUTF8ZZ")):
    doc = index.documents.add()
    doc.relative_path, doc.text = path, text
    doc.symbols.add().symbol = "cxx . . $ DB/A#"
raw = index.SerializeToString().replace(b"ZZBADUTF8ZZ", b"\xff\xfeBADUTF8ZZ")
open(sys.argv[2], "wb").write(raw)
PY
printf 'src/a.cpp\n' > changed.txt && : > deleted.txt
python3 scripts/scip_harness/scip_to_delta.py --index t.scip --commit abc --full \
  --changed-files changed.txt --deleted-files deleted.txt --source-root root --dry-run out.json
python3 -c "import json; d = json.load(open('out.json')); print({k: d.get(k) for k in ('delta_version', 'skipped_files', 'features', 'stats')})"
{'delta_version': 1, 'skipped_files': [], 'features': ['ctor_calls'], 'stats': {'factory_ctor_edges': 0, 'skipped_generated': 0, 'skipped_failed': 1}}

With contrib/bad.h added to changed.txt, the delta has skipped_files ['contrib/bad.h'], delta_version 2 and no features.

Expected behavior

  1. tail claims ctor_calls only when self._claims_ctor_calls and self._run.ctors_complete and not skipped, so a scan that missed any document withholds the claim. With the feature absent apply_delta writes no scip_ctor_calls, and code.callers reads a constructor's empty answer as lower_bound with ctor_edges_absent; no server change is needed. I have this as a follow-up pull request for after Skip a SCIP document that fails to decode or convert; its file keeps its rows, marked stale #1704 merges, with two tests: the converter withholds the claim when the scan skipped a document outside its files, and the converter-to-apply-to-code.callers path ends in lower_bound.
  2. Open: whether a run that withholds the claim should clear scip_ctor_calls, for example by the apply writing the state 0 when a full run's delta lacks the feature. Today the bit stays set after a clean full run until a mark lowers it. This needs a maintainer decision, since it makes the apply write state for a delta that does not name a feature.

Environment

#1704 head 226a92c4a638f6f0a985950d33bdeafd6e5163b1; Loom main at 82dc31216fd252db028fa57eca570fe87258e64a for the comparison.
Python 3.12, python-protobuf, the vendored scip_pb2; scip_to_delta.py in --dry-run mode, no ClickHouse and no scip-clang.

Related issues and pull requests

Related: #1704

Additional context

How this was found

Found and reproduced with AI assistance.

Redaction

  • I removed tokens, keys, passwords and personal or customer data from everything above.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0