OSDN Git Service

compiler: Don't check for hidden fields on struct assignments.
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / types.cc
index 37cca83..fed83b3 100644 (file)
@@ -37,8 +37,7 @@ extern "C"
 // Class Type.
 
 Type::Type(Type_classification classification)
-  : classification_(classification), btype_(NULL),
-    type_descriptor_decl_(NULL_TREE)
+  : classification_(classification), btype_(NULL), type_descriptor_var_(NULL)
 {
 }
 
@@ -241,7 +240,7 @@ Type::points_to() const
 // Return whether this is an open array type.
 
 bool
-Type::is_open_array_type() const
+Type::is_slice_type() const
 {
   return this->array_type() != NULL && this->array_type()->length() == NULL;
 }
@@ -458,7 +457,7 @@ Type::are_compatible_for_binop(const Type* lhs, const Type* rhs)
   if (lhs->is_nil_type()
       && (rhs->points_to() != NULL
          || rhs->interface_type() != NULL
-         || rhs->is_open_array_type()
+         || rhs->is_slice_type()
          || rhs->map_type() != NULL
          || rhs->channel_type() != NULL
          || rhs->function_type() != NULL))
@@ -466,7 +465,7 @@ Type::are_compatible_for_binop(const Type* lhs, const Type* rhs)
   if (rhs->is_nil_type()
       && (lhs->points_to() != NULL
          || lhs->interface_type() != NULL
-         || lhs->is_open_array_type()
+         || lhs->is_slice_type()
          || lhs->map_type() != NULL
          || lhs->channel_type() != NULL
          || lhs->function_type() != NULL))
@@ -557,7 +556,7 @@ Type::are_assignable_check_hidden(const Type* lhs, const Type* rhs,
   if (rhs->is_nil_type()
       && (lhs->points_to() != NULL
          || lhs->function_type() != NULL
-         || lhs->is_open_array_type()
+         || lhs->is_slice_type()
          || lhs->map_type() != NULL
          || lhs->channel_type() != NULL
          || lhs->interface_type() != NULL))
@@ -606,7 +605,7 @@ Type::are_assignable_check_hidden(const Type* lhs, const Type* rhs,
 bool
 Type::are_assignable(const Type* lhs, const Type* rhs, std::string* reason)
 {
-  return Type::are_assignable_check_hidden(lhs, rhs, true, reason);
+  return Type::are_assignable_check_hidden(lhs, rhs, false, reason);
 }
 
 // Like are_assignable but don't check for hidden fields.
@@ -663,7 +662,7 @@ Type::are_convertible(const Type* lhs, const Type* rhs, std::string* reason)
     {
       if (rhs->integer_type() != NULL)
        return true;
-      if (rhs->is_open_array_type() && rhs->named_type() == NULL)
+      if (rhs->is_slice_type() && rhs->named_type() == NULL)
        {
          const Type* e = rhs->array_type()->element_type()->forwarded();
          if (e->integer_type() != NULL
@@ -675,7 +674,7 @@ Type::are_convertible(const Type* lhs, const Type* rhs, std::string* reason)
 
   // A string may be converted to []byte or []int.
   if (rhs->is_string_type()
-      && lhs->is_open_array_type()
+      && lhs->is_slice_type()
       && lhs->named_type() == NULL)
     {
       const Type* e = lhs->array_type()->element_type()->forwarded();
@@ -769,68 +768,6 @@ Type::hash_string(const std::string& s, unsigned int h)
   return h;
 }
 
-// Default check for the expression passed to make.  Any type which
-// may be used with make implements its own version of this.
-
-bool
-Type::do_check_make_expression(Expression_list*, source_location)
-{
-  go_unreachable();
-}
-
-// Return whether an expression has an integer value.  Report an error
-// if not.  This is used when handling calls to the predeclared make
-// function.
-
-bool
-Type::check_int_value(Expression* e, const char* errmsg,
-                     source_location location)
-{
-  if (e->type()->integer_type() != NULL)
-    return true;
-
-  // Check for a floating point constant with integer value.
-  mpfr_t fval;
-  mpfr_init(fval);
-
-  Type* dummy;
-  if (e->float_constant_value(fval, &dummy) && mpfr_integer_p(fval))
-    {
-      mpz_t ival;
-      mpz_init(ival);
-
-      bool ok = false;
-
-      mpfr_clear_overflow();
-      mpfr_clear_erangeflag();
-      mpfr_get_z(ival, fval, GMP_RNDN);
-      if (!mpfr_overflow_p()
-         && !mpfr_erangeflag_p()
-         && mpz_sgn(ival) >= 0)
-       {
-         Named_type* ntype = Type::lookup_integer_type("int");
-         Integer_type* inttype = ntype->integer_type();
-         mpz_t max;
-         mpz_init_set_ui(max, 1);
-         mpz_mul_2exp(max, max, inttype->bits() - 1);
-         ok = mpz_cmp(ival, max) < 0;
-         mpz_clear(max);
-       }
-      mpz_clear(ival);
-
-      if (ok)
-       {
-         mpfr_clear(fval);
-         return true;
-       }
-    }
-
-  mpfr_clear(fval);
-
-  error_at(location, "%s", errmsg);
-  return false;
-}
-
 // A hash table mapping unnamed types to the backend representation of
 // those types.
 
@@ -913,33 +850,182 @@ Type::get_btype_without_hash(Gogo* gogo)
   return this->btype_;
 }
 
-// Any type which supports the builtin make function must implement
-// this.
+// Return a pointer to the type descriptor for this type.
 
 tree
-Type::do_make_expression_tree(Translate_context*, Expression_list*,
-                             source_location)
+Type::type_descriptor_pointer(Gogo* gogo, Location location)
 {
-  go_unreachable();
+  Type* t = this->forwarded();
+  if (t->type_descriptor_var_ == NULL)
+    {
+      t->make_type_descriptor_var(gogo);
+      go_assert(t->type_descriptor_var_ != NULL);
+    }
+  tree var_tree = var_to_tree(t->type_descriptor_var_);
+  if (var_tree == error_mark_node)
+    return error_mark_node;
+  return build_fold_addr_expr_loc(location.gcc_location(), var_tree);
 }
 
-// Return a pointer to the type descriptor for this type.
+// A mapping from unnamed types to type descriptor variables.
 
-tree
-Type::type_descriptor_pointer(Gogo* gogo)
+Type::Type_descriptor_vars Type::type_descriptor_vars;
+
+// Build the type descriptor for this type.
+
+void
+Type::make_type_descriptor_var(Gogo* gogo)
 {
-  Type* t = this->forwarded();
-  if (t->type_descriptor_decl_ == NULL_TREE)
+  go_assert(this->type_descriptor_var_ == NULL);
+
+  Named_type* nt = this->named_type();
+
+  // We can have multiple instances of unnamed types, but we only want
+  // to emit the type descriptor once.  We use a hash table.  This is
+  // not necessary for named types, as they are unique, and we store
+  // the type descriptor in the type itself.
+  Bvariable** phash = NULL;
+  if (nt == NULL)
     {
-      Expression* e = t->do_type_descriptor(gogo, NULL);
-      gogo->build_type_descriptor_decl(t, e, &t->type_descriptor_decl_);
-      go_assert(t->type_descriptor_decl_ != NULL_TREE
-                && (t->type_descriptor_decl_ == error_mark_node
-                    || DECL_P(t->type_descriptor_decl_)));
+      Bvariable* bvnull = NULL;
+      std::pair<Type_descriptor_vars::iterator, bool> ins =
+       Type::type_descriptor_vars.insert(std::make_pair(this, bvnull));
+      if (!ins.second)
+       {
+         // We've already build a type descriptor for this type.
+         this->type_descriptor_var_ = ins.first->second;
+         return;
+       }
+      phash = &ins.first->second;
     }
-  if (t->type_descriptor_decl_ == error_mark_node)
-    return error_mark_node;
-  return build_fold_addr_expr(t->type_descriptor_decl_);
+
+  std::string var_name;
+  if (nt == NULL)
+    var_name = this->unnamed_type_descriptor_var_name(gogo);
+  else
+    var_name = this->type_descriptor_var_name(gogo);
+
+  // Build the contents of the type descriptor.
+  Expression* initializer = this->do_type_descriptor(gogo, NULL);
+
+  Btype* initializer_btype = initializer->type()->get_backend(gogo);
+
+  // See if this type descriptor is defined in a different package.
+  bool is_defined_elsewhere = false;
+  if (nt != NULL)
+    {
+      if (nt->named_object()->package() != NULL)
+       {
+         // This is a named type defined in a different package.  The
+         // type descriptor should be defined in that package.
+         is_defined_elsewhere = true;
+       }
+    }
+  else
+    {
+      if (this->points_to() != NULL
+         && this->points_to()->named_type() != NULL
+         && this->points_to()->named_type()->named_object()->package() != NULL)
+       {
+         // This is an unnamed pointer to a named type defined in a
+         // different package.  The descriptor should be defined in
+         // that package.
+         is_defined_elsewhere = true;
+       }
+    }
+
+  Location loc = nt == NULL ? Linemap::predeclared_location() : nt->location();
+
+  if (is_defined_elsewhere)
+    {
+      this->type_descriptor_var_ =
+       gogo->backend()->immutable_struct_reference(var_name,
+                                                   initializer_btype,
+                                                   loc);
+      if (phash != NULL)
+       *phash = this->type_descriptor_var_;
+      return;
+    }
+
+  // See if this type descriptor can appear in multiple packages.
+  bool is_common = false;
+  if (nt != NULL)
+    {
+      // We create the descriptor for a builtin type whenever we need
+      // it.
+      is_common = nt->is_builtin();
+    }
+  else
+    {
+      // This is an unnamed type.  The descriptor could be defined in
+      // any package where it is needed, and the linker will pick one
+      // descriptor to keep.
+      is_common = true;
+    }
+
+  // We are going to build the type descriptor in this package.  We
+  // must create the variable before we convert the initializer to the
+  // backend representation, because the initializer may refer to the
+  // type descriptor of this type.  By setting type_descriptor_var_ we
+  // ensure that type_descriptor_pointer will work if called while
+  // converting INITIALIZER.
+
+  this->type_descriptor_var_ =
+    gogo->backend()->immutable_struct(var_name, is_common, initializer_btype,
+                                     loc);
+  if (phash != NULL)
+    *phash = this->type_descriptor_var_;
+
+  Translate_context context(gogo, NULL, NULL, NULL);
+  context.set_is_const();
+  Bexpression* binitializer = tree_to_expr(initializer->get_tree(&context));
+
+  gogo->backend()->immutable_struct_set_init(this->type_descriptor_var_,
+                                            var_name, is_common,
+                                            initializer_btype, loc,
+                                            binitializer);
+}
+
+// Return the name of the type descriptor variable for an unnamed
+// type.
+
+std::string
+Type::unnamed_type_descriptor_var_name(Gogo* gogo)
+{
+  return "__go_td_" + this->mangled_name(gogo);
+}
+
+// Return the name of the type descriptor variable for a named type.
+
+std::string
+Type::type_descriptor_var_name(Gogo* gogo)
+{
+  Named_type* nt = this->named_type();
+  Named_object* no = nt->named_object();
+  const Named_object* in_function = nt->in_function();
+  std::string ret = "__go_tdn_";
+  if (nt->is_builtin())
+    go_assert(in_function == NULL);
+  else
+    {
+      const std::string& unique_prefix(no->package() == NULL
+                                      ? gogo->unique_prefix()
+                                      : no->package()->unique_prefix());
+      const std::string& package_name(no->package() == NULL
+                                     ? gogo->package_name()
+                                     : no->package()->name());
+      ret.append(unique_prefix);
+      ret.append(1, '.');
+      ret.append(package_name);
+      ret.append(1, '.');
+      if (in_function != NULL)
+       {
+         ret.append(Gogo::unpack_hidden_name(in_function->name()));
+         ret.append(1, '.');
+       }
+    }
+  ret.append(no->name());
+  return ret;
 }
 
 // Return a composite literal for a type descriptor.
@@ -968,7 +1054,7 @@ Type::make_builtin_struct_type(int nfields, ...)
   va_list ap;
   va_start(ap, nfields);
 
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
   Struct_field_list* sfl = new Struct_field_list();
   for (int i = 0; i < nfields; i++)
     {
@@ -991,7 +1077,7 @@ std::vector<Named_type*> Type::named_builtin_types;
 Named_type*
 Type::make_builtin_named_type(const char* name, Type* type)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
   Named_object* no = Named_object::make_type(name, NULL, type, bloc);
   Named_type* ret = no->type_value();
   Type::named_builtin_types.push_back(ret);
@@ -1024,7 +1110,7 @@ Type::make_type_descriptor_type()
   static Type* ret;
   if (ret == NULL)
     {
-      source_location bloc = BUILTINS_LOCATION;
+      Location bloc = Linemap::predeclared_location();
 
       Type* uint8_type = Type::lookup_integer_type("uint8");
       Type* uint32_type = Type::lookup_integer_type("uint32");
@@ -1200,7 +1286,7 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
                                  Named_type* name, const Methods* methods,
                                  bool only_value_methods)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* td_type = Type::make_type_descriptor_type();
   const Struct_field_list* fields = td_type->struct_type()->fields();
@@ -1208,29 +1294,31 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
   Expression_list* vals = new Expression_list();
   vals->reserve(9);
 
+  if (!this->has_pointer())
+    runtime_type_kind |= RUNTIME_TYPE_KIND_NO_POINTERS;
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "Kind");
+  go_assert(p->is_field_name("Kind"));
   mpz_t iv;
   mpz_init_set_ui(iv, runtime_type_kind);
   vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
 
   ++p;
-  go_assert(p->field_name() == "align");
+  go_assert(p->is_field_name("align"));
   Expression::Type_info type_info = Expression::TYPE_INFO_ALIGNMENT;
   vals->push_back(Expression::make_type_info(this, type_info));
 
   ++p;
-  go_assert(p->field_name() == "fieldAlign");
+  go_assert(p->is_field_name("fieldAlign"));
   type_info = Expression::TYPE_INFO_FIELD_ALIGNMENT;
   vals->push_back(Expression::make_type_info(this, type_info));
 
   ++p;
-  go_assert(p->field_name() == "size");
+  go_assert(p->is_field_name("size"));
   type_info = Expression::TYPE_INFO_SIZE;
   vals->push_back(Expression::make_type_info(this, type_info));
 
   ++p;
-  go_assert(p->field_name() == "hash");
+  go_assert(p->is_field_name("hash"));
   mpz_set_ui(iv, this->hash_for_method(gogo));
   vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
 
@@ -1239,7 +1327,7 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
   this->type_functions(&hash_fn, &equal_fn);
 
   ++p;
-  go_assert(p->field_name() == "hashfn");
+  go_assert(p->is_field_name("hashfn"));
   Function_type* fntype = p->type()->function_type();
   Named_object* no = Named_object::make_function_declaration(hash_fn, NULL,
                                                             fntype,
@@ -1248,14 +1336,14 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
   vals->push_back(Expression::make_func_reference(no, NULL, bloc));
 
   ++p;
-  go_assert(p->field_name() == "equalfn");
+  go_assert(p->is_field_name("equalfn"));
   fntype = p->type()->function_type();
   no = Named_object::make_function_declaration(equal_fn, NULL, fntype, bloc);
   no->func_declaration_value()->set_asm_name(equal_fn);
   vals->push_back(Expression::make_func_reference(no, NULL, bloc));
 
   ++p;
-  go_assert(p->field_name() == "string");
+  go_assert(p->is_field_name("string"));
   Expression* s = Expression::make_string((name != NULL
                                           ? name->reflection(gogo)
                                           : this->reflection(gogo)),
@@ -1263,7 +1351,7 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
   vals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc));
 
   ++p;
-  go_assert(p->field_name() == "uncommonType");
+  go_assert(p->is_field_name("uncommonType"));
   if (name == NULL && methods == NULL)
     vals->push_back(Expression::make_nil(bloc));
   else
@@ -1277,7 +1365,7 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
     }
 
   ++p;
-  go_assert(p->field_name() == "ptrToThis");
+  go_assert(p->is_field_name("ptrToThis"));
   if (name == NULL)
     vals->push_back(Expression::make_nil(bloc));
   else
@@ -1306,7 +1394,7 @@ Type::uncommon_type_constructor(Gogo* gogo, Type* uncommon_type,
                                Named_type* name, const Methods* methods,
                                bool only_value_methods) const
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   const Struct_field_list* fields = uncommon_type->struct_type()->fields();
 
@@ -1314,10 +1402,10 @@ Type::uncommon_type_constructor(Gogo* gogo, Type* uncommon_type,
   vals->reserve(3);
 
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "name");
+  go_assert(p->is_field_name("name"));
 
   ++p;
-  go_assert(p->field_name() == "pkgPath");
+  go_assert(p->is_field_name("pkgPath"));
 
   if (name == NULL)
     {
@@ -1356,7 +1444,7 @@ Type::uncommon_type_constructor(Gogo* gogo, Type* uncommon_type,
     }
 
   ++p;
-  go_assert(p->field_name() == "methods");
+  go_assert(p->is_field_name("methods"));
   vals->push_back(this->methods_constructor(gogo, p->type(), methods,
                                            only_value_methods));
 
@@ -1389,7 +1477,7 @@ Type::methods_constructor(Gogo* gogo, Type* methods_type,
                          const Methods* methods,
                          bool only_value_methods) const
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   std::vector<std::pair<std::string, const Method*> > smethods;
   if (methods != NULL)
@@ -1436,7 +1524,7 @@ Type::method_constructor(Gogo*, Type* method_type,
                         const Method* m,
                         bool only_value_methods) const
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   const Struct_field_list* fields = method_type->struct_type()->fields();
 
@@ -1444,13 +1532,13 @@ Type::method_constructor(Gogo*, Type* method_type,
   vals->reserve(5);
 
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "name");
+  go_assert(p->is_field_name("name"));
   const std::string n = Gogo::unpack_hidden_name(method_name);
   Expression* s = Expression::make_string(n, bloc);
   vals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc));
 
   ++p;
-  go_assert(p->field_name() == "pkgPath");
+  go_assert(p->is_field_name("pkgPath"));
   if (!Gogo::is_hidden_name(method_name))
     vals->push_back(Expression::make_nil(bloc));
   else
@@ -1472,11 +1560,11 @@ Type::method_constructor(Gogo*, Type* method_type,
   Type* nonmethod_type = mtype->copy_without_receiver();
 
   ++p;
-  go_assert(p->field_name() == "mtyp");
+  go_assert(p->is_field_name("mtyp"));
   vals->push_back(Expression::make_type_descriptor(nonmethod_type, bloc));
 
   ++p;
-  go_assert(p->field_name() == "typ");
+  go_assert(p->is_field_name("typ"));
   if (!only_value_methods && m->is_value_method())
     {
       // This is a value method on a pointer type.  Change the type of
@@ -1499,7 +1587,7 @@ Type::method_constructor(Gogo*, Type* method_type,
   vals->push_back(Expression::make_type_descriptor(mtype, bloc));
 
   ++p;
-  go_assert(p->field_name() == "tfn");
+  go_assert(p->is_field_name("tfn"));
   vals->push_back(Expression::make_func_reference(no, NULL, bloc));
 
   ++p;
@@ -1600,7 +1688,7 @@ class Error_type : public Type
 
   Expression*
   do_type_descriptor(Gogo*, Named_type*)
-  { return Expression::make_error(BUILTINS_LOCATION); }
+  { return Expression::make_error(Linemap::predeclared_location()); }
 
   void
   do_reflection(Gogo*, std::string*) const
@@ -1719,9 +1807,9 @@ Named_type*
 Type::make_named_bool_type()
 {
   Type* bool_type = Type::make_boolean_type();
-  Named_object* named_object = Named_object::make_type("bool", NULL,
-                                                      bool_type,
-                                                      BUILTINS_LOCATION);
+  Named_object* named_object =
+    Named_object::make_type("bool", NULL, bool_type,
+                            Linemap::predeclared_location());
   Named_type* named_type = named_object->type_value();
   named_bool_type = named_type;
   return named_type;
@@ -1741,9 +1829,9 @@ Integer_type::create_integer_type(const char* name, bool is_unsigned,
   Integer_type* integer_type = new Integer_type(false, is_unsigned, bits,
                                                runtime_type_kind);
   std::string sname(name);
-  Named_object* named_object = Named_object::make_type(sname, NULL,
-                                                      integer_type,
-                                                      BUILTINS_LOCATION);
+  Named_object* named_object =
+    Named_object::make_type(sname, NULL, integer_type,
+                            Linemap::predeclared_location());
   Named_type* named_type = named_object->type_value();
   std::pair<Named_integer_types::iterator, bool> ins =
     Integer_type::named_integer_types.insert(std::make_pair(sname, named_type));
@@ -1877,8 +1965,9 @@ Float_type::create_float_type(const char* name, int bits,
 {
   Float_type* float_type = new Float_type(false, bits, runtime_type_kind);
   std::string sname(name);
-  Named_object* named_object = Named_object::make_type(sname, NULL, float_type,
-                                                      BUILTINS_LOCATION);
+  Named_object* named_object =
+    Named_object::make_type(sname, NULL, float_type,
+                            Linemap::predeclared_location());
   Named_type* named_type = named_object->type_value();
   std::pair<Named_float_types::iterator, bool> ins =
     Float_type::named_float_types.insert(std::make_pair(sname, named_type));
@@ -2001,9 +2090,9 @@ Complex_type::create_complex_type(const char* name, int bits,
   Complex_type* complex_type = new Complex_type(false, bits,
                                                runtime_type_kind);
   std::string sname(name);
-  Named_object* named_object = Named_object::make_type(sname, NULL,
-                                                      complex_type,
-                                                      BUILTINS_LOCATION);
+  Named_object* named_object =
+    Named_object::make_type(sname, NULL, complex_type,
+                            Linemap::predeclared_location());
   Named_type* named_type = named_object->type_value();
   std::pair<Named_complex_types::iterator, bool> ins =
     Complex_type::named_complex_types.insert(std::make_pair(sname,
@@ -2131,12 +2220,12 @@ String_type::do_get_backend(Gogo* gogo)
       Type* pb = Type::make_pointer_type(b);
       fields[0].name = "__data";
       fields[0].btype = pb->get_backend(gogo);
-      fields[0].location = UNKNOWN_LOCATION;
+      fields[0].location = Linemap::predeclared_location();
 
       Type* int_type = Type::lookup_integer_type("int");
       fields[1].name = "__length";
       fields[1].btype = int_type->get_backend(gogo);
-      fields[1].location = UNKNOWN_LOCATION;
+      fields[1].location = fields[0].location;
 
       backend_string_type = gogo->backend()->struct_type(fields);
     }
@@ -2229,9 +2318,9 @@ Named_type*
 Type::make_named_string_type()
 {
   Type* string_type = Type::make_string_type();
-  Named_object* named_object = Named_object::make_type("string", NULL,
-                                                      string_type,
-                                                      BUILTINS_LOCATION);
+  Named_object* named_object =
+    Named_object::make_type("string", NULL, string_type,
+                            Linemap::predeclared_location());
   Named_type* named_type = named_object->type_value();
   named_string_type = named_type;
   return named_type;
@@ -2654,7 +2743,7 @@ Function_type::make_function_type_descriptor_type()
 Expression*
 Function_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* ftdt = Function_type::make_function_type_descriptor_type();
 
@@ -2664,22 +2753,22 @@ Function_type::do_type_descriptor(Gogo* gogo, Named_type* name)
   vals->reserve(4);
 
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "commonType");
+  go_assert(p->is_field_name("commonType"));
   vals->push_back(this->type_descriptor_constructor(gogo,
                                                    RUNTIME_TYPE_KIND_FUNC,
                                                    name, NULL, true));
 
   ++p;
-  go_assert(p->field_name() == "dotdotdot");
+  go_assert(p->is_field_name("dotdotdot"));
   vals->push_back(Expression::make_boolean(this->is_varargs(), bloc));
 
   ++p;
-  go_assert(p->field_name() == "in");
+  go_assert(p->is_field_name("in"));
   vals->push_back(this->type_descriptor_params(p->type(), this->receiver(),
                                               this->parameters()));
 
   ++p;
-  go_assert(p->field_name() == "out");
+  go_assert(p->is_field_name("out"));
   vals->push_back(this->type_descriptor_params(p->type(), NULL,
                                               this->results()));
 
@@ -2697,7 +2786,7 @@ Function_type::type_descriptor_params(Type* params_type,
                                      const Typed_identifier* receiver,
                                      const Typed_identifier_list* params)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   if (receiver == NULL && params == NULL)
     return Expression::make_slice_composite_literal(params_type, NULL, bloc);
@@ -2985,7 +3074,7 @@ Function_type*
 Type::make_function_type(Typed_identifier* receiver,
                         Typed_identifier_list* parameters,
                         Typed_identifier_list* results,
-                        source_location location)
+                        Location location)
 {
   return new Function_type(receiver, parameters, results, location);
 }
@@ -3052,7 +3141,7 @@ Pointer_type::do_type_descriptor(Gogo* gogo, Named_type* name)
     }
   else
     {
-      source_location bloc = BUILTINS_LOCATION;
+      Location bloc = Linemap::predeclared_location();
 
       const Methods* methods;
       Type* deref = this->points_to();
@@ -3071,13 +3160,13 @@ Pointer_type::do_type_descriptor(Gogo* gogo, Named_type* name)
       vals->reserve(2);
 
       Struct_field_list::const_iterator p = fields->begin();
-      go_assert(p->field_name() == "commonType");
+      go_assert(p->is_field_name("commonType"));
       vals->push_back(this->type_descriptor_constructor(gogo,
                                                        RUNTIME_TYPE_KIND_PTR,
                                                        name, methods, false));
 
       ++p;
-      go_assert(p->field_name() == "elem");
+      go_assert(p->is_field_name("elem"));
       vals->push_back(Expression::make_type_descriptor(deref, bloc));
 
       return Expression::make_struct_composite_literal(ptr_tdt, vals, bloc);
@@ -3214,7 +3303,7 @@ class Call_multiple_result_type : public Type
   do_type_descriptor(Gogo*, Named_type*)
   {
     go_assert(saw_errors());
-    return Expression::make_error(UNKNOWN_LOCATION);
+    return Expression::make_error(Linemap::unknown_location());
   }
 
   void
@@ -3285,6 +3374,34 @@ Struct_field::field_name() const
     }
 }
 
+// Return whether this field is named NAME.
+
+bool
+Struct_field::is_field_name(const std::string& name) const
+{
+  const std::string& me(this->typed_identifier_.name());
+  if (!me.empty())
+    return me == name;
+  else
+    {
+      Type* t = this->typed_identifier_.type();
+      if (t->points_to() != NULL)
+       t = t->points_to();
+      Named_type* nt = t->named_type();
+      if (nt != NULL && nt->name() == name)
+       return true;
+
+      // This is a horrible hack caused by the fact that we don't pack
+      // the names of builtin types.  FIXME.
+      if (nt != NULL
+         && nt->is_builtin()
+         && nt->name() == Gogo::unpack_hidden_name(name))
+       return true;
+
+      return false;
+    }
+}
+
 // Class Struct_type.
 
 // Traversal.
@@ -3479,7 +3596,7 @@ Struct_type::find_local_field(const std::string& name,
        pf != fields->end();
        ++pf, ++i)
     {
-      if (pf->field_name() == name)
+      if (pf->is_field_name(name))
        {
          if (pindex != NULL)
            *pindex = i;
@@ -3493,7 +3610,7 @@ Struct_type::find_local_field(const std::string& name,
 
 Field_reference_expression*
 Struct_type::field_reference(Expression* struct_expr, const std::string& name,
-                            source_location location) const
+                            Location location) const
 {
   unsigned int depth;
   return this->field_reference_depth(struct_expr, name, location, NULL,
@@ -3506,7 +3623,7 @@ Struct_type::field_reference(Expression* struct_expr, const std::string& name,
 Field_reference_expression*
 Struct_type::field_reference_depth(Expression* struct_expr,
                                   const std::string& name,
-                                  source_location location,
+                                  Location location,
                                   Saw_named_type* saw,
                                   unsigned int* depth) const
 {
@@ -3520,7 +3637,7 @@ Struct_type::field_reference_depth(Expression* struct_expr,
        pf != fields->end();
        ++pf, ++i)
     {
-      if (pf->field_name() == name)
+      if (pf->is_field_name(name))
        {
          *depth = 0;
          return Expression::make_field_reference(struct_expr, i, location);
@@ -3751,7 +3868,7 @@ Struct_type::make_struct_type_descriptor_type()
 Expression*
 Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* stdt = Struct_type::make_struct_type_descriptor_type();
 
@@ -3766,13 +3883,13 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
   go_assert(methods == NULL || name == NULL);
 
   Struct_field_list::const_iterator ps = fields->begin();
-  go_assert(ps->field_name() == "commonType");
+  go_assert(ps->is_field_name("commonType"));
   vals->push_back(this->type_descriptor_constructor(gogo,
                                                    RUNTIME_TYPE_KIND_STRUCT,
                                                    name, methods, true));
 
   ++ps;
-  go_assert(ps->field_name() == "fields");
+  go_assert(ps->is_field_name("fields"));
 
   Expression_list* elements = new Expression_list();
   elements->reserve(this->fields_->size());
@@ -3787,7 +3904,7 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
       fvals->reserve(5);
 
       Struct_field_list::const_iterator q = f->begin();
-      go_assert(q->field_name() == "name");
+      go_assert(q->is_field_name("name"));
       if (pf->is_anonymous())
        fvals->push_back(Expression::make_nil(bloc));
       else
@@ -3798,7 +3915,7 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
        }
 
       ++q;
-      go_assert(q->field_name() == "pkgPath");
+      go_assert(q->is_field_name("pkgPath"));
       if (!Gogo::is_hidden_name(pf->field_name()))
        fvals->push_back(Expression::make_nil(bloc));
       else
@@ -3809,11 +3926,11 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
        }
 
       ++q;
-      go_assert(q->field_name() == "typ");
+      go_assert(q->is_field_name("typ"));
       fvals->push_back(Expression::make_type_descriptor(pf->type(), bloc));
 
       ++q;
-      go_assert(q->field_name() == "tag");
+      go_assert(q->is_field_name("tag"));
       if (!pf->has_tag())
        fvals->push_back(Expression::make_nil(bloc));
       else
@@ -3823,7 +3940,7 @@ Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
        }
 
       ++q;
-      go_assert(q->field_name() == "offset");
+      go_assert(q->is_field_name("offset"));
       fvals->push_back(Expression::make_struct_field_offset(this, &*pf));
 
       Expression* v = Expression::make_struct_composite_literal(element_type,
@@ -3965,8 +4082,8 @@ Struct_type::do_export(Export* exp) const
       if (p->has_tag())
        {
          exp->write_c_string(" ");
-         Expression* expr = Expression::make_string(p->tag(),
-                                                    BUILTINS_LOCATION);
+         Expression* expr =
+            Expression::make_string(p->tag(), Linemap::predeclared_location());
          expr->export_expression(exp);
          delete expr;
        }
@@ -4024,7 +4141,7 @@ Struct_type::do_import(Import* imp)
 
 Struct_type*
 Type::make_struct_type(Struct_field_list* fields,
-                      source_location location)
+                      Location location)
 {
   return new Struct_type(fields, location);
 }
@@ -4183,43 +4300,6 @@ Array_type::do_hash_for_method(Gogo* gogo) const
   return this->element_type_->hash_for_method(gogo) + 1;
 }
 
-// See if the expression passed to make is suitable.  The first
-// argument is required, and gives the length.  An optional second
-// argument is permitted for the capacity.
-
-bool
-Array_type::do_check_make_expression(Expression_list* args,
-                                    source_location location)
-{
-  go_assert(this->length_ == NULL);
-  if (args == NULL || args->empty())
-    {
-      error_at(location, "length required when allocating a slice");
-      return false;
-    }
-  else if (args->size() > 2)
-    {
-      error_at(location, "too many expressions passed to make");
-      return false;
-    }
-  else
-    {
-      if (!Type::check_int_value(args->front(),
-                                _("bad length when making slice"), location))
-       return false;
-
-      if (args->size() > 1)
-       {
-         if (!Type::check_int_value(args->back(),
-                                    _("bad capacity when making slice"),
-                                    location))
-           return false;
-       }
-
-      return true;
-    }
-}
-
 // Get a tree for the length of a fixed array.  The length may be
 // computed using a function call, so we must only evaluate it once.
 
@@ -4277,23 +4357,24 @@ get_backend_slice_fields(Gogo* gogo, Array_type* type,
 
   Type* pet = Type::make_pointer_type(type->element_type());
   Btype* pbet = pet->get_backend(gogo);
+  Location ploc = Linemap::predeclared_location();
 
   Backend::Btyped_identifier* p = &(*bfields)[0];
   p->name = "__values";
   p->btype = pbet;
-  p->location = UNKNOWN_LOCATION;
+  p->location = ploc;
 
   Type* int_type = Type::lookup_integer_type("int");
 
   p = &(*bfields)[1];
   p->name = "__count";
   p->btype = int_type->get_backend(gogo);
-  p->location = UNKNOWN_LOCATION;
+  p->location = ploc;
 
   p = &(*bfields)[2];
   p->name = "__capacity";
   p->btype = int_type->get_backend(gogo);
-  p->location = UNKNOWN_LOCATION;
+  p->location = ploc;
 }
 
 // Get a tree for the type of this array.  A fixed array is simply
@@ -4333,129 +4414,6 @@ Array_type::get_backend_length(Gogo* gogo)
   return tree_to_expr(this->get_length_tree(gogo));
 }
 
-// Handle the builtin make function for a slice.
-
-tree
-Array_type::do_make_expression_tree(Translate_context* context,
-                                   Expression_list* args,
-                                   source_location location)
-{
-  go_assert(this->length_ == NULL);
-
-  Gogo* gogo = context->gogo();
-  tree type_tree = type_to_tree(this->get_backend(gogo));
-  if (type_tree == error_mark_node)
-    return error_mark_node;
-
-  tree values_field = TYPE_FIELDS(type_tree);
-  go_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(values_field)),
-                   "__values") == 0);
-
-  tree count_field = DECL_CHAIN(values_field);
-  go_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(count_field)),
-                   "__count") == 0);
-
-  tree element_type_tree = type_to_tree(this->element_type_->get_backend(gogo));
-  if (element_type_tree == error_mark_node)
-    return error_mark_node;
-  tree element_size_tree = TYPE_SIZE_UNIT(element_type_tree);
-
-  // The first argument is the number of elements, the optional second
-  // argument is the capacity.
-  go_assert(args != NULL && args->size() >= 1 && args->size() <= 2);
-
-  tree length_tree = args->front()->get_tree(context);
-  if (length_tree == error_mark_node)
-    return error_mark_node;
-  if (!DECL_P(length_tree))
-    length_tree = save_expr(length_tree);
-  if (!INTEGRAL_TYPE_P(TREE_TYPE(length_tree)))
-    length_tree = convert_to_integer(TREE_TYPE(count_field), length_tree);
-
-  tree bad_index = Expression::check_bounds(length_tree,
-                                           TREE_TYPE(count_field),
-                                           NULL_TREE, location);
-
-  length_tree = fold_convert_loc(location, TREE_TYPE(count_field), length_tree);
-  tree capacity_tree;
-  if (args->size() == 1)
-    capacity_tree = length_tree;
-  else
-    {
-      capacity_tree = args->back()->get_tree(context);
-      if (capacity_tree == error_mark_node)
-       return error_mark_node;
-      if (!DECL_P(capacity_tree))
-       capacity_tree = save_expr(capacity_tree);
-      if (!INTEGRAL_TYPE_P(TREE_TYPE(capacity_tree)))
-       capacity_tree = convert_to_integer(TREE_TYPE(count_field),
-                                          capacity_tree);
-
-      bad_index = Expression::check_bounds(capacity_tree,
-                                          TREE_TYPE(count_field),
-                                          bad_index, location);
-
-      tree chktype = (((TYPE_SIZE(TREE_TYPE(capacity_tree))
-                       > TYPE_SIZE(TREE_TYPE(length_tree)))
-                      || ((TYPE_SIZE(TREE_TYPE(capacity_tree))
-                           == TYPE_SIZE(TREE_TYPE(length_tree)))
-                          && TYPE_UNSIGNED(TREE_TYPE(capacity_tree))))
-                     ? TREE_TYPE(capacity_tree)
-                     : TREE_TYPE(length_tree));
-      tree chk = fold_build2_loc(location, LT_EXPR, boolean_type_node,
-                                fold_convert_loc(location, chktype,
-                                                 capacity_tree),
-                                fold_convert_loc(location, chktype,
-                                                 length_tree));
-      if (bad_index == NULL_TREE)
-       bad_index = chk;
-      else
-       bad_index = fold_build2_loc(location, TRUTH_OR_EXPR, boolean_type_node,
-                                   bad_index, chk);
-
-      capacity_tree = fold_convert_loc(location, TREE_TYPE(count_field),
-                                      capacity_tree);
-    }
-
-  tree size_tree = fold_build2_loc(location, MULT_EXPR, sizetype,
-                                  element_size_tree,
-                                  fold_convert_loc(location, sizetype,
-                                                   capacity_tree));
-
-  tree chk = fold_build2_loc(location, TRUTH_AND_EXPR, boolean_type_node,
-                            fold_build2_loc(location, GT_EXPR,
-                                            boolean_type_node,
-                                            fold_convert_loc(location,
-                                                             sizetype,
-                                                             capacity_tree),
-                                            size_zero_node),
-                            fold_build2_loc(location, LT_EXPR,
-                                            boolean_type_node,
-                                            size_tree, element_size_tree));
-  if (bad_index == NULL_TREE)
-    bad_index = chk;
-  else
-    bad_index = fold_build2_loc(location, TRUTH_OR_EXPR, boolean_type_node,
-                               bad_index, chk);
-
-  tree space = context->gogo()->allocate_memory(this->element_type_,
-                                               size_tree, location);
-
-  space = fold_convert(TREE_TYPE(values_field), space);
-
-  if (bad_index != NULL_TREE && bad_index != boolean_false_node)
-    {
-      tree crash = Gogo::runtime_error(RUNTIME_ERROR_MAKE_SLICE_OUT_OF_BOUNDS,
-                                      location);
-      space = build2(COMPOUND_EXPR, TREE_TYPE(space),
-                    build3(COND_EXPR, void_type_node,
-                           bad_index, crash, NULL_TREE),
-                    space);
-    }
-
-  return gogo->slice_constructor(type_tree, space, length_tree, capacity_tree);
-}
-
 // Return a tree for a pointer to the values in ARRAY.
 
 tree
@@ -4623,7 +4581,7 @@ Array_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 Expression*
 Array_type::array_type_descriptor(Gogo* gogo, Named_type* name)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* atdt = Array_type::make_array_type_descriptor_type();
 
@@ -4633,22 +4591,22 @@ Array_type::array_type_descriptor(Gogo* gogo, Named_type* name)
   vals->reserve(3);
 
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "commonType");
+  go_assert(p->is_field_name("commonType"));
   vals->push_back(this->type_descriptor_constructor(gogo,
                                                    RUNTIME_TYPE_KIND_ARRAY,
                                                    name, NULL, true));
 
   ++p;
-  go_assert(p->field_name() == "elem");
+  go_assert(p->is_field_name("elem"));
   vals->push_back(Expression::make_type_descriptor(this->element_type_, bloc));
 
   ++p;
-  go_assert(p->field_name() == "slice");
+  go_assert(p->is_field_name("slice"));
   Type* slice_type = Type::make_array_type(this->element_type_, NULL);
   vals->push_back(Expression::make_type_descriptor(slice_type, bloc));
 
   ++p;
-  go_assert(p->field_name() == "len");
+  go_assert(p->is_field_name("len"));
   vals->push_back(Expression::make_cast(p->type(), this->length_, bloc));
 
   ++p;
@@ -4662,7 +4620,7 @@ Array_type::array_type_descriptor(Gogo* gogo, Named_type* name)
 Expression*
 Array_type::slice_type_descriptor(Gogo* gogo, Named_type* name)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* stdt = Array_type::make_slice_type_descriptor_type();
 
@@ -4672,13 +4630,13 @@ Array_type::slice_type_descriptor(Gogo* gogo, Named_type* name)
   vals->reserve(2);
 
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "commonType");
+  go_assert(p->is_field_name("commonType"));
   vals->push_back(this->type_descriptor_constructor(gogo,
                                                    RUNTIME_TYPE_KIND_SLICE,
                                                    name, NULL, true));
 
   ++p;
-  go_assert(p->field_name() == "elem");
+  go_assert(p->is_field_name("elem"));
   vals->push_back(Expression::make_type_descriptor(this->element_type_, bloc));
 
   ++p;
@@ -4804,28 +4762,6 @@ Map_type::do_hash_for_method(Gogo* gogo) const
          + 2);
 }
 
-// Check that a call to the builtin make function is valid.  For a map
-// the optional argument is the number of spaces to preallocate for
-// values.
-
-bool
-Map_type::do_check_make_expression(Expression_list* args,
-                                  source_location location)
-{
-  if (args != NULL && !args->empty())
-    {
-      if (!Type::check_int_value(args->front(), _("bad size when making map"),
-                                location))
-       return false;
-      else if (args->size() > 1)
-       {
-         error_at(location, "too many arguments when making map");
-         return false;
-       }
-    }
-  return true;
-}
-
 // Get the backend representation for a map type.  A map type is
 // represented as a pointer to a struct.  The struct is __go_map in
 // libgo/map.h.
@@ -4838,89 +4774,36 @@ Map_type::do_get_backend(Gogo* gogo)
     {
       std::vector<Backend::Btyped_identifier> bfields(4);
 
+      Location bloc = Linemap::predeclared_location();
+
       Type* pdt = Type::make_type_descriptor_ptr_type();
       bfields[0].name = "__descriptor";
       bfields[0].btype = pdt->get_backend(gogo);
-      bfields[0].location = BUILTINS_LOCATION;
+      bfields[0].location = bloc;
 
       Type* uintptr_type = Type::lookup_integer_type("uintptr");
       bfields[1].name = "__element_count";
       bfields[1].btype = uintptr_type->get_backend(gogo);
-      bfields[1].location = BUILTINS_LOCATION;
+      bfields[1].location = bloc;
 
       bfields[2].name = "__bucket_count";
       bfields[2].btype = bfields[1].btype;
-      bfields[2].location = BUILTINS_LOCATION;
+      bfields[2].location = bloc;
 
       Btype* bvt = gogo->backend()->void_type();
       Btype* bpvt = gogo->backend()->pointer_type(bvt);
       Btype* bppvt = gogo->backend()->pointer_type(bpvt);
       bfields[3].name = "__buckets";
       bfields[3].btype = bppvt;
-      bfields[3].location = BUILTINS_LOCATION;
+      bfields[3].location = bloc;
 
       Btype *bt = gogo->backend()->struct_type(bfields);
-      bt = gogo->backend()->named_type("__go_map", bt, BUILTINS_LOCATION);
+      bt = gogo->backend()->named_type("__go_map", bt, bloc);
       backend_map_type = gogo->backend()->pointer_type(bt);
     }
   return backend_map_type;
 }
 
