Choreographic programming is a programming paradigm, whereby the overall behaviour of a distributed system is coded as a choreography from a global viewpoint. The choreography can then be automatically compiled (projected) to a correct implementation for each participant. Choreographic programming relieves the programmer from manually writing the separate send and receive actions performed by participants and avoids the problem of communication mismatches. However, the applicability of this paradigm in the real world remains largely unexplored for two reasons. First, while there have been several proposals of choreographic programming languages, none of them have been used to implement a realistic, widely-used protocol. Thus there is a lack of experience on how realistic choreographic programs are structured and on the relevance of the features explored in theoretical models. Second, applications of choreographic programming shown so far are intrusive since each participant must use exactly the code projected from the choreography. This prevents using the projected code with existing third-party implementations of some participants. We carry out the first development in choreographic programming of a widespread real-world protocol: the Internet Relay Chat (IRC) protocol. Our development is based on Choral, an object-oriented choreographic programming language. Two of Choral's features are key to our implementation: higher-order choreographies for modelling the complex interaction patterns due to IRC's asynchronous nature; and user-definable communication semantics for achieving interoperability with third-party implementations. We also discover a missing piece: the capability of statically detecting that choices on alternative distributed behaviours are appropriately communicated by means of message types. We extend the Choral compiler with an elegant solution based on subtyping.
翻译:编舞编程是一种编程范式,通过从全局视角将分布式系统的整体行为编码为编舞,进而可自动编译(投影)为每个参与者的正确实现。该范式使程序员无需手动编写参与者各自执行的发送与接收操作,并避免了通信不匹配问题。然而,该范式在现实世界中的适用性仍主要受限于两个原因:其一,尽管已有多种编舞编程语言提案,但尚未有语言被用于实现真实且广泛使用的协议,因此缺乏对现实编舞程序结构及理论模型所探索特征相关性的实践经验;其二,目前展示的编舞编程应用具有侵入性——每个参与者必须严格使用从编舞投影出的代码,这阻碍了投影代码与现有第三方参与者实现的集成。我们首次将编舞编程应用于真实世界广泛使用的协议——互联网中继聊天(IRC)协议。该开发基于面向对象的编舞编程语言Choral,其两个特性对实现至关重要:高阶编舞用于建模IRC异步性导致的复杂交互模式,以及用户可定义的通信语义用于实现与第三方实现的互操作性。我们还发现一个缺失环节:静态检测通过消息类型恰当通信的备选分布式行为选择的能力。我们通过基于子类型的优雅方案扩展了Choral编译器。