Files
pytorch/torch/csrc/jit/frontend/function_schema_parser.h
rzou 5b98d43488 Verify types in custom op schemas (#124520)
Before this PR, we didn't check that types in a schema were valid. This
is because TorchScript treats unknown types as type variables.

This PR checks types in a schema for the TORCH_LIBRARY APIs. To do this,
we add an `allow_typevars` flag to parseSchema so that TorchScript can
use allow_typevars=True. We also add some error messages for common
mistakes (e.g. using int64_t or double in schema).

Test Plan:
- new tests

Differential Revision: [D56432690](https://our.internmc.facebook.com/intern/diff/D56432690)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/124520
Approved by: https://github.com/albanD
2024-04-23 14:18:35 +00:00

24 lines
704 B
C++

#pragma once
#include <ATen/core/function_schema.h>
#include <c10/macros/Macros.h>
#include <string>
#include <variant>
namespace torch {
namespace jit {
// allow_typevars: If true, we assume that lowercase types that we don't
// understand are type variables. This is only needed for TorchScript (and not
// not needed for custom ops).
TORCH_API std::variant<c10::OperatorName, c10::FunctionSchema> parseSchemaOrName(
const std::string& schemaOrName,
bool allow_typevars = true);
TORCH_API c10::FunctionSchema parseSchema(
const std::string& schema,
bool allow_typevars = true);
TORCH_API c10::OperatorName parseName(const std::string& name);
} // namespace jit
} // namespace torch