This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH]: Optimize binfo walking


This patch improves the binfo walking by replacing the existing
machinery with dfs_walk_all and dfs_walk_once specializations.  The latter
uses the CLASSTYPE_DIAMOND_SHAPED flag to determine whether it needs
to go marking the bases.  I also changed the API to remove the queue
function.  Its functionality can be folded into the pre order function, along
with a new dfs_skip_bases return value from same.

I folded dfs_accessible_queue_p and associated functions into a further
specialization of dfs_walk_once, as it is only required in one place.

booted & tested on i686-pc-linux-gnu.  Verified with the CSL ABI testsuite.
Timing shows about .5% improvement.

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2004-10-08  Nathan Sidwell  <nathan@codesourcery.com>

	* cp-tree.h (dfs_walk, dfs_walk_real, dfs_unmark, markedp,
	unmarkedp): Remove.
	(dfs_skip_bases, dfs_walk_all, dfs_walk_once): New.
	* class.c (struct find_final_overrider_data): Remove most_derived,
	vpath_list and vpath fields.  Add path field.
	(dfs_find_final_ocerrider_1): Add DEPTH parameter. Adjust.
	(dfs_find_final_overrider): Rename to ...
	(dfs_find_final_overrider_pre): ... here. Adjust.
	(dfs_find_final_overrider_post): Adjust.
	(dfs_find_final_overrider_q): Fold into
	dfs_find_final_overrider_pre.
	(find_final_overrider): Adjust dfs searching.
	(dfs_modify_vtables): Don't mark binfo here.
	(modify_all_vtables): Use dfs_walk_once.
	(build_vtt_inits): Likwise. Use dfs_walk_all.
	(dfs_build_secondary_vptr_vtt_inits): Don't mark binfo here.
	Return dfs_skip_bases as appropriate.
	(dfs_fixup_binfo_vtbls): Return dfs_skip_bases as appropriate.
	* init.c (dfs_initialized_vtbl_ptrs): Return dfs_skip_bases as
	appropriate. Don't mark binfo here.
	(initialize_vtbl_ptrs): Use dfs_walk_once.
	* search.c (struct vbase_info): Remove unused struct.
	(access_in_type): Use dfs_walk_once.
	(dfs_access_in_type): Don't mark binfo here.
	(dfs_accessible_queue_p, dfs_accessible_p) Remove.
	Fold into ...
	(accessible_r): ... here. New. Specialize dfs_walk_once.
	(accessible_p): Use accessible_r.
	(lookup_field_queue_p): Remove. Fold into ...
	(lookup_field_r): ... here. Adjust.
	(lookup_member): Use dfs_walk_all.
	(dfs_walk_real, dfs_walk): Replace with ...
	(dfs_walk_all, dfs_walk_once): ... these.
	(dfs_walk_once_r, dfs_unmark_r): Workers for dfs_walk_once.
	(dfs_unmark, unmarkedp, markedp): Remove.
	(dfs_get_pure_virtuals): Don't mark binfo here.
	(get_pure_virtuals): Use dfs_walk_once.
	(dfs_debug_unmarked_p): Remove. Fold into ...
	(dfs_debug_mark): ... here.
	(note_debug_info_needed): Use dfs_walk_all.

Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.681
diff -c -3 -p -r1.681 class.c
*** cp/class.c	7 Oct 2004 17:48:26 -0000	1.681
--- cp/class.c	8 Oct 2004 09:13:34 -0000
*************** static void add_vcall_offset_vtbl_entrie
*** 155,163 ****
  static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
  static void add_vcall_offset (tree, tree, vtbl_init_data *);
  static void layout_vtable_decl (tree, int);
! static tree dfs_find_final_overrider (tree, void *);
  static tree dfs_find_final_overrider_post (tree, void *);
- static tree dfs_find_final_overrider_q (tree, int, void *);
  static tree find_final_overrider (tree, tree, tree);
  static int make_new_vtable (tree, tree);
  static int maybe_indent_hierarchy (FILE *, int, int);
--- 155,162 ----
  static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
  static void add_vcall_offset (tree, tree, vtbl_init_data *);
  static void layout_vtable_decl (tree, int);
! static tree dfs_find_final_overrider_pre (tree, void *);
  static tree dfs_find_final_overrider_post (tree, void *);
  static tree find_final_overrider (tree, tree, tree);
  static int make_new_vtable (tree, tree);
  static int maybe_indent_hierarchy (FILE *, int, int);
