Patchwork Go patch committed: Adjust recursive function type handling

login
register
mail settings
Submitter Ian Taylor
Date Dec. 16, 2010, 2:24 a.m.
Message ID <mcr62uuzc8j.fsf@google.com>
Download mbox | patch
Permalink /patch/75716/
State New
Headers show

Comments

Ian Taylor - Dec. 16, 2010, 2:24 a.m.
This patch to the Go frontend adjusts the handling of recursive function
types again.  Here I go back to a form of what the compiler used to do,
because the code I put in yesterday winds up building a function with
type ptr_type_node in some complex circumstances.  This will probably
need to shift at some point to a mechanism in which we update the early
return value, but this seems to work for now.  Bootstrapped and tested
on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 3c8f212dce6f go/types.cc
--- a/go/types.cc	Wed Dec 15 17:43:02 2010 -0800
+++ b/go/types.cc	Wed Dec 15 18:10:26 2010 -0800
@@ -6887,11 +6887,17 @@ 
       break;
 
     case TYPE_FUNCTION:
-      // Don't recur infinitely if a function type refers to itself.
-      // Ideally we would build a circular data structure here, but
-      // GENERIC can't handle them.
+      // GENERIC can't handle a pointer to a function type whose
+      // return type is a pointer to the function type itself.  It
+      // does into infinite loops when walking the types.
       if (this->seen_)
-	return ptr_type_node;
+	{
+	  Function_type* fntype = this->type_->function_type();
+	  if (fntype->results() != NULL
+	      && fntype->results()->size() == 1
+	      && fntype->results()->front().type()->forwarded() == this)
+	    return ptr_type_node;
+	}
       this->seen_ = true;
       t = Type::get_named_type_tree(gogo, this->type_);
       this->seen_ = false;