[cfe-dev] [clangd-dev] Delayed typo correction is fragile

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 16 10:29:05 PDT 2019


On Tue, Jul 16, 2019 at 10:18 AM David Blaikie via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> End of the TU sounds too late to me - IR generation is done incrementally
> (at the end of functions, for instance - though I'm not sure that's the
> only point), so leaving typos in until the end of the TU could lead to the
> "IR generation getting weird because of pending typo corrections" issue, no?
>

Well, we currently assert in ~Sema, which is after the end of the TU, so if
we hit today's assert, we've already done incremental codegen without
crashing. Diagnosing at end of TU doesn't make the situation worse. The way
I understand clang's incremental codegen strategy, we generate code after
every top level decl. We sometimes skip incremental codegen if errors have
been reported or if a Decl is invalid. I think it's a bug if an error
hasn't been reported but a delayed typo expr gets sent to codegen, and we
should add asserts to defend against that.


> On Mon, Jul 15, 2019 at 8:19 PM Ilya Biryukov via clangd-dev <
>>>> clangd-dev at lists.llvm.org> wrote:
>>>>
>>>>> We would like to avoid assertion failures for those, which leads me to
>>>>> the following questions:
>>>>> - Is there a way to quickly track down the place that miss the
>>>>> CorrectDelayedTypos* call?
>>>>>
>>>> A common pattern is that an error causes an Expr subtree to be
>>>> discarded, and the code that does so "forgets" to call CorrectDelayedTypos.
>>>> e.g. https://reviews.llvm.org/rL366200
>>>> There's usually a diagnostic emitted before the Expr is discarded, so
>>>> in these cases poking around the diag emit location often sheds light. But
>>>> my fear is there are tens or hundreds of these bugs, and it's hard to
>>>> enumerate them.
>>>>
>>>> At some level, this seems silly - if the Expr doesn't survive, its
>>>> typos don't need to be corrected to protect CodeGen from them. The
>>>> diagnostics are probably important though.
>>>> If we could ensure the diagnostics are emitted as Reid says, and reduce
>>>> the requirement to be that Exprs that survive parsing get typo-corrected,
>>>> then this might be tractable.
>>>>
>>>
Another idea is to weaken the assert to validate that either errors have
been reported, or there are no delayed typos. That would mean it's OK to
forget to diagnose typos if parts of the AST are invalid, since we expect
the user to fix their code and recompile, potentially discovering the typo
on the next compile.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190716/c9e9268d/attachment.html>


More information about the cfe-dev mailing list