*************** static void dump_thunk (FILE *, int, tre
*** 171,185 ****
  static tree build_vtable (tree, tree, tree);
  static void initialize_vtable (tree, tree);
  static void layout_nonempty_base_or_field (record_layout_info,
! 						   tree, tree, splay_tree);
  static tree end_of_class (tree, int);
  static bool layout_empty_base (tree, tree, splay_tree);
  static void accumulate_vtbl_inits (tree, tree, tree, tree, tree);
  static tree dfs_accumulate_vtbl_inits (tree, tree, tree, tree,
  					       tree);
  static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
! static void build_vcall_and_vbase_vtbl_entries (tree, 
! 							vtbl_init_data *);
  static void clone_constructors_and_destructors (tree);
  static tree build_clone (tree, tree);
  static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
--- 170,183 ----
  static tree build_vtable (tree, tree, tree);
  static void initialize_vtable (tree, tree);
  static void layout_nonempty_base_or_field (record_layout_info,
! 					   tree, tree, splay_tree);
  static tree end_of_class (tree, int);
  static bool layout_empty_base (tree, tree, splay_tree);
  static void accumulate_vtbl_inits (tree, tree, tree, tree, tree);
  static tree dfs_accumulate_vtbl_inits (tree, tree, tree, tree,
  					       tree);
  static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
! static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
  static void clone_constructors_and_destructors (tree);
  static tree build_clone (tree, tree);
  static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
*************** static tree dfs_fixup_binfo_vtbls (tree,
*** 192,202 ****
  static int record_subobject_offset (tree, tree, splay_tree);
  static int check_subobject_offset (tree, tree, splay_tree);
  static int walk_subobject_offsets (tree, subobject_offset_fn,
! 					   tree, splay_tree, tree, int);
  static void record_subobject_offsets (tree, tree, splay_tree, int);
  static int layout_conflict_p (tree, tree, splay_tree, int);
  static int splay_tree_compare_integer_csts (splay_tree_key k1,
! 						    splay_tree_key k2);
  static void warn_about_ambiguous_bases (tree);
  static bool type_requires_array_cookie (tree);
  static bool contains_empty_class_p (tree);
--- 190,200 ----
  static int record_subobject_offset (tree, tree, splay_tree);
  static int check_subobject_offset (tree, tree, splay_tree);
  static int walk_subobject_offsets (tree, subobject_offset_fn,
! 				   tree, splay_tree, tree, int);
  static void record_subobject_offsets (tree, tree, splay_tree, int);
  static int layout_conflict_p (tree, tree, splay_tree, int);
  static int splay_tree_compare_integer_csts (splay_tree_key k1,
! 					    splay_tree_key k2);
  static void warn_about_ambiguous_bases (tree);
  static bool type_requires_array_cookie (tree);
  static bool contains_empty_class_p (tree);
*************** typedef struct find_final_overrider_data
*** 1788,1802 ****
    tree fn;
    /* The base class in which the function was declared.  */
    tree declaring_base;
-   /* The most derived class in the hierarchy.  */
-   tree most_derived_type;
    /* The candidate overriders.  */
    tree candidates;
!   /* Each entry in this array is the next-most-derived class for a
!      virtual base class along the current path.  */
!   tree *vpath_list;
!   /* A pointer one past the top of the VPATH_LIST.  */
!   tree *vpath;
  } find_final_overrider_data;
  
  /* Add the overrider along the current path to FFOD->CANDIDATES.
--- 1786,1795 ----
    tree fn;
    /* The base class in which the function was declared.  */
    tree declaring_base;
    /* The candidate overriders.  */
    tree candidates;
!   /* Path to most derived.  */
!   VEC (tree) *path;
  } find_final_overrider_data;
  
  /* Add the overrider along the current path to FFOD->CANDIDATES.
*************** typedef struct find_final_overrider_data
*** 1804,1825 ****
  
  static bool
  dfs_find_final_overrider_1 (tree binfo, 
! 			    tree *vpath, 
! 			    find_final_overrider_data *ffod)
  {
    tree method;
  
    /* If BINFO is not the most derived type, try a more derived class.
       A definition there will overrider a definition here.  */
!   if (!same_type_p (BINFO_TYPE (binfo), ffod->most_derived_type))
      {
!       tree derived;
! 
!       if (BINFO_VIRTUAL_P (binfo))
! 	derived = *--vpath;
!       else
! 	derived = BINFO_INHERITANCE_CHAIN (binfo);
!       if (dfs_find_final_overrider_1 (derived, vpath, ffod))
  	return true;
      }
  
