-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor typechecker #995
Refactor typechecker #995
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick first review, still need to dive deeper into the code
(* model name - don't love this here *) | ||
let model_name = ref "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably model_name
should be a field in Ast.program
and also included in Env.t
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do need it to be a mutable reference somewhere, unless we want to pass it as an argument to all the major frontend functions. It being in the environment makes a little more sense than in the typechecker, but I think it would still be in the Environment
module, not each tenv
mapping
I haven’t yet. The changes that he makes to the typechecker are pretty minimal though, and adapting them should be straightforward (I’d be happy to do it in his branch if he would welcome it) |
I've removed the failing test (it will be addressed separately #1011) so this should be good to go with approval @SteveBronder @nhuurre |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one thing to fix in the tests for python, but I think besides that most of my parts are comments. So code looks good!
How does this look in the current state @nhuurre @SteveBronder? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
Just merging master in hopes that this is the next PR merged. Needs approval from @SteveBronder still before GitHub will allow it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
This is following on the discussion here #966.
The typechecker has several historical oddities and design decisions that don't make sense with the way the project has gone. To be clear, I'm not anti-monad or anything, I just think the typechecker can and should be simple to read an understand. By using the OCaml exception handling internally, it's possible to make each function very clear while still returning a Result at the high-level interface to the rest of the compiler.
This mainly has implications for the developers and open PRs like #675 #742 . I'm very happy to help update those PRs as needed.
Summary:
Validation
is gone. Eachcheck_
function either returns the typed segment of the AST it is responsible for, or throws an error which is caught bycheck_program
. Functions that start withverify_
either throw an error or return unit. This (indirectly) closes Semantic check should only use applicative interface #265Typechecker.ml
. This was mainly because I keptSemantic_check.ml
around during development so I needed a new name, I'm not attached to it.Validation
aside. It makes things like function overloading much easier to reason about and removes the rather hacky way of doing scope etc used before.Stan_math_signatures
is not gone, but it is far less used and we can work on simplifying this further later.Why?:
liftA2 (a, b) |> (fun ua ub -> ...
that add no functionality besides satisfying the monad(* WARNING: SIDE EFFECTING *)
comments.Submission Checklist
Release notes
Refactored Stan typechecker.
Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)