]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactor expandiface
authorMatthew Dempsky <mdempsky@google.com>
Thu, 25 Jul 2019 00:09:15 +0000 (17:09 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 26 Aug 2019 19:39:05 +0000 (19:39 +0000)
Move checkdupfields call into expandiface, and inline/simplify offmod.
More prep work for implementing #6977.

Change-Id: I958ae87f761ec25a8fa7298a2a3019eeca5b25ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/187518
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/align.go

index b45fd472531948130ec7bb7287e176b993058db0..073d9f2a126cf9ac8a76c5bc071c788acba7ae77 100644 (file)
@@ -59,25 +59,22 @@ func expandiface(t *types.Type) {
                        fields = append(fields, f)
                }
        }
+
        sort.Sort(methcmp(fields))
+       checkdupfields("method", fields)
+
+       if int64(len(fields)) >= thearch.MAXWIDTH/int64(Widthptr) {
+               yyerror("interface too large")
+       }
+       for i, f := range fields {
+               f.Offset = int64(i) * int64(Widthptr)
+       }
 
        // Access fields directly to avoid recursively calling dowidth
        // within Type.Fields().
        t.Extra.(*types.Interface).Fields.Set(fields)
 }
 
-func offmod(t *types.Type) {
-       o := int32(0)
-       for _, f := range t.Fields().Slice() {
-               f.Offset = int64(o)
-               o += int32(Widthptr)
-               if int64(o) >= thearch.MAXWIDTH {
-                       yyerror("interface too large")
-                       o = int32(Widthptr)
-               }
-       }
-}
-
 func widstruct(errtype *types.Type, t *types.Type, o int64, flag int) int64 {
        starto := o
        maxalign := int32(flag)
@@ -381,14 +378,6 @@ func dowidth(t *types.Type) {
                t.Align = uint8(w)
        }
 
-       if t.Etype == TINTER {
-               // We defer calling these functions until after
-               // setting t.Width and t.Align so the recursive calls
-               // to dowidth within t.Fields() will succeed.
-               checkdupfields("method", t.FieldSlice())
-               offmod(t)
-       }
-
        lineno = lno
 
        if defercalc == 1 {