16. Interop and ABI
TL;DR (5 lines)
- Interop is a narrow boundary, not a default tool.
- The chapter should expose coupling cost clearly.
- Unsafe or foreign edges must stay visible.
- Safe wrappers are part of the teaching model.
- The goal is controlled integration, not hidden magic.
Frequent mistakes
- Letting foreign assumptions spread through ordinary code.
- Skipping the boundary rationale and teaching raw syntax only.
- Using interop examples with no visible safe wrapper around them.
Prerequisites: book/chapters/15-pipeline.html. See also: book/chapters/15-pipeline.html, book/chapters/27-grammar.html, book/chapters/31-build-errors.html.
Concrete Problem
Interop pages become dangerous when they normalize foreign boundaries instead of isolating them.
Red Thread (Single Project)
One narrow bridge surface translates between a Vitte-facing contract and an external-facing edge.
For what
This chapter helps the reader keep foreign or runtime boundaries explicit and narrow.
What you are going to do
You will inspect one bridge-like helper, then compare it to a misuse where the foreign edge leaks too far.
Coherent example
space demo/interop
unsafe proc call_host(code: int) -> int {
if code < 0 { give 11 }
give 0
}
Global explanation
Interop is not a convenience feature. It is a coupling boundary. The chapter should therefore explain why the foreign edge exists, how narrow it is, and how the rest of the program stays readable around it.
Invalid case
proc leaked_host(code: int) -> int {
unsafe
give code
}
This invalid case is intentionally small. It exists to isolate the contract failure that the chapter is trying to teach.
Common pitfalls
- Letting foreign assumptions spread through ordinary code.
- Skipping the boundary rationale and teaching raw syntax only.
- Using interop examples with no visible safe wrapper around them.
Short exercise
Wrap the interop call in a safer procedure that exposes a domain-oriented result instead of a raw foreign detail.
Summary in 5 points
- Interop is a narrow boundary, not a default tool.
- The chapter should expose coupling cost clearly.
- Unsafe or foreign edges must stay visible.
- Safe wrappers are part of the teaching model.
- The goal is controlled integration, not hidden magic.
Mini quiz
- What contract is the coherent example trying to make explicit?
- Why does the invalid example fail?
- What boundary should remain visible if you extend the example?
See also
Next best action
Extend the coherent example by one small, justified step and keep the same contract visible from input to output.