diff options
author | Matthew Dempsky <mdempsky@google.com> | 2022-08-04 10:32:51 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2022-08-04 10:32:51 -0700 |
commit | a10afb15e060386615dcc0ecf2bd60ca3abbc04c (patch) | |
tree | a89e2d4e921b2b966aee9d86cbdd3d5ff9df01c7 /src/cmd/compile/internal/reflectdata/helpers.go | |
parent | 85d87b9c7507628144db51bd1e7e80cc3afed128 (diff) | |
parent | d558507db42d600e5ad82748bda0cb91df57b97d (diff) | |
download | go-git-a10afb15e060386615dcc0ecf2bd60ca3abbc04c.tar.gz |
all: REVERSE MERGE dev.unified (d558507) into master
This commit is a REVERSE MERGE.
It merges dev.unified back into its parent branch, master.
This marks the end of development on dev.unified.
Merge List:
+ 2022-08-04 d558507db4 [dev.unified] all: merge master (85d87b9) into dev.unified
+ 2022-08-03 c9f2150cfb [dev.unified] cmd/compile: start using runtime dictionaries
+ 2022-07-30 994ff78ba0 [dev.unified] go/internal: set underlying types in proper order
+ 2022-07-28 23554d4744 [dev.unified] all: merge master (462b78f) into dev.unified
+ 2022-07-28 c8d5ccf82e [dev.unified] go/internal/gcimporter: flatten imports
+ 2022-07-28 ac0844ec27 [dev.unified] cmd/compile: move "has init" to private metadata
+ 2022-07-28 f995946094 [dev.unified] cmd/compile: implement simple inline body pruning heuristic
+ 2022-07-28 f2851c67fd [dev.unified] cmd/compile: allow inlining to fail gracefully
+ 2022-07-28 831fdf1dff [dev.unified] cmd/compile: extract nil handling from exprType
+ 2022-07-28 92798176e7 [dev.unified] cmd/compile: write iface conversion RTTI into unified IR
+ 2022-07-28 9b70178d58 [dev.unified] cmd/compile: write RTTI into unified IR export data
+ 2022-07-25 fc72b7705d [dev.unified] cmd/compile: add method expressions to dictionaries
+ 2022-07-25 f48fa643f1 [dev.unified] cmd/compile: remove obsolete RTTI wiring
+ 2022-07-22 131f981df0 [dev.unified] cmd/compile: make Unified IR always writes concrete type for const exprs
+ 2022-07-20 ae43bdc3e3 Merge "[dev.unified] all: merge master (8e1e64c) into dev.unified" into dev.unified
+ 2022-07-19 7a8ba83b72 [dev.unified] cmd/compile/internal/reflectdata: remove hasRType's `required` param
+ 2022-07-19 64cd6faa13 [dev.unified] cmd/compile/internal/noder: simplify mixed tag/case RTTI wiring
+ 2022-07-19 a4c5198a3c [dev.unified] cmd/compile/internal/noder: better switch statements
+ 2022-07-19 318027044a [dev.unified] cmd/compile/internal/noder: explicit nil handling
+ 2022-07-19 e971b6a9be [dev.unified] test: add switch test case for tricky nil handling
+ 2022-07-19 878439cfe5 [dev.unified] cmd/compile/internal/noder: preserve RTTI for select statements
+ 2022-07-19 e376746e54 [dev.unified] cmd/compile/internal/noder: wire RTTI for implicit conversions
+ 2022-07-19 c846fd8e13 [dev.unified] cmd/compile/internal/noder: implicit conversions for binary exprs
+ 2022-07-19 ebd34e3e45 [dev.unified] test: relax panic message expectations
+ 2022-07-19 76a82f09d6 [dev.unified] cmd/compile/internal/noder: prefer *At functions
+ 2022-07-19 de649a2a98 [dev.unified] all: merge master (8e1e64c) into dev.unified
+ 2022-07-19 055a5e55fa [dev.unified] test: change Unicode file/package name to use characters not translated by macOS.
+ 2022-07-18 2cf632cd57 [dev.unified] cmd/compile/internal/reflectdata: prefer ITabAddrAt in ConvIfaceTypeWord
+ 2022-07-12 9371a65584 internal/pkgbits: change EnableSync into a dynamic knob
+ 2022-07-01 d667be8831 [dev.unified] cmd/compile/internal/walk: RType fields for range assignments
+ 2022-06-30 1b838e9556 [dev.unified] all: merge master (993c387) into dev.unified
+ 2022-06-30 0a503cf43a [dev.unified] cmd/compile: refactor `range` desugaring
+ 2022-06-30 3635b07d16 [dev.unified] cmd/compile/internal/noder: implicit conversions for multi-valued expressions
+ 2022-06-30 e7219cc093 [dev.unified] cmd/compile/internal/noder: refactor N:1 expression handling
+ 2022-06-30 2f3ef73e18 [dev.unified] test: tweak nilcheck test
+ 2022-06-30 95d7ce9ab1 [dev.unified] test: break escape_iface.go into unified/nounified variants
+ 2022-06-30 f751319a0b [dev.unified] test: relax live_regabi.go
+ 2022-06-30 e3cdc981c8 [dev.unified] cmd/compile/internal/walk: fix typo in debug print
+ 2022-06-29 2280d897d6 [dev.unified] test: add regress test for generic select statements
+ 2022-06-27 4b78ece3d7 [dev.unified] cmd/compile: drop package height from Unified IR importer
+ 2022-06-27 398d46d538 [dev.unified] cmd/compile/internal/types2: remove package height
+ 2022-06-24 e7100adbca [dev.unified] all: merge master (5a1c5b8) into dev.unified
+ 2022-06-23 09a838ad86 [dev.unified] cmd/compile: rename haveRType and implicitExpr
+ 2022-06-23 421e9e9db2 [dev.unified] cmd/compile: implicit conversions for return statements
+ 2022-06-23 a3fea7796a [dev.unified] cmd/compile/internal/noder: implicit conversions for writer.assignStmt
+ 2022-06-23 82a958a661 [dev.unified] cmd/compile/internal/noder: refactor stmtAssign generation
+ 2022-06-23 711dacd8cf [dev.unified] cmd/compile/internal/noder: implicit conversion of call arguments
+ 2022-06-23 46b01ec667 [dev.unified] cmd/compile/internal/noder: remove needType logic
+ 2022-06-23 a3e474f867 [dev.unified] cmd/compile/internal/noder: implicit conversions for complits
+ 2022-06-23 5f5422a2dd [dev.unified] cmd/compile/internal/noder: start writing implicit conversions
+ 2022-06-23 9cb784ac69 [dev.unified] cmd/compile/internal/noder: add pkgWriter.typeOf helper
+ 2022-06-23 c70e93ff3d [dev.unified] cmd/compile/internal/typecheck: replace unreachable code with assert
+ 2022-06-23 20e1d5ac8c [dev.unified] cmd/compile: special case f(g()) calls in Unified IR
+ 2022-06-23 61ae2b734c [dev.unified] cmd/compile: plumb rtype through OSWITCH/OCASE clauses
+ 2022-06-23 3d432b6c4b [dev.unified] cmd/compile: plumb rtype through for OMAPLIT
+ 2022-06-23 7368647ac6 [dev.unified] cmd/compile: start setting RType fields for Unified IR
+ 2022-06-23 5960f4ec10 [dev.unified] cmd/compile: add RType fields
+ 2022-06-21 5e0258c700 [dev.unified] cmd/compile: avoid reflectType in ssagen
+ 2022-06-21 93833cd5d8 [dev.unified] cmd/compile: extract rtype code from walk
+ 2022-06-21 f70775ff22 [dev.unified] cmd/compile: refactor reflectdata.{TypePtr,ITabAddr}
+ 2022-06-21 fc5dad6646 [dev.unified] cmd/compile/internal/walk: minor prep refactoring
+ 2022-06-16 1f4e8afafe [dev.unified] all: merge master (635b124) into dev.unified
+ 2022-06-15 8a9485c023 [dev.unified] test: extract different inline test between unified and non-unified
+ 2022-06-14 394ea70cc9 [dev.unified] cmd/compile: more Unified IR docs and review
+ 2022-06-10 f73ad3d24d [dev.unified] test: add regress tests for #53276 and #53328
+ 2022-06-09 8ef8b60e18 [dev.unified] cmd/compile/internal/noder: stop handling type expressions as expressions
+ 2022-06-09 1a6c96bb9b [dev.unified] test: relax issue7921.go diagnostic message
+ 2022-06-09 c50c6bbc03 [dev.unified] cmd/compile: set base.Pos when process assignDef in Unified IR
+ 2022-06-09 d6df08693c [dev.unified] cmd/compile: fix unified IR don't report type size too large error
+ 2022-06-08 e7ef58542c [dev.unified] cmd/compile: restore Unified IR linkname pragma diagnostic
+ 2022-06-07 9e5c968021 [dev.unified] cmd/compile: visit LHS before RHS/X in assign/for statement
+ 2022-06-06 46ddf0873e [dev.unified] cmd/compile: export/import implicit attribute for conversion exprs
+ 2022-06-06 a8780f94c3 [dev.unified] cmd/compile: fix missing method value wrapper in unified IR
+ 2022-06-06 3a1f1e1575 [dev.unified] cmd/compile: remove package height
+ 2022-06-06 df7cb59de4 [dev.unified] cmd/compile: only sort symbols by name and package path
+ 2022-06-06 b39ac80871 [dev.unified] cmd/compile/internal/noder: push exprBlank up into assignment handling
+ 2022-06-06 55fc07e164 [dev.unified] cmd/compile/internal/noder: add optExpr for optional expressions
+ 2022-06-06 6c33f1d52e [dev.unified] cmd/compile/internal/noder: rename exprName to exprGlobal
+ 2022-06-06 4d28fcabb4 [dev.unified] all: update codereview.cfg for dev.unified branch
Change-Id: I604d057735e8a365621c91c206f9e46eabb4679b
Diffstat (limited to 'src/cmd/compile/internal/reflectdata/helpers.go')
-rw-r--r-- | src/cmd/compile/internal/reflectdata/helpers.go | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/reflectdata/helpers.go b/src/cmd/compile/internal/reflectdata/helpers.go new file mode 100644 index 0000000000..99461cff52 --- /dev/null +++ b/src/cmd/compile/internal/reflectdata/helpers.go @@ -0,0 +1,226 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package reflectdata + +import ( + "cmd/compile/internal/base" + "cmd/compile/internal/ir" + "cmd/compile/internal/types" + "cmd/internal/src" +) + +func hasRType(n, rtype ir.Node, fieldName string) bool { + if rtype != nil { + return true + } + + // We make an exception for `init`, because we still depend on + // pkginit for sorting package initialization statements, and it + // gets confused by implicit conversions. Also, because + // package-scope statements can never be generic, so they'll never + // require dictionary lookups. + if base.Debug.Unified != 0 && ir.CurFunc.Nname.Sym().Name != "init" { + ir.Dump("CurFunc", ir.CurFunc) + base.FatalfAt(n.Pos(), "missing %s in %v: %+v", fieldName, ir.CurFunc, n) + } + + return false +} + +// assertOp asserts that n is an op. +func assertOp(n ir.Node, op ir.Op) { + base.AssertfAt(n.Op() == op, n.Pos(), "want %v, have %v", op, n) +} + +// assertOp2 asserts that n is an op1 or op2. +func assertOp2(n ir.Node, op1, op2 ir.Op) { + base.AssertfAt(n.Op() == op1 || n.Op() == op2, n.Pos(), "want %v or %v, have %v", op1, op2, n) +} + +// kindRType asserts that typ has the given kind, and returns an +// expression that yields the *runtime._type value representing typ. +func kindRType(pos src.XPos, typ *types.Type, k types.Kind) ir.Node { + base.AssertfAt(typ.Kind() == k, pos, "want %v type, have %v", k, typ) + return TypePtrAt(pos, typ) +} + +// mapRType asserts that typ is a map type, and returns an expression +// that yields the *runtime._type value representing typ. +func mapRType(pos src.XPos, typ *types.Type) ir.Node { + return kindRType(pos, typ, types.TMAP) +} + +// chanRType asserts that typ is a map type, and returns an expression +// that yields the *runtime._type value representing typ. +func chanRType(pos src.XPos, typ *types.Type) ir.Node { + return kindRType(pos, typ, types.TCHAN) +} + +// sliceElemRType asserts that typ is a slice type, and returns an +// expression that yields the *runtime._type value representing typ's +// element type. +func sliceElemRType(pos src.XPos, typ *types.Type) ir.Node { + base.AssertfAt(typ.IsSlice(), pos, "want slice type, have %v", typ) + return TypePtrAt(pos, typ.Elem()) +} + +// concreteRType asserts that typ is not an interface type, and +// returns an expression that yields the *runtime._type value +// representing typ. +func concreteRType(pos src.XPos, typ *types.Type) ir.Node { + base.AssertfAt(!typ.IsInterface(), pos, "want non-interface type, have %v", typ) + return TypePtrAt(pos, typ) +} + +// AppendElemRType asserts that n is an "append" operation, and +// returns an expression that yields the *runtime._type value +// representing the result slice type's element type. +func AppendElemRType(pos src.XPos, n *ir.CallExpr) ir.Node { + assertOp(n, ir.OAPPEND) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return sliceElemRType(pos, n.Type()) +} + +// CompareRType asserts that n is a comparison (== or !=) operation +// between expressions of interface and non-interface type, and +// returns an expression that yields the *runtime._type value +// representing the non-interface type. +func CompareRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { + assertOp2(n, ir.OEQ, ir.ONE) + base.AssertfAt(n.X.Type().IsInterface() != n.Y.Type().IsInterface(), n.Pos(), "expect mixed interface and non-interface, have %L and %L", n.X, n.Y) + if hasRType(n, n.RType, "RType") { + return n.RType + } + typ := n.X.Type() + if typ.IsInterface() { + typ = n.Y.Type() + } + return concreteRType(pos, typ) +} + +// ConvIfaceTypeWord asserts that n is conversion to interface type, +// and returns an expression that yields the *runtime._type or +// *runtime.itab value necessary for implementing the conversion. +// +// - *runtime._type for the destination type, for I2I conversions +// - *runtime.itab, for T2I conversions +// - *runtime._type for the source type, for T2E conversions +func ConvIfaceTypeWord(pos src.XPos, n *ir.ConvExpr) ir.Node { + assertOp(n, ir.OCONVIFACE) + src, dst := n.X.Type(), n.Type() + base.AssertfAt(dst.IsInterface(), n.Pos(), "want interface type, have %L", n) + if hasRType(n, n.TypeWord, "TypeWord") { + return n.TypeWord + } + if dst.IsEmptyInterface() { + return concreteRType(pos, src) // direct eface construction + } + if !src.IsInterface() { + return ITabAddrAt(pos, src, dst) // direct iface construction + } + return TypePtrAt(pos, dst) // convI2I +} + +// ConvIfaceSrcRType asserts that n is a conversion from +// non-interface type to interface type (or OCONVIDATA operation), and +// returns an expression that yields the *runtime._type for copying +// the convertee value to the heap. +func ConvIfaceSrcRType(pos src.XPos, n *ir.ConvExpr) ir.Node { + assertOp2(n, ir.OCONVIFACE, ir.OCONVIDATA) + if hasRType(n, n.SrcRType, "SrcRType") { + return n.SrcRType + } + return concreteRType(pos, n.X.Type()) +} + +// CopyElemRType asserts that n is a "copy" operation, and returns an +// expression that yields the *runtime._type value representing the +// destination slice type's element type. +func CopyElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { + assertOp(n, ir.OCOPY) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return sliceElemRType(pos, n.X.Type()) +} + +// DeleteMapRType asserts that n is a "delete" operation, and returns +// an expression that yields the *runtime._type value representing the +// map type. +func DeleteMapRType(pos src.XPos, n *ir.CallExpr) ir.Node { + assertOp(n, ir.ODELETE) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return mapRType(pos, n.Args[0].Type()) +} + +// IndexMapRType asserts that n is a map index operation, and returns +// an expression that yields the *runtime._type value representing the +// map type. +func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node { + assertOp(n, ir.OINDEXMAP) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return mapRType(pos, n.X.Type()) +} + +// MakeChanRType asserts that n is a "make" operation for a channel +// type, and returns an expression that yields the *runtime._type +// value representing that channel type. +func MakeChanRType(pos src.XPos, n *ir.MakeExpr) ir.Node { + assertOp(n, ir.OMAKECHAN) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return chanRType(pos, n.Type()) +} + +// MakeMapRType asserts that n is a "make" operation for a map type, +// and returns an expression that yields the *runtime._type value +// representing that map type. +func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node { + assertOp(n, ir.OMAKEMAP) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return mapRType(pos, n.Type()) +} + +// MakeSliceElemRType asserts that n is a "make" operation for a slice +// type, and returns an expression that yields the *runtime._type +// value representing that slice type's element type. +func MakeSliceElemRType(pos src.XPos, n *ir.MakeExpr) ir.Node { + assertOp2(n, ir.OMAKESLICE, ir.OMAKESLICECOPY) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return sliceElemRType(pos, n.Type()) +} + +// RangeMapRType asserts that n is a "range" loop over a map value, +// and returns an expression that yields the *runtime._type value +// representing that map type. +func RangeMapRType(pos src.XPos, n *ir.RangeStmt) ir.Node { + assertOp(n, ir.ORANGE) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return mapRType(pos, n.X.Type()) +} + +// UnsafeSliceElemRType asserts that n is an "unsafe.Slice" operation, +// and returns an expression that yields the *runtime._type value +// representing the result slice type's element type. +func UnsafeSliceElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { + assertOp(n, ir.OUNSAFESLICE) + if hasRType(n, n.RType, "RType") { + return n.RType + } + return sliceElemRType(pos, n.Type()) +} |