[protocolbuffers/protobuf]生成的 kotlin 代码仍然抛出“内联的预期性能影响微不足道”警告

2024-05-11 174 views
7

与 #8896 中的断言和变更日志相反,与 3.18.1 一起打包在 jar 中的协议二进制文件似乎不包含此更改。

一些证据:

$ sha1sum <the file>
00b97c1fefac42a993e66cdd10760b7797b67cfb  $HOME/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protoc/3.18.1/b97c1fefac42a993e66cdd10760b7797b67cfb/protoc-3.18.1-linux-x86_64.exe

$ strings $HOME/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protoc/3.18.1/b97c1fefac42a993e66cdd10760b7797b67cfb/protoc-3.18.1-linux-x86_64.exe |grep -i suppresswarnings
@SuppressWarnings({"unused"})
@SuppressWarnings({"rawtypes"})
@java.lang.SuppressWarnings("unchecked")
@SuppressWarnings({"rawtypes"})
@SuppressWarnings({"rawtypes"})
@java.lang.SuppressWarnings({"unchecked", "fallthrough"})
@java.lang.SuppressWarnings({"ReferenceEquality"})
  @SuppressWarnings("deprecation")
  @SuppressWarnings("deprecation")
  @SuppressWarnings("deprecation")
    @SuppressWarnings("deprecation")
    @SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
            @SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")

$ strings $HOME/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protoc/3.18.1/b97c1fefac42a993e66cdd10760b7797b67cfb/protoc-3.18.1-linux-x86_64.exe |grep INLIN
template<> PROTOBUF_NOINLINE $classtype$* Arena::CreateMaybeMessage< $classtype$ >(Arena* arena) {
inline PROTOBUF_ALWAYS_INLINE void _internal_set_$name$(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE bool _internal_$name$_donated() const;
inline PROTOBUF_ALWAYS_INLINE
inline PROTOBUF_ALWAYS_INLINE

我可能会得出结论,当构建 3.18.1 jar 时,它错误地包含了较旧的本机二进制文件,但是:

$ $HOME/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protoc/3.18.1/b97c1fefac42a993e66cdd10760b7797b67cfb/protoc-3.18.1-linux-x86_64.exe --version
libprotoc 3.18.1

您使用什么版本的 protobuf 以及什么语言? 版本:3.18.1 语言:Java 和 Kotlin

什么操作系统(Linux、Windows...)和版本? 软呢帽 33

您使用什么运行时/编译器(例如,python 版本或 gcc 版本) Java 11,Gradle 插件 0.8.17

你做了什么? 从 protobuf 生成 Kotlin 代码

您期望看到 生成的 Kotlin 代码包含什么@SuppressWarnings("NOTHING_TO_INLINE")

你看到了什么? 生成的 Kotlin 代码不包含@SuppressWarnings,因此我收到警告;)

关于您的项目/环境我们还应该了解的其他信息

回答

4

可能,但你确定你是用协议 3.18.1 生成的吗?我问这个问题是因为我最近浪费了一天左右的时间,因为我没有使用我认为的 protoc 版本。

9

您没有看到抑制,因为它不像其他一些警告那样具有“@SupressWarnings”,而是 Kotlin 生成的代码包含 @Suppress("NOTHING_TO_INLINE")。如果您仍然看到警告,您可以分享您看到的警告以及您尝试生成的原型文件吗?

2

@埃尔哈罗:

您确定您是使用 protoc 3.18.1 生成的吗?

是的,非常确定!我运行了打包在 jar 中的 protoc 二进制文件,它声称它是 3.18.1...此外,strings该二进制文件的输出不包含NOTHING_TO_INLINE.

编辑:从另一台计算机仔细检查(注意这是 Mac;以前是 Fedora Linux):

$ wget https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.18.1/protoc-3.18.1-osx-x86_64.exe

$ shasum protoc-3.18.1-osx-x86_64.exe
41fb14ef4e0d76a12b5f444908d9711b97c8eb75  protoc-3.18.1-osx-x86_64.exe

$ chmod 755 protoc-3.18.1-osx-x86_64.exe
$ ./protoc-3.18.1-osx-x86_64.exe --version
libprotoc 3.18.1

$ strings protoc-3.18.1-osx-x86_64.exe |grep INLIN
template<> PROTOBUF_NOINLINE $classtype$* Arena::CreateMaybeMessage< $classtype$ >(Arena* arena) {
inline PROTOBUF_ALWAYS_INLINE void _internal_set_$name$(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE bool _internal_$name$_donated() const;
inline PROTOBUF_ALWAYS_INLINE
inline PROTOBUF_ALWAYS_INLINE
$ strings protoc-3.18.1-osx-x86_64.exe |grep Suppress
  @SuppressWarnings("deprecation")
  @SuppressWarnings("deprecation")
  @SuppressWarnings("deprecation")
    @SuppressWarnings("deprecation")
    @SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
            @SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
@SuppressWarnings({"unused"})
@SuppressWarnings({"rawtypes"})
@Suppress("UNCHECKED_CAST")
@java.lang.SuppressWarnings("unchecked")
@SuppressWarnings({"rawtypes"})
@SuppressWarnings({"rawtypes"})
@java.lang.SuppressWarnings({"ReferenceEquality"})
@java.lang.SuppressWarnings({"unchecked", "fallthrough"})
8

我想我发现了这个错误,而且它似乎特定于非精简字符串字段,我希望我的 PR #9102 能够修复它。

1

我想我发现了这个错误,而且它似乎特定于非精简字符串字段,我希望我的 PR #9102 能够修复它。

万分感谢!出于好奇,你知道为什么我的strings搜索没有找到任何证据,即使我减少了 grep 的限制(例如SuppressINLIN)?也许模板被压缩了还是什么?

5

我认为这是因为它们不适合您,这似乎特定于您的原始文件中的字段类型。希望修复后你会得到匹配的结果。

5

您能否分享您尝试生成代码的原型(或者它具有什么样的字段)以及您看到的警告?只是想确保这是我修复的特定情况,并且没有其他类似的情况。

8

原型看起来像这样:

message Foo {
  string irrelevant = 1;
}

message Bar {
  repeated Foo foos = 1;
}

然后,在为 Bar 生成的代码中,将出现以下内容。只有这两个plusAssign方法有inline修饰符。

fun com.google.protobuf.kotlin.DslList<Foo, FoosProxy>.add(value: Foo)

inline operator fun com.google.protobuf.kotlin.DslList<Foo, FoosProxy>.plusAssign(value: Foo)

fun com.google.protobuf.kotlin.DslList<Foo, FoosProxy>.addAll(values: kotlin.collections.Iterable<Foo>)

inline operator fun com.google.protobuf.kotlin.DslList<Foo, FoosProxy>.plusAssign(values: kotlin.collections.Iterable<Foo>)

operator fun com.google.protobuf.kotlin.DslList<Foo, FoosProxy>.set(index: kotlin.Int, value: Foo)

fun com.google.protobuf.kotlin.DslList<Foo, FoosProxy>.clear()

ISTM #9102 将修复它,因为警告仅针对plusAssign.

5

你能看看 3.19.0 是否修复了这个问题吗?