Skip to content

Commit 0125260

Browse files
pytorchmergebotcleonard530
authored andcommitted
Revert "[Reland] Use std::string_view in torchgen (pytorch#158625)"
This reverts commit 972e409. Reverted pytorch#158625 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it seems to break a couple of ExecuTorch tests for Vulkan backend ([comment](pytorch#158625 (comment)))
1 parent 99ed33b commit 0125260

File tree

8 files changed

+11
-9
lines changed

8 files changed

+11
-9
lines changed

test/test_overrides.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,8 @@ def _simple_type_parser(func, arg_name, arg_type):
940940
return None
941941
elif arg_type == "ScalarType":
942942
return torch.float32
943+
elif arg_type == "c10::string_view":
944+
return ""
943945
elif arg_type in ("std::string_view", "::std::string_view"):
944946
return ""
945947
elif arg_type == "SymInt":

tools/autograd/load_derivatives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ def repl(m: re.Match[str]) -> str:
969969
if nctype.type == OptionalCType(BaseCType(stringT)):
970970
formula = re.sub(
971971
rf"\b{name}\b",
972-
f"{name}.has_value() ? std::optional<::std::string_view>({name}.value()) : std::nullopt",
972+
f"{name}.has_value() ? std::optional<std::string_view>({name}.value()) : std::nullopt",
973973
formula,
974974
)
975975

torch/csrc/utils/python_arg_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static std::unordered_map<std::string, ParameterType> type_map = {
4646
{"DeviceIndex", ParameterType::INT64},
4747
{"Stream", ParameterType::STREAM},
4848
{"std::string", ParameterType::STRING},
49+
{"c10::string_view", ParameterType::STRING},
4950
{"std::string_view", ParameterType::STRING},
5051
{"::std::string_view", ParameterType::STRING},
5152
{"Dimname", ParameterType::DIMNAME},

torchgen/api/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def argument_type_str(
683683
elif t.name == BaseTy.float:
684684
return "double"
685685
elif t.name == BaseTy.str:
686-
return "std::string_view"
686+
return "c10::string_view"
687687
elif t.name in [
688688
BaseTy.Tensor,
689689
BaseTy.bool,

torchgen/api/types/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
float8_e4m3fnT = BaseCppType("at", "Float8_e4m3fn")
5353
float8_e4m3fnuzT = BaseCppType("at", "Float8_e4m3fnuz")
5454
float8_e8m0fnuT = BaseCppType("at", "Float8_e8m0fnu")
55-
stringT = BaseCppType("std", "string_view")
55+
stringT = BaseCppType("c10", "string_view")
5656
generatorT = BaseCppType("at", "Generator")
5757
scalarTypeT = BaseCppType("at", "ScalarType")
5858
tensorT = BaseCppType("at", "Tensor")

torchgen/api/types/types_base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ class BaseCType(CType):
8181
type: BaseCppType
8282

8383
def cpp_type(self, *, strip_ref: bool = False) -> str:
84-
if self.type.ns == "std":
85-
return "::" + str(self.type)
8684
return str(self.type)
8785

8886
def remove_const_ref(self) -> CType:

torchgen/dest/lazy_ir.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def gen(self, schema: LazyIrSchema) -> list[str]:
256256
[
257257
# This code is just special casing the mapping from string_view -> strings
258258
f"{a.name}({a.name}.has_value() ? ::std::make_optional(std::string(*{a.name})) : ::std::nullopt)"
259-
if a.lazy_type.cpp_type() == "::std::optional<::std::string_view>"
259+
if a.lazy_type.cpp_type() == "::std::optional<c10::string_view>"
260260
else f"{a.name}({a.name})"
261261
for a in scalar_args
262262
]
@@ -266,9 +266,9 @@ def gen(self, schema: LazyIrSchema) -> list[str]:
266266
scalar_decls = "\n ".join(
267267
[
268268
f"std::string {a.name};"
269-
if a.lazy_type.cpp_type() == "::std::string_view"
269+
if a.lazy_type.cpp_type() == "c10::string_view"
270270
else f"::std::optional<std::string> {a.name};"
271-
if a.lazy_type.cpp_type() == "::std::optional<::std::string_view>"
271+
if a.lazy_type.cpp_type() == "::std::optional<c10::string_view>"
272272
else f"{a.lazy_type.cpp_type()} {a.name};"
273273
for a in scalar_args
274274
]

torchgen/static_runtime/generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ def ivalue_type_conversion_method(
323323
),
324324
BaseTy.str: (
325325
(False, "toStringView()"),
326-
(False, "toOptional<std::string_view>()"),
326+
(False, "toOptional<c10::string_view>()"),
327+
(False, "toOptional<::std::string_view>()"),
327328
),
328329
}
329330

0 commit comments

Comments
 (0)