[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 19:37:10 PST 2024


owenca wrote:

> However, for clangd users, a crucial difference between `guessLanguage()` vs. other code in libFormat that uses `UnwrappedLineParser`, is that `guessLanguage()` gets called as soon as a file is opened in the editor, while the other code is only called if the user explicitly tries to format the file.
> 
> For the files affected by this OOM (single-file libraries like [miniaudio](https://github.com/mackron/miniaudio/blob/master/miniaudio.h), [mathlink](https://github.com/clangd/clangd/issues/1384), [minilzo](http://www.oberhumer.com/opensource/lzo/#minilzo), [blis](https://github.com/llvm/llvm-project/issues/60151), where the large number of configuration-related preprocessor branches and the large number of lines in the file conspire to make the combined length of all permutations intractable to work with), the number of users who merely **use** these libraries (and so may open them in the editor to look at the header, but will not try to format it) far exceeds the number of users who actually **develop** these libraries (who would edit and format the header). Thus, by avoiding the problem in `guessLanguage()`, we would resolve the issue for >99% of clangd users that run into it, which would be a significant improvement.

If we add a `bool GuessObjC` parameter to `guessLanguage()`, would that solve the problem?

https://github.com/llvm/llvm-project/pull/78925


More information about the cfe-commits mailing list