-// Return an expression for a newly allocated map.
-
-tree
-Map_type::do_make_expression_tree(Translate_context* context,
-                                 Expression_list* args,
-                                 source_location location)
-{
-  tree bad_index = NULL_TREE;
-
-  tree expr_tree;
-  if (args == NULL || args->empty())
-    expr_tree = size_zero_node;
-  else
-    {
-      expr_tree = args->front()->get_tree(context);
-      if (expr_tree == error_mark_node)
-       return error_mark_node;
-      if (!DECL_P(expr_tree))
-       expr_tree = save_expr(expr_tree);
-      if (!INTEGRAL_TYPE_P(TREE_TYPE(expr_tree)))
-       expr_tree = convert_to_integer(sizetype, expr_tree);
-      bad_index = Expression::check_bounds(expr_tree, sizetype, bad_index,
-                                          location);
-    }
-
-  tree map_type = type_to_tree(this->get_backend(context->gogo()));
-
-  static tree new_map_fndecl;
-  tree ret = Gogo::call_builtin(&new_map_fndecl,
-                               location,
-                               "__go_new_map",
-                               2,
-                               map_type,
-                               TREE_TYPE(TYPE_FIELDS(TREE_TYPE(map_type))),
-                               context->gogo()->map_descriptor(this),
-                               sizetype,
-                               expr_tree);
-  if (ret == error_mark_node)
-    return error_mark_node;
-  // This can panic if the capacity is out of range.
-  TREE_NOTHROW(new_map_fndecl) = 0;
-
-  if (bad_index == NULL_TREE)
-    return ret;
-  else
-    {
-      tree crash = Gogo::runtime_error(RUNTIME_ERROR_MAKE_MAP_OUT_OF_BOUNDS,
-                                      location);
-      return build2(COMPOUND_EXPR, TREE_TYPE(ret),
-                   build3(COND_EXPR, void_type_node,
-                          bad_index, crash, NULL_TREE),
-                   ret);
-    }
-}
-
 // The type of a map type descriptor.
 
 Type*
