Back To Schedule

Generic Arity: Definition-Checked Variadics in Carbon

09:00 - 10:30 Thursday 2nd May 2024 MT Lauder Seminar Room
Advanced
Future C++

In this talk, I will describe an approach to modeling variadic functions in the type system, by treating them as strongly typed functions that are generic over their arity, rather than as templates that are instantiated and then duck-typed. This forms the basis of the current proposed design for variadic functions in Carbon, an experimental C++ successor language.

Variadic functions are functions that are generic with respect to the arity (number of parameters), rather than only the types of the parameters. In C++, each instantiation of a generic function must be typechecked separately. However, in Carbon, generic functions can be definition-checked, meaning that the function body is fully type-checked once, using only the type constraints declared in the function signature. To extend Carbon's approach to variadic functions, we have to be able to reason about variadic argument lists as values with types, and solve problems like:

  • How do we represent types with variadic components?
  • How do we type-check function calls when we don't yet know which arguments correspond to which parameters?
  • How can the syntax provide enough type information for definition checking to succeed, without overwhelming the business logic?

Carbon also prioritizes build performance, so we need a way to express variadic logic that can avoid the quadratic overhead (or worse) that often arises from C++'s recursion-oriented variadics model. And, as a C++ successor language, we need to do all that without compromising the expressive power of C++ variadics.

I will give an overview of how we plan to solve these problems in Carbon, enabling both tools and users to reason about the correctness of variadic code once and for all, rather than one instantiation at a time. You don't need previous familiarity with Carbon; I will introduce the relevant parts of the language as part of my talk.

View Slides

Geoffrey Romer

Software EngineerGoogle

I'm a software engineer at Google, where I work on the Carbon project. I'm the lead designer for Carbon's support for sum types, subscripting, and variadics, among other things, and I've contributed extensively to the prototype Carbon interpreter. Prior to that I was a member of the C++ Libraries team, where I wrote Google's C++ concurrency guide, created the initial design for the Abseil hash framework, and authored the Core Coroutines C++ standard proposal. I'm also a co-owner of Google's C++ style guide.