[PATCH] Canonical types (1/3)

Doug Gregor doug.gregor@gmail.com
Wed Dec 6 15:04:00 GMT 2006


On 12/5/06, Mark Mitchell <mark@codesourcery.com> wrote:
> OK, that's great.  Unfortunately, I think you should to do that again
> with the final patch, which I know takes a while.  Feel free to post a
> more casually tested patch for me to provisionally review, if you like.

Okay. I have attached the revised patch. As before, it is separated
into 3 different parts: -gcc for the C/common bits, -cp for the C++
front end, -objc for the Objective-C(++) front end. ChangeLog follows.

I have made the following changes to this patch:
  - Switched from -f(no-)check-canonical-types to --param
verify-canonical-types=(0|1); documented in invoke.texi.
  - Add documentation for the new macros, both in tree.h and c-tree.texi.
  - Switched the behavior of build_variant_type_copy to propagate
canonical type information (the common case); this shrunk the patch
quite a bit, because fewer callers have to patch up TYPE_CANONICAL.
  - Removed the structural equality bit (+ padding) from the _TYPE
nodes, using TYPE_CANONICAL == NULL_TREE instead. We now only
introduce one extra pointer into every _TYPE node.
  - Don't build canonical types when we're constructing a type that
requires structural equality.

This patch has been "lightly" tested, by which I mean that it
bootstraps with C, C++, Objective-C, Objective-C++, and Java; "make
check"s for C, C++, Objective-C, Objective-C++, and libstdc++. No
canonical-type warnings or new failures anywhere on i686-pc-linux-gnu.

Before committing, I also need to run the same tests with
"--disable-checking" (to turn off canonical-type verification
throughout), and repeat the whole suite of tests on
powerpc-apple-darwin8.8.0.

Assuming there are no failures from any of these tests, okay to commit?

  Cheers,
  Doug

2006-12-06  Douglas Gregor  <doug.gregor@gmail.com>

	* c-common.c(c_common_nodes_and_builtins): Since variants of
	void_type_node get built before it is given a name, we need to
	give those variants the name, too.
	(complete_array_type): We need to work with the canonical main
	type of the array, from which we will build the qualified version.
	* params.def (PARAM_VERIFY_CANONICAL_TYPES): New.
	* print-tree.c (print_node): Display canonical type information
	for each type.
	* stor-layout.c (layout_type): When we don't know the
	alignment of a type for which we're building an array, we end up
	guessing wrong, so make the type require structural equality.
	* tree.c (make_node_stat): When we build a new type, it is its
	own canonical type.
	(build_type_attribute_qual_variant): When building an attribute
	variant, its canonical type is the non-attribute variant. However,
	if the attributes are target-dependent and they differ, we need to
	use structural equality checks for this type.
	(build_qualified_type): A qualified type is not equivalent to its
	unqualified variant; set the canonical type appropriately.
	(build_distinct_type_copy): When building a distinct type from
	another type, the new type is its own canonical type.
	(build_variant_type_copy): When building a new type variant, we
	assume that it is equivalent to the original type.
	(build_pointer_type_for_mode): When building a pointer type, also
	build a canonical type pointer.
	(build_reference_type_for_mode): When building a reference type,
	also build a canonical type reference.
	(build_index_type): When we can't hash an index type (e.g.,
	because its maximum value is negative), the index type requires
	structural equality tests.
	(build_array_type): Build the canonical form of an array type.
	(build_function_type): Function types require structural equality,
	because they contain default arguments, attributes, etc.
	(build_method_type_directly): Ditto for method types.
	(build_offset_type): Build the canonical offset type.
	(build_complex_type): Build the canonical vector type.
	(make_vector_type): Build the canonical vector type.
	* tree.h (TYPE_CANONICAL): New.
	(TYPE_STRUCTURAL_EQUALITY_P): New.
	(SET_TYPE_STRUCTURAL_EQUALITY): New.
	(struct tree_type): Added "canonical" field.
	* params.h (VERIFY_CANONICAL_TYPES): New.
	* doc/c-tree.texi (TYPE_CANONICAL): Document.
	(TYPE_STRUCTURAL_EQUALITY_P): Document.
	(SET_TYPE_STRUCTURAL_EQUALITY): Document.
	* doc/invoke.texi (verify-canonical-types): Document --param
	parameter for verifying canonical types.
	
2006-12-06  Douglas Gregor  <doug.gregor@gmail.com>

	* typeck.c (structural_comptypes): Renamed from "comptypes".
	(comptypes): Use canonical type information to perform fast type
	comparison. When VERIFY_CANONICAL_TYPES, verify that the
	canonical type comparison returns the same results as we would see
	from the current, structural check. Support COMPARE_STRUCTURAL
	when we need structural checks.
	* decl.c (typename_compare): Fix comment.
	(build_typename_type): TYPENAME_TYPE nodes require structural
	equality checks, because they resolve different based on the
	current class type.
	(make_unbound_class_template): UNBOUND_CLASS_TEMPLATE nodes
	require structural equality checks (for now).
	(build_ptrmemfunc_type): Build the canonical pointer to member
	function type.
	(compute_array_index_type): Whenever we build a new index type
	to represent the size of an array in a template, we need to mark
	this index type as requiring structural equality. This goes for
	arrays with value-dependent sizes with the current ABI, or all
	arrays with ABI-1.
	* tree.c (cplus_array_hash): New.
	(struct cplus_array_info): New.
	(cplus_array_compare): New.
	(cplus_array_htab): New.
	(build_cplus_array_type_1): Use a hash table to cache the array
	types we build. Build the canonical array type for each array
	type.
	(cp_build_qualified_type_real): When building a cv-qualified array
	type, use the hash table of array types and build canonical array
	types as necessary.
	(bind_template_template_parm): BOUND_TEMPLATE_TEMPLATE_PARM nodes
	use structural equality (for now).
	* cp-tree.h (COMPARE_STRUCTURAL): New.
	* pt.c (canonical_template_parms): New.
	(canonical_type_parameter): New.
	(process_template_parm): Find the canonical type parameter.
	(lookup_template_class): When we have named the primary template
	type, set the canonical type for our template class to the primary
	template type. If any of the template arguments need structural
	equality checks, the template class needs structural equality
	checks.
	(tsubst): When reducing the level of a template template
	parameter, we require structural equality tests for the resulting
	parameter because its template parameters have not had their types
	canonicalized. When reducing a template type parameter, find the
	canonical reduced type parameter.
	(any_template_arguments_need_structural_equality_p): New.

2006-12-06  Douglas Gregor  <doug.gregor@gmail.com>
	
	* objc-act.c (objc_build_volatilized_type): Keep track of
	canonical types.
	(objc_get_protocol_qualified_type): Ditto.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: canonical-types-gcc.patch
Type: text/x-patch
Size: 18697 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061206/ab1f0ea0/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: canonical-types-cp.patch
Type: text/x-patch
Size: 17174 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061206/ab1f0ea0/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: canonical-types-objc.patch
Type: text/x-patch
Size: 1014 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061206/ab1f0ea0/attachment-0002.bin>


More information about the Gcc-patches mailing list