Accept any record wire on an input read only for its attributes

An element generic declared on a reading input, absent from the output
and from every other input, has nowhere to go and nothing to be: the
node reads its declared attributes and never the element. That is an
attr-to-element map, so it accepts any upstream record wire.

The blessing is inferred rather than marked, since the signature already
says it. The two substrate pieces were both in place: the element rides
as the byte-carried token, so the registry takes one generic row instead
of a row per element type, and the reads resolve against the input's own
layout as they always have. Only the passthrough rule stood in the way,
in the three places that enforced it.

A generic the output carries, or one on an input with no reads, is
unchanged and still owes an implementations list.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Dennis Kobert
2026-09-09 12:15:40 +00:00
parent f04d439b33
commit 5baeb8fd46
6 changed files with 138 additions and 7 deletions

View File

@@ -135,7 +135,14 @@ fn validate_record_io(parsed: &ParsedNodeFn) {
let element = writes.as_ref().map(|writes| &writes.element).unwrap_or(&value);
match &token {
Some(token) => {
if !matches!(crate::codegen::bare_ident(element), Some(ident) if ident == token) {
// An opaque reading input never looks at its element, so it writes
// a fresh one rather than carrying the input's through.
let opaque_reading = crate::codegen::classify::opaque_reading_carrier(parsed).is_some();
if opaque_reading {
if crate::codegen::contains_open_generic(parsed, element) {
emit_error!(parsed.output_type.span(), "an opaque reading input writes a concrete element, since `{}` is never read", token);
}
} else if !matches!(crate::codegen::bare_ident(element), Some(ident) if ident == token) {
emit_error!(parsed.output_type.span(), "a generic element passes through unchanged: return `{}` in the first tuple position", token);
}
}
@@ -430,13 +437,16 @@ fn validate_implementations_for_generics(parsed: &ParsedNodeFn) {
(crate::codegen::ir::NodeKind::RecordIo, crate::codegen::ir::Element::Generic(ident)) => Some(ident.clone()),
_ => None,
};
// An opaque reading carrier's element is never looked at, so it needs no
// rows: the node registers one generic row and accepts any record wire.
let opaque_reading = crate::codegen::classify::opaque_reading_carrier(parsed);
let opaque_record_generic = |ty: &Type| {
let (stripped, _) = crate::codegen::ir::strip_ilist(ty);
let ident = match &stripped {
Type::Path(path) => path.path.get_ident(),
_ => None,
};
ident.is_some() && (ident == routing.as_ref().map(|routing| &routing.generic) || ident == record_token.as_ref())
ident.is_some() && (ident == routing.as_ref().map(|routing| &routing.generic) || ident == record_token.as_ref() || ident == opaque_reading.as_ref())
};
if !has_skip_impl && !parsed.fn_generics.is_empty() {