@@ -4949,7 +4832,7 @@ Map_type::make_map_type_descriptor_type()
 Expression*
 Map_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* mtdt = Map_type::make_map_type_descriptor_type();
 
@@ -4959,17 +4842,17 @@ Map_type::do_type_descriptor(Gogo* gogo, Named_type* name)
   vals->reserve(3);
 
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "commonType");
+  go_assert(p->is_field_name("commonType"));
   vals->push_back(this->type_descriptor_constructor(gogo,
                                                    RUNTIME_TYPE_KIND_MAP,
                                                    name, NULL, true));
 
   ++p;
-  go_assert(p->field_name() == "key");
+  go_assert(p->is_field_name("key"));
   vals->push_back(Expression::make_type_descriptor(this->key_type_, bloc));
 
   ++p;
-  go_assert(p->field_name() == "elem");
+  go_assert(p->is_field_name("elem"));
   vals->push_back(Expression::make_type_descriptor(this->val_type_, bloc));
 
   ++p;
@@ -4978,6 +4861,129 @@ Map_type::do_type_descriptor(Gogo* gogo, Named_type* name)
   return Expression::make_struct_composite_literal(mtdt, vals, bloc);
 }
 
+// A mapping from map types to map descriptors.
+
+Map_type::Map_descriptors Map_type::map_descriptors;
+
+// Build a map descriptor for this type.  Return a pointer to it.
+
+tree
+Map_type::map_descriptor_pointer(Gogo* gogo, Location location)
+{
+  Bvariable* bvar = this->map_descriptor(gogo);
+  tree var_tree = var_to_tree(bvar);
+  if (var_tree == error_mark_node)
+    return error_mark_node;
+  return build_fold_addr_expr_loc(location.gcc_location(), var_tree);
+}
+
+// Build a map descriptor for this type.
+
+Bvariable*
+Map_type::map_descriptor(Gogo* gogo)
+{
+  std::pair<Map_type*, Bvariable*> val(this, NULL);
+  std::pair<Map_type::Map_descriptors::iterator, bool> ins =
+    Map_type::map_descriptors.insert(val);
+  if (!ins.second)
+    return ins.first->second;
+
+  Type* key_type = this->key_type_;
+  Type* val_type = this->val_type_;
+
+  // The map entry type is a struct with three fields.  Build that
+  // struct so that we can get the offsets of the key and value within
+  // a map entry.  The first field should technically be a pointer to
+  // this type itself, but since we only care about field offsets we
+  // just use pointer to bool.
+  Type* pbool = Type::make_pointer_type(Type::make_boolean_type());
+  Struct_type* map_entry_type =
+    Type::make_builtin_struct_type(3,
+                                  "__next", pbool,
+                                  "__key", key_type,
+                                  "__val", val_type);
+
+  Type* map_descriptor_type = Map_type::make_map_descriptor_type();
+
+  const Struct_field_list* fields =
+    map_descriptor_type->struct_type()->fields();
+
+  Expression_list* vals = new Expression_list();
+  vals->reserve(4);
+
+  Location bloc = Linemap::predeclared_location();
+
+  Struct_field_list::const_iterator p = fields->begin();
+
+  go_assert(p->is_field_name("__map_descriptor"));
+  vals->push_back(Expression::make_type_descriptor(this, bloc));
+
+  ++p;
+  go_assert(p->is_field_name("__entry_size"));
+  Expression::Type_info type_info = Expression::TYPE_INFO_SIZE;
+  vals->push_back(Expression::make_type_info(map_entry_type, type_info));
+
+  Struct_field_list::const_iterator pf = map_entry_type->fields()->begin();
+  ++pf;
+  go_assert(pf->is_field_name("__key"));
+
+  ++p;
+  go_assert(p->is_field_name("__key_offset"));
+  vals->push_back(Expression::make_struct_field_offset(map_entry_type, &*pf));
+
+  ++pf;
+  go_assert(pf->is_field_name("__val"));
+
+  ++p;
+  go_assert(p->is_field_name("__val_offset"));
+  vals->push_back(Expression::make_struct_field_offset(map_entry_type, &*pf));
+
+  ++p;
+  go_assert(p == fields->end());
+
+  Expression* initializer =
+    Expression::make_struct_composite_literal(map_descriptor_type, vals, bloc);
+
+  std::string mangled_name = "__go_map_" + this->mangled_name(gogo);
+  Btype* map_descriptor_btype = map_descriptor_type->get_backend(gogo);
+  Bvariable* bvar = gogo->backend()->immutable_struct(mangled_name, true,
+                                                     map_descriptor_btype,
+                                                     bloc);
+
+  Translate_context context(gogo, NULL, NULL, NULL);
+  context.set_is_const();
+  Bexpression* binitializer = tree_to_expr(initializer->get_tree(&context));
+
+  gogo->backend()->immutable_struct_set_init(bvar, mangled_name, true,
+                                            map_descriptor_btype, bloc,
+                                            binitializer);
+
+  ins.first->second = bvar;
+  return bvar;
+}
+
+// Build the type of a map descriptor.  This must match the struct
+// __go_map_descriptor in libgo/runtime/map.h.
+
+Type*
+Map_type::make_map_descriptor_type()
+{
+  static Type* ret;
+  if (ret == NULL)
+    {
+      Type* ptdt = Type::make_type_descriptor_ptr_type();
+      Type* uintptr_type = Type::lookup_integer_type("uintptr");
+      Struct_type* sf =
+       Type::make_builtin_struct_type(4,
+                                      "__map_descriptor", ptdt,
+                                      "__entry_size", uintptr_type,
+                                      "__key_offset", uintptr_type,
+                                      "__val_offset", uintptr_type);
+      ret = Type::make_builtin_named_type("__go_map_descriptor", sf);
+    }
+  return ret;
+}
+
 // Reflection string for a map.
 
 void
