Add a 'Repr' pass for generating generic representations#1381
Draft
Add a 'Repr' pass for generating generic representations#1381
Conversation
4 tasks
jiribenes
commented
Apr 16, 2026
Comment on lines
+77
to
+80
| val capId = Id("$rose") | ||
| val capParam = BlockParam(capId, ifaceTpe, Set.empty) | ||
|
|
||
| RoseMetadata(op.id, ifaceTpe, opTpe, capParam) |
Contributor
Author
There was a problem hiding this comment.
This is wrong, it generates a single param id that gets reused in multiple functions, which makes the LLVM backend uneasy
b-studios
added a commit
that referenced
this pull request
Apr 21, 2026
This implements implicits similar to
> Daan Leijen, Tim Whiting: Syntactic Implicit Parameters with Static
Overloading
It also implements their use to get source positions in the code.
### Syntax and Intended Behaviour
Putting a `?` in front of a value/block parameter makes it potentially
implicit. If *trailing* implicit parameters are missing, an argument is
generated as follows (e.g.):
- value argument called `$x`: `$x`
- value argument called `sourcePosition`:
`SourcePosition("somefilename.effekt",10,3,10,6)` (corresponding to the
source position of the called function, ~~without~~ with argument list)
- value argument called `callId`: A statically unique integer for *this*
call (unique within an Effekt compiler run).
- value argument of type `(...) => ... at {...}`: instantiated to `box
{...}` with whatever the block argument would be instantiated to.
- block argument called `$foo` of type `(A){B=>C} => D` : `{ (a: A){b: B
=> C} => $foo(a){b} }` (eta-expanded to allow for this call to also
receive implicit arguments)
- block argument with an interface type, called `$x`: `$x`
### Implementation strategy
- In `Namer`,
- find the set of all implicit parameters that any of the overloads
could require (i.e. for all functions of that name, all implicit
parameters) and generate the source for them already.
- then name-resolve them, but collect errors and just store them (for
now)
- in `Typer`,
- instantiate the arguments (i.e., currently, hardcoded copy of the
block literal and corresponding annotations, or just copying them),
refreshing them and typechecking them against their respective
parameters
- only happens if at this point, no errors were reported in this case
(otherwise, aborts)
- annotate the instantiated arguments
- in `ExplicitCapabilities`, actually change the source to pass the
annotated arguments explicitly.
### TODO and limitations
- [x] ~~Check if this works for more than the existing examples (find at
least the worst bugs)~~ The tests should be testing a good part of
possible uses now.
- [x] This *will* cause *Typer* to run indefinitely or stack-overflow if
the search is not terminated by a type/name error. We could try to catch
those cases somehow, but this is nontrivial (and will reject valid
programs).
- Opinions?
- The recursion is ~~quite indirect (and not actual recursion) in typer,
and~~ (we can check for recursive uses when checking implicit arguments
after instantiating them - this is separate now anyway) at a point where
we don't necessarily have the concrete types (due to unification), so
checking for "decreasing type size" or similar is potentially hard.
- Now aborts if, at the same name, we have 10 levels where the expected
type does not get smaller.
- [x] Syntax bikeshedding
- [ ] If merging this, we might want to change #1381 / #1123 s.t. they
provide only the definitions for base and recursive cases (not for all
types used etc).
---------
Co-authored-by: Jonathan Immanuel Brachthäuser <jonathan.brachthaeuser@uni-tuebingen.de>
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.
Resolves #1374
It's still pretty ad-hoc and I'm planning to continue working on this during downtimes :)