--- 1797,1814 ----
  
  static bool
  dfs_find_final_overrider_1 (tree binfo, 
! 			    find_final_overrider_data *ffod,
! 			    unsigned depth)
  {
    tree method;
  
    /* If BINFO is not the most derived type, try a more derived class.
       A definition there will overrider a definition here.  */
!   if (depth)
      {
!       depth--;
!       if (dfs_find_final_overrider_1
! 	  (VEC_index (tree, ffod->path, depth), ffod, depth))
  	return true;
      }
  
*************** dfs_find_final_overrider_1 (tree binfo, 
*** 1853,1888 ****
  /* Called from find_final_overrider via dfs_walk.  */
  
  static tree
! dfs_find_final_overrider (tree binfo, void* data)
  {
    find_final_overrider_data *ffod = (find_final_overrider_data *) data;
  
    if (binfo == ffod->declaring_base)
!     dfs_find_final_overrider_1 (binfo, ffod->vpath, ffod);
  
    return NULL_TREE;
  }
  
  static tree
! dfs_find_final_overrider_q (tree derived, int ix, void *data)
  {
-   tree binfo = BINFO_BASE_BINFO (derived, ix);
    find_final_overrider_data *ffod = (find_final_overrider_data *) data;
  
-   if (BINFO_VIRTUAL_P (binfo))
-     *ffod->vpath++ = derived;
-   
-   return binfo;
- }
- 
- static tree
- dfs_find_final_overrider_post (tree binfo, void *data)
- {
-   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
- 
-   if (BINFO_VIRTUAL_P (binfo))
-     ffod->vpath--;
-   
    return NULL_TREE;
  }
  
--- 1842,1864 ----
  /* Called from find_final_overrider via dfs_walk.  */
  
  static tree
! dfs_find_final_overrider_pre (tree binfo, void *data)
  {
    find_final_overrider_data *ffod = (find_final_overrider_data *) data;
  
    if (binfo == ffod->declaring_base)
!     dfs_find_final_overrider_1 (binfo, ffod, VEC_length (tree, ffod->path));
!   VEC_safe_push (tree, ffod->path, binfo);
  
    return NULL_TREE;
  }
  
  static tree
! dfs_find_final_overrider_post (tree binfo ATTRIBUTE_UNUSED, void *data)
  {
    find_final_overrider_data *ffod = (find_final_overrider_data *) data;
+   VEC_pop (tree, ffod->path);
  
    return NULL_TREE;
  }
  
*************** find_final_overrider (tree derived, tree
*** 1920,1942 ****
    /* Determine the depth of the hierarchy.  */
    ffod.fn = fn;
    ffod.declaring_base = binfo;
-   ffod.most_derived_type = BINFO_TYPE (derived);
    ffod.candidates = NULL_TREE;
!   /* The virtual depth cannot be greater than the number of virtual
!      bases.  */
!   ffod.vpath_list = (tree *) xcalloc
!     (VEC_length (tree, CLASSTYPE_VBASECLASSES (BINFO_TYPE (derived))),
!      sizeof (tree));
!   ffod.vpath = ffod.vpath_list;
! 
!   dfs_walk_real (derived,
! 		 dfs_find_final_overrider,
! 		 dfs_find_final_overrider_post,
! 		 dfs_find_final_overrider_q,
! 		 &ffod);
  
!   free (ffod.vpath_list);
  
    /* If there was no winner, issue an error message.  */
    if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
      {
--- 1896,1909 ----
    /* Determine the depth of the hierarchy.  */
    ffod.fn = fn;
    ffod.declaring_base = binfo;
    ffod.candidates = NULL_TREE;
!   ffod.path = VEC_alloc (tree, 30);
  
!   dfs_walk_all (derived, dfs_find_final_overrider_pre,
! 		dfs_find_final_overrider_post, &ffod);
  
+   VEC_free (tree, ffod.path);
+   
    /* If there was no winner, issue an error message.  */
    if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
      {
*************** dfs_modify_vtables (tree binfo, void* da
*** 2208,2215 ****
  				    &virtuals, ix);
      }
  
-   BINFO_MARKED (binfo) = 1;
- 
    return NULL_TREE;
  }
  
--- 2175,2180 ----
*************** modify_all_vtables (tree t, tree virtual
*** 2229,2236 ****
    tree *fnsp;
  
    /* Update all of the vtables.  */
!   dfs_walk (binfo, dfs_modify_vtables, unmarkedp, t);
!   dfs_walk (binfo, dfs_unmark, markedp, t);
  
    /* Add virtual functions not already in our primary vtable. These
       will be both those introduced by this class, and those overridden
--- 2194,2200 ----
    tree *fnsp;
  
    /* Update all of the vtables.  */
!   dfs_walk_once (binfo, NULL, dfs_modify_vtables, t);
  
    /* Add virtual functions not already in our primary vtable. These
       will be both those introduced by this class, and those overridden
*************** build_vtt_inits (tree binfo, tree t, tre
*** 6763,6769 ****
    /* Recursively add the secondary VTTs for non-virtual bases.  */
    for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
      if (!BINFO_VIRTUAL_P (b))
!       inits = build_vtt_inits (BINFO_BASE_BINFO (binfo, i), t, inits, index);
        
    /* Add secondary virtual pointers for all subobjects of BINFO with
       either virtual bases or reachable along a virtual path, except
--- 6727,6733 ----
    /* Recursively add the secondary VTTs for non-virtual bases.  */
    for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
      if (!BINFO_VIRTUAL_P (b))
!       inits = build_vtt_inits (b, t, inits, index);
        
    /* Add secondary virtual pointers for all subobjects of BINFO with
       either virtual bases or reachable along a virtual path, except
*************** build_vtt_inits (tree binfo, tree t, tre
*** 6773,6781 ****
    data.inits = NULL;
    data.type_being_constructed = BINFO_TYPE (binfo);
    
!   dfs_walk_real (binfo, dfs_build_secondary_vptr_vtt_inits,
! 		 NULL, unmarkedp, &data);
!   dfs_walk (binfo, dfs_unmark, markedp, 0);
  
    *index = data.index;
  
--- 6737,6743 ----
    data.inits = NULL;
    data.type_being_constructed = BINFO_TYPE (binfo);
    
!   dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
  
    *index = data.index;
  
*************** build_vtt_inits (tree binfo, tree t, tre
*** 6802,6808 ****
        }
    else
      /* Remove the ctor vtables we created.  */
!     dfs_walk (binfo, dfs_fixup_binfo_vtbls, 0, binfo);
  
    return inits;
  }
--- 6764,6770 ----
        }
    else
      /* Remove the ctor vtables we created.  */
!     dfs_walk_all (binfo, dfs_fixup_binfo_vtbls, NULL, binfo);
  
    return inits;
  }
*************** dfs_build_secondary_vptr_vtt_inits (tree
*** 6815,6841 ****
  {
    secondary_vptr_vtt_init_data *data = (secondary_vptr_vtt_init_data *)data_;
  
-   BINFO_MARKED (binfo) = 1;
- 
    /* We don't care about bases that don't have vtables.  */
    if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
!     return NULL_TREE;
  
    /* We're only interested in proper subobjects of the type being
       constructed.  */
    if (same_type_p (BINFO_TYPE (binfo), data->type_being_constructed))
      return NULL_TREE;
  
-   /* We're not interested in non-virtual primary bases.  */
-   if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
-     return NULL_TREE;
- 
    /* We're only interested in bases with virtual bases or reachable
       via a virtual path from the type being constructed.  */
!   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
!       && !binfo_via_virtual (binfo, data->type_being_constructed))
      return NULL_TREE;
! 
    /* Record the index where this secondary vptr can be found.  */
    if (data->top_level_p)
      {
--- 6777,6801 ----
  {
    secondary_vptr_vtt_init_data *data = (secondary_vptr_vtt_init_data *)data_;
  
    /* We don't care about bases that don't have vtables.  */
    if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
!     return dfs_skip_bases;
  
    /* We're only interested in proper subobjects of the type being
       constructed.  */
    if (same_type_p (BINFO_TYPE (binfo), data->type_being_constructed))
      return NULL_TREE;
  
    /* We're only interested in bases with virtual bases or reachable
       via a virtual path from the type being constructed.  */
!   if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
! 	|| binfo_via_virtual (binfo, data->type_being_constructed)))
!     return dfs_skip_bases;
!   
!   /* We're not interested in non-virtual primary bases.  */
!   if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
      return NULL_TREE;
!   
    /* Record the index where this secondary vptr can be found.  */
    if (data->top_level_p)
      {
*************** dfs_fixup_binfo_vtbls (tree binfo, void*
*** 6873,6881 ****
  {
    tree vtable = BINFO_VTABLE (binfo);
  
    /* If we scribbled the construction vtable vptr into BINFO, clear it
       out now.  */
!   if (vtable && TREE_CODE (vtable) == TREE_LIST
        && (TREE_PURPOSE (vtable) == (tree) data))
      BINFO_VTABLE (binfo) = TREE_CHAIN (vtable);
  
--- 6833,6850 ----
  {
    tree vtable = BINFO_VTABLE (binfo);
  
+   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
+     /* If this class has no vtable, none of its bases do.  */
+     return dfs_skip_bases;
+   
+   if (!vtable)
+     /* This might be a primary base, so have no vtable in this
+        hierarchy.  */
+     return NULL_TREE;
+   
    /* If we scribbled the construction vtable vptr into BINFO, clear it
       out now.  */
!   if (TREE_CODE (vtable) == TREE_LIST
        && (TREE_PURPOSE (vtable) == (tree) data))
      BINFO_VTABLE (binfo) = TREE_CHAIN (vtable);
  
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.1057
diff -c -3 -p -r1.1057 cp-tree.h
*** cp/cp-tree.h	7 Oct 2004 17:48:27 -0000	1.1057
--- cp/cp-tree.h	8 Oct 2004 09:13:46 -0000
*************** extern tree binfo_from_vbase			(tree);
*** 4014,4031 ****
  extern tree binfo_for_vbase			(tree, tree);
  extern tree look_for_overrides_here		(tree, tree);
  extern int check_final_overrider		(tree, tree);
! extern tree dfs_walk                            (tree,
! 						 tree (*) (tree, void *),
! 						 tree (*) (tree, int, void *),
! 						 void *);
! extern tree dfs_walk_real                      (tree,
! 						tree (*) (tree, void *),
! 						tree (*) (tree, void *),
! 						tree (*) (tree, int, void *),
! 						void *);
! extern tree dfs_unmark                          (tree, void *);
! extern tree markedp                             (tree, int, void *);
! extern tree unmarkedp                           (tree, int, void *);
  extern tree binfo_via_virtual                   (tree, tree);
  extern tree build_baselink                      (tree, tree, tree, tree);
  extern tree adjust_result_of_qualified_name_lookup
--- 4014,4024 ----
  extern tree binfo_for_vbase			(tree, tree);
  extern tree look_for_overrides_here		(tree, tree);
  extern int check_final_overrider		(tree, tree);
! #define dfs_skip_bases ((tree)1)
! extern tree dfs_walk_all (tree, tree (*) (tree, void *),
! 			  tree (*) (tree, void *), void *);
! extern tree dfs_walk_once (tree, tree (*) (tree, void *),
! 			   tree (*) (tree, void *), void *);
  extern tree binfo_via_virtual                   (tree, tree);
  extern tree build_baselink                      (tree, tree, tree, tree);
  extern tree adjust_result_of_qualified_name_lookup
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.397
diff -c -3 -p -r1.397 init.c
*** cp/init.c	4 Oct 2004 15:07:50 -0000	1.397
--- cp/init.c	8 Oct 2004 09:13:53 -0000
*************** finish_init_stmts (bool is_global, tree 
*** 101,108 ****
  static tree
  dfs_initialize_vtbl_ptrs (tree binfo, void *data)
  {
!   if ((!BINFO_PRIMARY_P (binfo) || BINFO_VIRTUAL_P (binfo))
!       && TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
      {
        tree base_ptr = TREE_VALUE ((tree) data);
  
--- 101,110 ----
  static tree
  dfs_initialize_vtbl_ptrs (tree binfo, void *data)
  {
!   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
!     return dfs_skip_bases;
!   
!   if (!BINFO_PRIMARY_P (binfo) || BINFO_VIRTUAL_P (binfo))
      {
        tree base_ptr = TREE_VALUE ((tree) data);
  
*************** dfs_initialize_vtbl_ptrs (tree binfo, vo
*** 111,118 ****
        expand_virtual_init (binfo, base_ptr);
      }
  
-   BINFO_MARKED (binfo) = 1;
- 
    return NULL_TREE;
  }
  
--- 113,118 ----
*************** initialize_vtbl_ptrs (tree addr)
*** 132,140 ****
       class.  We do these in pre-order because we can't find the virtual
       bases for a class until we've initialized the vtbl for that
       class.  */
!   dfs_walk_real (TYPE_BINFO (type), dfs_initialize_vtbl_ptrs,
! 		 NULL, unmarkedp, list);
!   dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, type);
  }
  
  /* Return an expression for the zero-initialization of an object with
--- 132,138 ----
       class.  We do these in pre-order because we can't find the virtual
       bases for a class until we've initialized the vtbl for that
       class.  */
!   dfs_walk_once (TYPE_BINFO (type), dfs_initialize_vtbl_ptrs, NULL, list);
  }
  
  /* Return an expression for the zero-initialization of an object with
Index: cp/search.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/search.c,v
retrieving revision 1.325
diff -c -3 -p -r1.325 search.c
*** cp/search.c	7 Oct 2004 17:48:36 -0000	1.325
--- cp/search.c	8 Oct 2004 09:14:00 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 36,64 ****
  #include "toplev.h"
  #include "stack.h"
  
- struct vbase_info 
- {
-   /* The class dominating the hierarchy.  */
-   tree type;
-   /* A pointer to a complete object of the indicated TYPE.  */
-   tree decl_ptr;
-   tree inits;
- };
- 
  static int is_subobject_of_p (tree, tree);
  static base_kind lookup_base_r (tree, tree, base_access, bool, tree *);
  static int dynamic_cast_base_recurse (tree, tree, bool, tree *);
- static tree dfs_debug_unmarkedp (tree, int, void *);
  static tree dfs_debug_mark (tree, void *);
  static int check_hidden_convs (tree, int, int, tree, tree, tree);
  static tree split_conversions (tree, tree, tree, tree);
  static int lookup_conversions_r (tree, int, int,
  				 tree, tree, tree, tree, tree *, tree *);
  static int look_for_overrides_r (tree, tree);
- static tree lookup_field_queue_p (tree, int, void *);
  static tree lookup_field_r (tree, void *);
! static tree dfs_accessible_queue_p (tree, int, void *);
! static tree dfs_accessible_p (tree, void *);
  static tree dfs_access_in_type (tree, void *);
  static access_kind access_in_type (tree, tree);
  static int protected_accessible_p (tree, tree, tree);
--- 36,55 ----
  #include "toplev.h"
  #include "stack.h"
  
  static int is_subobject_of_p (tree, tree);
  static base_kind lookup_base_r (tree, tree, base_access, bool, tree *);
  static int dynamic_cast_base_recurse (tree, tree, bool, tree *);
  static tree dfs_debug_mark (tree, void *);
+ static tree dfs_walk_once_r (tree, tree (*pre_fn) (tree, void *),
+ 			     tree (*post_fn) (tree, void *), void *data);
+ static void dfs_unmark_r (tree);
  static int check_hidden_convs (tree, int, int, tree, tree, tree);
  static tree split_conversions (tree, tree, tree, tree);
  static int lookup_conversions_r (tree, int, int,
  				 tree, tree, tree, tree, tree *, tree *);
  static int look_for_overrides_r (tree, tree);
  static tree lookup_field_r (tree, void *);
! static tree accessible_r (tree, bool);
  static tree dfs_access_in_type (tree, void *);
  static access_kind access_in_type (tree, tree);
  static int protected_accessible_p (tree, tree, tree);
*************** dfs_access_in_type (tree binfo, void *da
*** 663,672 ****
    /* Note the access to DECL in TYPE.  */
    SET_BINFO_ACCESS (binfo, access);
  
-   /* Mark TYPE as visited so that if we reach it again we do not
-      duplicate our efforts here.  */
-   BINFO_MARKED (binfo) = 1;
- 
    return NULL_TREE;
  }
  
--- 654,659 ----
*************** access_in_type (tree type, tree decl)
*** 688,734 ****
      The algorithm we use is to make a post-order depth-first traversal
      of the base-class hierarchy.  As we come up the tree, we annotate
      each node with the most lenient access.  */
!   dfs_walk_real (binfo, 0, dfs_access_in_type, unmarkedp, decl);
!   dfs_walk (binfo, dfs_unmark, markedp,  0);
  
    return BINFO_ACCESS (binfo);
  }
  
- /* Called from accessible_p via dfs_walk.  */
- 
- static tree
- dfs_accessible_queue_p (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
- {
-   tree binfo = BINFO_BASE_BINFO (derived, ix);
-   
-   if (BINFO_MARKED (binfo))
-     return NULL_TREE;
- 
-   /* If this class is inherited via private or protected inheritance,
-      then we can't see it, unless we are a friend of the derived class.  */
-   if (BINFO_BASE_ACCESS (derived, ix) != access_public_node
-       && !is_friend (BINFO_TYPE (derived), current_scope ()))
-     return NULL_TREE;
- 
-   return binfo;
- }
- 
- /* Called from accessible_p via dfs_walk.  */
- 
- static tree
- dfs_accessible_p (tree binfo, void *data ATTRIBUTE_UNUSED)
- {
-   access_kind access;
- 
-   BINFO_MARKED (binfo) = 1;
-   access = BINFO_ACCESS (binfo);
-   if (access != ak_none
-       && is_friend (BINFO_TYPE (binfo), current_scope ()))
-     return binfo;
- 
-   return NULL_TREE;
- }
- 
  /* Returns nonzero if it is OK to access DECL through an object
     indicated by BINFO in the context of DERIVED.  */
  
--- 675,685 ----
      The algorithm we use is to make a post-order depth-first traversal
      of the base-class hierarchy.  As we come up the tree, we annotate
      each node with the most lenient access.  */
!   dfs_walk_once (binfo, NULL, dfs_access_in_type, decl);
  
    return BINFO_ACCESS (binfo);
  }
  
  /* Returns nonzero if it is OK to access DECL through an object
     indicated by BINFO in the context of DERIVED.  */
  
*************** friend_accessible_p (tree scope, tree de
*** 855,860 ****
--- 806,848 ----
    return 0;
  }
  
+ static tree
+ accessible_r (tree binfo, bool once)
+ {
+   tree rval = NULL_TREE;
+   unsigned ix;
+   tree base_binfo;
+   
+   /* Find the next child binfo to walk.  */
+   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+     {
+       bool mark = once && BINFO_VIRTUAL_P (base_binfo);
+ 
+       if (mark && BINFO_MARKED (base_binfo))
+ 	continue;
+   
+       /* If the base is inherited via private or protected
+      	 inheritance, then we can't see it, unless we are a friend of
+      	 the current binfo.  */
+       if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node
+ 	  && !is_friend (BINFO_TYPE (binfo), current_scope ()))
+ 	continue;
+ 
+       if (mark)
+ 	BINFO_MARKED (base_binfo) = 1;
+ 
+       rval = accessible_r (base_binfo, once);
+       if (rval)
+ 	return rval;
+     }
+   
+   if (BINFO_ACCESS (binfo) != ak_none
+       && is_friend (BINFO_TYPE (binfo), current_scope ()))
+     rval = binfo;
+   
+   return rval;
+ }
+ 
  /* DECL is a declaration from a base class of TYPE, which was the
     class used to name DECL.  Return nonzero if, in the current
     context, DECL is accessible.  If TYPE is actually a BINFO node,
*************** accessible_p (tree type, tree decl)
*** 941,952 ****
      {
        /* Walk the hierarchy again, looking for a base class that allows
  	 access.  */
!       t = dfs_walk (binfo, dfs_accessible_p, dfs_accessible_queue_p, 0);
!       /* Clear any mark bits.  Note that we have to walk the whole tree
! 	 here, since we have aborted the previous walk from some point
! 	 deep in the tree.  */
!       dfs_walk (binfo, dfs_unmark, 0,  0);
  
        return t != NULL_TREE;
      }
  }
--- 929,956 ----
      {
        /* Walk the hierarchy again, looking for a base class that allows
  	 access.  */
!       t = accessible_r
! 	(binfo, CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)));
  
+       if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
+ 	;/* We are not diamond shaped, and therefore cannot
+ 	    encounter the same binfo twice.  */
+       else if (!BINFO_INHERITANCE_CHAIN (binfo))
+ 	{
+ 	  /* We are at the top of the hierachy, and can use the
+              CLASSTYPE_VBASECLASSES list for unmarking the virtual
+              bases.  */
+ 	  VEC (tree) *vbases;
+ 	  unsigned ix;
+ 	  tree base_binfo;
+ 	  
+ 	  for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
+ 	       VEC_iterate (tree, vbases, ix, base_binfo); ix++)
+ 	    BINFO_MARKED (base_binfo) = 0;
+ 	}
+       else
+ 	dfs_unmark_r (binfo);
+       
        return t != NULL_TREE;
      }
  }
