[Cleanup] Remove using namespace tvm::runtime
from headers
#17246
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this commit, various header files had
using namespace tvm::runtime
, which imports all names fromtvm::runtime
into the current namespace.These imports can cause compilation errors depending on the order of
#include
statements. For example, the#include <tvm/relay/attrs/transform.h>
file uses the unqualified nameBool
to refer to::tvm::Bool
, a subclass ofPrimExpr
. If a different header file specifiesusing namespace tvm::runtime
within thetvm::relay
namespace, then the unqualified nameBool
ambiguously refers to either::tvm::Bool
or::tvm::runtime::Bool
.In MSVC, this can cause even further compilation errors. By default, MSVC does not follow the C++ standard for name resolution in templates. The standard requires that any names in a template that do not depend on template parameters be resolved when the template is declared. However, MSVC instead resolves these names when the template is instantiated. As a result, the same
using namespace tvm::runtime
may cause a compilation error if it occurs after the template's declaration, but before the template's usage.(TVM provides the
/permissive-
flag to MSVC builds specifically to disable MSVC's non-standard name resolution, so this only impacts downstream forks that disable this flag. See #16343 for more details.)This commit removes
using namespace tvm::runtime
, replacing them with explicitusing tvm::runtime::SOME_SPECIFIC_SYMBOL
where necessary. This resolves both the include-order dependency for standards-compliant compilers, and the compilation errors for MSVC's default build.