tvm icon indicating copy to clipboard operation
tvm copied to clipboard

[Lint] Add check to prevent usage of #include <regex>

Open Lunderberg opened this issue 1 year ago • 3 comments

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

Lunderberg avatar Jan 16 '24 20:01 Lunderberg

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.

Lunderberg avatar Jan 16 '24 20:01 Lunderberg

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.

Lunderberg avatar Jan 24 '24 15:01 Lunderberg

Merged from main to PR branch, to resolve CI breakage that was fixed in https://github.com/apache/tvm/pull/16546.

Lunderberg avatar Feb 09 '24 20:02 Lunderberg

Rebased this PR onto main, in order to update the stale CI results.

Lunderberg avatar Feb 23 '24 15:02 Lunderberg