<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 28, 2014 at 3:10 PM, Ben Langmuir <span dir="ltr"><<a href="mailto:blangmuir@apple.com" target="_blank">blangmuir@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=""><br>
> On Jul 28, 2014, at 4:31 AM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
><br>
> Hi Richard,<br>
><br>
> while working with module maps for layering checks a problem with __FILE__ we noticed triggered a couple of questions.<br>
><br>
> The problem is that __FILE__ uses the path of the first 'stat' call (as that is how FileManager::getFile() works).<br>
<br>
</div>I was thinking about this a while ago and independently of this issue I would really like to change this behaviour at some point.  The name of a file is a property of how you look it up, not an intrinsic part of the file itself.</blockquote>
<div><br></div><div>I agree. We have incorrectly conflated the notion of the file identity (inode) with the directory entriy, and we can't tell the two apart. This leads to weird behavior in a number of places. For instance:</div>
<div><br></div><div> a/</div><div>  x.h: #include "y.h"</div><div>  y.h: int a = 0;</div><div> b/</div><div>  x.h: symlink to a/x.h</div><div>  y.h: int b = 0;</div><div> main.c:</div><div>  #include "a/x.h"</div>
<div>  #include "b/x.h"</div><div>  int main() { return a + b; }</div><div><br></div><div>On a correct compiler, this would work. For clang, it fails, because b/x.h's #include finds a/y.h, because we use the path by which we first found x.h as the One True Path to x.h. (This also leads to wrong __FILE__, etc.)</div>
<div><br></div><div>I tried fixing this ~2 years ago by splitting FileEntry into separate dentry and inode classes, but this rapidly snowballed and exposed the same design error being made in various other components. We should fix this, and it seems the right way to address the problem here, but it's a big task.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
> Currently we parse all module maps at the beginning of the TU, and stat all headers while doing so; there is a FIXME in ModuleMapParser::parseHeaderDecl that reminds us this might not be a good idea, and that we'd want to somehow lazily stat the headers anyway.<br>

> Regardless, currently the first 'stat' to a header when using strict-decluse is usually the way the header is referenced by its module's module map; this is often very different from what the user expects, and certainly different from how this used to work (using -I relative path via which a header is usually found).<br>

<br>
</div>Just to make sure I understand the issue: the file name is correct, it’s just showing up relative to the module map file rather than relative to an include path?<br>
<div class="im HOEnZb"><br>
><br>
> There are multiple possible solutions, but the first one we thought about was to fix the header stat'ing FIXME, which would naturally solve this problem by pushing the first stat of the header after the stat from the #include.<br>

> The problem with that approach is:<br>
> 1. We currently have some places that look up a module for a header; we at least need to resolve the headers of all direct dependencies of the module map; I'm unsure what the effect of only finding the headers of the current module and its direct dependencies would be.<br>

> 2. We need to find a place in the code at which to resolve / stat all headers in the current module map (and its direct dependencies); this needs to be after preprocessing (thus we'd need to delay diags related to modules while parsing #include directives). It seems to me like this would allow us to also resolve headers only for the current module and its direct deps, at least if my theory is correct that preprocessing would happen once per file per module being built (even on recursive module build invocations)<br>

><br>
> After looking into it, it seems like this is significant effort, so we're somewhat hoping to find an intermediate solution that is less effort and allows us to fix the above problems together with the work on full modules.<br>

><br>
> Thoughts?<br>
> /Manuel<br>
</div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br>
</div></div></blockquote></div><br></div></div>