Identifier names convey useful information about the intended semantics of code. Name-based program analyses use this information, e.g., to detect bugs, to predict types, and to improve the readability of code. At the core of name-based analyses are semantic representations of identifiers, e.g., in the form of learned embeddings. The high-level goal of such a representation is to encode whether two identifiers, e.g., len and size, are semantically similar. Unfortunately, it is currently unclear to what extent semantic representations match the semantic relatedness and similarity perceived by developers. This paper presents IdBench, the first benchmark for evaluating semantic representations against a ground truth created from thousands of ratings by 500 software developers. We use IdBench to study state-of-the-art embedding techniques proposed for natural language, an embedding technique specifically designed for source code, and lexical string distance functions. Our results show that the effectiveness of semantic representations varies significantly and that the best available embeddings successfully represent semantic relatedness. On the downside, no existing technique provides a satisfactory representation of semantic similarities, among other reasons because identifiers with opposing meanings are incorrectly considered to be similar, which may lead to fatal mistakes, e.g., in a refactoring tool. Studying the strengths and weaknesses of the different techniques shows that they complement each other. As a first step toward exploiting this complementarity, we present an ensemble model that combines existing techniques and that clearly outperforms the best available semantic representation.
翻译:标识符名称传递了有关代码预想语义的有用信息。 不幸的是, 以名称为基础的程序分析使用这种信息, 例如用于检测错误、 预测类型以及提高代码的可读性。 以名称为基础的分析核心是识别符的语义表达方式, 例如, 以学习嵌入形式 。 这种表达方式的高级目标是编码两种识别符( 例如, len 和大小) 的嵌入技术是否在语义上相似 。 不幸的是, 目前尚不清楚 语义表达方式与开发者所察觉的语义相关性和相似性相匹配的程度 。 本文展示了 Id Bench, 这是根据500 软件开发者 上千个评级所创建的地面真相来评估语义表达方式的第一个基准 。 我们使用 Id Bench 来研究自然语言所推荐的“ ”, 一种专门为源代码设计的嵌入技术, 以及词义字符串距离功能 。 我们的结果显示, 语义表示语义表达方式的有效性与开发者所见的语义上的最佳嵌系关联性步骤 。 在目前使用的每一种方法中,,, 没有一种令人信义化的语义化 。