diff --git a/.lintrunner.toml b/.lintrunner.toml index 0221924386..04dca4a340 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -196,3 +196,91 @@ command = [ '@{{PATHSFILE}}', ] is_formatter = true + +[[linter]] +code = 'NOSTDINC' +include_patterns = [ + "**/*.c", + "**/*.cpp", + "**/*.h", + "**/*.hpp", +] +exclude_patterns = [ + '**/devtools/**', + '**/test/**', + '**/testing_util/**', + '**/third-party/**', + 'backends/**', + 'devtools/**', + 'examples/**', + 'extension/**', + 'kernels/optimized/**', + 'scripts/**', + 'third-party/**', + 'util/**', +] +command = [ + 'python', + '-m', + 'lintrunner_adapters', + 'run', + 'grep_linter', + '--pattern=([^\\S\r\n]*#include\s*<(deque|exception|forward_list|functional|list|map|multimap|multiset|priority_queue|queue|set|stack|string|unordered_map|unordered_multimap|unordered_multiset|unordered_set|vector)>)', + '--linter-name=NOSTDINC', + '--error-name=Standard C++ container include in core', + """--error-description=\ + Standard library containers should not be included in ExecuTorch core \ + because they may call malloc, which is not allowed in core. \ + """, + '--', + '@{{PATHSFILE}}', +] + +[[linter]] +code = 'NOTORCHINC' +include_patterns = [ + "**/*.c", + "**/*.cpp", + "**/*.h", + "**/*.hpp", +] +exclude_patterns = [ + '**/devtools/**', + '**/fb/**', + '**/test/**', + '**/tests/**', + '**/testing_util/**', + '**/third-party/**', + 'backends/**', + 'codegen/templates/RegisterDispatchKeyCustomOps.cpp', + 'codegen/templates/RegisterSchema.cpp', + 'devtools/**', + 'examples/**', + 'exir/verification/bindings.cpp', + 'extension/**', + 'kernels/optimized/**', + 'runtime/core/exec_aten/**', + 'runtime/executor/tensor_parser_aten.cpp', + 'scripts/**', + 'test/**', + 'third-party/**', + 'util/**', +] +command = [ + 'python', + '-m', + 'lintrunner_adapters', + 'run', + 'grep_linter', + '--pattern=#include\s+[<"](aten/|ATen/|torch/)', + '--linter-name=NOTORCHINC', + '--error-name=ATen or torch include', + """--error-description=\ + PyTorch includes in ExecuTorch core are prohibited to prevent \ + accidentally breaking core's requirements; please make sure this \ + header complies (e.g., no streams/malloc/syscalls) and then include \ + a patch to update this linter.\ + """, + '--', + '@{{PATHSFILE}}', +] diff --git a/extension/llm/custom_ops/op_sdpa.cpp b/extension/llm/custom_ops/op_sdpa.cpp index 8afec156d5..50fa933833 100644 --- a/extension/llm/custom_ops/op_sdpa.cpp +++ b/extension/llm/custom_ops/op_sdpa.cpp @@ -16,7 +16,6 @@ #include #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include #ifdef ET_USE_THREADPOOL diff --git a/extension/llm/runner/image.h b/extension/llm/runner/image.h index d3c4e8d945..67fb893951 100644 --- a/extension/llm/runner/image.h +++ b/extension/llm/runner/image.h @@ -9,9 +9,8 @@ // A simple image struct. #pragma once -#include -// patternlint-disable-next-line executorch-cpp-nostdinc #include +#include #include namespace executorch { diff --git a/extension/llm/runner/multimodal_runner.h b/extension/llm/runner/multimodal_runner.h index 1af9cb6fa2..94539c65cc 100644 --- a/extension/llm/runner/multimodal_runner.h +++ b/extension/llm/runner/multimodal_runner.h @@ -13,13 +13,10 @@ #pragma once #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include #include diff --git a/extension/llm/runner/stats.h b/extension/llm/runner/stats.h index f9462d24cd..79c5781e33 100644 --- a/extension/llm/runner/stats.h +++ b/extension/llm/runner/stats.h @@ -12,7 +12,6 @@ #include #include #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include namespace executorch { diff --git a/extension/llm/runner/text_decoder_runner.h b/extension/llm/runner/text_decoder_runner.h index c6f8a0ca67..ca4d127e51 100644 --- a/extension/llm/runner/text_decoder_runner.h +++ b/extension/llm/runner/text_decoder_runner.h @@ -14,7 +14,6 @@ #include #include #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include namespace executorch { diff --git a/extension/llm/runner/text_prefiller.h b/extension/llm/runner/text_prefiller.h index 9dbaec40e6..2f1d5ae2b7 100644 --- a/extension/llm/runner/text_prefiller.h +++ b/extension/llm/runner/text_prefiller.h @@ -13,7 +13,6 @@ #include #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include namespace executorch { diff --git a/extension/llm/tokenizer/tokenizer.h b/extension/llm/tokenizer/tokenizer.h index 52983d9075..c987857a30 100644 --- a/extension/llm/tokenizer/tokenizer.h +++ b/extension/llm/tokenizer/tokenizer.h @@ -9,9 +9,7 @@ #pragma once #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include -// patternlint-disable-next-line executorch-cpp-nostdinc #include #include diff --git a/extension/parallel/thread_parallel.h b/extension/parallel/thread_parallel.h index bbce211597..8b174075ae 100644 --- a/extension/parallel/thread_parallel.h +++ b/extension/parallel/thread_parallel.h @@ -9,7 +9,6 @@ #pragma once #include -// @nolint PATTERNLINT Ok to use stdlib for this optional library #include namespace executorch { diff --git a/kernels/optimized/vec/vec_base.h b/kernels/optimized/vec/vec_base.h index 4a386f9e8c..5ff4327e6f 100644 --- a/kernels/optimized/vec/vec_base.h +++ b/kernels/optimized/vec/vec_base.h @@ -1,7 +1,5 @@ #pragma once -// @nolint PATTERNLINT is required for std::equal_to, etc. - #include #include #include diff --git a/runtime/core/exec_aten/testing_util/tensor_factory.h b/runtime/core/exec_aten/testing_util/tensor_factory.h index 2ea21e9583..9f8f7e9db7 100644 --- a/runtime/core/exec_aten/testing_util/tensor_factory.h +++ b/runtime/core/exec_aten/testing_util/tensor_factory.h @@ -14,10 +14,8 @@ #ifdef USE_ATEN_LIB #include #else // !USE_ATEN_LIB -#include -// @nolint PATTERNLINT Ok to use stdlib for this test framework #include -// @nolint PATTERNLINT Ok to use stdlib for this test framework +#include #include #endif // !USE_ATEN_LIB