From eb6d1cbe4ab12b48e5ce2d8725b84a7b07e3f889 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 12 Nov 2024 11:56:23 -0800 Subject: [PATCH 1/2] [ExecuTorch] Remove PATTERNLINT suppressions Pull Request resolved: https://github.com/pytorch/executorch/pull/6692 The linter these are suppressing was removed in D63859186. ghstack-source-id: 253169885 Differential Revision: [D65507718](https://our.internmc.facebook.com/intern/diff/D65507718/) --- extension/llm/custom_ops/op_sdpa.cpp | 1 - extension/llm/runner/image.h | 3 +-- extension/llm/runner/multimodal_runner.h | 3 --- extension/llm/runner/stats.h | 1 - extension/llm/runner/text_decoder_runner.h | 1 - extension/llm/runner/text_prefiller.h | 1 - extension/llm/tokenizer/tokenizer.h | 2 -- extension/parallel/thread_parallel.h | 1 - kernels/optimized/vec/vec_base.h | 2 -- runtime/core/exec_aten/testing_util/tensor_factory.h | 4 +--- 10 files changed, 2 insertions(+), 17 deletions(-) diff --git a/extension/llm/custom_ops/op_sdpa.cpp b/extension/llm/custom_ops/op_sdpa.cpp index 8afec156d53..50fa9338338 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 d3c4e8d945d..67fb8939518 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 1af9cb6fa29..94539c65cc6 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 f9462d24cd0..79c5781e337 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 c6f8a0ca676..ca4d127e516 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 9dbaec40e63..2f1d5ae2b75 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 52983d90753..c987857a305 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 bbce211597d..8b174075ae9 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 4a386f9e8ce..5ff4327e6f5 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 2ea21e95839..9f8f7e9db75 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 From 5ecef894f646c1af4b0be68af34d4e71910a3a06 Mon Sep 17 00:00:00 2001 From: pytorchbot Date: Wed, 13 Nov 2024 12:09:59 -0800 Subject: [PATCH 2/2] Add NOSTDINC and NOTORCHINC lintrunner (#6822) [ExecuTorch] Add NOSTDINC and NOTORCHINC lintrunner Pull Request resolved: https://github.com/pytorch/executorch/pull/6693 Prohibit standard C++ container, aten, and torch includes in core, at least pending further review. Note that non-core directories, such as extension/, test/, and any testing_util/ subdirectories, are exempted. ghstack-source-id: 253193810 Differential Revision: [D65541332](https://our.internmc.facebook.com/intern/diff/D65541332/) Co-authored-by: Scott Wolchok --- .lintrunner.toml | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/.lintrunner.toml b/.lintrunner.toml index 02219243861..04dca4a3406 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}}', +]