Pages

17 September 2022

ICFP 2022

Here are notes for some of the presentations I attended at ICFP 2022 in Ljubljana, Slovenia. Most of those notes will only be useful for myself but here is my:

TL;DR 

Here are the topics I enjoyed the most (in no particular order):
  • Infinite traversals with the Predictable typeclass
  • David Christiansen's keynote drawing a future for Haskell
  • Modelling probabilistic models with the probfx library
  • Open Transactional Actions to get IO + STM
  • The advent of OCaml 5 with concurrency and associated tooling
  • The ongoing work to make GHC more modular
  • The Functional Architecture workshop (lead by Mike Sperber)
  • The rec-def library by Joachim Breitner
Now for the fuzzy feelings:
  • it is really great to be able to see people in person again. Online conferences are just not my thing. Half the point is being able to have informal discussions
  • it feels great to be part of this intersection of academia and industry. They (academia) give us solutions we (industry) give them new problems
  • I like the melting pot between the various languages like Haskell and OCaml, but also Adga, Coq and all the research languages. Being in the same place really benefits everyone 
  • I am fascinated to see that we are still finding new calculi on top of the lambda calculus with new and better ways to execute them
  • Yes it's still tough to walk around with an imposter syndrome but hey I had a meaningful conversation about a language for quantum computing so it's not that bad :-)
  • Funding is probably still a problem for Haskell, many ideas, not enough time. But there is definitely some momentum. The past months have been better than before and it seems that it's only improving

NOTES

Haskell Implementors workshop (Sunday)

The Haskell Implementors workshop gathers GHC developers and users discussing the evolution of the language and tooling. Here are my highlights for this year. 

State of GHC 

 The 6-months cadence is bringing us useful production-oriented features like: 
  •   profiling without -prof 
  •   stacktraces 
Some notable community initiatives: 
  • the Haskell error message index 
  • proposal: Hackage.X overlay to spread out changes faster (anyone can propose a patch to a library when a new GHC version is out) 
  • proposal: "tick-tock" release cadence -> long-term maintenance releases + frequent non-backported releases 
Compiling Mu with GHC: Halfway Down the Rabbit Hole

Mu is a non-lazy Haskell 98 language used at Standard Charted with millions of lines of code. It contains features not present in GHC to support relational algebra types and programs: 
  • open data kinds 
  • closed type families with fundeps, etc... 
Cortex is the internal language used by Mu and SC is trying to port it to GHC in order to reduce the maintenance burden. It is not trivial because the GHC API is not well-defined nor stable.
One library from Digital Asset helps. ghc-lib-generator turns a GHC source tree into a standalone package (= turns GHC into a library). 

Some code now compiles with GHC much more work remains to be done around specialization/monophormization etc... 

A Termination Checker for Haskell Rewrite Rules

Rewrite rules are generally not checked. We just hope that: 
  • they terminate 
  • they are consistent (produce the same results depending on the order they are being applied) 
GSOL is a termination + confluence GHC plugin which has been used to check 177 Haskell package (that tool won some termination and checking competitions in 2018 and 2022, yes there is such a thing). 

