dispatch

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package dispatch synthesizes Go's implicit structural interface satisfaction into explicit "implements" edges (RES-02, Phase 5 Pattern 3): a struct whose method set (by name+arity, D-06's bounded-matching discipline) is a superset of an interface's own method-spec set is synthesized as implementing that interface. Go's declared-implements counterpart for Java/C# (Pattern 2: promoting a resolved extends/ implements reference when its target is an interface node) lives in resolve.go instead, since that promotion happens inline while resolving a RefKindEmbeds unresolved ref and needs no separate synthesis pass.

Every edge this package emits carries Provenance="heuristic" + Metadata["synthesizedBy"] (RES-03/D-07) — additive within SchemaVersion 1, no schema change. Matching is bounded via an inverted methodName->[]interfaceID pre-filter built BEFORE the struct×interface comparison loop (D-06) — never an O(structs × interfaces) nested loop over all pairs.

Index

Constants

View Source
const SynthesizedBy = "go-structural-methodset"

SynthesizedBy is the Metadata["synthesizedBy"] value every edge this package emits carries (RES-03) — the ONE heuristic this package implements. Java/C#'s declared-implements promotion (resolve.go, Pattern 2) uses its own distinct value ("declared-implements") so a reader of the committed graph can tell the two heuristics apart.

Variables

This section is empty.

Functions

func SynthesizeImplements

func SynthesizeImplements(structMethods TypeMethods, interfaceMethods InterfaceSpecs, interfaceEmbeds map[string][]string) []*schema.Edge

SynthesizeImplements returns one "implements" edge per (struct, interface) pair where structMethods[structID]'s method set is a superset — by (Name, Arity) — of the interface's own method-spec set, composed transitively through interfaceEmbeds (interface embeds interface). An interface with zero methods, even after composing embeds, is never a synthesis target (Go's `interface{}` is trivially satisfied by everything; synthesizing an edge for that would be pure noise, not a useful dispatch target).

Bounding (D-06): an inverted methodName->[]interfaceID index is built ONCE, before any struct is compared against a candidate interface — a struct is only ever compared against interfaces sharing at least one method name, never against the full interface set. interfaceEmbeds composition is bounded by the number of INTERFACES alone (a visited-set-guarded walk, cycle-safe), independent of struct count, so a wide or deeply-embedded interface graph cannot blow up the struct comparison either.

Types

type InterfaceSpecs

type InterfaceSpecs map[string][]goextract.MethodSpec

InterfaceSpecs maps an interface node id to the method specs it declares directly in its own body (embedded interfaces are NOT pre-flattened here — SynthesizeImplements composes them itself via interfaceEmbeds).

type TypeMethods

type TypeMethods map[string][]goextract.MethodSpec

TypeMethods maps a struct node id to the method specs it declares — after Pass 2 has resolved every struct's full (possibly cross-file) method set via "contains" edges, exactly like TestResolve_CrossFileMethodContainment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL