Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow partial function evaluation to be caught by bindings #967

Merged
merged 13 commits into from
Feb 8, 2024

Conversation

Baltoli
Copy link
Contributor

@Baltoli Baltoli commented Feb 5, 2024

This PR extends the backend's ability to recover from errors when partial functions are evaluated in the context of a bindings library. Rather then unconditionally crashing the entire host process, we throw an exception that the bindings code can catch and translate to a C-ABI error structure for the backend to deal with.

Previously, we implemented this behaviour for hooks (#955); this PR does the same for general partial function evaluation. The changes are as follows:

  • Refactor (as discussed previously) the implementation of finish_rewriting from LLVM IR into C++.
  • Add a new code-generation flag to enable the new error behaviour.
  • Modify llvm-kompile to pass this flag when compiling a bindings library.
  • Read the flag to change behaviour in the appropriate places in the runtime library.
  • Add a test that the C bindings can safely try to evaluate undefined partial functions and catch an error when the evaluation fails.

Fixes #925

The majority of the code here doesn't need to be written as hand-coded
LLVM (bar one tailcc call), so we can push the implementation into C++
to make subsequent refactorings easier.
@Baltoli Baltoli self-assigned this Feb 5, 2024
@Baltoli Baltoli marked this pull request as ready for review February 6, 2024 12:00
Copy link
Contributor

@gtrepta gtrepta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rv-jenkins rv-jenkins merged commit 01b4196 into master Feb 8, 2024
7 checks passed
@rv-jenkins rv-jenkins deleted the safer-partial branch February 8, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose "safely evaluate partial function" binding
3 participants