@@ -5026,7 +5032,7 @@ Map_type::do_import(Import* imp)
 // Make a map type.
 
 Map_type*
-Type::make_map_type(Type* key_type, Type* val_type, source_location location)
+Type::make_map_type(Type* key_type, Type* val_type, Location location)
 {
   return new Map_type(key_type, val_type, location);
 }
@@ -5061,29 +5067,6 @@ Channel_type::is_identical(const Channel_type* t,
          && this->may_receive_ == t->may_receive_);
 }
 
-// Check whether the parameters for a call to the builtin function
-// make are OK for a channel.  A channel can take an optional single
-// parameter which is the buffer size.
-
-bool
-Channel_type::do_check_make_expression(Expression_list* args,
-                                     source_location location)
-{
-  if (args != NULL && !args->empty())
-    {
-      if (!Type::check_int_value(args->front(),
-                                _("bad buffer size when making channel"),
-                                location))
-       return false;
-      else if (args->size() > 1)
-       {
-         error_at(location, "too many arguments when making channel");
-         return false;
-       }
-    }
-  return true;
-}
-
 // Return the tree for a channel type.  A channel is a pointer to a
 // __go_channel struct.  The __go_channel struct is defined in
 // libgo/runtime/channel.h.
@@ -5096,72 +5079,13 @@ Channel_type::do_get_backend(Gogo* gogo)
     {
       std::vector<Backend::Btyped_identifier> bfields;
       Btype* bt = gogo->backend()->struct_type(bfields);
-      bt = gogo->backend()->named_type("__go_channel", bt, BUILTINS_LOCATION);
+      bt = gogo->backend()->named_type("__go_channel", bt,
+                                       Linemap::predeclared_location());
       backend_channel_type = gogo->backend()->pointer_type(bt);
     }
   return backend_channel_type;
 }
 