*************** struct lookup_field_info {
*** 969,1001 ****
    const char *errstr;
  };
  
- /* Returns nonzero if BINFO is not hidden by the value found by the
-    lookup so far.  If BINFO is hidden, then there's no need to look in
-    it.  DATA is really a struct lookup_field_info.  Called from
-    lookup_field via breadth_first_search.  */
- 
- static tree
- lookup_field_queue_p (tree derived, int ix, void *data)
- {
-   tree binfo = BINFO_BASE_BINFO (derived, ix);
-   struct lookup_field_info *lfi = (struct lookup_field_info *) data;
- 
-   /* Don't look for constructors or destructors in base classes.  */
-   if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
-     return NULL_TREE;
- 
-   /* If this base class is hidden by the best-known value so far, we
-      don't need to look.  */
-   if (lfi->rval_binfo && derived == lfi->rval_binfo)
-     return NULL_TREE;
- 
-   /* If this is a dependent base, don't look in it.  */
-   if (BINFO_DEPENDENT_BASE_P (binfo))
-     return NULL_TREE;
-   
-   return binfo;
- }
- 
  /* Within the scope of a template class, you can refer to the to the
     current specialization with the name of the template itself.  For
     example:
--- 973,978 ----
*************** lookup_field_r (tree binfo, void *data)
*** 1075,1080 ****
--- 1052,1067 ----
    tree type = BINFO_TYPE (binfo);
    tree nval = NULL_TREE;
  
+   /* If this is a dependent base, don't look in it.  */
+   if (BINFO_DEPENDENT_BASE_P (binfo))
+     return NULL_TREE;
+   
+   /* If this base class is hidden by the best-known value so far, we
+      don't need to look.  */
+   if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
+       && !BINFO_VIRTUAL_P (binfo))
+     return dfs_skip_bases;
+ 
    /* First, look for a function.  There can't be a function and a data
       member with the same name, and if there's a function and a type
       with the same name, the type is hidden by the function.  */
