tvm
tvm copied to clipboard
[Lint] Add check to prevent usage of #include <regex>
Currently, the pytorch wheels available through pip install use the pre-C++11 ABI by setting -DUSE_CXX11_ABI=0 [0]. If TVM were to user the pre-C++11 ABI, this would cause breakages with dynamically-linked LLVM environments.
This commit adds a lint check to search for use of #include <regex> in any C++ files. Use of this header should be avoided, as its implementation is not supported by gcc's dual ABI. This ABI incompatibility results in runtime errors either when std::regex is called from TVM, or when std::regex is called from pytorch, depending on which library was loaded first.
This restriction can be removed when a version of pytorch compiled using -DUSE_CXX11_ABI=1 is available from PyPI.
[0] https://github.com/pytorch/pytorch/issues/51039
This rule is currently implemented in terms of find and grep, as I couldn't find any options in cpplint to check for specific header files, and clang-tidy would be too much overhead for a single linting rule.
The PR https://github.com/apache/tvm/pull/16465 exposes a PackedFunc wrapper for Python's regex matching. The limited functionality it has, checking for a match without returning any extracted results, is sufficient for all existing uses of #include <regex> found by the new lint rule. After it lands, this PR can be updated to use the new wrapper function instead of std::regex.
Merged from main to PR branch, to resolve CI breakage that was fixed in https://github.com/apache/tvm/pull/16546.
Rebased this PR onto main, in order to update the stale CI results.