<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 15, 2012, at 4:59 PM, Richard Smith wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Tue, May 15, 2012 at 10:55 AM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
On May 15, 2012, at 8:04 AM, Abramo Bagnara <<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a>> wrote:<br>
<br>
> Il 15/05/2012 16:36, Douglas Gregor ha scritto:<br>
>><br>
>> On May 15, 2012, at 12:40 AM, Abramo Bagnara wrote:<br>
>><br>
>>> Another much related issue is shown by the following:<br>
>>><br>
>>> void sort(int (*compare)(int x, int y), int* x);<br>
>>><br>
>>> Which should be the correct context of ParmVarDecl's inside<br>
>>> FunctionType (i.e. int x and int y)?<br>
>><br>
>><br>
>> The DeclContext notion breaks down a little bit here, because we<br>
>> don't create a context for FunctionTypes (and shouldn't). I'd rather<br>
>> that the inner ParmVarDecls be in the 'sort's FunctionDecl.<br>
><br>
> Also if I don't have any problem with this I'd like to understand why<br>
> you think that FunctionTypeLoc should not have a pointer to a<br>
> DeclContext where the args are registered (that for FunctionDecl<br>
> function type is the very same FunctionDecl).<br>
<br>
</div>I'd rather not spend any storage on a DeclContext* in the FunctionTypeLoc.<br>
<div class="im"><br>
> Apart this issue we have added to our AST visitors an experimental<br>
> assertion to verify that if the DeclContext for declaration D is DC,<br>
> then the DeclContext DC indeed contains declaration D.<br>
><br>
> We get tons of assertion failures (e.g. for FunctionDecl or<br>
> CXXRecordDecl inside a template declaration).<br>
><br>
> We'd like to understand if this is unexpected (and in general we should<br>
> always have that if D points to DC then DC should contains D) or if we<br>
> are equivocating the overall design of DeclContext's.<br>
<br>
<br>
</div>For non-function, non-block DeclContext, this is an important invariant.<br>
<br>
For function and block contexts, it doesn't matter: all of the declarations will be reachable via other means, because they are part of the declaration or one of the statements in the definition. If we're to do any work in the area of DeclContext for functions and blocks, I would much rather make them simpler---by eliminating both the lookup tables and the list of lexical declarations---and save the storage, rather than making them meet an invariant that doesn't seem to have any benefits.</blockquote>
<div><br></div><div>The lookup tables for functions were removed by the work which Nick and I did on DeclContext name lookup in March, except for local function declarations, which don't seem to use the Scope mechanism for name lookup. We didn't dig deeply into that issue at the time, but it would need to be fixed before we could abandon the lexical decl chains for functions entirely.</div></div></blockquote><div><br></div><div>Local function declarations definitely need fixing. IIRC, they still have the wrong semantic declaration context (as do local extern variables). And if we fix them, we can refactor just a little to kill off that LookupPtr in FunctionDecl's DeclContext (e.g., by splitting DeclContext into DeclContext and SearchableDeclContext).</div><br><blockquote type="cite"><div class="gmail_quote"><div>That said, the invariant that the decls list on a DeclContext is exactly the list of Decls which have that DC as their lexical context would be useful. In particular, it could be useful for some clients to guarantee that traversing Decls by recursively iterating all lexical decls in all DCs would, in fact, reach all Decls.</div>
</div>
</blockquote></div><div><br></div>Okay, I agree that this is a useful general invariant.<div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Doug</div></div></body></html>