*************** lookup_field_r (tree binfo, void *data)
*** 1092,1098 ****
    /* If there is no declaration with the indicated name in this type,
       then there's nothing to do.  */
    if (!nval)
!     return NULL_TREE;
  
    /* If we're looking up a type (as with an elaborated type specifier)
       we ignore all non-types we find.  */
--- 1079,1085 ----
    /* If there is no declaration with the indicated name in this type,
       then there's nothing to do.  */
    if (!nval)
!     goto done;
  
    /* If we're looking up a type (as with an elaborated type specifier)
       we ignore all non-types we find.  */
*************** lookup_field_r (tree binfo, void *data)
*** 1119,1132 ****
  	  if (e != NULL)
  	    nval = TYPE_MAIN_DECL (e->type);
  	  else 
! 	    return NULL_TREE;
  	}
      }
  
    /* You must name a template base class with a template-id.  */
    if (!same_type_p (type, lfi->type) 
        && template_self_reference_p (type, nval))
!     return NULL_TREE;
  
    /* If the lookup already found a match, and the new value doesn't
       hide the old one, we might have an ambiguity.  */
--- 1106,1119 ----
  	  if (e != NULL)
  	    nval = TYPE_MAIN_DECL (e->type);
  	  else 
! 	    goto done;
  	}
      }
  
    /* You must name a template base class with a template-id.  */
    if (!same_type_p (type, lfi->type) 
        && template_self_reference_p (type, nval))
