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: 1 addition & 1 deletion checker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ cc_library(
deps = [
":type_checker_builder",
"//common:decl",
"//common/internal:signature",
"//common:signature",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/types:span",
Expand Down
10 changes: 5 additions & 5 deletions checker/type_checker_subset_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "absl/types/span.h"
#include "checker/type_checker_builder.h"
#include "common/decl.h"
#include "common/internal/signature.h"
#include "common/signature.h"

namespace cel {

Expand All @@ -33,8 +33,8 @@ TypeCheckerSubset::FunctionPredicate IncludeOverloadsByIdPredicate(
if (overload_ids.contains(overload.id())) {
return true;
}
auto signature = common_internal::MakeOverloadSignature(
function, overload.args(), overload.member());
auto signature =
MakeOverloadSignature(function, overload.args(), overload.member());
return signature.ok() && overload_ids.contains(*signature);
};
}
Expand All @@ -52,8 +52,8 @@ TypeCheckerSubset::FunctionPredicate ExcludeOverloadsByIdPredicate(
if (overload_ids.contains(overload.id())) {
return false;
}
auto signature = common_internal::MakeOverloadSignature(
function, overload.args(), overload.member());
auto signature =
MakeOverloadSignature(function, overload.args(), overload.member());
return !signature.ok() || !overload_ids.contains(*signature);
};
}
Expand Down
38 changes: 37 additions & 1 deletion common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ cc_test(
],
)

cc_library(
name = "signature",
srcs = ["signature.cc"],
hdrs = ["signature.h"],
deps = [
":ast",
":type",
":type_spec_resolver",
"//internal:status_macros",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
"@com_google_protobuf//:protobuf",
],
)

cc_test(
name = "signature_test",
srcs = ["signature_test.cc"],
deps = [
":ast",
":signature",
":type",
":type_kind",
":type_spec_resolver",
"//internal:testing",
"//internal:testing_descriptor_pool",
"@com_google_absl//absl/base:no_destructor",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/status:statusor",
"@com_google_protobuf//:protobuf",
],
)

