[1/2,D] Don't recursively look for a symbol in all imports of imported modules.

Message ID CABOHX+fEAnMeMceeMnihAGghkn=fSuWF4GZmwdx57svk5-+zeQ@mail.gmail.com
State New, archived
Headers

Commit Message

Iain Buclaw Oct. 11, 2015, 11:23 a.m. UTC
  Consider the following pathological case:
---
module A;
import B, C;
---
module C;
import A;
---

When looking up a symbol in module 'B' from module 'A', although it
won't lead to infinite recursion, it will cause a to and fro to occur
between the two cyclic imports.  This get exponentially worse when
there are tens or hundreds of modules all importing each other.

Although there is a genuine case to recursively search imports from
foreign modules, this only makes sense in D for 'public' imports,
which would be expressed as:
---
module A;
import B;
---
module B;
public import C;  // All symbols in 'C' are available to any module
that imports 'B'
---

However there is no way to detect this as of today in DWARFv4.  Only
DW_TAG_imported_declarations get a DW_AT_accessibility attribute.
Though perhaps DW_AT_visibility would be more accurate because 'static
import' would be considered as qualified.

But I digress on matters outside the scope of this patch. :-)

Regards,
Iain.
---
  

Patch

gdb/ChangeLog:

	* d-namespace.c (d_lookup_symbol_imports): Avoid recursive lookups from
	cyclic imports.

---
diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c
index e8f4c6f..da5da58 100644
--- a/gdb/d-namespace.c
+++ b/gdb/d-namespace.c
@@ -508,9 +508,9 @@  d_lookup_symbol_imports (const char *scope, const char *name,
 		    {
 		      /* Skip the '.'  */
 		      name_scope++;
-		      sym = d_lookup_symbol_imports (current->import_src,
-						     name + name_scope,
-						     block, domain, 0);
+		      sym = d_lookup_symbol_in_module (current->import_src,
+						       name + name_scope,
+						       block, domain, 1);
 		    }
 		}
 	    }
@@ -519,8 +519,8 @@  d_lookup_symbol_imports (const char *scope, const char *name,
 	      /* If this import statement creates no alias, pass
 		 current->import_src as MODULE to direct the search
 		 towards the imported module.  */
-	      sym = d_lookup_symbol_imports (current->import_src,
-					     name, block, domain, 0);
+	      sym = d_lookup_symbol_in_module (current->import_src,
+					       name, block, domain, 1);
 	    }
 	  current->searched = 0;
 	  discard_cleanups (searched_cleanup);