Thanks to visit codestin.com
Credit goes to pkg.go.dev

fingerprint

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package fingerprint defines a function to Encode types as strings with the property that identical types have equal string encodings, in most cases. In the remaining cases (mostly involving generic types), the encodings can be parsed using Parse into Tree form and matched using Matches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(t types.Type) (_ string, tricky bool)

Encode returns an encoding of a types.Type such that, in most cases, Encode(x) == Encode(y) iff types.Identical(x, y).

For a minority of types, mostly involving type parameters, identity cannot be reduced to string comparison; these types are called "tricky", and are indicated by the boolean result.

In general, computing identity correctly for tricky types requires the type checker. However, the fingerprint encoding can be parsed by Parse into a Tree form that permits simple matching sufficient to allow a type parameter to unify with any subtree; see [Match].

In the standard library, 99.8% of package-level types have a non-tricky method-set. The most common exceptions are due to type parameters.

fingerprint.Encode is defined only for the signature types of functions and methods. It must not be called for "untyped" basic types, nor the type of a generic function.

func Matches

func Matches(x, y Tree) bool

Matches reports whether two fingerprint trees match, meaning that under some conditions (for example, particular instantiations of type parameters) the two types may be identical.

Types

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

A Tree is a parsed form of a fingerprint for use with Matches.

func Parse

func Parse(fp string) Tree

Parse parses a fingerprint into tree form.

The input must have been produced by Encode at the same source version; parsing is thus infallible.

func (Tree) String

func (tree Tree) String() string

String returns the tree in an unspecified human-readable form.

Jump to

Keyboard shortcuts

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