Escape analysis (full scope analysis proposal)

Robert Jacques sandford at jhu.edu
Fri Oct 31 07:54:56 PDT 2008


On Thu, 30 Oct 2008 21:01:27 -0400, Michel Fortin  
<michel.fortin at michelf.com> wrote:

> 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.
>

Actually, what I meant was that o may be local or shared. However,  
assuming thin-locks, o  may be tested at runtime for share/local cheaply  
and the right allocation done.



More information about the Digitalmars-d mailing list