-// Handle the builtin function make for a channel.
-
-tree
-Channel_type::do_make_expression_tree(Translate_context* context,
-                                     Expression_list* args,
-                                     source_location location)
-{
-  Gogo* gogo = context->gogo();
-  tree channel_type = type_to_tree(this->get_backend(gogo));
-
-  Type* ptdt = Type::make_type_descriptor_ptr_type();
-  tree element_type_descriptor =
-    this->element_type_->type_descriptor_pointer(gogo);
-
-  tree bad_index = NULL_TREE;
-
-  tree expr_tree;
-  if (args == NULL || args->empty())
-    expr_tree = size_zero_node;
-  else
-    {
-      expr_tree = args->front()->get_tree(context);
-      if (expr_tree == error_mark_node)
-       return error_mark_node;
-      if (!DECL_P(expr_tree))
-       expr_tree = save_expr(expr_tree);
-      if (!INTEGRAL_TYPE_P(TREE_TYPE(expr_tree)))
-       expr_tree = convert_to_integer(sizetype, expr_tree);
-      bad_index = Expression::check_bounds(expr_tree, sizetype, bad_index,
-                                          location);
-    }
-
-  static tree new_channel_fndecl;
-  tree ret = Gogo::call_builtin(&new_channel_fndecl,
-                               location,
-                               "__go_new_channel",
-                               2,
-                               channel_type,
-                               type_to_tree(ptdt->get_backend(gogo)),
-                               element_type_descriptor,
-                               sizetype,
-                               expr_tree);
-  if (ret == error_mark_node)
-    return error_mark_node;
-  // This can panic if the capacity is out of range.
-  TREE_NOTHROW(new_channel_fndecl) = 0;
-
-  if (bad_index == NULL_TREE)
-    return ret;
-  else
-    {
-      tree crash = Gogo::runtime_error(RUNTIME_ERROR_MAKE_CHAN_OUT_OF_BOUNDS,
-                                      location);
-      return build2(COMPOUND_EXPR, TREE_TYPE(ret),
-                   build3(COND_EXPR, void_type_node,
-                          bad_index, crash, NULL_TREE),
-                   ret);
-    }
-}
-
 // Build a type descriptor for a channel type.
 
 Type*
@@ -5192,7 +5116,7 @@ Channel_type::make_chan_type_descriptor_type()
 Expression*
 Channel_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* ctdt = Channel_type::make_chan_type_descriptor_type();
 
@@ -5202,17 +5126,17 @@ Channel_type::do_type_descriptor(Gogo* gogo, Named_type* name)
   vals->reserve(3);
 
   Struct_field_list::const_iterator p = fields->begin();
-  go_assert(p->field_name() == "commonType");
+  go_assert(p->is_field_name("commonType"));
   vals->push_back(this->type_descriptor_constructor(gogo,
                                                    RUNTIME_TYPE_KIND_CHAN,
                                                    name, NULL, true));
 
   ++p;
-  go_assert(p->field_name() == "elem");
+  go_assert(p->is_field_name("elem"));
   vals->push_back(Expression::make_type_descriptor(this->element_type_, bloc));
 
   ++p;
-  go_assert(p->field_name() == "dir");
+  go_assert(p->is_field_name("dir"));
   // These bits must match the ones in libgo/runtime/go-type.h.
   int val = 0;
   if (this->may_receive_)
@@ -5751,15 +5675,17 @@ Interface_type::get_backend_empty_interface_type(Gogo* gogo)
     {
       std::vector<Backend::Btyped_identifier> bfields(2);
 
+      Location bloc = Linemap::predeclared_location();
+
       Type* pdt = Type::make_type_descriptor_ptr_type();
       bfields[0].name = "__type_descriptor";
       bfields[0].btype = pdt->get_backend(gogo);
-      bfields[0].location = UNKNOWN_LOCATION;
+      bfields[0].location = bloc;
 
       Type* vt = Type::make_pointer_type(Type::make_void_type());
       bfields[1].name = "__object";
       bfields[1].btype = vt->get_backend(gogo);
-      bfields[1].location = UNKNOWN_LOCATION;
+      bfields[1].location = bloc;
 
       empty_interface_type = gogo->backend()->struct_type(bfields);
     }
