IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.57k stars 479 forks source link

[Epic] Internals of builtins #4306

Open effectfully opened 2 years ago

effectfully commented 2 years ago

This issue is for dumping all the plans regarding builtins in a largely unstructured way.

effectfully commented 2 years ago

A lot of from the above has to be changed to become more efficient/expressive/etc. We'll need both major refactoring and small tweaking. This comment is about major refactorings.

effectfully commented 2 years ago

Minor things, all fairly low priority:

effectfully commented 2 years ago

The comment about major refactorings does not include two big things:

  1. documenting builtins
  2. collaborating with James to incorporate extensible builtins into the metatheory

It's probably too early to think about the latter right now, given how much the whole builtins machinery is going to change (if everything works out), so I'll focus on the former.

The inline docs in the source code are fairly good, they might use some polishing, but overall they seem pretty comprehensive. What is missing however is a high-level overview of the whole builtins machinery that one can read before diving into the specifics of each of its parts. We do have one such file, Builtins.md, but it was written long ago and it doesn't talk about polymorphic built-in types, builtin meaning inference etc.

Another thing we need is a doc (and presentation) on how to add a new built-in type or function. After all the recent refactorings it's completely trivial to add a new built-in type (regardless of whether it's monomorphic or polymorphic): it's basically just warnings/errors-driven copy-paste, but adding a new built-in function is trickier, because the polymorphic function over a polymorphic built-in type case is so much different to the other cases (improving upon the status quo is one of the major tasks).

PRs:

effectfully commented 2 years ago

Performance improvements in builtins-related PRs (each number is the mean performance change for validation benchmarks):

4173: -8.23%

4230: -5.09%

4264: -2.42%

4307: -12.01%

4317: -2.01%

4379: -1.78%

4397: -2.75%

4398: -2.02%

4421: -4.87%

4481: -6.7%

4496: -2.59%

4505: -3.2%

4516: -5.88%

4587: -7.91%

4778: -4.56%

4914: -10.35%

5061: -1.16%

5239: -3.12%