Skip to content

Commit

Permalink
[ExecuTorch] Add NOSTDINC and NOTORCHINC lintrunner
Browse files Browse the repository at this point in the history
Pull Request resolved: #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/)
  • Loading branch information
swolchok committed Nov 12, 2024
1 parent eb6d1cb commit 9981764
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}',
]

0 comments on commit 9981764

Please sign in to comment.