Dynamic / Last Resort Lookup

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic / Last Resort Lookup

Axel Naumann
Hi,

We need to implement something similar to dynamic scopes:

void f() {
  File::Open("serialized.data");
  object->func();
}

This will call func() on an object that was retrieved from the file
serialized.data (all of it happens at runtime). The part that blocks us
from implementing it is Sema: all the lookup hooks require a predefined
set of identifiers.

Attached patch creates a last resort, dynamic lookup: if that hook
(implemented by an abstract interface) has been provided, it will get
its chance to look up a symbol but only if all the other language
foreseen lookups have failed (i.e. with lowest precedence).

We believe that the cost for clang is minimal, but for us the benefit
would be huge. Any chance that I may check it in? Of course better ideas
and / or suggestions for naming improvements are very welcome :-)

Cheers, Axel.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Sema_DynamicLookup.diff (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic / Last Resort Lookup

Argyrios Kyrtzidis-2
On Feb 1, 2011, at 6:41 AM, Axel Naumann wrote:

> Hi,
>
> We need to implement something similar to dynamic scopes:
>
> void f() {
>  File::Open("serialized.data");
>  object->func();
> }
>
> This will call func() on an object that was retrieved from the file
> serialized.data (all of it happens at runtime).

Cool!

> The part that blocks us
> from implementing it is Sema: all the lookup hooks require a predefined
> set of identifiers.
>
> Attached patch creates a last resort, dynamic lookup: if that hook
> (implemented by an abstract interface) has been provided, it will get
> its chance to look up a symbol but only if all the other language
> foreseen lookups have failed (i.e. with lowest precedence).
>
> We believe that the cost for clang is minimal, but for us the benefit
> would be huge. Any chance that I may check it in? Of course better ideas
> and / or suggestions for naming improvements are very welcome :-)

This can have other uses as well, e.g. resolving names even if the header is missing.
This currently will only work for id-expressions, I'm assuming you are planning to handle failed namespace lookups, typename lookups, etc. ?

-Argiris

>
> Cheers, Axel.
> <Sema_DynamicLookup.diff>_______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic / Last Resort Lookup

Axel Naumann
Hi Argyrios,

Argyrios Kyrtzidis wrote on 02/02/2011 07:17 PM:
>> Attached patch creates a last resort, dynamic lookup: if that hook
>> (implemented by an abstract interface) has been provided, it will get
>> its chance to look up a symbol but only if all the other language
>> foreseen lookups have failed (i.e. with lowest precedence).
>
> This can have other uses as well, e.g. resolving names even if the header is missing.
> This currently will only work for id-expressions, I'm assuming you are planning to handle failed namespace lookups, typename lookups, etc. ?

Err, we don't have a use case for those (yet). Does that mean unless we
implement namespace, typename etc you don't want to see the patch in? Or
is it okay with you as is? The others can still be added to
DynamicLookup later, by whoever needs it.

Cheers, Axel.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic / Last Resort Lookup

Argyrios Kyrtzidis-2
On Feb 3, 2011, at 2:45 AM, Axel Naumann wrote:

> Hi Argyrios,
>
> Argyrios Kyrtzidis wrote on 02/02/2011 07:17 PM:
>>> Attached patch creates a last resort, dynamic lookup: if that hook
>>> (implemented by an abstract interface) has been provided, it will get
>>> its chance to look up a symbol but only if all the other language
>>> foreseen lookups have failed (i.e. with lowest precedence).
>>
>> This can have other uses as well, e.g. resolving names even if the header is missing.
>> This currently will only work for id-expressions, I'm assuming you are planning to handle failed namespace lookups, typename lookups, etc. ?
>
> Err, we don't have a use case for those (yet). Does that mean unless we
> implement namespace, typename etc you don't want to see the patch in? Or
> is it okay with you as is?

It's fine by me as it is.

> The others can still be added to
> DynamicLookup later, by whoever needs it.

Sounds good!

>
> Cheers, Axel.
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic / Last Resort Lookup

Douglas Gregor
In reply to this post by Axel Naumann

On Feb 3, 2011, at 2:45 AM, Axel Naumann wrote:

Hi Argyrios,

Argyrios Kyrtzidis wrote on 02/02/2011 07:17 PM:
Attached patch creates a last resort, dynamic lookup: if that hook
(implemented by an abstract interface) has been provided, it will get
its chance to look up a symbol but only if all the other language
foreseen lookups have failed (i.e. with lowest precedence).

This can have other uses as well, e.g. resolving names even if the header is missing.
This currently will only work for id-expressions, I'm assuming you are planning to handle failed namespace lookups, typename lookups, etc. ?

Err, we don't have a use case for those (yet). Does that mean unless we
implement namespace, typename etc you don't want to see the patch in? Or
is it okay with you as is? The others can still be added to
DynamicLookup later, by whoever needs it.

Well, I would rather see this patch handling the general case (e.g., in Sema::LookupName) rather than just id-expressions, since we don't want to have to augment *every* lookup in Sema with a similar "if (DynamicLookup && DynamicLookup->PerformLookup(R, S))" statement. Did you try that and run into problems?

- Doug

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic / Last Resort Lookup

Vassil Vassilev
Hi,

On 02/03/2011 08:24 PM, Douglas Gregor wrote:

>
>> Err, we don't have a use case for those (yet). Does that mean unless we
>> implement namespace, typename etc you don't want to see the patch in? Or
>> is it okay with you as is? The others can still be added to
>> DynamicLookup later, by whoever needs it.
>
> Well, I would rather see this patch handling the general case (e.g.,
> in Sema::LookupName) rather than just id-expressions, since we don't
> want to have to augment *every* lookup in Sema with a similar "if
> (DynamicLookup && DynamicLookup->PerformLookup(R, S))" statement. Did
> you try that and run into problems?
Good point! This makes more sense. I am attaching the new patch. Please
let us know do you want it in :)
Cheers,
Vassil

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Sema_DynamicLookup.diff (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic / Last Resort Lookup

Axel Naumann
Hi,

Vassil Vassilev wrote on 02/04/2011 03:40 PM:
> On 02/03/2011 08:24 PM, Douglas Gregor wrote:
>> Well, I would rather see this patch handling the general case (e.g.,
>> in Sema::LookupName) rather than just id-expressions,
>
> Good point! This makes more sense. I am attaching the new patch. Please
> let us know do you want it in :)

Do we have a green light for checking in this patch?

Cheers, Axel.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Sema_DynamicLookup.diff (4K) Download Attachment