<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><div class="">On Feb 5, 2014, at 2:29 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 5, 2014 at 12:43 PM, Ben Langmuir<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class="gmail_quote"><div class="im"><br class="">On Feb 5, 2014, at 11:18 AM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:<br class=""><br class="">> I'm not especially fond of treating annot_module_begin and annot_module_include differently. That'll mean we get completely different diagnostics for a '#include' in a bad place depending on whether it's including something in the same top-level module or something in a different top-level module.<br class="">><br class=""><br class=""></div>I approached this from the other side and didn't like that annot_module_include is handled so differently from @import.</blockquote><div class=""><br class=""></div><div class="">I think they're fundamentally different, at least currently:</div><div class=""><br class=""></div><div class="">#include sometimes triggers a submodule build (in the same preprocessor + parser + sema) so must only appear at the top level in such a case. We also want the #include to behave (effectively) the same whether it textually includes a file or imports a module, so that people don't accidentally write code that means different things with compilers that support modules and with compilers that do not (or depending on which module a particular header is part of, or the order in which submodules of a module are built).</div><div class=""><br class=""></div><div class="">Conversely, @import merely makes declaration and macro names visible. It never triggers an in-situ submodule build (sometimes a different module will be built in a separate thread and context, but that's not a problem). It can't (reliably) be used to import a submodule of the same module. So, there's no *technical* reason not to allow @import anywhere, as far as I can tell. That said, some of these properties are probably bugs in @import, and maybe it should act more like #include.</div></div></div></div></div></blockquote><div><br class=""></div><div>Sounds like you know much more about this than I do :) </div><div><br class=""></div><div>When you say “sometimes a different module will be build in a separate thread and context” does that include building a submodule of the current module, or can that never happen?’</div><div><br class=""></div><div>I agree that there is no technical reason @import can’t live anywhere, and as you say I would like to constrain it to be more like #include in this respect.</div><div><br class=""></div><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class="gmail_quote"><div class="im">> I'm also not sure that the diagnostic change here is an improvement. Previously:<br class="">><br class="">> #include "not_module.h"<br class="">> #include "module.h"<br class="">><br class="">> ... where not_module.h contains:<br class="">><br class="">> class X {<br class="">>   // ...<br class="">> // whoops, forgot the '};'<br class="">><br class="">> would give a "missing '}'" diagnostic, pointing at the '{' that is left un-closed. It now gives a mysterious 'must be at the top level' diagnostic, not pointing at the '}' any more, followed by more errors (because 'module.h' didn't get imported and because the code after the #include is still within the class). The error here was almost certainly that a '}' was missing, so this seems like a regression.<br class=""><br class=""></div>Ick, I’ll take a look at this case.<br class=""><div class="im"><br class="">><br class="">> In what cases does this change allow us to recover from errors better?<br class=""><br class=""><br class=""></div>Whenever an implicit import is not at top level, we currently give errors like ‘expected expression’, or ‘expected }’, pointing at the location on #include/#import, and give no hint as to how a preprocessor directive (#include) could be the source of the error.</blockquote><div class=""><br class=""></div><div class="">We can, and almost certainly should, customize the ExpectAndConsume diagnostic for the case where the current token is one of the annot_module_* tokens. I think that's probably the best way to attack this issue.</div></div></div></div></div></blockquote><div><br></div><div>I’ll look into this.</div><br><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class="gmail_quote">To make matters worse, once you break out of whatever parsing context you were in due to the module_include, any following code is likely to become errors.<br class=""><br class="">int foo() {<br class="">  int x = 5;<br class="">  #import “Bar.h” // expected }<br class="">  if (x == 6) {// expected identifier or (<br class="">    ++x; // expected identifier or (<br class="">  }<br class="">  return 1; // expected identifier of (<br class="">} // extraneous closing brace</blockquote><div class=""><br class=""></div><div class="">Do you think this is actually a likely error case? I find it implausible that someone would deliberately include a modular header into the middle of some scope. I think it's vastly more likely that they missed a close brace before the include.</div></div></div></div></div></blockquote><div><br class=""></div><div>This was prompted by code like the following being spotted "in the wild" (where the actual header is in a system module):</div><div><br class=""></div><div>@implementation SomeClass</div><div>#import <system/header.h></div><div>// … more stuff here</div><div>@end</div><div><br class=""></div><div>I have no data to support it being a common case, but I’d like to improve the error if possible.</div><div><br class=""></div><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">If this really is a likely scenario, then I think we should make the diagnostic for an unexpected annot_module_* a FatalError, because there's simply no way we can reasonably recover (we have two recovery options, and either of them is disastrous if we're in the other situation).</div></div></div></div></div></blockquote></div><br class=""><div class="">Wouldn’t this make your example even worse? Instead of getting a bogus error (an #import not being at top level) followed by the actual error (missing }) you would only see the bogus one?</div><div class=""><br></div><div class="">Ben</div></body></html>