Repository navigation
docs: correct three effects limitations that were broader than the truth - #565
Merged
Merged
Conversation
Two of the limitations recorded on the showcase were not limitations, and the
third described a failure mode the compiler no longer has.
Capabilities are not stateless. Capability methods have no `self`, which is
true and worth saying, but the note went further and said Flow has no mutable
globals, so a handler "cannot accumulate state (e.g. a real collecting
test-spy or a metrics counter)". Both of those work:
let mut call_count: i32 = 0
capability CountingLogger {
effect Log,
function info(msg: string) -> void { call_count = call_count + 1 },
}
-> handler ran 3 times
A spy collecting numbers into a static array works too. The real limit is the
type: module statics must be a primitive, a fixed array of primitives, or
ptr<T>, so a handler accumulating strings or structs has nowhere to put them.
That is now what the page says, with issue #562 for the underlying question.
Dynamic capability objects no longer fail the way the note describes. It said
the `capability EffectName` parameter style "type-checks and generates C
syntax-cleanly" and then silently falls back to zeroed defaults. It does not:
strict type checking rejects it, and under --lenient it emits C referencing an
undeclared identifier. Still bad, but loudly rather than silently, and worth
saying accurately. Issue #561.
The type-inference workaround is removed. `let m: string = msg` existed
because capability method bodies did not know their own parameter types, so a
string parameter printed as a float. Fixed in #560, so the example now passes
the parameter straight to printf and still verifies.
A stated limitation that is not real costs readers work, which is why these
are worth correcting rather than leaving.
Effects showcase: 27 of 28 blocks verified, the last one an intentional
pattern illustration. Unit 1517 passed, links clean.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
From the limitations list. Two of them are not limitations, and the third describes a failure mode the compiler no longer has. Issues filed for the ones that are real: #561, #562, #563, #564.
"Capabilities are stateless" — not true
The note said Flow has no mutable globals, so a handler "cannot accumulate state (e.g. a real collecting test-spy or a metrics counter)". Both of those work today.
A metrics counter:
A collecting spy, into a static array:
Capability methods have no
self, which is true and worth saying. The real limit is the type: module statics must be a primitive, a fixed array of primitives, orptr<T>, so a handler accumulating strings or structs has nowhere to put them. That is now what the page says, with #562 for whether the restriction should be widened."Dynamic capability objects fall back to zeroed defaults" — no longer
The note said the
capability EffectNameparameter style "type-checks and generates C syntax-cleanly" and then silently ignores the parameter, which would be the worst possible outcome. It does not do that:and under
--lenientit reaches clang and fails there:Still bad — a clang error about a symbol the author never wrote — but loud rather than silent. Corrected on the page, with #561 for making it a proper Flow diagnostic or implementing it.
The type-inference workaround is gone
let m: string = msgexisted because capability method bodies did not know their own parameter types, so astringparameter printed as a float. Fixed in #560. The example now passes the parameter straight through and still verifies.Why this is worth a PR of its own
A stated limitation that is not real costs readers work: it pushes them to a more awkward pattern for cases the language already handles. Two of the three here would have done exactly that.
Validation
check_doc_examples.py --check-ledger,check_doc_links.pyclean