Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions test/test_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,6 @@ def _simple_type_parser(func, arg_name, arg_type):
return None
elif arg_type == "ScalarType":
return torch.float32
elif arg_type == "c10::string_view":
return ""
elif arg_type in ("std::string_view", "::std::string_view"):
return ""
elif arg_type == "SymInt":
Expand Down
2 changes: 1 addition & 1 deletion tools/autograd/load_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def repl(m: re.Match[str]) -> str:
if nctype.type == OptionalCType(BaseCType(stringT)):
formula = re.sub(
rf"\b{name}\b",
f"{name}.has_value() ? std::optional<std::string_view>({name}.value()) : std::nullopt",
f"{name}.has_value() ? std::optional<::std::string_view>({name}.value()) : std::nullopt",
formula,
)

Expand Down
1 change: 0 additions & 1 deletion torch/csrc/utils/python_arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ static std::unordered_map<std::string, ParameterType> type_map = {
{"DeviceIndex", ParameterType::INT64},
{"Stream", ParameterType::STREAM},
{"std::string", ParameterType::STRING},
{"c10::string_view", ParameterType::STRING},
{"std::string_view", ParameterType::STRING},
{"::std::string_view", ParameterType::STRING},
{"Dimname", ParameterType::DIMNAME},
Expand Down
2 changes: 1 addition & 1 deletion torchgen/api/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def argument_type_str(
elif t.name == BaseTy.float:
return "double"
elif t.name == BaseTy.str:
return "c10::string_view"
return "std::string_view"
elif t.name in [
BaseTy.Tensor,
BaseTy.bool,
Expand Down
2 changes: 1 addition & 1 deletion torchgen/api/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
float8_e4m3fnT = BaseCppType("at", "Float8_e4m3fn")
float8_e4m3fnuzT = BaseCppType("at", "Float8_e4m3fnuz")
float8_e8m0fnuT = BaseCppType("at", "Float8_e8m0fnu")
stringT = BaseCppType("c10", "string_view")
stringT = BaseCppType("std", "string_view")
generatorT = BaseCppType("at", "Generator")
scalarTypeT = BaseCppType("at", "ScalarType")
tensorT = BaseCppType("at", "Tensor")
Expand Down
2 changes: 2 additions & 0 deletions torchgen/api/types/types_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class BaseCType(CType):
type: BaseCppType

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

def remove_const_ref(self) -> CType:
Expand Down
6 changes: 3 additions & 3 deletions torchgen/dest/lazy_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def gen(self, schema: LazyIrSchema) -> list[str]:
[
# This code is just special casing the mapping from string_view -> strings
f"{a.name}({a.name}.has_value() ? ::std::make_optional(std::string(*{a.name})) : ::std::nullopt)"
if a.lazy_type.cpp_type() == "::std::optional<c10::string_view>"
if a.lazy_type.cpp_type() == "::std::optional<::std::string_view>"
else f"{a.name}({a.name})"
for a in scalar_args
]
Expand All @@ -266,9 +266,9 @@ def gen(self, schema: LazyIrSchema) -> list[str]:
scalar_decls = "\n ".join(
[
f"std::string {a.name};"
if a.lazy_type.cpp_type() == "c10::string_view"
if a.lazy_type.cpp_type() == "::std::string_view"
else f"::std::optional<std::string> {a.name};"
if a.lazy_type.cpp_type() == "::std::optional<c10::string_view>"
if a.lazy_type.cpp_type() == "::std::optional<::std::string_view>"
else f"{a.lazy_type.cpp_type()} {a.name};"
for a in scalar_args
]
Expand Down
3 changes: 1 addition & 2 deletions torchgen/static_runtime/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ def ivalue_type_conversion_method(
),
BaseTy.str: (
(False, "toStringView()"),
(False, "toOptional<c10::string_view>()"),
(False, "toOptional<::std::string_view>()"),
(False, "toOptional<std::string_view>()"),
),
}

Expand Down
Loading