Repository navigation
FFI: keep the safety of a foreign import in the AST - #576
Merged
Merged
Conversation
A foreign import can be marked unsafe, safe or interruptible. Add a Safety type and record the annotation in ForImp, with Safe when none is given, as in the Haskell report, and show it in the pretty printer. Nothing uses it yet, so the generated code is unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
dmjio
added a commit
to haskell-miso/MicroHs
that referenced
this pull request
Nov 12, 2026
Resolve conflicts with augustss#573 and augustss#576: ForImp now carries the Safety field, and tests/Makefile has both testforimpforall and testffiname. generated/mhs.c is regenerated from the merged source. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is the split-out you suggested in #561: the safety annotation of a
foreign import(unsafe,safeorinterruptible) is now recorded in the AST. Nothing uses it yet, so the generated code is unchanged.Changes
MicroHs.Expr: a new typeand
ForImpcarries it:The pretty printer shows it.
MicroHs.Parse:pSafetyreturns the annotation. When there is none, the result isSafe, which is the default in the Haskell 2010 report (section 8.4.3).MicroHs.TypeCheck,MicroHs.Desugar: the pattern matches onForImptake the extra field. The type checker passes it along and the desugarer ignores it.Notes
foreign import ccall safe ..., since the AST does not record whether the keyword was written. If you would rather have this printed only when it was given (for example with aMaybe Safety), I am happy to change it.dsDefas FFI: allow an explicit forall in the type of a foreign import #574, so whichever is merged second will need a small rebase. I will take care of that, and of rebasing JavaScript FFI for the emscripten target #561 on top of this.Testing
make runtestpasses, andhlintreports no hints for the changed files.generated/mhs.cis regenerated in a separate commit.Thank you for the review and the guidance on #561.