Escape analysis (full scope analysis proposal)

Michel Fortin michel.fortin at michelf.com
Thu Oct 30 18:01:27 PDT 2008


On 2008-10-30 09:04:10 -0400, "Robert Jacques" <sandford at jhu.edu> said:

> Just to clarify:
>    	void test2(scope MyObject o)	// the scope of o is a parent of test2
>   	{
>   		int i;			// the scope of i is test2
>   		foo(o, &i);		// foo(o,&i) requires &i to have o's scope or a parent 
> of  o's scope, so i must be heap (the root parent) allocated.
>   	}
> 
> A problem I see is that once shared/local are introduced, you have  
> multiple heaps where i should be allocated, depending on the runtime 
> type  of o. How would this be handled in this scheme?

Well, it all depends if foo wants the second argument of i must be 
shared or not. If foo's declaration was like this:

	void foo(scope MyObject o, scope(o) shared int* i);

then you'd need to use "shared int i" in test2 to avoid an error at the 
call site.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list