cc_library(
name = "expr",
srcs = ["expr.cc"],
Expand Down Expand Up @@ -145,9 +181,9 @@ cc_library(
hdrs = ["decl.h"],
deps = [
":constant",
":signature",
":type",
":type_kind",
"//common/internal:signature",
"//internal:status_macros",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base:core_headers",
Expand Down
5 changes: 2 additions & 3 deletions common/decl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "common/internal/signature.h"
#include "common/signature.h"
#include "common/type.h"
#include "common/type_kind.h"

Expand Down Expand Up @@ -117,8 +117,7 @@ void AddOverloadInternal(std::string_view function_name,
}

absl::StatusOr<std::string> signature =
common_internal::MakeOverloadSignature(function_name, overload.args(),
overload.member());
MakeOverloadSignature(function_name, overload.args(), overload.member());
if (!signature.ok()) {
status = signature.status();
return;
Expand Down
36 changes: 0 additions & 36 deletions common/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -135,39 +135,3 @@ cc_library(
"@com_google_protobuf//src/google/protobuf/io",
],
)

cc_library(
name = "signature",
srcs = ["signature.cc"],
hdrs = ["signature.h"],
deps = [
"//common:ast",
"//common:type",
"//common:type_spec_resolver",
"//internal:status_macros",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
"@com_google_protobuf//:protobuf",
],
)

cc_test(
name = "signature_test",
srcs = ["signature_test.cc"],
deps = [
":signature",
"//common:ast",
"//common:type",
"//common:type_kind",
"//common:type_spec_resolver",
"//internal:testing",
"//internal:testing_descriptor_pool",
"@com_google_absl//absl/base:no_destructor",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/status:statusor",
"@com_google_protobuf//:protobuf",
],
)
6 changes: 3 additions & 3 deletions common/internal/signature.cc → common/signature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/internal/signature.h"
#include "common/signature.h"

#include <cstddef>
#include <cstring>
Expand All @@ -34,7 +34,7 @@
#include "google/protobuf/arena.h"
#include "google/protobuf/descriptor.h"

namespace cel::common_internal {
namespace cel {

// Signature generator helper functions.
namespace {
Expand Down Expand Up @@ -637,4 +637,4 @@ absl::StatusOr<Type> ParseType(std::string_view signature, google::protobuf::Are
return cel::ConvertTypeSpecToType(type_spec, arena, pool);
}

} // namespace cel::common_internal
} // namespace cel
10 changes: 5 additions & 5 deletions common/internal/signature.h → common/signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef THIRD_PARTY_CEL_CPP_COMMON_INTERNAL_SIGNATURE_H_
#define THIRD_PARTY_CEL_CPP_COMMON_INTERNAL_SIGNATURE_H_
#ifndef THIRD_PARTY_CEL_CPP_COMMON_SIGNATURE_H_
#define THIRD_PARTY_CEL_CPP_COMMON_SIGNATURE_H_

#include <string>
#include <string_view>
Expand All @@ -25,7 +25,7 @@
#include "google/protobuf/arena.h"
#include "google/protobuf/descriptor.h"

namespace cel::common_internal {
namespace cel {

// Generates a signature for a `cel::Type`, which is a string representation of
// the type.
Expand Down Expand Up @@ -96,6 +96,6 @@ struct ParsedFunctionOverload {
absl::StatusOr<ParsedFunctionOverload> ParseFunctionSignature(
std::string_view signature);

} // namespace cel::common_internal
} // namespace cel

#endif // THIRD_PARTY_CEL_CPP_COMMON_INTERNAL_SIGNATURE_H_
#endif // THIRD_PARTY_CEL_CPP_COMMON_SIGNATURE_H_
33 changes: 15 additions & 18 deletions common/internal/signature_test.cc → common/signature_test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common/internal/signature.h"
#include "common/signature.h"
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,7 +30,7 @@
#include "internal/testing_descriptor_pool.h"
#include "google/protobuf/arena.h"

namespace cel::common_internal {
namespace cel {
namespace {

using ::absl_testing::IsOkAndHolds;
Expand Down Expand Up @@ -77,8 +77,7 @@ using TypeSignatureTest = testing::TestWithParam<TypeSignatureTestCase>;
TEST_P(TypeSignatureTest, TypeSignature) {
const auto& param = GetParam();

absl::StatusOr<std::string> signature =
common_internal::MakeTypeSpecSignature(param.type);
absl::StatusOr<std::string> signature = MakeTypeSpecSignature(param.type);
if (!param.expected_error.empty()) {
EXPECT_THAT(signature, StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr(param.expected_error)));
Expand Down Expand Up @@ -257,25 +256,24 @@ INSTANTIATE_TEST_SUITE_P(TypeSignatureTest, TypeSignatureTest,
ValuesIn(GetTypeSignatureTestCases()));

TEST(TypeSignatureTest, UnsupportedTypes) {
EXPECT_THAT(common_internal::MakeTypeSignature(UnknownType{}),
EXPECT_THAT(MakeTypeSignature(UnknownType{}),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Unsupported Type kind: *unknown*")));

EXPECT_THAT(common_internal::MakeTypeSignature(ErrorType{}),
EXPECT_THAT(MakeTypeSignature(ErrorType{}),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Unsupported type in signature: *error*")));

EXPECT_THAT(common_internal::MakeTypeSpecSignature(
TypeSpec(static_cast<PrimitiveType>(999))),
EXPECT_THAT(MakeTypeSpecSignature(TypeSpec(static_cast<PrimitiveType>(999))),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Unsupported primitive type")));

EXPECT_THAT(common_internal::MakeTypeSpecSignature(
TypeSpec(static_cast<WellKnownTypeSpec>(999))),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Unsupported well-known type")));
EXPECT_THAT(
MakeTypeSpecSignature(TypeSpec(static_cast<WellKnownTypeSpec>(999))),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Unsupported well-known type")));

EXPECT_THAT(common_internal::MakeTypeSpecSignature(TypeSpec(
EXPECT_THAT(MakeTypeSpecSignature(TypeSpec(
PrimitiveTypeWrapper(static_cast<PrimitiveType>(999)))),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Unsupported wrapper type")));
Expand Down Expand Up @@ -308,8 +306,7 @@ TEST_P(OverloadSignatureTest, OverloadSignature) {
const auto& param = GetParam();

absl::StatusOr<std::string> signature =
common_internal::MakeOverloadSignature(param.function_name, param.args,
param.is_member);
MakeOverloadSignature(param.function_name, param.args, param.is_member);
if (!param.expected_error.empty()) {
EXPECT_THAT(signature, StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr(param.expected_error)));
Expand Down Expand Up @@ -433,8 +430,8 @@ std::vector<OverloadSignatureTestCase> GetOverloadSignatureTestCases() {
}

TEST(OverloadSignatureTest, MemberFunctionNoReceiverError) {
auto signature = common_internal::MakeOverloadSignature(
"hello", std::vector<TypeSpec>{}, true);
auto signature =
MakeOverloadSignature("hello", std::vector<TypeSpec>{}, true);
EXPECT_THAT(signature,
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Member function with no receiver")));
Expand Down Expand Up @@ -784,4 +781,4 @@ TEST(OverloadSignatureTest, ArgumentTypeVector) {
}

} // namespace
} // namespace cel::common_internal
} // namespace cel
4 changes: 2 additions & 2 deletions env/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ cc_library(
"//common:constant",
"//common:container",
"//common:decl",
"//common:signature",
"//common:type",
"//common/internal:signature",
"//compiler",
"//compiler:compiler_factory",
"//compiler:standard_library",
Expand Down Expand Up @@ -124,7 +124,7 @@ cc_library(
":config",
"//common:ast",
"//common:constant",
"//common/internal:signature",
"//common:signature",
"//internal:status_macros",
"//internal:strings",
"@com_google_absl//absl/algorithm:container",
Expand Down
8 changes: 3 additions & 5 deletions env/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "common/constant.h"
#include "common/container.h"
#include "common/decl.h"
#include "common/internal/signature.h"
#include "common/signature.h"
#include "common/type.h"
#include "compiler/compiler.h"
#include "compiler/compiler_factory.h"
Expand Down Expand Up @@ -71,8 +71,7 @@ bool ShouldIncludeFunction(const Config::StandardLibraryConfig& config,
return false;
}
absl::StatusOr<std::string> signature =
common_internal::MakeOverloadSignature(function, overload.args(),
overload.member());
MakeOverloadSignature(function, overload.args(), overload.member());
if (signature.ok() && config.excluded_functions.contains(std::make_pair(
std::string(function), *std::move(signature)))) {
return false;
Expand All @@ -89,8 +88,7 @@ bool ShouldIncludeFunction(const Config::StandardLibraryConfig& config,
// Ok to call MakeOverloadSignature() again, because in practice either
// included or excluded functions may be specified, but not both.
absl::StatusOr<std::string> signature =
common_internal::MakeOverloadSignature(function, overload.args(),
overload.member());
MakeOverloadSignature(function, overload.args(), overload.member());
if (signature.ok() && config.included_functions.contains(std::make_pair(
std::string(function), *std::move(signature)))) {
return true;
Expand Down
Loading
Loading