Skip to content

Replace the function inlining mechanism with new platform operators#1484

Merged
pavpanchekha merged 19 commits intomainfrom
functions-in-platform
Apr 25, 2026
Merged

Replace the function inlining mechanism with new platform operators#1484
pavpanchekha merged 19 commits intomainfrom
functions-in-platform

Conversation

@pavpanchekha
Copy link
Copy Markdown
Contributor

@pavpanchekha pavpanchekha commented Jan 27, 2026

In Herbie, you can write a named FPCore, as in (FPCore name (...) ...). Then, in later FPCores, you can write (name <expr>) to call that FPCore; you have to do the correct number of arguments and types and everything but it'll do what you expect. Currently, the way this works is a little hash table on the side called *functions* storing named FPCores and their definitions; when the desugarer sees one of these named functions, it'll inline the definition.

This PR switches functions to just use the platform feature. When Herbie sees a named FPCore, it'll add that an operator to the current platform, using the name for the :fpcore format and the spec and implementation for the operator spec and impl. Herbie will now generate direct calls to this operator, which is nice, and the rewriter still has access to the spec so can inline if it wants.

WIP:

  • I don't think this works with places; it probably needs a re-register pass somehow for places, or we need to switch to parsing in places.
  • I'm a bit worried that we'll generate self-calls or reverse-calls. Maybe that's fine, because right now we do expect humans to manually update the FPCore?

@pavpanchekha
Copy link
Copy Markdown
Contributor Author

An update on this PR. It now seems correct. I have reviewed all but the big four files: read.rkt, platform-language.rkt, load-platform.rkt, and platform-state.rkt. I think the contents of those are correct but I am not thrilled with the internal APIs.

@pavpanchekha pavpanchekha marked this pull request as ready for review April 19, 2026 20:41
@pavpanchekha
Copy link
Copy Markdown
Contributor Author

I'm now pretty happy with results, but the nightly fails. Will investigate, but I think we're close to merging.

@pavpanchekha pavpanchekha merged commit 1dbb0fc into main Apr 25, 2026
6 checks passed
@pavpanchekha pavpanchekha deleted the functions-in-platform branch April 25, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant