-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cleanup] Remove using namespace tvm::runtime
from headers
#17246
[Cleanup] Remove using namespace tvm::runtime
from headers
#17246
Conversation
Re-apply the change from upstream apache#16343. See apache#17246 for an example of the type of bug that can result from MSVC's default non-standard name resolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp block this in light of #16183 (comment)
Good point. I think this change is beneficial regardless of #16183, but the FFI changes touch so many parts of TVM that I wouldn't want to declare them 100% independent. |
Prior to this commit, various header files had `using namespace tvm::runtime`, which imports all names from `tvm::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 name `Bool` to refer to `::tvm::Bool`, a subclass of `PrimExpr`. If a different header file specifies `using namespace tvm::runtime` within the `tvm::relay` namespace, then the unqualified name `Bool` 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 apache#16343 for more details.) This commit removes `using namespace tvm::runtime`, replacing them with explicit `using 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.
757518d
to
4a01e78
Compare
Rebased these changes onto main, and this PR should be land-able now that the performance regressions from #16183 have been resolved. |
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.