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 8package typecheck 9 10import ( 11 "cmd/compile/internal/base" 12 "cmd/compile/internal/ir" 13 "cmd/compile/internal/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. 21var HaveInlineBody = func(fn *ir.Func) bool { 22 base.Fatalf("HaveInlineBody not overridden") 23 panic("unreachable") 24} 25 26func 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. 38var typeSymIdx = make(map[*types.Type][2]int64) 39 40func 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} 54