Skip to content

compiler, reflect: expose function signature information - #6217

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
jakebailey:reflect-function-signatures
Nov 9, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:devfrom
jakebailey:reflect-function-signatures

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This adds NumIn, NumOut, In, Out, and IsVariadic.

Obviously, this begs the question "why"? Well, I do have Call, MakeFunc, etc, all working!

Fixes #4458
Fixes #6170 (well, the posted error; I suspect they want more)
For #3943
For #2650
For #2494

@jakebailey
jakebailey force-pushed the reflect-function-signatures branch 3 times, most recently from 6a4337e to 66e4245 Compare November 8, 2026 22:02
@davecheney

Copy link
Copy Markdown
Contributor

@jakebailey thank you for working on this. I think the type-code key also needs to distinguish variadic functions.

getTypeCodeName gives func([]int) and func(...int) the same key. The collision predates this change, but it causes the new IsVariadic and String implementations to return incorrect information when both signatures occur.

For example:

package main

import (
	"fmt"
	"reflect"
)

func main() {
	fixed := reflect.TypeFor[func([]int)]()
	variadic := reflect.TypeFor[func(...int)]()

	fmt.Println(fixed.String(), fixed.IsVariadic())
	fmt.Println(variadic.String(), variadic.IsVariadic())
}

Go prints:

func([]int) false
func(...int) true

With this change, it prints:

func([]int) false
func([]int) false

Both types share a descriptor, so whichever signature is encountered first determines the variadic flag for both. Including the variadic flag in the type-code key should distinguish them.

One non-blocking note: the uint8 input count means function types with more than 255 parameters now fail to compile when a type descriptor is needed. The failure is explicit rather than a silent miscompile, so this is probably fine to leave until someone tries to write that function.

Function types lack parameter and result metadata, so reflection cannot
inspect their signatures and formats them only as func. Programs using
NumIn, NumOut, In, Out, or IsVariadic need the same information as Go.

Fixes 4458
For 3943
For 2650
For 2494
@jakebailey
jakebailey force-pushed the reflect-function-signatures branch from 66e4245 to 2cfe3cf Compare November 9, 2026 00:18

@davecheney davecheney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you

@deadprogram

Copy link
Copy Markdown
Member

Thanks @jakebailey and to @davecheney for review. Now merging.

@deadprogram
deadprogram merged commit 4febfc3 into tinygo-org:dev Nov 9, 2026
30 checks passed
@jakebailey
jakebailey deleted the reflect-function-signatures branch November 9, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants