[includes] Reduce IWYU exports from SkTypes.h

SkTypes.h was found exporting <stddef.h> and <stdint.h>.
Thus if a Skia file includes SkTypes.h, it did not need
to include either of those files to use things like
size_t or uint8_t respectively. [1]

This also resulted in strange IWYU warnings like:
warning: size_t is defined in "include/core/SkTypes.h", which isn't directly #included.

Thus, this CL removes those additional exports, and as a result,
adds many more includes of <cstddef> and <cstdint>.

The second change this CL is to not use the default IWYU
mappings which are hard-coded into IWYU [2]. These defaults
are valid, but make suggestions for the C version of
headers and not the C++ ones (i.e. <stddef.h> over <cstddef>).

To make these recommendations align better with our preferred
style (the C++ ones), we use IWYU with --no_default_mappings
and then have to expand our existing mappings to better deal
with how IWYU would resolve some of these headers.

[1] https://codereview.chromium.org/1207893002/#msg49
[2] 4c0f396159/iwyu_include_picker.cc (L1221-L1234)

Change-Id: Iafebe190f8f3e86f252147b9f538c182bcc34af4
Bug: skia:13052
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/555516
Auto-Submit: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Kevin Lubick 2022-07-01 15:07:54 -04:00 committed by SkCQ
parent 48b27317b4
commit 68d6ff9222
66 changed files with 193 additions and 35 deletions

View File

@ -193,9 +193,9 @@
#else
#include "include/config/SkUserConfig.h"
#endif
// IWYU pragma: end_exports
#include <stddef.h>
#include <stdint.h>
// IWYU pragma: end_exports
// Post SkUserConfig.h checks and such.
#if !defined(SK_DEBUG) && !defined(SK_RELEASE)

View File

@ -14,6 +14,7 @@
#include "include/sksl/DSLModifiers.h"
#include "include/sksl/SkSLPosition.h"
#include <cstdint>
#include <string_view>
#include <utility>

View File

@ -14,7 +14,7 @@
#include "include/sksl/DSLType.h"
#include "include/sksl/SkSLPosition.h"
#include <stdint.h>
#include <cstdint>
#include <memory>
#include <string_view>
#include <utility>

View File

@ -9,6 +9,8 @@
#define SKSL_POSITION
#include "include/core/SkTypes.h"
#include <cstdint>
#include <string_view>
namespace SkSL {

View File

@ -13,7 +13,7 @@
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include <stdint.h>
#include <cstdint>
#include <memory>
#include <vector>

View File

@ -10,6 +10,8 @@
#include "include/core/SkTypes.h"
#include <cstddef>
struct SkBase64 {
public:
enum Error {

View File

@ -18,6 +18,8 @@
#include "include/core/SkTypes.h"
#include <cstdint>
class SK_API SkEventTracer {
public:

View File

@ -22,6 +22,8 @@
#include "include/private/SkTDArray.h"
#include "include/utils/SkNoDrawCanvas.h"
#include <cstddef>
namespace sktext {
class GlyphRunList;
}

View File

@ -21,6 +21,8 @@
#include "include/private/SkTDArray.h"
#include "include/utils/SkNWayCanvas.h"
#include <cstddef>
namespace sktext {
class GlyphRunList;
}

View File

@ -14,6 +14,9 @@
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include <cstddef>
#include <cstdint>
class SK_API SkParse {
public:
static int Count(const char str[]); // number of scalars or int values

View File

@ -13,6 +13,8 @@
#include "include/core/SkTypes.h"
#include "include/private/SkShadowFlags.h"
#include <cstdint>
class SkCanvas;
class SkMatrix;
class SkPath;

View File

@ -12,7 +12,8 @@
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include <string.h>
#include <cstddef>
#include <string>
class SkCanvas;
class SkFont;

View File

@ -11,7 +11,7 @@
#include "include/private/SkSLSampleUsage.h"
#include "include/private/SkTArray.h"
#include <stdint.h>
#include <cstdint>
#include <memory>
#include <set>

View File

@ -22,6 +22,8 @@
#include "src/sksl/ir/SkSLProgram.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>

View File

@ -24,6 +24,7 @@
#include "src/sksl/ir/SkSLVariableReference.h"
#include <cmath>
#include <cstdint>
#include <limits>
#include <optional>
#include <string>

View File

@ -30,6 +30,7 @@
#include "src/sksl/ir/SkSLProgram.h"
#include <algorithm>
#include <climits>
#include <initializer_list>
#include <memory>
#include <type_traits>

View File

@ -25,6 +25,7 @@
#include "src/sksl/SkSLLexer.h"
#include "src/sksl/SkSLProgramSettings.h"
#include <cstddef>
#include <memory>
#include <optional>
#include <string>

View File

@ -59,6 +59,7 @@
#include <algorithm>
#include <climits>
#include <cstddef>
#include <memory>
#include <string>
#include <string_view>

View File

@ -10,7 +10,9 @@
#include "include/core/SkTypes.h"
#include <stdarg.h>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <string>
namespace SkSL {

View File

@ -10,7 +10,7 @@
#include "src/sksl/SkSLMemoryPool.h"
#include <stddef.h>
#include <cstddef>
#include <memory>
namespace SkSL {

View File

@ -15,6 +15,8 @@
#include "src/sksl/SkSLContext.h"
#include "src/sksl/ir/SkSLSymbolTable.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string_view>
#include <string>

View File

@ -7,13 +7,13 @@
#include "include/private/SkSLString.h"
#include <cerrno>
#include <cmath>
#include <errno.h>
#include <cstdio>
#include <cstdlib>
#include <locale>
#include <memory>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
std::string skstd::to_string(float value) {

View File

@ -30,6 +30,7 @@
#include "src/sksl/ir/SkSLVarDeclarations.h"
#include "src/sksl/ir/SkSLVariable.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>

View File

@ -21,6 +21,7 @@
#include "src/sksl/ir/SkSLType.h"
#include "src/sksl/ir/SkSLVariableReference.h"
#include <cstddef>
#include <memory>
namespace SkSL {

View File

@ -63,6 +63,7 @@
#include "src/sksl/spirv.h"
#include <algorithm>
#include <cstddef>
#include <functional>
#include <limits>
#include <memory>

View File

@ -16,7 +16,7 @@
#include "src/sksl/codegen/SkSLCodeGenerator.h"
#include "src/sksl/ir/SkSLType.h"
#include <stdint.h>
#include <cstdint>
#include <initializer_list>
#include <set>
#include <string>

View File

@ -68,6 +68,7 @@
#include <cmath>
#include <set>
#include <string>
#include <type_traits>
#include <utility>

View File

@ -25,10 +25,10 @@
#include "src/sksl/ir/SkSLVariable.h"
#include "src/sksl/spirv.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <stack>
#include <string>
#include <string_view>
#include <vector>

View File

@ -62,7 +62,7 @@
#include "src/sksl/tracing/SkVMDebugTrace.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iterator>
#include <string_view>

View File

@ -11,6 +11,7 @@
#include "src/core/SkVM.h"
#include "src/sksl/ir/SkSLType.h"
#include <cstddef>
#include <memory>
#include <string>
#include <vector>

View File

@ -8,16 +8,16 @@
#ifndef SKSL_WGSLCODEGENERATOR
#define SKSL_WGSLCODEGENERATOR
#include <stdint.h>
#include <string_view>
#include <type_traits>
#include <utility>
#include "include/private/SkSLDefines.h"
#include "include/private/SkTHash.h"
#include "include/sksl/SkSLOperator.h"
#include "src/sksl/codegen/SkSLCodeGenerator.h"
#include <cstdint>
#include <string_view>
#include <type_traits>
#include <utility>
namespace sknonstd {
template <typename T> struct is_bitmask_enum;
} // namespace sknonstd

View File

@ -49,6 +49,7 @@
#include "src/sksl/ir/SkSLVariable.h"
#include "src/sksl/transform/SkSLTransform.h"
#include <cstddef>
#include <type_traits>
#include <vector>

View File

@ -25,6 +25,7 @@
#include "src/sksl/ir/SkSLFunctionPrototype.h"
#include "src/sksl/ir/SkSLVariable.h"
#include <cstddef>
#include <memory>
#include <string>
#include <vector>

View File

@ -14,6 +14,8 @@
#include "src/sksl/ir/SkSLType.h"
#include "src/sksl/ir/SkSLVariable.h"
#include <cstddef>
namespace SkSL {
bool ChildCall::hasProperty(Property property) const {

View File

@ -17,6 +17,7 @@
#include "src/sksl/ir/SkSLLiteral.h"
#include "src/sksl/ir/SkSLType.h"
#include <cstddef>
#include <optional>
namespace SkSL {

View File

@ -22,6 +22,8 @@
#include "src/sksl/ir/SkSLSymbolTable.h"
#include "src/sksl/ir/SkSLUnresolvedFunction.h"
#include <cstddef>
namespace SkSL {
std::unique_ptr<Expression> FieldAccess::Convert(const Context& context,

View File

@ -38,6 +38,8 @@
#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string_view>

View File

@ -28,6 +28,7 @@
#include "src/sksl/ir/SkSLUnresolvedFunction.h"
#include "src/sksl/ir/SkSLVariable.h"
#include <cstddef>
#include <initializer_list>
#include <utility>

View File

@ -35,6 +35,7 @@
#include "src/sksl/transform/SkSLProgramWriter.h"
#include <algorithm>
#include <cstddef>
#include <forward_list>
#include <string_view>
#include <unordered_map>

View File

@ -22,6 +22,7 @@
#include "src/sksl/ir/SkSLType.h"
#include "src/sksl/ir/SkSLTypeReference.h"
#include <cstdint>
#include <optional>
namespace SkSL {

View File

@ -20,6 +20,8 @@
#include "src/sksl/ir/SkSLLiteral.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <optional>
namespace SkSL {

View File

@ -13,6 +13,8 @@
#include "include/private/SkSLSymbol.h"
#include "include/private/SkTHash.h"
#include <cstddef>
#include <cstdint>
#include <forward_list>
#include <memory>
#include <string>

View File

@ -15,6 +15,8 @@
#include "include/sksl/SkSLPosition.h"
#include "src/sksl/spirv.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>

View File

@ -15,6 +15,7 @@
#include "include/sksl/SkSLPosition.h"
#include "src/sksl/ir/SkSLType.h"
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>

View File

@ -12,6 +12,7 @@
#include "include/sksl/SkSLPosition.h"
#include "src/sksl/ir/SkSLExpression.h"
#include <cstdint>
#include <memory>
#include <string>

View File

@ -14,8 +14,8 @@
#include "src/core/SkVM.h"
#include "src/sksl/ir/SkSLType.h"
#include <cstdint>
#include <memory>
#include <stdint.h>
#include <string>
#include <vector>

View File

@ -24,6 +24,7 @@
#include "src/codec/SkCodecImageGenerator.h"
#include <algorithm>
#include <cstddef>
#include <memory>
#include <utility>
#include <vector>

View File

@ -8,6 +8,8 @@
#include "include/utils/SkBase64.h"
#include <cstdint>
#define DecodePad -2
#define EncodePad 64

View File

@ -22,6 +22,8 @@
#include "src/core/SkWriter32.h"
#include "src/utils/SkCanvasStack.h"
#include <cstddef>
#include <cstdint>
#include <utility>
/*

View File

@ -12,6 +12,8 @@
#include "include/private/SkTDArray.h"
#include "include/private/SkTo.h"
#include <cstdint>
class SkCharToGlyphCache {
public:
SkCharToGlyphCache();

View File

@ -33,8 +33,10 @@
#include "src/core/SkPathPriv.h"
#include "src/core/SkScalerContext.h"
#include <string.h>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>

View File

@ -22,6 +22,7 @@
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iterator>
#include <utility>

View File

@ -21,10 +21,12 @@
#include "include/utils/SkNWayCanvas.h"
#include "src/utils/SkMultiPictureDocumentPriv.h"
#include <limits.h>
#include <string.h>
#include <algorithm>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <string>
/*
File format:

View File

@ -7,9 +7,8 @@
#include "include/utils/SkParse.h"
#include <iterator> // for std::size
#include <stdlib.h>
#include <string.h>
#include <cstdlib>
#include <string>
static inline bool is_between(int c, int min, int max)
{

View File

@ -4,15 +4,16 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/utils/SkParse.h"
#include "include/core/SkColor.h"
#include "include/core/SkTypes.h"
#include <string.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <string>
static constexpr const char* gColorNames[] = {
"aliceblue",

View File

@ -16,7 +16,7 @@
#include "include/utils/SkParsePath.h"
#include "src/core/SkGeometry.h"
#include <stdio.h>
#include <cstdio>
static inline bool is_between(int c, int min, int max) {
return (unsigned)(c - min) <= (unsigned)(max - min);

View File

@ -27,8 +27,9 @@
#include "src/core/SkConvertPixels.h"
#include "src/core/SkGeometry.h"
#include <string.h>
#include <algorithm>
#include <cstdint>
#include <string>
namespace {
enum CubicCtrlPts {

View File

@ -11,7 +11,7 @@
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include <stdint.h>
#include <cstdint>
struct SkRect;
template <typename T> class SkTDArray;

View File

@ -12,6 +12,8 @@
#include "include/private/SkTArray.h"
#include "src/sksl/SkSLProgramSettings.h"
#include <cstddef>
namespace SkShaderUtils {
class GLSLPrettyPrint {

View File

@ -27,6 +27,8 @@
#include "src/utils/SkPolyUtils.h"
#include <algorithm>
#include <cstdint>
#if SK_SUPPORT_GPU
#include "src/gpu/ganesh/geometry/GrPathUtils.h"

View File

@ -51,12 +51,12 @@ class GrColorInfo;
class GrRecordingContext;
#endif
#include <string.h>
#include <algorithm>
#include <cstdint>
#include <cstddef>
#include <functional>
#include <memory>
#include <new>
#include <string>
#include <utility>
class SkArenaAlloc;

View File

@ -5,6 +5,9 @@
#include "include/core/SkTypes.h"
#include <cstddef>
#include <cstdint>
typedef int32_t SkUnichar;
namespace SkUTF {

View File

@ -15,8 +15,8 @@
#endif
#include <algorithm>
#include <cstdarg>
#include <sstream>
#include <stdarg.h>
#include <string>
#include <utility>

View File

@ -14,6 +14,7 @@
#include "src/core/SkVM.h"
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <vector>

View File

@ -12,16 +12,34 @@
{ include: ["<__algorithm/stable_sort.h>", "private", "<algorithm>", "public"] },
{ include: ["<__algorithm/upper_bound.h>", "private", "<algorithm>", "public"] },
{ symbol: ["INT32_MAX", "public", "<climits>", "public"]},
{ symbol: ["abs", "public", "<cmath>", "public"]},
{ symbol: ["uint8_t", "public", "<cstdint>", "public"]},
# The first of these is the preferred include, but the others are acceptable.
{ symbol: ["size_t", "public", "<cstddef>", "public"]},
{ symbol: ["size_t", "public", "<cstdio>", "public"]},
{ symbol: ["size_t", "public", "<cstdlib>", "public"]},
{ symbol: ["size_t", "public", "<cstring>", "public"]},
{ symbol: ["size_t", "public", "<ctime>", "public"]},
{ symbol: ["size_t", "public", "<cuchar>", "public"]},
{ symbol: ["size_t", "public", "<cwchar>", "public"]},
{ symbol: ["int8_t", "public", "<cstdint>", "public"]},
{ symbol: ["int16_t", "public", "<cstdint>", "public"]},
{ symbol: ["int32_t", "public", "<cstdint>", "public"]},
{ symbol: ["int64_t", "public", "<cstdint>", "public"]},
{ symbol: ["uint8_t", "public", "<cstdint>", "public"]},
{ symbol: ["uint16_t", "public", "<cstdint>", "public"]},
{ symbol: ["uint32_t", "public", "<cstdint>", "public"]},
{ symbol: ["uint64_t", "public", "<cstdint>", "public"]},
{ include: ["<__functional/function.h>", "private", "<functional>", "public"] },
{ include: ["<__iterator/access.h>", "private", "<iterator>", "public"] },
{ include: ["<__iterator/distance.h>", "private", "<iterator>", "public"] },
# The first of these is the preferred include, but the others are acceptable.
{ include: ["<__iterator/size.h>", "private", "<array>", "public"] },
{ include: ["<__iterator/size.h>", "private", "<deque>", "public"] },
{ include: ["<__iterator/size.h>", "private", "<forward_list>", "public"] },
@ -43,9 +61,17 @@
{ include: ["<__tree>", "private", "<set>", "public"] },
{ symbol: ["std::istringstream", "public", "<sstream>", "public"] },
{ symbol: ["std::ostringstream", "public", "<sstream>", "public"] },
{ symbol: ["std::stringstream", "public", "<sstream>", "public"] },
{ symbol: ["std::stringbuf", "public", "<sstream>", "public"] },
{ symbol: ["std::basic_istringstream", "public", "<sstream>", "public"] },
{ symbol: ["std::basic_ostringstream", "public", "<sstream>", "public"] },
{ symbol: ["std::basic_stringstream", "public", "<sstream>", "public"] },
{ symbol: ["std::basic_stringbuf", "public", "<sstream>", "public"] },
{ symbol: ["va_list", "public", "<stdarg.h>", "public"] },
{ include: ["<string.h>", "public", "<string>", "public"] },
{ symbol: ["std::string", "public", "<string>", "public"] },
{ include: ["<__hash_table>", "private", "<unordered_map>", "public"] },
@ -56,4 +82,61 @@
{ include: ["<__utility/pair.h>", "private", "<utility>", "public"] },
{ symbol: ["std::__bit_reference", "public", "<vector>", "public"] },
# Without these, IWYU won't accept the C++ wrappers and throws
# a mysterious "cyclical import" error.
# https://github.com/include-what-you-use/include-what-you-use/blob/4c0f39615982c57a9cb313c971c6f45fca1cc1fe/iwyu_include_picker.cc#L573
{ include: ["<assert.h>", "public", "<cassert>", "public"] },
{ include: ["<complex.h>", "public", "<ccomplex>", "public"] },
{ include: ["<ctype.h>", "public", "<cctype>", "public"] },
{ include: ["<errno.h>", "public", "<cerrno>", "public"] },
{ include: ["<fenv.h>", "public", "<cfenv>", "public"] },
{ include: ["<float.h>", "public", "<cfloat>", "public"] },
{ include: ["<inttypes.h>", "public", "<cinttypes>", "public"] },
{ include: ["<iso646.h>", "public", "<ciso646>", "public"] },
{ include: ["<limits.h>", "public", "<climits>", "public"] },
{ include: ["<locale.h>", "public", "<clocale>", "public"] },
{ include: ["<math.h>", "public", "<cmath>", "public"] },
{ include: ["<setjmp.h>", "public", "<csetjmp>", "public"] },
{ include: ["<signal.h>", "public", "<csignal>", "public"] },
{ include: ["<stdalign.h>", "public", "<cstdalign>", "public"] },
{ include: ["<stdarg.h>", "public", "<cstdarg>", "public"] },
{ include: ["<stdbool.h>", "public", "<cstdbool>", "public"] },
{ include: ["<stddef.h>", "public", "<cstddef>", "public"] },
{ include: ["<stdint.h>", "public", "<cstdint>", "public"] },
{ include: ["<stdio.h>", "public", "<cstdio>", "public"] },
{ include: ["<stdlib.h>", "public", "<cstdlib>", "public"] },
{ include: ["<string.h>", "public", "<string>", "public"] },
{ include: ["<string.h>", "public", "<cstring>", "public"] },
{ include: ["<tgmath.h>", "public", "<ctgmath>", "public"] },
{ include: ["<time.h>", "public", "<ctime>", "public"] },
{ include: ["<uchar.h>", "public", "<cuchar>", "public"] },
{ include: ["<wchar.h>", "public", "<cwchar>", "public"] },
{ include: ["<wctype.h>", "public", "<cwctype>", "public"] },
# From https://github.com/include-what-you-use/include-what-you-use/blob/4c0f39615982c57a9cb313c971c6f45fca1cc1fe/iwyu_include_picker.cc#L327
{ symbol: ["std::allocator", "private", "<memory>", "public"] },
{ symbol: ["std::allocator", "private", "<string>", "public"] },
{ symbol: ["std::allocator", "private", "<vector>", "public"] },
{ symbol: ["std::allocator", "private", "<map>", "public"] },
{ symbol: ["std::allocator", "private", "<set>", "public"] },
{ symbol: ["std::char_traits", "private", "<string>", "public"] },
{ symbol: ["std::char_traits", "private", "<ostream>", "public"] },
{ symbol: ["std::char_traits", "private", "<istream>", "public"] },
# We are pretty forgiving with iostream headers. If we specify
# any of them, that is generally sufficient.
# https://github.com/include-what-you-use/include-what-you-use/blob/4c0f39615982c57a9cb313c971c6f45fca1cc1fe/iwyu_include_picker.cc#L995
{include: ["<ios>", "public", "<istream>", "public"] },
{include: ["<ios>", "public", "<ostream>", "public"] },
{include: ["<iosfwd>", "public", "<ios>", "public"] },
{include: ["<iosfwd>", "public", "<streambuf>", "public"] },
{include: ["<istream>", "public", "<fstream>", "public"] },
{include: ["<istream>", "public", "<iostream>", "public"] },
{include: ["<istream>", "public", "<sstream>", "public"] },
{include: ["<ostream>", "public", "<fstream>", "public"] },
{include: ["<ostream>", "public", "<iostream>", "public"] },
{include: ["<ostream>", "public", "<istream>", "public"] },
{include: ["<ostream>", "public", "<sstream>", "public"] },
{include: ["<streambuf>", "public", "<ios>", "public"] },
]

View File

@ -60,6 +60,7 @@ else
# not consistent with detecting that.
external/clang_linux_amd64/usr/bin/include-what-you-use \
-Xiwyu --keep="include/core/SkTypes.h" \
-Xiwyu --no_default_mappings \
-Xiwyu --mapping_file=$MAPPING_FILE $@ 2>/dev/null
# IWYU returns 2 if everything looks good. It returns some other non-zero exit code otherwise.
if [ $? -eq 2 ]; then
@ -70,6 +71,7 @@ else
# analysis. If we aren't sure why IWYU wants to include something, try changing verbose to 3.
external/clang_linux_amd64/usr/bin/include-what-you-use \
-Xiwyu --keep="include/core/SkTypes.h" \
-Xiwyu --no_default_mappings \
-Xiwyu --mapping_file=$MAPPING_FILE -Xiwyu --no_comments \
-Xiwyu --quoted_includes_first -Xiwyu --verbose=3 $@
exit 1 # fail the build