!     goto done;
  
    /* If the lookup already found a match, and the new value doesn't
       hide the old one, we might have an ambiguity.  */
*************** lookup_field_r (tree binfo, void *data)
*** 1165,1170 ****
--- 1152,1161 ----
        lfi->rval_binfo = binfo;
      }
  
+  done:
+   /* Don't look for constructors or destructors in base classes.  */
+   if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
+     return dfs_skip_bases;
    return NULL_TREE;
  }
  
*************** lookup_member (tree xbasetype, tree name
*** 1251,1258 ****
    lfi.type = type;
    lfi.name = name;
    lfi.want_type = want_type;
!   dfs_walk_real (basetype_path, &lookup_field_r, 0,
! 		 &lookup_field_queue_p, &lfi);
    rval = lfi.rval;
    rval_binfo = lfi.rval_binfo;
    if (rval_binfo)
--- 1242,1248 ----
    lfi.type = type;
    lfi.name = name;
    lfi.want_type = want_type;
!   dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
    rval = lfi.rval;
    rval_binfo = lfi.rval_binfo;
    if (rval_binfo)
*************** adjust_result_of_qualified_name_lookup (
*** 1526,1591 ****
  
  
  /* Walk the class hierarchy within BINFO, in a depth-first traversal.
!    PREFN is called in preorder, while POSTFN is called in postorder.
!    If they ever returns a non-NULL value, that value is immediately
!    returned and the walk is terminated.  Both PREFN and POSTFN can be
!    NULL.  At each node, PREFN and POSTFN are passed the binfo to
!    examine.  Before each base-binfo of BINFO is walked, QFN is called.
!    If the value returned is nonzero, the base-binfo is walked;
!    otherwise it is not.  If QFN is NULL, it is treated as a function
!    which always returns 1.  All callbacks are passed DATA whenever
!    they are called.  */
  
  tree
! dfs_walk_real (tree binfo,
! 	       tree (*prefn) (tree, void *),
! 	       tree (*postfn) (tree, void *),
! 	       tree (*qfn) (tree, int, void *),
! 	       void *data)
  {
!   int i;
    tree base_binfo;
!   tree rval = NULL_TREE;
! 
    /* Call the pre-order walking function.  */
!   if (prefn)
      {
!       rval = (*prefn) (binfo, data);
        if (rval)
  	return rval;
      }
  
!   /* Process the basetypes.  */
!   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
      {
!       if (qfn)
  	{
! 	  base_binfo = (*qfn) (binfo, i, data);
! 	  if (!base_binfo)
  	    continue;
  	}
!       rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
        if (rval)
  	return rval;
      }
! 
    /* Call the post-order walking function.  */
!   if (postfn)
!     rval = (*postfn) (binfo, data);
    
!   return rval;
  }
  
! /* Exactly like dfs_walk_real, except that there is no pre-order
!    function call and  FN is called in post-order.  */
  
  tree
! dfs_walk (tree binfo,
! 	  tree (*fn) (tree, void *),
! 	  tree (*qfn) (tree, int, void *),
! 	  void *data)
  {
!   return dfs_walk_real (binfo, 0, fn, qfn, data);
  }
  
  /* Check that virtual overrider OVERRIDER is acceptable for base function
--- 1516,1673 ----
  
  
  /* Walk the class hierarchy within BINFO, in a depth-first traversal.
!    PRE_FN is called in preorder, while POST_FN is called in postorder.
!    If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
!    walked.  If PRE_FN or POST_FN returns a different non-NULL value,
!    that value is immediately returned and the walk is terminated.  One
!    of PRE_FN and POST_FN can be NULL.  At each node, PRE_FN and
!    POST_FN are passed the binfo to examine and the caller's DATA
!    value.  All paths are walked, thus virtual and morally virtual
!    binfos can be multiply walked.  */
  
  tree
! dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
! 	      tree (*post_fn) (tree, void *), void *data)
  {
!   tree rval;
!   unsigned ix;
    tree base_binfo;
!   
    /* Call the pre-order walking function.  */
!   if (pre_fn)
      {
!       rval = pre_fn (binfo, data);
!       if (rval)
! 	{
! 	  if (rval == dfs_skip_bases)
! 	    goto skip_bases;
! 	  return rval;
! 	}
!     }
! 
!   /* Find the next child binfo to walk.  */
!   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
!     {
!       rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
        if (rval)
  	return rval;
      }
  
!  skip_bases:
!   /* Call the post-order walking function.  */
!   if (post_fn)
!     return post_fn (binfo, data);
!   return NULL_TREE;
! }
! 
! /* Worker for dfs_walk_once.  This behaves as dfs_walk_all, except
!    that binfos are walked at most once.  */
! 
! static tree
! dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
! 		 tree (*post_fn) (tree, void *), void *data)
! {
!   tree rval;
!   unsigned ix;
!   tree base_binfo;
!   
!   /* Call the pre-order walking function.  */
!   if (pre_fn)
      {
!       rval = pre_fn (binfo, data);
!       if (rval)
  	{
! 	  if (rval == dfs_skip_bases)
! 	    goto skip_bases;
! 	  
! 	  return rval;
! 	}
!     }
! 
!   /* Find the next child binfo to walk.  */
!   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
!     {
!       if (BINFO_VIRTUAL_P (base_binfo))
! 	{
! 	  if (BINFO_MARKED (base_binfo))
  	    continue;
+ 	  BINFO_MARKED (base_binfo) = 1;
  	}
!   
!       rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, data);
        if (rval)
  	return rval;
      }
