compiler, reflect, runtime: remove zero field from type descriptor
authorIan Lance Taylor <ian@gcc.gnu.org>
Thu, 29 Oct 2015 18:14:50 +0000 (18:14 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Thu, 29 Oct 2015 18:14:50 +0000 (18:14 +0000)
    Type descriptors picked up a zero field because the gc map
    implementation used it.  However, it's since been dropped by the gc
    library.  It was never used by gccgo.  Drop it now in preparation for
    upgrading to the Go 1.5 library.

    Reviewed-on: https://go-review.googlesource.com/16486

From-SVN: r229546

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/types.cc
libgo/go/reflect/type.go
libgo/runtime/go-type.h
libgo/runtime/go-unsafe-pointer.c
libgo/runtime/proc.c

index 8d3547b32953d32ca634c969b3ce94c5c2782ff0..987bd684c59f1f6e0b5366734f2298d02b163d7f 100644 (file)
@@ -1,4 +1,4 @@
-57da43e8159bfe1a31e49683c371cf36e2fb6051
+85994dd0a88d1b24b2ddfc9c9ab22ee16c9e8b54
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 363fd5cff18406f774c828d308c87ae9fadc9d7d..6708be93cf7295020e0cb38e2fcabee6a30cb510 100644 (file)
@@ -42,9 +42,6 @@ Gogo::Gogo(Backend* backend, Linemap* linemap, int, int pointer_size)
     pkgpath_(),
     pkgpath_symbol_(),
     prefix_(),
-    zero_value_(NULL),
-    zero_value_size_(0),
-    zero_value_align_(0),
     pkgpath_set_(false),
     pkgpath_from_option_(false),
     prefix_from_option_(false),
@@ -638,87 +635,6 @@ Gogo::current_bindings() const
     return this->globals_;
 }
 
-// Return the special variable used as the zero value of types.
-
-Named_object*
-Gogo::zero_value(Type *type)
-{
-  if (this->zero_value_ == NULL)
-    {
-      Location bloc = Linemap::predeclared_location();
-
-      // We will change the type later, when we know the size.
-      Type* byte_type = this->lookup_global("byte")->type_value();
-
-      Expression* zero = Expression::make_integer_ul(0, NULL, bloc);
-      Type* array_type = Type::make_array_type(byte_type, zero);
-
-      Variable* var = new Variable(array_type, NULL, true, false, false, bloc);
-      this->zero_value_ = Named_object::make_variable("go$zerovalue", NULL,
-                                                     var);
-    }
-
-  // The zero value will be the maximum required size.
-  int64_t size;
-  bool ok = type->backend_type_size(this, &size);
-  if (!ok) {
-    go_assert(saw_errors());
-    size = 4;
-  }
-  if (size > this->zero_value_size_)
-    this->zero_value_size_ = size;
-
-  int64_t align;
-  ok = type->backend_type_align(this, &align);
-  if (!ok) {
-    go_assert(saw_errors());
-    align = 4;
-  }
-  if (align > this->zero_value_align_)
-    this->zero_value_align_ = align;
-
-  return this->zero_value_;
-}
-
-// Return whether V is the zero value variable.
-
-bool
-Gogo::is_zero_value(Variable* v) const
-{
-  return this->zero_value_ != NULL && this->zero_value_->var_value() == v;
-}
-
-// Return the backend variable for the special zero value, or NULL if
-// it is not needed.
-
-Bvariable*
-Gogo::backend_zero_value()
-{
-  if (this->zero_value_ == NULL)
-    return NULL;
-
-  Type* byte_type = this->lookup_global("byte")->type_value();
-  Btype* bbtype_type = byte_type->get_backend(this);
-
-  Type* int_type = this->lookup_global("int")->type_value();
-
-  Expression* e = Expression::make_integer_int64(this->zero_value_size_,
-                                                int_type,
-                                                Linemap::unknown_location());
-  Translate_context context(this, NULL, NULL, NULL);
-  Bexpression* blength = e->get_backend(&context);
-
-  Btype* barray_type = this->backend()->array_type(bbtype_type, blength);
-
-  std::string zname = this->zero_value_->name();
-  Bvariable* zvar =
-    this->backend()->implicit_variable(zname, barray_type, false,
-                                      true, true, this->zero_value_align_);
-  this->backend()->implicit_variable_set_init(zvar, zname, barray_type,
-                                             false, true, true, NULL);
-  return zvar;
-}
-
 // Add statements to INIT_STMTS which run the initialization
 // functions for imported packages.  This is only used for the "main"
 // package.
