8000 bug(lockfile): include LOGIC and contracts in semantic hashes and cache invalidation · Issue #193 · Mnehmos/mnehmos.nls.lang · GitHub
[go: up one dir, main page]

Skip to content

bug(lockfile): include LOGIC and contracts in semantic hashes and cache invalidation #193

Closed

Description

@Mnehmos

Audited on master at 5630d74ec9cd912d4e2f325349f1943cbc15bcc6. This is a scoped implementation item under #147, based on the typed control/dataflow/effect audit. Proposed syntax below is illustrative unless explicitly marked as a current reproducer.

Problem and current evidence

nlsc/lockfile.py:66–72 hashes only identifier, PURPOSE, RETURNS, input names/types, and DEPENDS. LOGIC, guards, input constraints, and edge cases are absent. That hash is used by nlsc/diff.py:30–94, verify_lockfile(), and rebuild_from_lockfile() in nlsc/lockfile.py:408–510.

Reproduced through the public Python APIs:

from nlsc.parser import parse_nl_file
from nlsc.emitter import emit_python
from nlsc.lockfile import generate_lockfile, verify_lockfile, rebuild_from_lockfile
from nlsc.diff import get_anlu_changes

source = """@module hash_audit
[probe]
PURPOSE: Hash fixture
LOGIC:
  1. x = 1 + 0
RETURNS: x
"""
before = parse_nl_file(source)
after = parse_nl_file(source.replace("x = 1 + 0", "x = 2 + 0"))
lock = generate_lockfile(before, emit_python(before), "hash_audit.py")
print(get_anlu_changes(after, lock))  # status='unchanged'
print(verify_lockfile(lock, after))   # []
rebuilt = rebuild_from_lockfile(after, lock)
ns = {}
exec(rebuilt.code, ns)
print(rebuilt.used_cache, ns["probe"]())  # True, 1

The edited program should produce 2. This demonstrates stale reuse by the rebuild API; it does not assert that every CLI compile path currently invokes that API.

Implementation hints

  • Replace the hand-built partial string with a versioned canonical representation of all executable semantics and contracts.
  • Include ordered LOGIC/control, guards and error payloads, edge cases, constraints, result expressions/types, and literal/foreign implementations. Extend the representation when effects, failure sets, and typestate are introduced.
  • Separate local semantic identity from effective compilation identity. The latter also depends on referenced types/operations, imported contracts, target, backend/compiler semantics version, and compilation mode.
  • Define source/documentation hashing separately if needed; preserve statement/guard order and literal contents while normalizing irrelevant formatting.
  • Version/migrate lock entries and conservatively invalidate older incomplete entries. Reuse the eventual canonical IR serializer rather than introducing a second semantic model.

Acceptance criteria

  • The reproducer reports modified, fails old-lock verification, and never reuses the stale body as a valid match.
  • Changes to a guard, error payload, constraint, branch predicate, or foreign implementation invalidate relevant entries.
  • A changed dependency contract invalidates affected callers' checked/compiled artifacts.
  • Repeated builds have deterministic semantic hashes; insignificant formatting does not accidentally change the chosen semantic identity.
  • Old lockfiles have a documented migration/rebuild path.

Related: #23, #144, #149. This is an immediate correctness fix and a prerequisite for trusting cached typed/effect validation.

Implementation ordering

Can begin immediately; integrate with the checked IR work under #147. Add the regression fixtures before implementation.

Activity

  1. added
    bugSomething isn't working
    coreCore language semantics and design
    trustProvenance and audit trails
    on Sep 10, 2026
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

    bugSomething isn't workingcoreCore language semantics and designpriority-highImportant, address soontrustProvenance and audit trails

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0