Skip to content

Commit

Permalink
[ExecuTorch] Add NOSTDINC and NOTORCHINC lintrunner
Browse files Browse the repository at this point in the history
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.

Differential Revision: [D65541332](https://our.internmc.facebook.com/intern/diff/D65541332/)

ghstack-source-id: 252107495
Pull Request resolved: #6693
  • Loading branch information
swolchok committed Nov 6, 2024
1 parent 0f5810f commit 0997acc
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,87 @@ command = [
'@{{PATHSFILE}}',
]
is_formatter = true

[[linter]]
code = 'NOSTDINC'
include_patterns = [
"**/*.c",
"**/*.cpp",
"**/*.h",
"**/*.hpp",
]
exclude_patterns = [
'**/devtools/**',
'**/test/**',
'**/testing_util/**',
'**/third-party/**',
'backends/mediatek/**',
'backends/vulkan/**',
'backends/xnnpack/**',
'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/**',
'**/testing_util/**',
'**/third-party/**',
'backends/mediatek/**',
'backends/vulkan/**',
'backends/xnnpack/**',
'devtools/**',
'examples/**',
'extension/**',
'kernels/optimized/**',
'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 0997acc

Please sign in to comment.