Good news: all those rules are terminating. 
Maybe bad news, there are many non-confluent rules (for example in Control.Arrow

Annotating Deeply Embedded Languages 

Accelerate is a Haskell library to run computations on different hardware like GPUs. It uses a deeply embedded DSL where terms are eventually translated to other programs. 

Problem: how to relate the code which is effectively executed, with arbitrary names, to the names in the original Haskell code? 

Accelerate defined a new constraint which generates compilation error when a HasCallStack constraint is missing in a sequence of function calls. 

type SourceMapped = (?requiresSourceMapping :: ReadTheDocs, HasCallStack) data ReadTheDocs = TakenCareOf sourceMap :: HasCallStack => (SourceMapped => a) -> a

This is probably a good thing for users of free monads but the thing I really need is [exception stacktraces :-). 

Modularizing GHC 

This work is led by a small group at IOG who need to have better backend for GHCJS in order to integrate off-chain JavaScript code in their execution pipeline. 

Problem: GHC is a very old compiler which could benefit from a *lot* of refactorings. The details can be found in ghc-modularity but one obvious example is the sharing of a DynFlags data type which contains dynamic configuration flags which have more than 600 uses. 

We can expect from this work: 
  • easier experiments with GHC 
  • easier integration with other tools in the eco-system 
  • maybe even better performances 
Recursive definitions 

Typical example of an elegant recursive computation in Haskell: compute the transitive closure of a graph. 

Problem: what if the graph is cyclic?

ref-def is a library with a R datatype allowing the recursive definition of sets. It uses unsafePerformIO under the hood but offers a pure interface. 

Across the pond 

 Let's compare the Haskell and the Racket ecosystems. For example Hoogle is nice but 
`hoogle --local` does not work out of the box because it needs information that only Cabal has.

On the other hand all the tools for Racket, documentation, build tool, compiler, etc... are integrated as libraries usable directly from the repl. 

Why is Racket better? 
  • the context is shared by all the libraries / tools 
  • the context API is very stable 
Haskell Playground 

 The Haskell Playground started as a pastebin for Haskell but it supports now several versions of GHC and produces Core/ASM code. Beside the communication and test of snippets this can be very useful to investigate performance and optimisation issues IMO. 

CSI: Haskell: Fault-Localization in Lazy Languages using Runtime Tracing

Idea: use the Haskell coverage support to add trace information when runtime errors occur - since Haskell is lazy it is likely that the producer of a faulty value is going to be close to its consumer If we report this (summarized) trace information in the error report then we have a form of data flow analysis and we can use it to track down the source of faulty data.

ICFP Day 1

Keynote: Programming the network

Network programming is fairly static with a strong division between a "control plane" (what's the topology of the network) and a "data plane"
(how data is routed from one node to another).

But it would be nice to make it more programmable:
  • take an existing in-house network and move it to the cloud keeping the same topology
  • do traffic engineering. Traditionally done with a protocol, today we'd like to run optimisers and change the config more dynamically
  • debug the traffic: understand how a given packet flows
  • support caching, coordination protocols, have failure detectors built into the network
PL techniques can be used to support this. The NetKAT DSL describes links and behaviours which can then be compiled to forwarding tables.
We can also use techniques to make sure that some security policies are maintained when a network is reconfigured.

The Theory of Call-by-Value Solvability

The lambda calculus is a minimal calculus, with no notion of "result".
We need to be able to distinguish divergent terms from other terms.

The proper way, the one that gives a consistent theory, is to define a notion of "solvability":
  • a term is solvable if there is a head context H such that H<t> reduces to identity

This is a way of saying that some non-terminating terms can still be subterms of a terminating term and it's ok. There are different characterizations of solvability and one of them is multitypes (multisets of intersected types)

A Simple and Efficient Implementation of Strong Call by Need by an Abstract Machine

Reminder: call by need is like call by name, terms are only evaluated when required but they are evaluated once. How to implement this calculus efficiently?

 1. Start with an abstract machine (KN machine)
 2. deconstruct it to some functional code (definitial interpreter)
 3. optimise the functional code
 4. reconstruct an optimal machine (RKNL machine)

How can we make sure that RKNL implements strong CBN? This is proven through a "Ghost Abstract Machine" which simplifies the rules

The implementation efficiency is proven via a potential function.

Multi-types and reasonable space

In a computational model time is modelled as number of steps to compute something,
and space is modelled as the maximum size of visited configurations.

We can use multi-types to relate the type of a term to the size of derivation of a subterm, hence give an idea of the time taken. What about space? If sharing is used in a machine (for time reasons) then space is hard to compute.

The Space Krivine Abstract Machine accounts for space: sharing is limited to terms (to account for the size of the input), and garbage collection is eager.

The Space KAM is a good ("reasonable" = linearly closed to the reality) space cost model (there's a translation to a Turing Machine to a Space KAM).

Unfortunately multi-types do not account for the size of closures.
Idea: enrich multi-types with closure types. A multi-set is labelled with a natural number for the closure size.
Then closure types are a complete and sound methodology for the Space KAM.

Future work: type systems for space complexity analysis (this is not doable for time since type inference is an undecidable property)

Denotational semantics as a foundation for cost recurrence extraction for functional languages

Can we use denotational semantics to come up with the equations for calculating the algorithmic cost of a function? Several steps:

 1. transform the program into a writer monad with usage costs
 2. interpret in a model, using naturals to interpret a tree for example
 3. have a theorem to prove that we really have a model of the recurrence language

Random Testing of a Higher-Order Blockchain Language (experience report)

In smart contracts we need to deal with:

 1. static semantic bugs: an exception is thrown and the contract function cannot be executed
 2. cost semantic bugs: not enough gas is charged for expensive computations => DDOS attacks
 3. compiler exploit: a compiler can be exploited by sending some code that blows up the size of the generated program

Can we use property-based testing to avoid this? Scilla is a smart contract language based System F + extensions and is not Turing complete (it has structural recursion).

Scilla has an OCaml monadic interpreter. How to generate well-typed terms for System F?

Use QuickChick (Coq library):
  • easy to define generators for ASTs
  • can generate OCaml code
  • has support for fuzzing
Generating type applications in a bit tricky. The trick is to use "unsubstitution".

Bugs were found in:
  • the interpreter: conversion bugs
  • the interpreter: charged gas
  • typeflow analysis
A Completely Unique Account of Enumeration

Enumerators can enumerate all the values of a data type. This can be useful for testing
in the way that smallcheck and leancheck do with the idea that
"If a program fails to meet its specification in some cases, it almost always fails in some simple case".

This work has found a way to define enumerations that are provably:
  • complete: they list all elements
  • unique: they produce each element once
  • fair: they interleave elements of lists
They have also shown that enumerators can be derived from Generics and keep the same properties. It also works with indexed type families. The paper mentions that Generics with true sums-of-products would be better (I agree, I think that should be the default way to have generics).

After discussing with one of the authors and doing a bit of experimentation I realized
that it was hard to do an enumeration of value by size because of the way recursion is handled in recursive data types. The way it is done, we get an enumeration per depth in a tree for example. I think I need to come back to something like FEAT.

ICFP Day 2

Keynote: Call-by-Push-Value, Quantitatively

The Bang Calculus, introduced in 2016, is a call by push value calculus which encompasses call by name (CBN) and call by value (CBV). It is complete and coherent (It took 4 years and some iterations to prove this!)

Concretely speaking the bang calculus adds some constructs to the lambda calculus:
  •  !t "bang", to make a thunk)
  •  der "dereliction", to force a thunk
  •  explicit substitution.

Then 3 rules are given for its execution:

  1. Beta rule: introduces a new explicit substitution (let binding)
  2. substitution: substitutes a bang term
  3. value/computation "dereliction": der(!t) -> t

This calculus has a resource aware semantic, its complete and confluent (and all evaluation sequences to normal form have the same length We have some translations from CBN/CBV to the Bang calculus (due to Girard in '76). This allows to prove some qualitative properties: soundness, completeness.

What about quantitative properties: how much time / space?

Idea: use non-idempotent multitypes: types are multisets (duplicated elements -> then you can count things!) Those types can type non-terminating terms so there's no decidable type inference.

However it is possible to show some properties like time + space <= nb nodes in type derivation.
It is even possible to go further and find some properties for time and space independently.

Another interesting property is: decide if a type is inhabitable. An algorithm has been defined to do this: it terminates, is sound, complete, and finds all the generators for those terms.

Datatype-Generic Programming Meets Elaborator Reflection

For each datatype defined in Agda, like 'List' we expect to have corresponding proofs
like `here` and `there` to do some lookups:

data Any {p} (P : A → Set p) : List A → Set (a ⊔ p) where
  here  : ∀ {x xs} (px  : P x)      → Any P (x ∷ xs)
  there : ∀ {x xs} (pxs : Any P xs) → Any P (x ∷ xs)

Problem: this is tedious and looks quite mechanical to derive
Idea: use the elaborator reflection to define those data type. This would be a bit like using Generics / TemplateHaskell in Haskell.
Main difficulty; writing generic code is difficult and error-prone

Practical generic programming over a universe of datatypes

This is a variation of the previous talk. Can we derive properties like deriving Eq in Agda?
This team has defined some support for generics (a "universe of descriptions") plus some combinators to be able to do that. And now (among other things) decidable equality can be implemented by just deriving it from some data types.

Structural Versus Pipeline Composition of Higher-Order Functions (experience report)

Context: try to have students solve problems using higher-order functions
Problem: most problems are either too easy or to hard
Insight: there's a difference between structural composition and pipeline composition

structural
  example_fun :: [a] -> b
  example_fun as = hof1 (\inner -> hof2 arg inner) as

pipeline
  example_fun :: [a] -> b
  example_fun as = hof1 f (hof2 g as)

An experiment was run on student and it turns out, contrary to experts intuition, that structural solutions are easier to find.

For example "map elements in a list of lists and filter each list", which is `map (filter condition)`.
The reason for this might be related to program synthesis and the fact that structural composition imposes more constraints on the possible types.

ICFP Day 3

Keynote: Retrofitting concurrency

How to add concurrency to OCaml 4.0?

In 2014, OCaml was used a lot but with a GIL like Python. The objective was to add concurrency without breaking anything:
  • OCaml has low latency ~10ms tolerance. We want to keep an efficient GC
  • we need to make sure that the maintenance burden stays low by not having 2 runtimes like GHC
  • existing sequential programs should run the same
Main points:
  • there were several iterations and even a full rewrite to implement a concurrent garbage collector (major heap -> mostly concurrent, minor heap -> stop the world parallel)
  • working on data races showed the need for a new memory model with a "DRF-SC" guarantee (data-race-freedom sequential-consistency)
  • instead of baking the scheduler in the runtime system like in GHC extract it as a library (trying to extract the Scheduler from GHC's RTS proved to be really hard)
  • implement delimited continuations, they are easier to understand than shift/reset
  • care for users, don't break their code. Most of the code is likely to stay sequential
  • use build tools to ease the transition: OPAM heath check checks the compatibiliy of package on every 5.0-alpha release
  • benchmark on _real_ programs (Coq, Irmin - database, for example). http://sandmark.tarides.com is a benchmarking site as a service
  • invest in tooling
  • it is hard to maintain a separate fork for 7 years, hard to keep up with main
  • it is hard to get approbation from the main developers
  • peer-reviewed papers add credibility to such and effort
  • tooling + benchmarks help
  • the last 10% to finish Ocaml 5 now requires lots of engineering effort, and less of academic effort

Many more things to come with the vision of being as fast as Rust with a GC and have the type safety of ML.

Beyond Relooper: Recursive Translation of Unstructured Control Flow to Structured Control Flow

Control flow in WASM is very simple:
  • if ... then ... else ... conditionals
  • loop ... end loop (no conditionals)
  • block ... end block of code
  • br k escape the current nesting(s)
Problem: translate structured programming with functions, variables, conditionals to the to the form above in a compiler. 

There's a heuristic algorithm for this kind of thing in the JavaScript world (Relooper) but a complete solution has been described since the '70s! That algorithm is hard to understand and has 3 passes. Can we do better?

Yes! Use functional programming and techniques from static analysis

  1. build and ADT
  2. from the outside in
  3. by recursion over dominator trees (which is a notion of which unique nodes need to be executed before executing something else) in the control flow graph
  4. order children by reverse postorder
  5. use control context for branches

Note: within one day Joachim Breitner was able to use his rec-def library to make the code even nicer: https://www.joachim-breitner.de/blog/795-rec-def__Dominators_case_study

Automatically Deriving Control-Flow Graph Generators From Operational Semantics

Various control graphs can be produced from a given program depending on how much information we want to keep. Some analyzers / model checkers need different CFGs. But what is a CFG anyway? Is there a systematic way to derive a CFG from the semantics of a language?

The answer is yes by using abstract machines and abstract evaluation

Analyzing binding extent in CPS

"we are the anti-MLton". MLton is a full program SML compiler for high-performance executables:
  • by monomorphization
  • by defunctionalization
3CPS is a totally different approach:
  •  flexible
  •  separate compilation
  •  keep polymorphic terms
  •  aimed at making FP fast
Problem
  FP is all about keeping track of the environment.
  when there are closures some bindings must move from the stack to the heap

Idea:
  • define 3 "extents": heap / stack / register
  • every variable has an extent describing its lifetime
  • heap extent: every variable has it but it is the most heavyweight machine resource
  • stack extent: the binding lifetime must be shorter than the stack frame around it. As a syntactic approximation: If there's no reference from x in a lambda it's ok (because we don't need a closure)
  • register extent. As a syntactic approximation: there is no function call between the definition of a variable and its uses
The paper shows how to do a lot better than syntactic approximations and as a result rewrites some programs so that 90% of their variables can be moved to the stack. And this analysis is fast to perform.


Question from SPJ: "I envy your work, how will it work for lazy evaluation?". 
Answer "it's always a good thing if SPJ is envying your work etc..." (I did not understand the answer :|)

Note: this work looks actually quite close to the work presented by Stephen Dolan on using global / local modalities to keep values on the stack.

do Unchained

Context: reimplementing Lean 4 in Lean
Problem: some imperative C++ was hard to translate, the do notation had to be used
Idea
  • implement some "imperative lean" with a new syntax
  • model effects as monad transformers: mutation becomes State, return becomes Except monad, for in / break / continue become ExceptT + fold + ExceptT
It was first implemented as a macro in Lean.

Consequences:
  • "invisible destructive updates"
  • intensively used in Lean 4 but also in 31 out of 43 repositories, people are even starting to use it with the identity monad
Fusing industry and academia at Github

Semantic is a tool which can understand 9 targets languages  (no Haskell yet because the syntax is a bit complex, and there are less users than ruby :-)) and:
  • helps make a table of contents in PR
  • provides code navigation. This is a high traffic service, no issues or outages
4 case studies in how academia helped:

 1. parsing: they are many parsers, one for each language. Running native tooling is not maintainable. tree-sitter is an incremental, error-tolerant parser. The grammar is in a JavaScript DSL. It gives a consistent API. It is based on GLR parsing, sufficiently expressive for Ruby and fast enough for Github

 2. syntax: can we share syntax types? Yes with a data types a la carte approach, including the case where the code can't parse. The team implemented fast-sum, an "open union" record to work with > 140 syntax nodes for Typescript.

 3. diffing: can we have syntax-aware diffing to get better diffs? Using recursion schemes helped here because diffing is a recursive operation

 4. program analysis: understand programs!
    Implementing this necessitated a new effects library to mix several state effects + non-determinism => fused-effects

Difficulties:
  • a la carte syntax is a bit imprecise
  • build times, editor tooling
  • Generic programming is hard
Successes:
  • 30k req/min -> one bug one day because of a crash in the GHC event loop (because of one particular issue with Dell servers)
  • tree-sitter became foundational
  • recursion schemes work great
  • algebraic effects are awesome
Modelling probabilistic models

A probabilistic model is aa set of relationships between random variables. For example a linear regression. We can use it in 2 ways
  • simulation: to simulate some outcome
  • inference: to compute the model parameters based on the observations
ProbFX is a Haskell library doing this elegantly. The models are:
  • first-class citizens
  • compositional
  • typed
Example

HMM: Hidden Markov Model -> takes a transition model, an observable model for one node and replicates it to get a chain. This can be used to model an epidemic with the the SIR model (susceptible / infected / recovered).

Constraint-based type-inference for FreezeML

'70 Hindler-Milner type inference (algorithm W)
'80 constraint-based type system and inference (more extensible than algo W). Pratically used by GHC
'90 ML with first-class polymorphism (supporting forall a. [a] -> [a], polymorphic instantiation forall b. b -> b/a) -> large design space
'20 FreezeML tries to use algorithm W, focuses on simplicity

single :: forall a. a -> [a], id :: forall b. b -> b

what is single id?

FreezeML uses "freezing" to distinguish the 2 cases:

  single id : [a -> a]
  single |id| : [forall b. b -> b]


Linearly Qualified Types: Generic inference for capabilities and uniqueness

A linear function 'a %1 -> b' should be read as "if the function is consumed exactly once then the resource is consumed exactly once". When your code requires a linear function then you can pass a resource to that function and you know that it will be used safely

Problem: some simple cases are still quite ugly to implement

swap :: Int -> Int -> MArray a %1 -> MArray a
swap i j as =
  let
    !(as, Ur ai) = get i as
    !(as'', Ur aj) = get j as'
    as''' = set i aj as''
    as'''' = set j ai as''''
  in
    as''''

Idea: use GHC constraints (and define "linear constraints")

swap :: RW n %1 => Int -> Int -> MArray n a -> () < RW n
swap i j as = let
  !Ur ai = get i as
  !Ur aj = get j as
  !() = set i aj as
  !() = set j ai as
  in ()

newMArray :: Int (MArray a %1 -> Ur b) %1 -> Ur b

fromList :: Linearly %1 => [a] -> Array a
fromList as = do
  let arr = newArray (length as)
  let arr' = foldr (uncurry set) (zip [1..] as)
  freeze arr'

Haskell Symposium Day 1

Keynote: Cause and effects

This was mostly a talk about "Why I fell in love with Haskell and effects" and a QandA session around fused-effects.

Principle of least privilege: using Alternative instead of Maybe gives you additional power. Because then you can use List, NonDeterm etc... Just require what you need and not more.

Question: checked exceptions can be painful. Did you feel that pain?
Answer:
  • one possibility: one error type to rule them all -> bad because coupling
  • one effect per error type: annoying to track
  • good: prism to extract a specific type out of a global error type. Note: we can do the same thing with lenses and State where we project only the state we need
Question: what about purity? what about having to lift?
Answer: purity / impurity is not so much the question but value vs computation is more relevant.
        For example when getting results if we get a value we get the "least privileged entity" in a sense

Functional Architecture open space

This was not part of the Haskell symposium but I had the opportunity to discuss functional architectures around:
  • writing modular applications with records of functions (I quickly introduced registry)
  • are large architectures still functional? (cf "turning the database inside out" and what is done at Standard Chartered with relational data as data structures)
  • the pitfalls of domain modelling (we traded some examples)
Kudos to Mike Sperber for organizing this!

A Totally Predictable Outcome: An Investigation of Traversals of Infinite Structures

Traversable functors have been fully characterized as being polynomial functors.
But this proof only works in a finitary setting! What about Haskell with its infinite lists?
For example we cannot traverse an infinite list with Maybe because we need to know if there is a Nothing in the list at some stage.

Short answer: infinite traversals are productive iff they use "Predictable Applicative functors".

newtype Later a = Later a deriving (Functor, Applicative)
predictable :: Later (f a) -> f (Later a)

There are more Predictables than Representables (ex Writer)
There are Predictables that are not Applicatives
There are Predictables that are not strictly positive

The paper explores all of this including the traversal of bi-infinite lists where you can infinitely append elements on both ends!

Open Transactional Actions: Interacting with non-transactional resources in STM Haskell

We want to be able to use IO in STM Haskell. Open Transactional Actions allow this:

newtype OT a

liftIO :: IO a -> OT a
onCommit :: IO () -> OT ()
onAbort :: IO () -> OT ()
abort :: OT a
runOT :: OT a -> STM a
```

Once you have described what it means to commit and abort you can mix IO and STM resources.
Examples:
  • file access with file locks
  • unique id generator
  • concurrent hash set
  • concurrent linked list
Haskell / OCaml symposium Day 2

Keynote: Industrial strength laziness

Can we build and publish about tools?

Publishing challenges:
  • expert users are expensive
  • inexperienced programmers are only one target group
  • how to do user studies well
  • what we can measure might not be the most relevant to practice. "my refactoring does not introduce bugs" is good but not the only thing
  • maintenance of tools gives no tenure
  • maintenance takes a lot of time (GHC churn etc...)
Some dreams

Dream 1: context aware editor for actions. For example Scala and .
Dream 2: incremental feedback
Dream 3: Haskell debuggers
Dream 4: Add typeclass laws to typeclass definitions -> this gets us automated refactorings! and we can generate tests
Dream 5: Calculate programs (cf Idris with specification / case splitting), better integrate Liquid Haskell
Dream 6: Extensible documentation (inspired by scribble) to add diagrams for example. Better integration of tutorials
Dream 7: Static semantics for software evolution -> checking API compatibility
Dream 8: How should big teams build big applications with Haskell?

Make an impact

Pay attention to what other communities value. Example design patterns, we can still some in Haskell As a high-pain tolerant community we need to attract low-pain tolerant people

The Haskell Foundation
  • funding CI for GHC
  • the Haskell Error Index. This made to support other tools, like Cabal, Stack, HLS, etc...
  • security advisories: as a data source for cabal, dependabot. To ease ISO 27001 certification
  • the haskell interlude podcast
  • the haskell optimisation Handbook (organised by Jeffrey Young -  from IOG)
  • support the community process and audit of the "lottery factor" (better name than the "bus factor" IMO)
  • technical Working group, stability working group
Questions:

How to help with accessibility of the language?
  • filter out the "good" libraries
  • have a culture of using GHC2021 as the default extension
  • promote only 2 books on the front page

Suggestion: large scale refactoring tools, have hints of performance optimisations
Suggestion: talk to M. Snoyman to pick up the case studies they did
How to help people get on board with developing on GHC, HLS etc...?
SPJ: how can we push existing programs to use LiquidHaskell?

Efficient “out of heap” pointers for multicore OCaml

A page table classifies if a pointer is inside the major heap. People starting storing pointers to outside the OCaml heap. In OCaml 4.14: speed-up GC with prefetching.
This works shows that a page table can speed-up marking even with concurrency and have other uses: huge pages, etc...

Memo: an incremental computation library that powers Dune

Memo supports Internal incremental building in dune (OCaml build tool) with
  • parallelism
  • memoization: we don't want to re-read a file many times
  • let* is a bind in OCaml
  • errors are de-duplicated (it kind of memoize / de-duplicate errors and keeps stack traces)
  • it is incremental and if errors are fixed they disappear
Dune is not yet used at Jane Street because 30 millions of lines of code and Dune is not yet fast enough (the graph is too big).

Problem: what about cycles / deadlocks in the build graph? Not trivial to detect deadlocks with concurrency
Solution: use incremental graph detection. The naive solution doesn't scale. Bender 2015 provides a solution and a working library (even proved in Coq). It is in O(m (square-root m)) which is not yet optimal for Jane Street.

Idea: skip the reading edges (still took 35% of the build time)
Idea: check only paths that lead to blocking edges (now execution time is negligeable - but no proof of correctness yet)

Further work: graph flattening, bottom-up/top-down traversal (start from the leaves), storing memoization tables on disk, generalize to other concurrency monads.

Stack allocation for OCaml

Short lived allocations are cheap but not free:
  • space is not reused quickly
  • poor L1 cache usage
  • GC advances towards the next release
We could write all our code in the same function, but how can we safely use several functions? 

Rust with lifetime annotations allows this but is syntactically overweight. It can be polymorphic and higher-order functions become higher-rank which means that type inference stops working.

This work uses a different approach with modal types:
  • local or global applied to variable bindings
  • local bindings never escape their region
  • global bindings can never refer to stack-allocated values
  • less expressive than region variables but simpler
The modalities show in the function types

  string -> unit vs local_ string -> unit

Functions can also return values on the stack. They get allocated on the parent stack frame

Examples

val iter : local_ ('a -> unit) -> 'a list -> unit
  the closure can not be captured by iter
  let count = ref
  List.iter ... (use count)

  in that case the count ref can be local because it won't escape iter

What about tail-recursion? To make sure it works we need to make sure that we don't grow the stack.

What about currying? the first iter is not the same as val iter : local_ ('a -> unit) -> ('a list -> unit)
it more like val iter : local_ ('a -> unit) -> local_ ('a list -> unit) so eta expansion might be necessary

What about the with_resource pattern?

val with_file : filename: string -> local_ (local_ filehandle -> 'a) -> 'a

This means that this simple addition to the type system could be useful in other contexts (proving that the file handle is not captured, modifying mutable arrays etc...)

Continuous monitoring of runtime events

Run health checks in production, do some analysis. New in OCaml 5.0
  • most probes in the default runtime
  • APIs (OCaml, C)
  • controllable with env. variables
  • very low overhead
Implemented with:
  • per-domain ring buffers: one producer / many consumers (this means that events will be overwritten and can be missed)
  • file backed memory mapped so accessible from outside processes
30ns when enabled, 0.8% in retired instructions

Next:
  • new runtime probes
  • custom events
  • more work in libraries and tooling
Programming is (should be) fun!

Programming is not coding
  • there's often no good specification to meet, just a vague understanding
  • joint exploration of achievable specifications, possible implementations
  • it rarely relies on physical parameters for mechanical tolerance etc...
  • we are limited by our ideas and the arising complexity
This means that bugs are not just programming errors, they are an opportunity to learn:
  • they should have names and mitigation strategies
  • it's ok to have bugs. We start with simple assumptions and we explore the space of what's possible
Gerald shared some of his insights with Maxwell's equations, eval/apply in a Scheme interpreter, electric circuits, classical mechanics or how they (re)discovered automatic forward differentiation with a colleague with the use of differential objects

Philosophy is also never far from programming with questions about: referent expressions, identity, mutation, the Ravens paradox, etc...

In summary programming is fun because it brings :
  • the pleasure of analogies
  • philosophical contemplation
  • the pleasure of debugging, of the hunt
  • the pleasure of discovery of good ideas
  • the pleasure of clarity: make difficult subjects clear
and it's even better when we share it as fre (libre) software: cf gnu.org/philosophy/free-sw.html

No comments: