We present a kind inference algorithm for the FREEST programming language. The input to the algorithm is FREEST source code with (possibly part of) kind annotations replaced by kind variables. The algorithm infers concrete kinds for all kind variables. We ran the algorithm on the FREEST test suite by first replacing kind annotation on all type variables by fresh kind variables, and concluded that the algorithm correctly infers all kinds. Non surprisingly, we found out that programmers do not choose the most general kind in 20% of the cases.
2022
Inf. & Comp.
Polymorphic lambda calculus with context-free session types
Session types provide a typing discipline for structured communication on bidirectional channels. Context-free session types overcome the restriction to tail recursive protocols characteristic of conventional session types. This extension enables the serialization and deserialization of tree structures in a fully type-safe manner. We present the theory underlying the language FreeST 2, which features context-free session types in an extension of System F with linear types and a kinding system to distinguish message types, session types, and channel types. The system presents metatheoretical challenges which we address: contractivity in the presence of polymorphism, a non-trivial equational theory on types, and decidability of type equivalence. We also establish standard results on typing preservation, progress, and a characterization of erroneous processes.
Communication plays a significant role in concurrent software systems. The concurrent agents that communicate with each other may exchange a massive number of messages and, to avoid unexpected behaviours, these messages should follow a protocol capable of accounting for their order and form. Session types offer mechanisms to model these interactions while ensuring safety properties like the absence of communication errors and deadlocks. They describe structured interaction of processes on heterogeneously typed communication channels. Regular session types impose that protocols must have a tail-recursive structure. On the other hand, context-free session types, proposed by Thiemann and Vasconcelos, drop the tail recursion restriction, thus allowing recursion to occur at any part of the type. The resulting system bears enhanced session types, capable of defining protocols that describe the serialisation of non-regular structures. Moreover, context-free session types can define complex protocols like serialising a tree-like structure without resorting to techniques like higher-order channels. Our work is based on FreeST, a concurrent programming language based on a core functional language, with primitives for creating new threads, new channels and communicating on those channels. In FreeST, channels are bidirectional and governed by context-free session types. With this work, we aim to increase the usability of FreeST by introducing impredicative polymorphism, by adding higher-order kinds and type operators, and by adopting algorithms that provide local type inference.
Writing concurrent programs with races is cumbersome and may dictate the fall of any software. The difficulty in writing concurrent programs often originates from complex communication patterns among different parties. FreeST was born with the purpose of simplifying the specification and implementation of communicating systems through the use of session types, supported by a powerful type checker. Unfortunately, linear session types are bound to a 1-to-1 communication which means that cooperation between more than two processes is neither simple nor efficient. In this work, we propose shared context-free session types to overcome this restriction. This newly implemented feature opens up a new world of use cases, which include shared state, producer-consumer architectures, and FreeST’s standard IO. This paper uses a store as a running example to show how shared channels improve FreeST’s usability in comparison to linear channels, and how it maintains expressiveness without complicating code.
2020
TACAS’20
Deciding the Bisimilarity of Context-Free Session Types
We present an algorithm to decide the equivalence of context-free session types, practical to the point of being incorporated in a compiler. We prove its soundness and completeness. We further evaluate its behaviour in practice. In the process, we introduce an algorithm to decide the bisimilarity of simple grammars.
Session types describe patterns of interaction on communicating channels. Traditional session types include a form of choice whereby servers offer a collection of options, of which each client picks exactly one. This sort of choice constitutes a particular case of separated choice: offering on one side, selecting on the other. We introduce mixed choices in the context of session types and argue that they increase the flexibility of program development at the same time that they reduce the number of synchronisation primitives to exactly one. We present a type system incorporating subtyping and prove preservation and absence of runtime errors for well-typed processes. We further show that classical (conventional) sessions can be faithfully and tightly embedded in mixed choices. Finally, we discuss algorithmic type checking and a runtime system built on top of a conventional (choice-less) message-passing architecture.
2019
PLACES’19
FreeST: Context-free Session Types in a Functional Language
FreeST is an experimental concurrent programming language. Based on a core linear functional programming language, it features primitives to fork new threads, and for channel creation and communication. A powerful type system of context-free session types governs the interaction on channels. The compiler builds on a novel algorithm for deciding type equivalence of context-free session types. This abstract provides a gentle introduction to the language and discusses the validation process and runtime system.
INFORUM’22
Uma linguagem de programação com escolhas mistas em tipos de sessão
A abstração e formalização da comunicação inerente a sistemas de software é fundamental para a confiabilidade de sistemas concorrentes. Neste trabalho propomos um sistema de tipos que enriquece os tipos de sessão, permitindo escolhas mistas entre input e output. Na linguagem que propomos, FreestMC, os processos podem, a cada momento, decidir entre ler e escrever num dado canal. Um sistema de tipos de sessão garante, ainda assim, que os processos seguem o protocolo.
2018
INFORUM’18
Uma linguagem de programação com tipos de sessão independentes do contexto
Os sistemas de software distribuídos têm uma comunicação bastante intensiva onde o elevado número de mensagens trocadas entre processos tende a tornar a codificação dos mesmos bastante complexa. Os tipos de sessão foram propostos para responder a esta necessidade, permitindo definir protocolos na forma de tipos que representam "interações corretas" do sistema e que garantem propriedades tais como a inexistência de erros na comunicação e de situações de impasse. Os tipos de sessão tradicionais são descritos por linguagens regulares, permitindo, por exemplo, a definição de protocolos na forma de lista mas não em forma de árvore. Neste artigo apresenta-se uma linguagem de programação concorrente, explicitamente tipificada, onde os processos comunicam exclusivamente por troca de mensagens cujos protocolos são definidos por tipos de sessão livres do contexto.
M.Sc. Thesis
Almeida, B. (2018). Uma linguagem de programação com tipos de sessão independentes do contexto.