On Tue, Apr 14, 2015 at 11:48 AM, Ian Lance Taylor <i...@golang.org> wrote:
> This patch to the GCC 5 branch fixes PR 65755.  This is a conservative
> patch for the branch.  I will shortly apply a more complete, less
> conservative, patch to trunk.  This patch simply adds the receiver
> type when producing the pkgpath or the reflection string for a type
> defined within a method.  It also emits the pkgpath in the reflection
> string even when not using the -fgo-pkgpath option.  For this patch
> bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.

This is the patch to fix the same problem on mainline.  This patch
changes the libraries to consistently use the type reflection string
to determine whether two types are the same.  This simplifies the code
and permits us to change the PkgPath to be consistently the same as
the gc compiler.  Also put the receiver type in the type reflection
string, as for the GCC 5 branch patch.  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff -r 468b832d9163 go/types.cc
--- a/go/types.cc       Fri Apr 10 17:49:24 2015 -0700
+++ b/go/types.cc       Fri Apr 17 11:13:56 2015 -0700
@@ -2253,22 +2253,7 @@
          const std::string& pkgpath(package == NULL
                                     ? gogo->pkgpath()
                                     : package->pkgpath());
-         n.assign(pkgpath);
-         unsigned int index;
-         const Named_object* in_function = name->in_function(&index);
-         if (in_function != NULL)
-           {
-             n.append(1, '.');
-             n.append(Gogo::unpack_hidden_name(in_function->name()));
-             if (index > 0)
-               {
-                 char buf[30];
-                 snprintf(buf, sizeof buf, "%u", index);
-                 n.append(1, '.');
-                 n.append(buf);
-               }
-           }
-         s = Expression::make_string(n, bloc);
+         s = Expression::make_string(pkgpath, bloc);
          vals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc));
        }
     }
@@ -9102,22 +9087,17 @@
     }
   if (!this->is_builtin())
     {
-      // We handle -fgo-prefix and -fgo-pkgpath differently here for
-      // compatibility with how the compiler worked before
-      // -fgo-pkgpath was introduced.  When -fgo-pkgpath is specified,
-      // we use it to make a unique reflection string, so that the
-      // type canonicalization in the reflect package will work.  In
-      // order to be compatible with the gc compiler, we put tabs into
-      // the package path, so that the reflect methods can discard it.
+      // When -fgo-pkgpath or -fgo-prefix is specified, we use it to
+      // make a unique reflection string, so that the type
+      // canonicalization in the reflect package will work.  In order
+      // to be compatible with the gc compiler, we put tabs into the
+      // package path, so that the reflect methods can discard it.
       const Package* package = this->named_object_->package();
-      if (gogo->pkgpath_from_option())
-       {
-         ret->push_back('\t');
-         ret->append(package != NULL
-                     ? package->pkgpath_symbol()
-                     : gogo->pkgpath_symbol());
-         ret->push_back('\t');
-       }
+      ret->push_back('\t');
+      ret->append(package != NULL
+                 ? package->pkgpath_symbol()
+                 : gogo->pkgpath_symbol());
+      ret->push_back('\t');
       ret->append(package != NULL
                  ? package->package_name()
                  : gogo->package_name());
@@ -9126,6 +9106,14 @@
   if (this->in_function_ != NULL)
     {
       ret->push_back('\t');
+      const Typed_identifier* rcvr =
+       this->in_function_->func_value()->type()->receiver();
+      if (rcvr != NULL)
+       {
+         Named_type* rcvr_type = rcvr->type()->deref()->named_type();
+         ret->append(Gogo::unpack_hidden_name(rcvr_type->name()));
+         ret->push_back('.');
+       }
       ret->append(Gogo::unpack_hidden_name(this->in_function_->name()));
       ret->push_back('$');
       if (this->in_function_index_ > 0)
diff -r 468b832d9163 libgo/go/reflect/type.go
--- a/libgo/go/reflect/type.go  Fri Apr 10 17:49:24 2015 -0700
+++ b/libgo/go/reflect/type.go  Fri Apr 17 11:13:56 2015 -0700
@@ -1940,13 +1940,7 @@
        if t == nil {
                return nil
        }
-       u := t.uncommon()
-       var s string
-       if u == nil || u.PkgPath() == "" {
-               s = t.rawString()
-       } else {
-               s = u.PkgPath() + "." + u.Name()
-       }
+       s := t.rawString()
        canonicalTypeLock.RLock()
        if r, ok := canonicalType[s]; ok {
                canonicalTypeLock.RUnlock()
diff -r 468b832d9163 libgo/runtime/go-typedesc-equal.c
--- a/libgo/runtime/go-typedesc-equal.c Fri Apr 10 17:49:24 2015 -0700
+++ b/libgo/runtime/go-typedesc-equal.c Fri Apr 17 11:13:56 2015 -0700
@@ -24,16 +24,5 @@
     return 0;
   if (td1->__code != td2->__code || td1->__hash != td2->__hash)
     return 0;
-  if (td1->__uncommon != NULL && td1->__uncommon->__name != NULL)
-    {
-      if (td2->__uncommon == NULL || td2->__uncommon->__name == NULL)
-       return 0;
-      return (__go_ptr_strings_equal (td1->__uncommon->__name,
-                                     td2->__uncommon->__name)
-             && __go_ptr_strings_equal (td1->__uncommon->__pkg_path,
-                                        td2->__uncommon->__pkg_path));
-    }
-  if (td2->__uncommon != NULL && td2->__uncommon->__name != NULL)
-    return 0;
   return __go_ptr_strings_equal (td1->__reflection, td2->__reflection);
 }

Reply via email to