Files
topics_compiler/slides/main.md
T
2026-06-02 22:57:36 +02:00

1.5 KiB

theme, paginate, _paginate, footer, _footer, style
theme paginate _paginate footer _footer style
dracula true false Topics in Compilers and Concurrency · Julius Fischer · 10.06.2026 h1 { position: absolute; top: 60px; left: 75px; right: 75px; }

Destination Calculus:

A Linear 𝜆-Calculus for Purely Functional Memory Writes

Topics in Compiler and Concurrency

Julius Fischer

10. Juni 2026

What are Destinations?

  • Destination Passing Style
    • Imperative
    • Function takes destination instead of returning structure

Example in C

int* vec_add(int v1[], int v2[], int size) {
    int* res =  malloc(size * sizeof(int));
    for (int i = 0; i < size; i++) {
        res[i] = v1[i] + v2[i];
    }
    return res;
}
  • Add an 'out parameter'
void dps_vec_add(int res[], int v1[], int v2[], int size) {
    for (int i = 0; i < size; i++) {
        res[i] = v1[i] + v2[i];
    }
}

Motivation for DPS

  • Typical functional map implementation
map f (x:xs) = (f x : map f xs1)
> (f x : map f xs) 
> (map f x1 : (f x2 : map f xs2)) 
> ...
  • Not tail recursive
    • Performance issue
    • Inefficient stack growth
map f (x:xs) dest = map f xs (push dest (f x))
> map f xs1 (push dest (f x1))
> map f xs2 (push dest (f x2))

DPS in functional languages

  • Just add pointers to mutable data?
    • Int \mapsto Int \mapsto Int \mapsto \textcolor{red}{T}
    • \textcolor{red}{T *}\mapsto Int \mapsto Int \mapsto Int \mapsto Void

Destination Calculus

  • It's

Referenes