Skip to content

feat(kernel-utils): narrowInterfaceGuard - #1051

Draft
ci-belphegor wants to merge 1 commit into
grypez/narrowing-4-e2e-testfrom
grypez/narrowing-5-narrow-interface-guard
Draft

feat(kernel-utils): narrowInterfaceGuard#1051
ci-belphegor wants to merge 1 commit into
grypez/narrowing-4-e2e-testfrom
grypez/narrowing-5-narrow-interface-guard

Conversation

@ci-belphegor

Copy link
Copy Markdown

Explanation

The algebraic heart of narrowing, and the PR that most deserves scrutiny — hence deliberately free of exos, promises, and provenance. A pure narrowInterfaceGuard({ name, baseGuard, delta }) => InterfaceGuard that conjoins each delta pattern onto the corresponding argument position, inherits arity, optional and rest positions and return guards verbatim, drops methods the delta does not name, and asyncifies every method guard.

Position i addresses the base's guard at i walking required arguments, then optionals, then the rest guard, and stays in whichever category it lands in. A delta cannot promote an optional to required and cannot change arity.

Dropping unlisted methods makes the safe outcome the default: forgetting a method removes authority rather than granting it.

Notes for reviewers

A position landing in the rest guard conjoins onto that one guard, and therefore constrains every trailing argument rather than only the position named — a rest guard is a single pattern, so per-position narrowing is unrepresentable there without changing arity. It stays ⊆ the base, and the surprise runs in the safe direction: the author gets less authority than intended, never more. Tested, and specified in the design doc.

An empty delta must be a no-op, not a narrowing. { readFile: [] } is defined as keeping a method entirely unchanged, so the claim soundness needs is ⊆, not ⊂.

The two "method not in methodGuards" errors are split on defaultGuards, which is a seam rather than a stylistic choice: a strict interface has defaultGuards: undefined, so the method genuinely does not exist, whereas a 'passable' interface admits it and merely guards it by default. PR 8 replaces only the second arm.

getGuardAt is deliberately not reused here. It maps a position to a guard, but narrowing has to write back into the category the position landed in; threading it through would have forced a non-null assertion or an unreachable undefined branch. Mapping over the base's own argGuards/optionalArgGuards makes the category boundary the loop bound, so it is the same walk with no duplicated logic.

Unmarks no ratchet cases.

Stack

PR 5 of 12. Base: #1050.

Derive the interface guard of a narrowing: conjoin each delta pattern onto
the base's guard at the argument position it addresses, inherit arity, the
required/optional/rest split, and return guards verbatim, drop methods the
delta does not name, and asyncify every method guard for forwarding.

The guard is constructed as a conjunction with the base's own rather than
checked against it, so it admits no call the base does not. That is the
precondition join needs to disjoin two deltas without a pattern subtyping
decision procedure.

A delta naming a method the base guards by default still throws; PR-8
relaxes that arm into synthesizing a guard from the delta.

No exos, promises, or provenance — narrow wraps this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ci-belphegor
ci-belphegor force-pushed the grypez/narrowing-5-narrow-interface-guard branch from 64369a0 to 810752b Compare September 11, 2026 11:42
@ci-belphegor
ci-belphegor added this pull request to stack #1060 September 11, 2026 11:44
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.

1 participant