sway
sway copied to clipboard
Use `Handler` infra instead of `CompileResult`
The idea is to stop using the CompileResult<T> monad in sway_core. The type is a beautiful concept, and would be the go-to solution in Haskell. However, there is lacking proper language support for early returns (i.e. do notation in Haskell). Meanwhile, the ? operator is inappropriate for logging (writer monad), which is half of what CompileResult is (roughly (Maybe a, [Warning], [Error])).
Currently, use of CompileResult<T> results in a lot of noise dealing with error handling. For example, there's a bunch of code dealing with extending errors and warnings.
Instead of CompileResult, we can use the Handler concept in the parser, which is also the way rustc deals with emitting errors.