github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/typecheck/iimport.go (about)

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Indexed package import.
     6  // See iexport.go for the export data format.
     7  
     8  package typecheck
     9  
    10  import (
    11  	"github.com/go-asm/go/cmd/compile/base"
    12  	"github.com/go-asm/go/cmd/compile/ir"
    13  	"github.com/go-asm/go/cmd/compile/types"
    14  )
    15  
    16  // HaveInlineBody reports whether we have fn's inline body available
    17  // for inlining.
    18  //
    19  // It's a function literal so that it can be overridden for
    20  // GOEXPERIMENT=unified.
    21  var HaveInlineBody = func(fn *ir.Func) bool {
    22  	base.Fatalf("HaveInlineBody not overridden")
    23  	panic("unreachable")
    24  }
    25  
    26  func SetBaseTypeIndex(t *types.Type, i, pi int64) {
    27  	if t.Obj() == nil {
    28  		base.Fatalf("SetBaseTypeIndex on non-defined type %v", t)
    29  	}
    30  	if i != -1 && pi != -1 {
    31  		typeSymIdx[t] = [2]int64{i, pi}
    32  	}
    33  }
    34  
    35  // Map imported type T to the index of type descriptor symbols of T and *T,
    36  // so we can use index to reference the symbol.
    37  // TODO(mdempsky): Store this information directly in the Type's Name.
    38  var typeSymIdx = make(map[*types.Type][2]int64)
    39  
    40  func BaseTypeIndex(t *types.Type) int64 {
    41  	tbase := t
    42  	if t.IsPtr() && t.Sym() == nil && t.Elem().Sym() != nil {
    43  		tbase = t.Elem()
    44  	}
    45  	i, ok := typeSymIdx[tbase]
    46  	if !ok {
    47  		return -1
    48  	}
    49  	if t != tbase {
    50  		return i[1]
    51  	}
    52  	return i[0]
    53  }