[clangd] Compute scopes eagerly in IncludeFixer
authorIlya Biryukov <ibiryukov@google.com>
Tue, 6 Aug 2019 11:37:50 +0000 (11:37 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Tue, 6 Aug 2019 11:37:50 +0000 (11:37 +0000)
commit56bdb0c5082547229ff668405bde2ef5254ee817
tree5a8e82a0e567d29a9d45a8288be0f045b917b36f
parent2836cf0b72aa84e67998e0db7105e783f3a111dc
[clangd] Compute scopes eagerly in IncludeFixer

Summary:
Computing lazily leads to crashes. In particular, computing scopes may
produce diagnostics (from inside template instantiations) and we
currently do it when processing another diagnostic, which leads to
crashes.

Moreover, we remember and access 'Scope*' when computing scopes. This
might lead to invalid memory access if the Scope is deleted by the time
we run the delayed computation. We did not actually construct an example
when this happens, though.

From the VCS and review history, it seems the optimization was
introduced in the initial version without a mention of any performance
benchmarks justifying the performance gains. This led me to a
conclusion that the optimization was premature, so removing it to avoid
crashes seems like the right trade-off at that point.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65796

llvm-svn: 368019
clang-tools-extra/clangd/IncludeFixer.cpp
clang-tools-extra/clangd/IncludeFixer.h
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp