Implement Typed IR#504
Conversation
This will be replaced with `Symbol.erasedType`.
`Call`, `Lambda`, `Select`, and `DynSelect` is left for a future commit.
LPTK
left a comment
There was a problem hiding this comment.
Some possible next immediate steps:
- Update printer to show the erased types at variable and member declaration/definition sites.
- Update
Loweringso it generates erased types from parameter type annotations, to be used to annotate the correspondingVarSymbol. - Make sure we are never overriding an existing erased type in a given symbol by using
softAssert, as a sanity check.
A subtlety we should get right: the erasure of annotated class parameter types should successfully propagate to their defining fields. Param has a ``fldSym` which can be used for this.
| new Rewriter(instId).applyBlock(ogBody), | ||
| mkReturnCall(restFunSym, restFunArgs)) | ||
| val refreshedFvSymbols = dtorBranchFnFvs(branchId._1).map(s => s -> new VarSymbol(Tree.Ident(s"fv_${s.nme}"))) | ||
| val refreshedFvSymbols = dtorBranchFnFvs(branchId._1).map(s => s -> new VarSymbol(Tree.Ident(s"fv_${s.nme}"), erasedType = N)) |
There was a problem hiding this comment.
It seems many cases like this one should carry over the previous erasedType somehow.
|
The current task list (work items created by me, organized by AI):
|
What does that mean?
This should be moved to phase B. In fact, it's the first thing yoiu should do, just so you can actually see what you're doing! |
Good point, I have updated to task list. |
Refinement of types during Lowering is implemented later.
After some really deep sessions and several MREs, here is the root cause of the issue: As expected, Binaryen's Example: (type $Object (sub (struct)))
(type $O (sub $Object (struct (field $i i32))))
(type $O_ctor (func (result (ref $O))))
(type $entry (func (result (ref null any))))
One solution is to use (type $Object (sub (struct)))
(rec
(type $O (sub $Object (struct (field $i i32))))
(type $O_ctor (func (result (ref $O)))))
(type $entry (func (result (ref null any)))) ;; (rec (type $entry ...))However, this would introduce a more subtle issue - If two classes have exactly the same type on everything, except one field, method parameter, or result type just so happens to be uninferrable in the IR and is coerced down into I can only think of two ways moving forward.
Let me know what you think about this. Edit: The MREs can be found here |
|
Thanks for looking into this!
Yes, can we just fork Binaryen, fix this, and open a PR? In the meantime, we just use our own fork. Can be done either with a Git submodule or by publishing our own npm package for the fork (or some other solution, whichever you prefer). |
Done in #536, although not as a submodule - I instead forked the Binaryen repo, patched it to add |
|
Please fix the conflicts of this branch, and let's try to merge it soon, isntead of letting it diverge again over weeks. |
|
Implemented this week:
Remaining Items as of this week:
Additional good-to-have refactoring:
All of these will be worked on the week after, and I'll go through the entire patchset and clean it up before marking this as ready for review. |
| blockImpl(stats, res) | ||
| case DefineVar(sym, rhs) :: stats => | ||
| term(rhs): r => | ||
| // Seed the binding's erased type before lowering the continuation, so that a later use of |
| // A local consumed by a *later* statement in the same (non-hoisted) block is | ||
| // seeded before that statement is lowered, so its erased type survives: both `n` | ||
| // and the forward use `m` stay `Int`, and the inferred return is `Int`. |
There was a problem hiding this comment.
This is all bs and not what I asked you to do at all. It's not the right design. I've already told you the types of variables are to be resolved by a resolver pass before Lowering. I never asked you to reimplement a broken and incomplete form of type inference...
You need to slow down with Claude, take a step back, and actually think about the design and about what your actual task is. And ask me before you make such choices in the design of the compiler.
|
TODO:
|
No description provided.