Skip to content

Warn when conflicting index-state values resolve to different entries - #12639

Open
mroncode wants to merge 6 commits into
haskell:masterfrom
mroncode:index-state-warning
Open

mroncode wants to merge 6 commits into
haskell:masterfrom
mroncode:index-state-warning

Conversation

@mroncode

@mroncode mroncode commented Nov 20, 2026 •

Copy link
Copy Markdown

Fixes #12637.

index-state can be set in cabal.project and its imports, cabal.project.freeze,
cabal.project.local and on the command line. The value read last wins, which was
silent. This PR warns when the values from more than one place resolve to different
entries of the package index, and names the source of the winning value in the -v2
message.

What changed

  • ProjectConfigShared has a new field, projectConfigIndexStateSources, a list of
    every index-state that was set together with where it came from. Lists append when
    configs are merged, so nothing is dropped. The parsec and legacy project file parsers
    tag values with the file they were read from; --index-state is tagged as the
    command line.
  • warnOnConflictingIndexStates (IndexUtils) resolves each candidate against the
    index cache (filterCache / isiMaxTime) and warns only if they land on different
    entries. If all values are equal it does not read the cache at all.
  • It is called from getSourcePackages in ProjectPlanning.
  • getSourcePackagesAtIndexStateFrom is a variant of getSourcePackagesAtIndexState
    that takes a description of where the value was set, so the -v2 message can say
    e.g. "(from cabal.project.local)". The original function is a wrapper, so other
    callers are unchanged.

Manual QA notes

With cabal.project setting index-state: 2025-01-01T00:00:00Z,
cabal.project.local setting 2025-03-01T00:00:00Z and
--index-state=2025-06-15T12:00:00Z on the command line, cabal build prints:

Warning: Several index-state values were given and they resolve to different
entries of the 'hackage.haskell.org' package index. The last one wins:
- cabal.project: 2025-01-01T00:00:00Z (index entry 2024-12-31T21:39:02Z)
- cabal.project.local: 2025-03-01T00:00:00Z (index entry 2025-02-28T23:02:30Z)
- the command line: 2025-06-15T12:00:00Z (index entry 2025-06-15T09:47:31Z)

At -v2: Using historical state as of 2025-06-15T12:00:00Z as explicitly requested (from the command line).

Two different timestamps that resolve to the same index entry (e.g. 2025-06-15T10:00:00Z
and 2025-06-15T12:00:00Z) produce no warning, and a single index-state produces no
warning.

Limitations / questions for reviewers

  • Repeated index-state: lines within one file are not compared (the parser keeps only
    the last one), and ~/.cabal/config is not tracked as a source.
  • I haven't added a new test for the warning itself yet. The existing parser tests now
    check the source tagging, and the unit test generators are updated. I'd appreciate
    guidance on whether a cabal-testsuite golden test is the right place for it.
  • Unrelated test failures seen locally on Windows: three Configure tests (file locked)
    and parallel.concurrent jobs.
  • I'm new to Haskell and to the Cabal codebase, I have read and tested it, and I'm happy to rework the design
    if you'd prefer a different approach.

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
    • Is the change significant? No.
  • The documentation has been updated, if necessary.
  • Manual QA notes have been included.
  • Tests have been added. (Existing tests updated; asking for guidance on a test for the warning.)

@mroncode
mroncode marked this pull request as ready for review November 24, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn on conflicting resolutions of index state

2 participants