Skip to content

Commit d5e6f42

Browse files
Revert "Use std::string_view in torchgen (pytorch#157050)"
This reverts commit 064288c. Reverted pytorch#157050 on behalf of https://github.com/jeanschmidt due to Seems to have broken internal builds, more details on D77449943. @ezyang may I count on your help to get those changes merged? ([comment](pytorch#157050 (comment)))
1 parent efbf07e commit d5e6f42

File tree

8 files changed

+12
-16
lines changed

8 files changed

+12
-16
lines changed

test/test_overrides.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ def _simple_type_parser(func, arg_name, arg_type):
675675
return None
676676
elif arg_type == "ScalarType":
677677
return torch.float32
678+
elif arg_type == "c10::string_view":
679+
return ""
678680
elif arg_type in ("std::string_view", "::std::string_view"):
679681
return ""
680682
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/dest/lazy_ir.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +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()
260-
in (
261-
"::std::optional<::std::string_view>",
262-
"::std::optional<std::string_view>",
263-
)
259+
if a.lazy_type.cpp_type() == "::std::optional<c10::string_view>"
264260
else f"{a.name}({a.name})"
265261
for a in scalar_args
266262
]
@@ -270,13 +266,9 @@ def gen(self, schema: LazyIrSchema) -> list[str]:
270266
scalar_decls = "\n ".join(
271267
[
272268
f"std::string {a.name};"
273-
if a.lazy_type.cpp_type() in ("::std::string_view", "std::string_view")
269+
if a.lazy_type.cpp_type() == "c10::string_view"
274270
else f"::std::optional<std::string> {a.name};"
275-
if a.lazy_type.cpp_type()
276-
in (
277-
"::std::optional<::std::string_view>",
278-
"::std::optional<std::string_view>",
279-
)
271+
if a.lazy_type.cpp_type() == "::std::optional<c10::string_view>"
280272
else f"{a.lazy_type.cpp_type()} {a.name};"
281273
for a in scalar_args
282274
]

torchgen/gen_aoti_c_shim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
BaseTy.SymInt: "c10::SymInt",
5555
BaseTy.Scalar: "c10::Scalar",
5656
BaseTy.float: "double",
57-
BaseTy.str: "std::string_view",
57+
BaseTy.str: "::std::string_view",
5858
BaseTy.DeviceIndex: "c10::DeviceIndex",
5959
BaseTy.Layout: "c10::Layout",
6060
BaseTy.MemoryFormat: "c10::MemoryFormat",

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)