A decade after its first release, the Go programming language has become a major programming language in the development landscape. While praised for its clean syntax and C-like performance, Go also contains a strong static type-system that prevents arbitrary type casting and arbitrary memory access, making the language type-safe by design. However, to give developers the possibility of implementing low-level code, Go ships with a special package called unsafe that offers developers a way around the type-safety of Go programs. The package gives greater flexibility to developers but comes at a higher risk of runtime errors, chances of non-portability, and the loss of compatibility guarantees for future versions of Go. In this paper, we present the first large-scale study on the usage of the unsafe package in 2,438 popular Go projects. Our investigation shows that unsafe is used in 24% of Go projects, motivated primarily by communicating with operating systems and C code, but is also commonly used as a source of performance optimization. Developers are willing to use unsafe to break language specifications (e.g., string immutability) for better performance and 6% of analyzed projects that use unsafe perform risky pointer conversions that can lead to program crashes and unexpected behavior. Furthermore, we report a series of real issues faced by projects that use unsafe, from crashing errors and non-deterministic behavior to having their deployment restricted from certain popular environments. Our findings can be used to understand how and why developers break type-safety in Go, and help motivate further tools and language development that could make the usage of unsafe in Go even safer.
翻译:在首次发布十年后,Go编程语言已成为发展格局中的主要编程语言。Go虽然因其清洁的语法和C类性能而受到赞扬,但也包含一个强大的静态类型系统,防止任意的投版和任意的记忆访问,使语言类型通过设计而变得安全。然而,为了使开发者有可能实施低级别代码,Go编程语言在首次发布之后十年后成为了开发者的主要编程语言语言。Go编程语言为开发者提供了更大的灵活性,但是在运行时间错误、不可移动的可能性以及未来版本Go的兼容性保障的丧失方面风险更大。在本文中,我们介绍了关于2,438个流行的Go项目中使用不安全组合的首个大规模研究,使语言类型安全。我们的调查显示,24 %的Go项目使用不安全,主要是与操作系统和C类代码的沟通,但也被普遍用作绩效优化的来源。 开发者愿意使用不安全的方法打破语言的规格(例如,串联不易移动性)来改进业绩,而6%的分析项目使用不安全的点转换方法,甚至导致不可靠地进行危险地点转换。在不精确的Go-rodition-room-rodudududududududududududududer-rodududududududududu,我们使用了不使用了某种行为, roducism roducismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismismmismismismismismismismismismismism