Patchwork Go patch committed: Avoid some unnecessary interface conversions

login
register
mail settings
Submitter Ian Taylor
Date June 14, 2012, 12:47 a.m.
Message ID <mcrehpiafdd.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/164777/
State New
Headers show

Comments

Ian Taylor - June 14, 2012, 12:47 a.m.
This patch to the Go compiler avoids some unnecessary interface
conversions.  I was comparing Type* pointers for equality, but that only
works if the types were defined before the code being compiled.  If they
were defined afterward, the types will normally be forward declarations.
They will wind up pointing to the same type, but the pointers won't be
equal.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 43610a429d23 go/expressions.cc
--- a/go/expressions.cc	Tue Jun 12 22:54:42 2012 -0700
+++ b/go/expressions.cc	Wed Jun 13 17:37:20 2012 -0700
@@ -168,7 +168,8 @@ 
   if (lhs_type_tree == error_mark_node)
     return error_mark_node;
 
-  if (lhs_type != rhs_type && lhs_type->interface_type() != NULL)
+  if (lhs_type->forwarded() != rhs_type->forwarded()
+      && lhs_type->interface_type() != NULL)
     {
       if (rhs_type->interface_type() == NULL)
 	return Expression::convert_type_to_interface(context, lhs_type,
@@ -179,7 +180,8 @@ 
 							  rhs_type, rhs_tree,
 							  false, location);
     }
-  else if (lhs_type != rhs_type && rhs_type->interface_type() != NULL)
+  else if (lhs_type->forwarded() != rhs_type->forwarded()
+	   && rhs_type->interface_type() != NULL)
     return Expression::convert_interface_to_type(context, lhs_type, rhs_type,
 						 rhs_tree, location);
   else if (lhs_type->is_slice_type() && rhs_type->is_nil_type())