@@ -5774,7 +5700,7 @@ static void
 get_backend_interface_fields(Gogo* gogo, Interface_type* type,
                             std::vector<Backend::Btyped_identifier>* bfields)
 {
-  source_location loc = type->location();
+  Location loc = type->location();
 
   std::vector<Backend::Btyped_identifier> mfields(type->methods()->size() + 1);
 
@@ -5808,7 +5734,7 @@ get_backend_interface_fields(Gogo* gogo, Interface_type* type,
   Type* vt = Type::make_pointer_type(Type::make_void_type());
   (*bfields)[1].name = "__object";
   (*bfields)[1].btype = vt->get_backend(gogo);
-  (*bfields)[1].location = UNKNOWN_LOCATION;
+  (*bfields)[1].location = Linemap::predeclared_location();
 }
 
 // Return a tree for an interface type.  An interface is a pointer to
@@ -5870,7 +5796,7 @@ Interface_type::make_interface_type_descriptor_type()
 Expression*
 Interface_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 {
-  source_location bloc = BUILTINS_LOCATION;
+  Location bloc = Linemap::predeclared_location();
 
   Type* itdt = Interface_type::make_interface_type_descriptor_type();
 
@@ -5880,13 +5806,13 @@ Interface_type::do_type_descriptor(Gogo* gogo, Named_type* name)
   ivals->reserve(2);
 
   Struct_field_list::const_iterator pif = ifields->begin();
-  go_assert(pif->field_name() == "commonType");
-  ivals->push_back(this->type_descriptor_constructor(gogo,
-                                                    RUNTIME_TYPE_KIND_INTERFACE,
-                                                    name, NULL, true));
+  go_assert(pif->is_field_name("commonType"));
+  const int rt = RUNTIME_TYPE_KIND_INTERFACE;
+  ivals->push_back(this->type_descriptor_constructor(gogo, rt, name, NULL,
+                                                    true));
 
   ++pif;
-  go_assert(pif->field_name() == "methods");
+  go_assert(pif->is_field_name("methods"));
 
   Expression_list* methods = new Expression_list();
   if (this->methods_ != NULL && !this->methods_->empty())
@@ -5904,13 +5830,13 @@ Interface_type::do_type_descriptor(Gogo* gogo, Named_type* name)
          mvals->reserve(3);
 
          Struct_field_list::const_iterator pmf = mfields->begin();
-         go_assert(pmf->field_name() == "name");
+         go_assert(pmf->is_field_name("name"));
          std::string s = Gogo::unpack_hidden_name(pm->name());
          Expression* e = Expression::make_string(s, bloc);
          mvals->push_back(Expression::make_unary(OPERATOR_AND, e, bloc));
 
          ++pmf;
-         go_assert(pmf->field_name() == "pkgPath");
+         go_assert(pmf->is_field_name("pkgPath"));
          if (!Gogo::is_hidden_name(pm->name()))
            mvals->push_back(Expression::make_nil(bloc));
          else
@@ -5921,7 +5847,7 @@ Interface_type::do_type_descriptor(Gogo* gogo, Named_type* name)
            }
 
          ++pmf;
-         go_assert(pmf->field_name() == "typ");
+         go_assert(pmf->is_field_name("typ"));
          mvals->push_back(Expression::make_type_descriptor(pm->type(), bloc));
 
          ++pmf;
@@ -5950,13 +5876,13 @@ Interface_type::do_reflection(Gogo* gogo, std::string* ret) const
   ret->append("interface {");
   if (this->methods_ != NULL)
     {
+      ret->push_back(' ');
       for (Typed_identifier_list::const_iterator p = this->methods_->begin();
           p != this->methods_->end();
           ++p)
        {
          if (p != this->methods_->begin())
-           ret->append(";");
-         ret->push_back(' ');
+           ret->append("; ");
          if (!Gogo::is_hidden_name(p->name()))
            ret->append(p->name());
          else
@@ -5972,8 +5898,9 @@ Interface_type::do_reflection(Gogo* gogo, std::string* ret) const
          sub = sub.substr(4);
          ret->append(sub);
        }
+      ret->push_back(' ');
     }
-  ret->append(" }");
+  ret->append("}");
 }
 
 // Mangled name.
@@ -6176,7 +6103,7 @@ Interface_type::do_import(Import* imp)
 
 Interface_type*
 Type::make_interface_type(Typed_identifier_list* methods,
-                         source_location location)
+                         Location location)
 {
   return new Interface_type(methods, location);
 }
