Skip to content

Detect duplicate order numbers in queries.ml at test time#2033

Open
Copilot wants to merge 3 commits into
masterfrom
copilot/detect-multiple-number-assignment
Open

Detect duplicate order numbers in queries.ml at test time#2033
Copilot wants to merge 3 commits into
masterfrom
copilot/detect-multiple-number-assignment

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

Reusing a number in Queries.Any.order causes a silent compile but segfaults at runtime due to type-unsafe query dispatch. This adds a check that catches the mistake before merge.

Changes

  • scripts/check-queries-order.py — parses src/domains/queries.ml, extracts all integer return values from the order match arms, and exits non-zero on any duplicate:
    ERROR: Duplicate numbers in order function in queries.ml: [5]
    
  • dune (root) — adds a (rule (alias runtest) ...) that runs the script as part of dune runtest / make test, so it is checked on every normal test run.

…te into semgrep CI

Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/28da8933-851d-467f-9742-b3a768ef73be

Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Copilot AI changed the title [WIP] Detect if number is assigned multiple times in order Detect duplicate order numbers in queries.ml at CI time May 14, 2026
Copilot AI requested a review from michael-schwarz May 14, 2026 04:30
Copy link
Copy Markdown
Member

@michael-schwarz michael-schwarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run as part of normal make test dune test workflow instead of as part of semgrep.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

Run as part of normal make test dune test workflow instead of as part of semgrep.

Done in 011aab6. Moved the check to the root dune file as a (rule (alias runtest) ...) so it runs as part of dune runtest / make test. The semgrep workflow change has been reverted.

Copilot AI changed the title Detect duplicate order numbers in queries.ml at CI time Detect duplicate order numbers in queries.ml at test time May 14, 2026
Copilot AI requested a review from michael-schwarz May 14, 2026 04:44
@michael-schwarz michael-schwarz marked this pull request as ready for review May 14, 2026 05:04
Copilot AI review requested due to automatic review settings May 14, 2026 05:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a test-time safeguard to prevent runtime segfaults caused by duplicate numeric tags in Queries.Any.order (a type-unsafe query dispatch mechanism), by checking src/domains/queries.ml during dune runtest / make test.

Changes:

  • Introduces scripts/check-queries-order.py to parse Queries.Any.order and fail if duplicate -> <int> values are found.
  • Hooks the check into the root dune runtest alias so it runs on normal test executions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
scripts/check-queries-order.py New Python script that extracts order numbers from queries.ml and fails on duplicates.
dune Adds a runtest-alias rule to execute the script as part of dune runtest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +54 to +56
seen: set[int] = set()
duplicates: set[int] = set()
for num_str in numbers:
Comment on lines +23 to +30
# Find the order function body.
# The function starts with "let order = function" and ends at the next
# top-level "let" binding at the same indentation level inside the module,
# or at the end of the file if no subsequent binding exists.
order_match = re.search(
r"let order = function\n(.*?)(?=\n\s{2,}let\b|\Z)",
content,
re.DOTALL,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

queries.ml: Detect if number is assigned multiple times in order

3 participants