mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 15:00:13 +01:00
Fundamentally, this uses forward declarations of Clang types to reduce the overall compile time cost of Clang headers across the codebase. Tracing and profiling showed ~2s of every check TU's ~8-12s compile time going just to parsing Clang frontend and AST headers pulled in via a few sem_ir and check headers that only use the Clang types by pointer or reference: - sem_ir/cpp_file.h (reached via sem_ir/file.h by ~150 TUs) included clang/Frontend/CompilerInstance.h, clang/CodeGen/ModuleBuilder.h, clang/AST/Mangle.h, and llvm/IR/Module.h. CppFile's accessors move out of line to a new cpp_file.cpp and the header now forward-declares the Clang types. - check/cpp/context.h (reached via check/context.h by ~100 TUs) included clang/Frontend/FrontendAction.h and clang/Parse/Parser.h, pulling in clang's Sema.h and ASTUnit.h. - sem_ir/clang_decl.h included clang/AST/Decl.h; the three small functions that need complete Clang types move out of line. - sem_ir/cpp_overload_set.h included clang/Sema/Overload.h solely for the three-field OverloadCandidateSet::OperatorRewriteInfo, which is now mirrored as CppOverloadSet::OperatorRewriteInfo, and clang/AST/Decl.h solely for a pointer. - sem_ir/name_scope.h's clang/AST/DeclBase.h include was vestigial. TUs (and more narrowly included headers) that genuinely use the Clang definitions now include the Clang headers directly. Representative compile times (fastbuild, aarch64), combined with the preceding instantiation-cost changes, relative to trunk: - check/eval.cpp: 11.85s -> 6.94s (-41%) - check/handle_operator.cpp: 7.71s -> 3.30s (-57%) - language_server.cpp: 6.68s -> 3.16s (-53%) - lower/handle.cpp: 6.75s -> 3.66s (-46%) - sem_ir/file.cpp: 8.60s -> 6.11s (-29%) - driver.cpp: 6.68s -> 4.78s (-28%) Measured full-rebuild impact (316 first-party TUs, fastbuild): -689.5s CPU, -29.9% relative to trunk. Assisted-by: Claude
169 lines
6.7 KiB
YAML
169 lines
6.7 KiB
YAML
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
---
|
|
# Get colors when outputting through `bazel build --config=clang-tidy`.
|
|
UseColor: true
|
|
# This is necessary for `--config=clang-tidy` to catch errors.
|
|
WarningsAsErrors: '*'
|
|
|
|
Checks:
|
|
# We turn on all of a few categories by default.
|
|
- '-*'
|
|
- 'bugprone-*'
|
|
- 'google-*'
|
|
- 'misc-*'
|
|
- 'modernize-*'
|
|
- 'performance-*'
|
|
- 'readability-*'
|
|
|
|
# Disabled due to the implied style choices.
|
|
- '-misc-const-correctness'
|
|
- '-misc-include-cleaner'
|
|
- '-misc-use-anonymous-namespace'
|
|
- '-modernize-deprecated-headers'
|
|
- '-modernize-return-braced-init-list'
|
|
- '-modernize-use-default-member-init'
|
|
- '-modernize-use-integer-sign-comparison'
|
|
- '-modernize-use-emplace'
|
|
- '-readability-avoid-nested-conditional-operator'
|
|
- '-readability-convert-member-functions-to-static'
|
|
- '-readability-else-after-return'
|
|
- '-readability-identifier-length'
|
|
- '-readability-implicit-bool-conversion'
|
|
- '-readability-make-member-function-const'
|
|
- '-readability-math-missing-parentheses'
|
|
- '-readability-static-definition-in-anonymous-namespace'
|
|
- '-readability-trailing-comma'
|
|
- '-readability-use-anyofallof'
|
|
|
|
# Warns when we have multiple empty cases in switches, which we do for comment
|
|
# reasons.
|
|
- '-bugprone-branch-clone'
|
|
# Frequently warns on multiple parameters of the same type.
|
|
- '-bugprone-easily-swappable-parameters'
|
|
# Finds issues like out-of-memory in main(). We don't use exceptions, so it's
|
|
# unlikely to find real issues.
|
|
- '-bugprone-exception-escape'
|
|
# Doesn't respect `[[clang::enum_extensibility(open)]]`.
|
|
- '-bugprone-invalid-enum-default-initialization'
|
|
# Has false positives in places such as using an argument to declare a name,
|
|
# which cannot have parentheses. For our limited use of macros, this is a
|
|
# common conflict.
|
|
- '-bugprone-macro-parentheses'
|
|
# Conflicts with integer type C++ style.
|
|
- '-bugprone-narrowing-conversions'
|
|
# Complains about reasonable code like `1 << 20` and would push us away from
|
|
# our integer type C++ style rules.
|
|
- '-bugprone-signed-bitwise'
|
|
# Has false positives for `enum_base.h`. Clang's built-in switch warnings
|
|
# cover most of our risk of bugs here.
|
|
- '-bugprone-switch-missing-default-case'
|
|
# In clang-tidy 16, has false positives on code like:
|
|
# while (auto name_ref = insts().Get(inst_id).TryAs<SemIR::NameRef>()) {
|
|
# inst_id = name_ref->value_id;
|
|
# ^ unchecked access to optional value
|
|
# }
|
|
- '-bugprone-unchecked-optional-access'
|
|
# Overlaps with `readability-function-size`.
|
|
- '-google-readability-function-size'
|
|
# Suggests usernames on TODOs, which we don't want.
|
|
- '-google-readability-todo'
|
|
# Extremely slow. TODO: Re-enable once
|
|
# https://github.com/llvm/llvm-project/issues/128797 is fixed.
|
|
- '-misc-confusable-identifiers'
|
|
# Overlaps with `-Wno-missing-prototypes`.
|
|
- '-misc-use-internal-linkage'
|
|
# Suggests `std::array`, which we could migrate to, but conflicts with the
|
|
# status quo.
|
|
- '-modernize-avoid-c-arrays'
|
|
# Warns on creation of SemIR typed insts, for which we do not currently want
|
|
# to use designated initialization.
|
|
- '-modernize-use-designated-initializers'
|
|
# Only fixes const methods, not non-const, which yields distracting results on
|
|
# accessors.
|
|
- '-modernize-use-nodiscard'
|
|
# We aren't using the ranges library due to performance concerns.
|
|
- '-modernize-use-ranges'
|
|
# Low value compared to the engineering cost.
|
|
- '-performance-enum-size'
|
|
# Duplicates `modernize-pass-by-value`.
|
|
- '-performance-unnecessary-value-param'
|
|
# Warns on enums which use the `LastValue = Value` pattern if all the other
|
|
# discriminants aren't given an explicit value.
|
|
- '-readability-enum-initial-value'
|
|
# Warns too frequently.
|
|
- '-readability-function-cognitive-complexity'
|
|
# Warns in reasonably documented situations.
|
|
- '-readability-magic-numbers'
|
|
# Warns on `= {}` which is also used to indicate which fields do not need to
|
|
# be explicitly initialized in aggregate initialization.
|
|
- '-readability-redundant-member-init'
|
|
# Broken, wants to remove parens from `*(p + 1)` and `("Foo" + s).str()`.
|
|
# TODO: Re-enable once https://github.com/llvm/llvm-project/issues/192435 and
|
|
# related bugs are fixed.
|
|
- '-readability-redundant-parentheses'
|
|
# Warns when callers use similar names as different parameters.
|
|
- '-readability-suspicious-call-argument'
|
|
|
|
CheckOptions:
|
|
# Don't warn on structs; done by ignoring when there are only public members.
|
|
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
|
|
value: true
|
|
|
|
# CamelCase names.
|
|
- key: readability-identifier-naming.ClassCase
|
|
value: CamelCase
|
|
- key: readability-identifier-naming.ClassConstantCase
|
|
value: CamelCase
|
|
- key: readability-identifier-naming.ConstexprVariableCase
|
|
value: CamelCase
|
|
- key: readability-identifier-naming.NamespaceCase
|
|
value: CamelCase
|
|
# Headers re-open LLVM and Clang namespaces to forward-declare their types,
|
|
# which is much cheaper to compile than including their headers.
|
|
- key: readability-identifier-naming.NamespaceIgnoredRegexp
|
|
value: '^(clang|llvm)$'
|
|
- key: readability-identifier-naming.StructCase
|
|
value: CamelCase
|
|
- key: readability-identifier-naming.TemplateParameterCase
|
|
value: CamelCase
|
|
- key: readability-identifier-naming.TypeAliasCase
|
|
value: CamelCase
|
|
- key: readability-identifier-naming.TypedefCase
|
|
value: CamelCase
|
|
- key: readability-identifier-naming.UnionCase
|
|
value: CamelCase
|
|
|
|
# lower_case names.
|
|
- key: readability-identifier-naming.ClassMemberCase
|
|
value: lower_case
|
|
- key: readability-identifier-naming.ParameterCase
|
|
value: lower_case
|
|
- key: readability-identifier-naming.VariableCase
|
|
value: lower_case
|
|
|
|
# TODO: This is for explorer's use of LLVM casting support, so we should be
|
|
# able to remove it once explorer is deleted.
|
|
- key: readability-identifier-naming.MethodIgnoredRegexp
|
|
value: '^classof$'
|
|
|
|
# This erroneously fires in C++20 mode with LLVM 16 clang-tidy, due to:
|
|
# https://github.com/llvm/llvm-project/issues/46097
|
|
- key: readability-identifier-naming.TemplateParameterIgnoredRegexp
|
|
value: '^expr-type$'
|
|
|
|
# Don't require writing a return type on lambdas.
|
|
- key: modernize-use-trailing-return-type.TransformLambdas
|
|
value: none
|
|
|
|
# Use lines rather than statements to measure function size, because
|
|
# for readability purposes we care about the code as written, before
|
|
# preprocessing.
|
|
- key: readability-function-size.StatementThreshold
|
|
value: none
|
|
- key: readability-function-size.LineThreshold
|
|
# Chose 800 to match the default for StatementThreshold.
|
|
value: 800
|