stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

Clean up AST by specifying vardecl as sized #1203

Closed WardBrian closed 2 years ago

WardBrian commented 2 years ago

We currently have the type of VarDecl set up so that it could hold an unsized type. This is never done in the AST, and leads to a lot of unecessary hand-wringing, like this unreachable code in the typechecker:

  | VarDecl {decl_type= Unsized _; _} ->
      (* currently unallowed by parser *)
      Common.FatalError.fatal_error_msg
        [%message "Don't support unsized declarations yet."]

We cannot do the same in the MIR, since certain optimizations actually can produce unsized declarations, namely function inlining

1097

Submission Checklist

Release notes

Internally clean up how variable declarations are represented.

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)

nhuurre commented 2 years ago

This cleans up the code nicely but I thought the plan has been to add unsized local variables to the language? Have you discussed this with Bob?

WardBrian commented 2 years ago

@bob-carpenter and I both seem to think now that something like auto or var from Java would be better than unsized declarations, for what it is worth.

If we do decide to add unsized declarations then reverting this change is just as easy as making it, but leaving this code there "just in case" seems unnecessary to me