Skip to content

A package's interface carries a generic function as source; the importer instantiates it and links its private callees from the bundle (#3401) - #3503

Merged
ehartford merged 1 commit into
mainfrom
generics-as-source
Nov 21, 2026
Merged

ehartford merged 1 commit into
mainfrom
generics-as-source

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #3401 (package bundles, order of work step 1, design §4: generics and comptime travel as source).

Before: a generic function was left out of a tree bundle's interface ("not exported at Level 0 (generic)"), so an importer that named one got "undefined variable".

Now: in a tree bundle the interface carries a free generic function's declaration as source. The importer parses it, checks it and instantiates it as it does from source. A private function of the package that the generic body calls is already printed in the interface (with its private visibility) and is defined in the bundle's object, so the instance links to it.

  • BundleInterfaceEmit: a free generic function is printed with render_decl; its fingerprint row is the hash of that text, so any edit to it is an interface change.
  • Parser: an interface declaration with type parameters keeps its body.
  • render: a group around a binary expression no longer prints a second pair of parentheses. Rendered text gained a pair each time it was read back and rendered again (if (w > best) became if ((w > best))), so the interface's fingerprint differed from the source's.

Tests: the fixture package gains widest[T], which calls the private clamp_width. ok_generic_function_instantiated and err_generic_function_wrong_argument give the same outcome against source and against the interface alone, and the interface reproduces the source's fingerprint (package-interface-check).

Still out: generic methods (in an impl) and generic types; comptime functions.

Battery green; :release-checks green.

…ter instantiates it and links its private callees from the bundle (#3401)
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