Open ameeratgithub opened 5 months ago
One approach is to have type checker that generates WASM types and is only compatible with the compiler. Another approach is to have similar structure of type checker to that of the interpreter but corrected. These types will be converted to WASM types as we're doing right now. The latter approach looks easier to implement and seems like it will take a lot less time than the former.
@obycode it would be great if you could give us your valuable input, particularly how much time it should take.
We cannot use Wasm types for the type-checker, as we lose a lot of information when converting Clarity types to Wasm types. I think the main problem with the current implementation is that there is not a pass to propagate the type inferencing through to all expressions. I think it would be reasonable to have an initial implementation of this done in a week, but then I would allow 4 weeks for completion. Thankfully, we already have lots of testing in place to validate these changes.
When implementing this type-checker, we should have two goals:
Thanks for your suggestions @obycode . I'll keep these in mind and will let you know if I need any help.
We've seen many problems in type-checker and many of them are scattered across different issues. If possible, it would be great if we can write those snippets at one place.
For those who aren't familiar with the details, I'm just going to explain one problem for now. Consider the following snippet
(list none none)
It returns
OptionalType(NoType)
and it does make sense, because it has no context. Now consider the following snippet(define-private (foo (el (optional int))) (is-eq el none)) (filter foo (list none none))
List shouldn't have type
OptionalType(NoType)
in this context because we're using this list withfoo
which acceptsOptionalType(Int)
.(list none none)
is compatible withOptionalType(Int)
so we should updateOptionalType(NoType)
toOptionalType(Int)
.There are many issues like this and having a bottom-up type checker can solve this problem effectively. With the bottom-up type checker, issues would be easier to solve because
none
)list
based on its elements.foo
to determine the type of(list none none)
).How long should it take? I had 1-1.5 weeks in my mind but may be I'm wrong here. Please feel free to correct me if I'm wrong or missing something.