@@ -6186,7 +6113,7 @@ Type::make_interface_type(Typed_identifier_list* methods,
 // Bind a method to an object.
 
 Expression*
-Method::bind_method(Expression* expr, source_location location) const
+Method::bind_method(Expression* expr, Location location) const
 {
   if (this->stub_ == NULL)
     {
@@ -6194,10 +6121,7 @@ Method::bind_method(Expression* expr, source_location location) const
       // the child class.
       return this->do_bind_method(expr, location);
     }
-
-  Expression* func = Expression::make_func_reference(this->stub_, NULL,
-                                                    location);
-  return Expression::make_bound_method(expr, func, location);
+  return Expression::make_bound_method(expr, this->stub_, location);
 }
 
 // Return the named object associated with a method.  This may only be
@@ -6228,7 +6152,7 @@ Named_method::do_type() const
 
 // Return the location of the method receiver.
 
-source_location
+Location
 Named_method::do_receiver_location() const
 {
   return this->do_type()->receiver()->location();
@@ -6237,11 +6161,10 @@ Named_method::do_receiver_location() const
 // Bind a method to an object.
 
 Expression*
-Named_method::do_bind_method(Expression* expr, source_location location) const
+Named_method::do_bind_method(Expression* expr, Location location) const
 {
-  Expression* func = Expression::make_func_reference(this->named_object_, NULL,
-                                                    location);
-  Bound_method_expression* bme = Expression::make_bound_method(expr, func,
+  Named_object* no = this->named_object_;
+  Bound_method_expression* bme = Expression::make_bound_method(expr, no,
                                                               location);
   // If this is not a local method, and it does not use a stub, then
   // the real method expects a different type.  We need to cast the
@@ -6262,7 +6185,7 @@ Named_method::do_bind_method(Expression* expr, source_location location) const
 
 Expression*
 Interface_method::do_bind_method(Expression* expr,
-                                source_location location) const
+                                Location location) const
 {
   return Expression::make_interface_field_reference(expr, this->name_,
                                                    location);
@@ -6336,22 +6259,22 @@ Named_type::message_name() const
 Type*
 Named_type::named_base()
 {
-  if (this->seen_ > 0)
+  if (this->seen_)
     return this;
-  ++this->seen_;
+  this->seen_ = true;
   Type* ret = this->type_->base();
-  --this->seen_;
+  this->seen_ = false;
   return ret;
 }
 
 const Type*
 Named_type::named_base() const
 {
-  if (this->seen_ > 0)
+  if (this->seen_)
     return this;
-  ++this->seen_;
+  this->seen_ = true;
   const Type* ret = this->type_->base();
-  --this->seen_;
+  this->seen_ = false;
   return ret;
 }
 
@@ -6361,11 +6284,11 @@ Named_type::named_base() const
 bool
 Named_type::is_named_error_type() const
 {
-  if (this->seen_ > 0)
+  if (this->seen_)
     return false;
-  ++this->seen_;
+  this->seen_ = true;
   bool ret = this->type_->is_error_type();
-  --this->seen_;
+  this->seen_ = false;
   return ret;
 }
 
@@ -6384,7 +6307,7 @@ Named_type::add_method(const std::string& name, Function* function)
 Named_object*
 Named_type::add_method_declaration(const std::string& name, Package* package,
                                   Function_type* type,
-                                  source_location location)
+                                  Location location)
 {
   if (this->local_methods_ == NULL)
     this->local_methods_ = new Bindings(NULL);
@@ -6515,11 +6438,11 @@ Named_type::interface_method_table(Gogo* gogo, const Interface_type* interface,
 bool
 Named_type::named_type_has_hidden_fields(std::string* reason) const
 {
-  if (this->seen_ > 0)
+  if (this->seen_)
     return false;
-  ++this->seen_;
+  this->seen_ = true;
   bool ret = this->type_->has_hidden_fields(this, reason);
-  --this->seen_;
+  this->seen_ = false;
   return ret;
 }
 
@@ -6565,7 +6488,7 @@ Find_type_use::type(Type* type)
   // essentially a pointer: a pointer, a slice, a function, a map, or
   // a channel.
   if (type->points_to() != NULL
-      || type->is_open_array_type()
+      || type->is_slice_type()
       || type->function_type() != NULL
       || type->map_type() != NULL
       || type->channel_type() != NULL)
@@ -6685,11 +6608,11 @@ Named_type::do_verify()
 bool
 Named_type::do_has_pointer() const
 {
-  if (this->seen_ > 0)
+  if (this->seen_)
     return false;
-  ++this->seen_;
+  this->seen_ = true;
   bool ret = this->type_->has_pointer();
-  --this->seen_;
+  this->seen_ = false;
   return ret;
 }
 
@@ -6784,7 +6707,7 @@ Named_type::convert(Gogo* gogo)
 
     case TYPE_ARRAY:
       // Slice types were completed in create_placeholder.
-      if (!base->is_open_array_type())
+      if (!base->is_slice_type())
        {
          Btype* bet = base->array_type()->get_backend_element(gogo);
          Bexpression* blen = base->array_type()->get_backend_length(gogo);
@@ -6874,7 +6797,7 @@ Named_type::create_placeholder(Gogo* gogo)
       break;
 
     case TYPE_ARRAY:
-      if (base->is_open_array_type())
+      if (base->is_slice_type())
        bt = gogo->backend()->placeholder_struct_type(this->name(),
                                                      this->location_);
       else
@@ -6907,7 +6830,7 @@ Named_type::create_placeholder(Gogo* gogo)
 
   this->named_btype_ = bt;
 
-  if (base->is_open_array_type())
+  if (base->is_slice_type())
     {
       // We do not record slices as dependencies of other types,
       // because we can fill them in completely here with the final
@@ -6991,14 +6914,14 @@ Named_type::do_get_backend(Gogo* gogo)
     case TYPE_FUNCTION:
       // Don't build a circular data structure.  GENERIC can't handle
       // it.
-      if (this->seen_ > 0)
+      if (this->seen_in_get_backend_)
        {
          this->is_circular_ = true;
          return gogo->backend()->circular_pointer_type(bt, true);
        }
-      ++this->seen_;
+      this->seen_in_get_backend_ = true;
       bt1 = Type::get_named_base_btype(gogo, base);
-      --this->seen_;
+      this->seen_in_get_backend_ = false;
       if (this->is_circular_)
        bt1 = gogo->backend()->circular_pointer_type(bt, true);
       if (!gogo->backend()->set_placeholder_function_type(bt, bt1))
@@ -7008,14 +6931,14 @@ Named_type::do_get_backend(Gogo* gogo)
     case TYPE_POINTER:
       // Don't build a circular data structure. GENERIC can't handle
       // it.
-      if (this->seen_ > 0)
+      if (this->seen_in_get_backend_)
        {
          this->is_circular_ = true;
          return gogo->backend()->circular_pointer_type(bt, false);
        }
-      ++this->seen_;
+      this->seen_in_get_backend_ = true;
       bt1 = Type::get_named_base_btype(gogo, base);
-      --this->seen_;
+      this->seen_in_get_backend_ = false;
       if (this->is_circular_)
        bt1 = gogo->backend()->circular_pointer_type(bt, false);
       if (!gogo->backend()->set_placeholder_pointer_type(bt, bt1))
@@ -7052,7 +6975,7 @@ Named_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 void
 Named_type::do_reflection(Gogo* gogo, std::string* ret) const
 {
-  if (this->location() != BUILTINS_LOCATION)
+  if (!Linemap::is_predeclared_location(this->location()))
     {
       const Package* package = this->named_object_->package();
       if (package != NULL)
@@ -7076,7 +6999,7 @@ Named_type::do_mangled_name(Gogo* gogo, std::string* ret) const
 {
   Named_object* no = this->named_object_;
   std::string name;
-  if (this->location() == BUILTINS_LOCATION)
+  if (Linemap::is_predeclared_location(this->location()))
     go_assert(this->in_function_ == NULL);
   else
     {
@@ -7166,7 +7089,7 @@ Named_type::do_export(Export* exp) const
 
 Named_type*
 Type::make_named_type(Named_object* named_object, Type* type,
-                     source_location location)
+                     Location location)
 {
   return new Named_type(named_object, type, location);
 }
@@ -7176,7 +7099,7 @@ Type::make_named_type(Named_object* named_object, Type* type,
 // all required stubs.
 
 void
-Type::finalize_methods(Gogo* gogo, const Type* type, source_location location,
+Type::finalize_methods(Gogo* gogo, const Type* type, Location location,
                       Methods** all_methods)
 {
   *all_methods = NULL;
@@ -7376,7 +7299,7 @@ Type::add_interface_methods_for_type(const Type* type,
 
 void
 Type::build_stub_methods(Gogo* gogo, const Type* type, const Methods* methods,
-                        source_location location)
+                        Location location)
 {
   if (methods == NULL)
     return;
@@ -7402,7 +7325,7 @@ Type::build_stub_methods(Gogo* gogo, const Type* type, const Methods* methods,
       Type* receiver_type = const_cast<Type*>(type);
       if (!m->is_value_method())
        receiver_type = Type::make_pointer_type(receiver_type);
-      source_location receiver_location = m->receiver_location();
+      Location receiver_location = m->receiver_location();
       Typed_identifier* receiver = new Typed_identifier(buf, receiver_type,
                                                        receiver_location);
 
@@ -7482,7 +7405,7 @@ Type::build_one_stub_method(Gogo* gogo, Method* method,
                            const char* receiver_name,
                            const Typed_identifier_list* params,
                            bool is_varargs,
-                           source_location location)
+                           Location location)
 {
   Named_object* receiver_object = gogo->lookup(receiver_name, NULL);
   go_assert(receiver_object != NULL);
@@ -7514,9 +7437,10 @@ Type::build_one_stub_method(Gogo* gogo, Method* method,
   go_assert(func != NULL);
   Call_expression* call = Expression::make_call(func, arguments, is_varargs,
                                                location);
+  call->set_hidden_fields_are_ok();
   size_t count = call->result_count();
   if (count == 0)
-    gogo->add_statement(Statement::make_statement(call));
+    gogo->add_statement(Statement::make_statement(call, true));
   else
     {
       Expression_list* retvals = new Expression_list();
@@ -7527,7 +7451,13 @@ Type::build_one_stub_method(Gogo* gogo, Method* method,
          for (size_t i = 0; i < count; ++i)
            retvals->push_back(Expression::make_call_result(call, i));
        }
-      Statement* retstat = Statement::make_return_statement(retvals, location);
+      Return_statement* retstat = Statement::make_return_statement(retvals,
+                                                                  location);
+
+      // We can return values with hidden fields from a stub.  This is
+      // necessary if the method is itself hidden.
+      retstat->set_hidden_fields_are_ok();
+
       gogo->add_statement(retstat);
     }
 }
@@ -7538,7 +7468,7 @@ Type::build_one_stub_method(Gogo* gogo, Method* method,
 Expression*
 Type::apply_field_indexes(Expression* expr,
                          const Method::Field_indexes* field_indexes,
-                         source_location location)
+                         Location location)
 {
   if (field_indexes == NULL)
     return expr;
@@ -7604,7 +7534,7 @@ Type::method_function(const Methods* methods, const std::string& name,
 Expression*
 Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr,
                           const std::string& name,
-                          source_location location)
+                          Location location)
 {
   if (type->deref()->is_error_type())
     return Expression::make_error(location);
@@ -7677,9 +7607,8 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr,
     {
       if (!ambig1.empty())
        error_at(location, "%qs is ambiguous via %qs and %qs",
-                Gogo::message_name(name).c_str(),
-                Gogo::message_name(ambig1).c_str(),
-                Gogo::message_name(ambig2).c_str());
+                Gogo::message_name(name).c_str(), ambig1.c_str(),
+                ambig2.c_str());
       else if (found_pointer_method)
        error_at(location, "method requires a pointer");
       else if (nt == NULL && st == NULL && it == NULL)
@@ -7807,7 +7736,7 @@ Type::find_field_or_method(const Type* type,
        pf != fields->end();
        ++pf)
     {
-      if (pf->field_name() == name)
+      if (pf->is_field_name(name))
        {
          *is_method = false;
          if (nt != NULL)
@@ -7850,8 +7779,10 @@ Type::find_field_or_method(const Type* type,
              // pass the ambiguity back to the caller.
              if (found_level == 0 || sublevel <= found_level)
                {
-                 found_ambig1 = pf->field_name() + '.' + subambig1;
-                 found_ambig2 = pf->field_name() + '.' + subambig2;
+                 found_ambig1 = (Gogo::message_name(pf->field_name())
+                                 + '.' + subambig1);
+                 found_ambig2 = (Gogo::message_name(pf->field_name())
+                                 + '.' + subambig2);
                  found_level = sublevel;
                }
            }
@@ -7875,8 +7806,8 @@ Type::find_field_or_method(const Type* type,
            {
              // We found an ambiguity.
              go_assert(found_parent != NULL);
-             found_ambig1 = found_parent->field_name();
-             found_ambig2 = pf->field_name();
+             found_ambig1 = Gogo::message_name(found_parent->field_name());
+             found_ambig2 = Gogo::message_name(pf->field_name());
            }
          else
            {
@@ -8117,7 +8048,7 @@ Forward_declaration_type::add_method(const std::string& name,
 Named_object*
 Forward_declaration_type::add_method_declaration(const std::string& name,
                                                 Function_type* type,
-                                                source_location location)
+                                                Location location)
 {
   Named_object* no = this->named_object();
   if (no->is_unknown())
@@ -8162,15 +8093,16 @@ Forward_declaration_type::do_get_backend(Gogo* gogo)
 Expression*
 Forward_declaration_type::do_type_descriptor(Gogo* gogo, Named_type* name)
 {
+  Location ploc = Linemap::predeclared_location();
   if (!this->is_defined())
-    return Expression::make_nil(BUILTINS_LOCATION);
+    return Expression::make_nil(ploc);
   else
     {
       Type* t = this->real_type();
       if (name != NULL)
        return this->named_type_descriptor(gogo, t, name);
       else
-       return Expression::make_type_descriptor(t, BUILTINS_LOCATION);
+       return Expression::make_type_descriptor(t, ploc);
     }
 }