1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Public shim around the Go canonical signature normaliser used by the
//! Go T1 implements-and-promotion pass.
//!
//! The body of the normaliser lives inside
//! [`pass_go_method_set`][crate::graph::unified::build::pass_go_method_set]
//! because it is implemented next to (and unit-tested with) the
//! satisfaction algorithm. The Go language plugin in `sqry-lang-go` is in
//! a different crate, so the internal `pub(crate)` symbol is not
//! reachable from there. This module exposes a single `pub fn`
//! delegating to the internal canonicaliser so the plugin and the pass
//! both compute the canonical signature with bit-identical bytes.
//!
//! # Determinism contract
//!
//! `canonicalise_go_signature(params, returns)` is a pure function of
//! its two inputs. The byte sequence returned is the same one that
//! `pass_go_method_set::canonicalise_signature` wraps in a
//! `NormalizedSignature`. Comparing two outputs with `==` is exactly the
//! signature-identity predicate prescribed by
//! `docs/development/go-implements-and-promotion/02_DESIGN.md` §4.1.3.
//!
//! The output is **always valid UTF-8** because the input is required to
//! be valid UTF-8 (Go source is UTF-8) and the normaliser preserves
//! byte-by-byte semantics for identifier and punctuation bytes while
//! collapsing only ASCII whitespace.
use cratecanonicalise_signature;
/// Canonicalise a Go function / method signature for cross-crate
/// emission of `GoMethodSignatureHint` / `GoFunctionSignatureHint`
/// hints.
///
/// `params` is the parameter-list text (with or without outer parens).
/// `returns` is the result clause text — empty string for void
/// functions, a single type for single-return shapes, or a
/// paren-wrapped list for multi-return shapes. Both inputs are
/// canonicalised per 02_DESIGN §4.1.2:
///
/// 1. Whitespace between modifier tokens is collapsed.
/// 2. Parameter names are erased.
/// 3. Variadic `...T` is preserved.
/// 4. (Step 4 — package qualification of bare identifiers — runs inside
/// the satisfaction pass, not here; both sides see the same lexical
/// input because the plugin emits the same param/return text the pass
/// would.)
/// 5. Generic type-parameter erasure runs in the plugin's
/// `canonicalize_type_text_with_params` before calling this function;
/// here we operate on the post-substitution text.
///
/// Returns the canonical signature as a `String`. The byte representation
/// is identical to the `Vec<u8>` carried by `NormalizedSignature`.