Skip to content

ISyntaxUtil: give the handwritten List cons struct its true SDataCon sort#1052

Open
nanavati wants to merge 1 commit into
B-Lang-org:mainfrom
nanavati:listcons-sdatacon-sort
Open

ISyntaxUtil: give the handwritten List cons struct its true SDataCon sort#1052
nanavati wants to merge 1 commit into
B-Lang-org:mainfrom
nanavati:listcons-sdatacon-sort

Conversation

@nanavati

@nanavati nanavati commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

What

ISyntaxUtil.itListCons — the hand-built type of the Cons constructor's internal struct
used by iMkCons/iMkList — rebuilt its tycon from struct shape alone, as
TIstruct SStruct [_1,_2]. The frontend records a positional data constructor's struct
as TIstruct (SDataCon parent False) fields (CParser), and that is what the canonical
Prelude::List_$Cons carries. Build the same SDataCon List sort here.

Why

iMkCons is the path IPrims takes to materialize a List result (e.g. PrimRealToDigits
via realToDigits; Real formatting in Printf hits the same prim). It is the only
handwritten multi-arg constructor (the other iMk* constructors are single-arg and need
no internal struct), so this is the lone site of its class. On main nothing compares the
payload — TyCon/ITCon comparisons are by qualified Id — so the disagreement is invisible
today, but the IType interning stack (#1048) enforces one (kind, sort) payload per
qualified name and ICEs on the mismatch. The corrected payload is exactly what
symtab-derived List_$Cons types already carry.

Validation

Found as a one-tycon-invariant ICE compiling bsc.real/evaluator/Introspect.bsv under
the interning stack's checker. With the fix, bsc.real/evaluator (30 passes) and
bsc.lib/Printf (5 passes) localchecks are fully green under the checked build, no
regolds; the full stack records fullparallel 20281/0/134.

Stack

Standalone on main. One of four independent fixes (#1051 (ATF canonical ids), #1052 (this),
#1053 (S0015 field position), #1054 (CIclass sort members)) below the reworked #1048.

ISyntaxUtil.itListCons hand-builds the type of the Cons constructor's
internal struct (Prelude::List_$Cons with fields _1, _2) for
iMkCons/iMkList -- the path IPrims takes to materialize a List result
(PrimRealToDigits and friends, reached from realToDigits and from Real
formatting in Printf/$format).  It rebuilt the tycon from struct shape
alone, tagging it (TIstruct SStruct [_1,_2]).

The frontend records a positional data constructor's struct as
TIstruct (SDataCon parent False) fields (CParser), and that is what
the List_$Cons tycon built from the Prelude's own source carries.  So
evaluated designs mix two distinct ISyntax nodes for the same tycon:
the frontend's correct form, and this hand-built one whose metadata is
factually wrong (an SStruct claim for what is a data constructor's
struct).  ITCon equality compares only the Id, so the disagreement is
latent today -- but anything that inspects the sort, or ever wants to
share type nodes, would see the two forms differ.

iMkCons is the only handwritten multi-arg constructor (the other iMk*
constructors are single-arg and need no internal struct), so this is
the lone site of its class.  Thread the true SDataCon identity.

Validated: full build, plus bsc.real/evaluator and bsc.lib/Printf
localchecks, green with no regolds.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vjo7EmAfHvZTWPDJ923FVz
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