!   
!  skip_bases:
    /* Call the post-order walking function.  */
!   if (post_fn)
!     return post_fn (binfo, data);
    
!   return NULL_TREE;
! }
! 
! /* Worker for dfs_walk_once. Recursively unmark the virtual base binfos of
!    BINFO.  */
!    
! static void
! dfs_unmark_r (tree binfo)
! {
!   unsigned ix;
!   tree base_binfo;
!   
!   /* Process the basetypes.  */
!   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
!     {
!       if (BINFO_VIRTUAL_P (base_binfo))
! 	{
! 	  if (!BINFO_MARKED (base_binfo))
! 	    continue;
! 	  BINFO_MARKED (base_binfo) = 0;
! 	}
!       /* Only walk, if it can contain more virtual bases.  */
!       if (CLASSTYPE_VBASECLASSES (BINFO_TYPE (base_binfo)))
! 	dfs_unmark_r (base_binfo);
!     }
  }
  
! /* Like dfs_walk_all, except that binfos are not multiply walked.  For
!    non-diamond shaped hierarchies this is the same as dfs_walk_all.
!    For diamond shaped hierarchies we must mark the virtual bases, to
!    avoid multiple walks.  */
  
  tree
! dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
! 	       tree (*post_fn) (tree, void *), void *data)
  {
!   tree rval;
! 
!   gcc_assert (pre_fn || post_fn);
!   
!   if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
!     /* We are not diamond shaped, and therefore cannot encounter the
!        same binfo twice.  */
!     rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
!   else
!     {
!       rval = dfs_walk_once_r (binfo, pre_fn, post_fn, data);
!       if (!BINFO_INHERITANCE_CHAIN (binfo))
! 	{
! 	  /* We are at the top of the hierachy, and can use the
!              CLASSTYPE_VBASECLASSES list for unmarking the virtual
!              bases.  */
! 	  VEC (tree) *vbases;
! 	  unsigned ix;
! 	  tree base_binfo;
! 	  
! 	  for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
! 	       VEC_iterate (tree, vbases, ix, base_binfo); ix++)
! 	    BINFO_MARKED (base_binfo) = 0;
! 	}
!       else
! 	dfs_unmark_r (binfo);
!     }
!   return rval;
  }
  
  /* Check that virtual overrider OVERRIDER is acceptable for base function
*************** dfs_get_pure_virtuals (tree binfo, void 
*** 1805,1812 ****
  	  VEC_safe_push (tree, CLASSTYPE_PURE_VIRTUALS (type),
  			 BV_FN (virtuals));
      }
-   
-   BINFO_MARKED (binfo) = 1;
  
    return NULL_TREE;
  }
--- 1887,1892 ----
*************** get_pure_virtuals (tree type)
*** 1825,1863 ****
       (A primary base is not interesting because the derived class of
       which it is a primary base will contain vtable entries for the
       pure virtuals in the base class.  */