@@ -6534,9 +6450,7 @@ Variable::get_backend_variable(Gogo* gogo, Named_object* function,
          Btype* btype = type->get_backend(gogo);
 
          Bvariable* bvar;
-         if (gogo->is_zero_value(this))
-           bvar = gogo->backend_zero_value();
-         else if (this->is_global_)
+         if (this->is_global_)
            bvar = backend->global_variable((package == NULL
                                             ? gogo->package_name()
                                             : package->package_name()),
index 6333c834c3581172327347aaf6a5eb99401bdb27..0b1f8ef3ca3c2ac982fe3bdd3b53d8093db549e3 100644 (file)
@@ -653,20 +653,6 @@ class Gogo
   named_types_are_converted() const
   { return this->named_types_are_converted_; }
 
-  // Return the variable to use for the zero value of TYPE.  All types
-  // shared the same zero value, and we make sure that it is large
-  // enough.
-  Named_object*
-  zero_value(Type *type);
-
-  // Return whether a variable is the zero value variable.
-  bool
-  is_zero_value(Variable* v) const;
-
-  // Create the zero value variable.
-  Bvariable*
-  backend_zero_value();
-
   // Write out the global values.
   void
   write_globals();
@@ -821,12 +807,6 @@ class Gogo
   std::string pkgpath_symbol_;
   // The prefix to use for symbols, from the -fgo-prefix option.
   std::string prefix_;
-  // The special zero value variable.
-  Named_object* zero_value_;
-  // The size of the zero value variable.
-  int64_t zero_value_size_;
-  // The alignment of the zero value variable, in bytes.
-  int64_t zero_value_align_;
   // Whether pkgpath_ has been set.
   bool pkgpath_set_;
   // Whether an explicit package path was set by -fgo-pkgpath.
index 5c8950a028b2324dfcad90897abd6eb81ac241c8..b4620ff0c86af54555da0e29de259ea2376b7424 100644 (file)
@@ -1529,7 +1529,7 @@ Type::make_type_descriptor_type()
       // The type descriptor type.
 
       Struct_type* type_descriptor_type =
-       Type::make_builtin_struct_type(12,
+       Type::make_builtin_struct_type(11,
                                       "kind", uint8_type,
                                       "align", uint8_type,
                                       "fieldAlign", uint8_type,
@@ -1541,8 +1541,7 @@ Type::make_type_descriptor_type()
                                       "string", pointer_string_type,
                                       "", pointer_uncommon_type,
                                       "ptrToThis",
-                                      pointer_type_descriptor_type,
-                                      "zero", unsafe_pointer_type);
+                                      pointer_type_descriptor_type);
 
       Named_type* named = Type::make_builtin_named_type("commonType",
                                                        type_descriptor_type);
@@ -2073,15 +2072,6 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
       vals->push_back(Expression::make_type_descriptor(pt, bloc));
     }
 
-  ++p;
-  go_assert(p->is_field_name("zero"));
-  Expression* z = Expression::make_var_reference(gogo->zero_value(this), bloc);
-  z = Expression::make_unary(OPERATOR_AND, z, bloc);
-  Type* void_type = Type::make_void_type();
-  Type* unsafe_pointer_type = Type::make_pointer_type(void_type);
-  z = Expression::make_cast(unsafe_pointer_type, z, bloc);
-  vals->push_back(z);
-
   ++p;
   go_assert(p == fields->end());
 
index 61b195563b637db3b6e8ff08c1ec40e7e46e219a..5cdfba556486feddbda8c5a0365bf3760de095aa 100644 (file)
@@ -262,7 +262,6 @@ type rtype struct {
        string        *string        // string form; unnecessary  but undeniably useful
        *uncommonType                // (relatively) uncommon fields
        ptrToThis     *rtype         // type for pointer to this type, if used in binary or has methods
-       zero          unsafe.Pointer // pointer to zero value
 }
 
 // Method on non-interface type
@@ -1129,7 +1128,6 @@ func (t *rtype) ptrTo() *rtype {
 
        p.uncommonType = nil
        p.ptrToThis = nil
-       p.zero = unsafe.Pointer(&make([]byte, p.size)[0])
        p.elem = t
 
        if t.kind&kindNoPointers != 0 {
@@ -1505,7 +1503,6 @@ func ChanOf(dir ChanDir, t Type) Type {
        ch.elem = typ
        ch.uncommonType = nil
        ch.ptrToThis = nil
-       ch.zero = unsafe.Pointer(&make([]byte, ch.size)[0])
 
        ch.gc = unsafe.Pointer(&chanGC{
                width: ch.size,
@@ -1561,7 +1558,6 @@ func MapOf(key, elem Type) Type {
        mt.elem = etyp
        mt.uncommonType = nil
        mt.ptrToThis = nil
-       mt.zero = unsafe.Pointer(&make([]byte, mt.size)[0])
        // mt.gc = unsafe.Pointer(&ptrGC{
        //      width:  unsafe.Sizeof(uintptr(0)),
        //      op:     _GC_PTR,
@@ -1848,7 +1844,6 @@ func SliceOf(t Type) Type {
        slice.elem = typ
        slice.uncommonType = nil
        slice.ptrToThis = nil
-       slice.zero = unsafe.Pointer(&make([]byte, slice.size)[0])
 
        if typ.size == 0 {
                slice.gc = unsafe.Pointer(&sliceEmptyGCProg)
@@ -1920,7 +1915,6 @@ func arrayOf(count int, elem Type) Type {
        // TODO:
        array.uncommonType = nil
        array.ptrToThis = nil
-       array.zero = unsafe.Pointer(&make([]byte, array.size)[0])
        array.len = uintptr(count)
        array.slice = slice.(*rtype)
 
index 72c9f56986eeb25e726f23a72d21251e588b7285..eb063ec67894ba100d1a732fc69369678ada2712 100644 (file)
@@ -108,11 +108,6 @@ struct __go_type_descriptor
   /* The descriptor for the type which is a pointer to this type.
      This may be NULL.  */
   const struct __go_type_descriptor *__pointer_to_this;
-
-  /* A pointer to a zero value for this type.  All types will point to
-     the same zero value, go$zerovalue, which is a common variable so
-     that it will be large enough.  */
-  void *__zero;
 };
 
 /* The information we store for each method of a type.  */
index a59ae852185e2b575cc48339ad5a9b5a75e228ee..ce82fcd4070638b1a1b0018a25357bd0b8fd791b 100644 (file)
@@ -10,9 +10,6 @@
 #include "go-type.h"
 #include "mgc0.h"
 
-/* A pointer with a zero value.  */
-static void *zero_pointer;
-
 /* This file provides the type descriptor for the unsafe.Pointer type.
    The unsafe package is defined by the compiler itself, which means
    that there is no package to compile to define the type
@@ -64,9 +61,7 @@ const struct __go_type_descriptor unsafe_Pointer =
   /* __uncommon */
   NULL,
   /* __pointer_to_this */
-  NULL,
-  /* __zero */
-  &zero_pointer
+  NULL
 };
 
 /* We also need the type descriptor for the pointer to unsafe.Pointer,
@@ -109,9 +104,7 @@ const struct __go_ptr_type pointer_unsafe_Pointer =
     /* __uncommon */
     NULL,
     /* __pointer_to_this */
-    NULL,
-    /* __zero */
-    &zero_pointer
+    NULL
   },
   /* __element_type */
   &unsafe_Pointer
index db8b94f28f77aab12712243311912ae9fa5a2b5a..8f82f5b9cc452318a47c87a8575ea51854e5cd74 100644 (file)
@@ -538,9 +538,7 @@ static struct __go_channel_type chan_bool_type_descriptor =
       /* __uncommon */
       NULL,
       /* __pointer_to_this */
-      NULL,
-      /* __zero */
-      NULL /* This value doesn't matter */
+      NULL
     },
     /* __element_type */
     &bool_type_descriptor,