Add typechecking compiler pass#37
Conversation
This seems natural to me. |
SpaceManiac
left a comment
There was a problem hiding this comment.
Minor things from first pass review, looks good overall
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
| pub enum PrimitiveType { | ||
| Unit, |
There was a problem hiding this comment.
Long term, if we're looking to track the Wasm component model, we'll want I/U 8/16 and char. But this doesn't need to happen now.
There was a problem hiding this comment.
I agree with having those types, but I'm not sure we necessarily need 1 to 1 parity to the wasm component model.
| pub enum ComparableType { | ||
| // TODO: unify with codegen StaticType? | ||
| Primitive(PrimitiveType), | ||
| Intermediate, |
There was a problem hiding this comment.
Maybe TokenIntermediate for clarity / to avoid confusion with codegen Intermediate?
There was a problem hiding this comment.
I'll make that change. It's a bit confusing since the one in the ast it's also Intermediate. But eventually my idea was to unify both types, so we can fix it that way eventually.
To be honest I feel like Intermediate in general is not the best name to the type (in the language), I would maybe call it FreeToken , UnboundToken or something like that.
Co-authored-by: SpaceManiac <tad@dcspark.io>
Changes in this PR:
Parser
Add syntax for (optional) type annotations on variables.
Add effect annotation syntax on coordination scripts
I feel like using
{}as delimiters here makes it a bit weird because it's too similar to the function body. But I also think it's the more proper syntax since that's the usual math notation for sets.I don't know if it's worth changing the function syntax for it though. It's also the syntax that was on the slides I think.
Add syntax to annotate yield and resume in utxo
Added just to be able to typecheck the
yieldinside themainbody, not necessarily because it's the best syntax. Also I couldn't find examples of these on the slides. We could put the annotation on the return type of the "function", but I don't see a good way of annotating theResumethat way.Other
loop { }was parsed as a record instead of a loop in the parser.raiseto not take an expression, since effects are not really expressions.Typechecking
This adds a typechecking pass to the compiler after name resolution, with type inference for locals. We don't necessarily need to keep this restriction, since the algorithm should work anyway, but I'm not sure it's worth it.
There are still many holes though, but I tried to cover at least most of the things needed for coordination scripts. The examples that we have don't typecheck yet though. In particular with tokens I think there are some type annotations missing in the AST that need to be added before.
Open question
I'm not sure what's the proper syntax to resume a utxo with a type. Should it be
utxo.resume(val)? We have aresumekeyword in the syntax, but it was meant more for the effect handlers.