!   dfs_walk (TYPE_BINFO (type), dfs_get_pure_virtuals, unmarkedp, type);
!   dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, type);
! }
! 
! /* DEPTH-FIRST SEARCH ROUTINES.  */
! 
! tree 
! markedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED) 
! {
!   tree binfo = BINFO_BASE_BINFO (derived, ix);
!   
!   return BINFO_MARKED (binfo) ? binfo : NULL_TREE; 
! }
! 
! tree
! unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED) 
! {
!   tree binfo = BINFO_BASE_BINFO (derived, ix);
!   
!   return !BINFO_MARKED (binfo) ? binfo : NULL_TREE; 
! }
! 
! /* The worker functions for `dfs_walk'.  These do not need to
!    test anything (vis a vis marking) if they are paired with
!    a predicate function (above).  */
! 
! tree
! dfs_unmark (tree binfo, void *data ATTRIBUTE_UNUSED)
! {
!   BINFO_MARKED (binfo) = 0;
!   return NULL_TREE;
  }
- 
  
  /* Debug info for C++ classes can get very large; try to avoid
     emitting it everywhere.
--- 1905,1912 ----
       (A primary base is not interesting because the derived class of
       which it is a primary base will contain vtable entries for the
       pure virtuals in the base class.  */
!   dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
  }
  
  /* Debug info for C++ classes can get very large; try to avoid
     emitting it everywhere.
*************** dfs_debug_mark (tree binfo, void *data A
*** 1905,1927 ****
  {
    tree t = BINFO_TYPE (binfo);
  
    CLASSTYPE_DEBUG_REQUESTED (t) = 1;
  
    return NULL_TREE;
  }
  
- /* Returns BINFO if we haven't already noted that we want debugging
-    info for this base class.  */
- 
- static tree 
- dfs_debug_unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
- {
-   tree binfo = BINFO_BASE_BINFO (derived, ix);
-   
-   return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo)) 
- 	  ? binfo : NULL_TREE);
- }
- 
  /* Write out the debugging information for TYPE, whose vtable is being
     emitted.  Also walk through our bases and note that we want to
     write out information for them.  This avoids the problem of not
--- 1954,1967 ----
  {
    tree t = BINFO_TYPE (binfo);
  
+   if (CLASSTYPE_DEBUG_REQUESTED (t))
+     return dfs_skip_bases;
+ 
    CLASSTYPE_DEBUG_REQUESTED (t) = 1;
  
    return NULL_TREE;
  }
  
  /* Write out the debugging information for TYPE, whose vtable is being
     emitted.  Also walk through our bases and note that we want to
     write out information for them.  This avoids the problem of not
*************** note_debug_info_needed (tree type)
*** 1938,1944 ****
        rest_of_type_compilation (type, toplevel_bindings_p ());
      }
  
!   dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
  }
  
  void
--- 1978,1984 ----
        rest_of_type_compilation (type, toplevel_bindings_p ());
      }
  
!   dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
  }
  
  void

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]