-
-
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
Deprecate forward decls #1277
Deprecate forward decls #1277
Conversation
How would this interact with the external C++ functions feature? I think a lot of this is good - generating forward decls for everything and removing any language from the documentation about the need for them is good. We can also make function declarations completely order-independent with this, if we’re willing to do 2 passes over the function block in typechecking, which I would like to see as part of a change like this. That said, I think we probably want to pair this with something like an More specific review on the code to follow, those are just my thoughts based on the PR description |
Oh, yeah, I forgot to talk about that.
in analogy with |
The thing I like about @extern("foo.hpp")
real foo(real); This annotation does 3 things:
I think an extern keyword could easily do 1 and 2, but I'm not sure how to do 3 with it. |
Codecov Report
@@ Coverage Diff @@
## master #1277 +/- ##
==========================================
- Coverage 88.81% 88.73% -0.09%
==========================================
Files 64 64
Lines 9668 9708 +40
==========================================
+ Hits 8587 8614 +27
- Misses 1081 1094 +13
|
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.
Overall I think this is very nice. Most of my comments are stylistic or asking for more clarification
src/frontend/Deprecation_analysis.ml
Outdated
when is_redundant_forwarddecl fundefs funname arguments -> | ||
acc | ||
@ [ ( funname.id_loc | ||
, "Forward declarations are deprecated and not needed for recursion." |
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 this wording should mention external C++ or just be very specific: "Foward declarations are not needed when the function is also defined and are deprecated in this case."
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.
We also generally mention if the canonicalize flag can fix this, and if there is an expiration on the deprecation.
The latter requires a bit more discussion of intent. I don't think we need to settle what it looks like, but if the goal is that somewhere down the line there is a special syntax for external functions and the current forward decls are completely gone, that's worth discussing
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 suspect that this + the unresolved comments above are probably the last substantial review this needs before approval.
Would you mind adding a test which shows function definitions being order-free (the snippet in the original PR text would suffice)? Besides that, I would also like for the PR to stan-dev/docs be written before merging this, since this requires some rather noticeable changes to the user-facing docs.
I'm going to hold off on a final review/approval until after the language meeting tomorrow in case anyone has some novel thoughts on |
During the language meeting we discussed the |
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!
Submission Checklist
Closes #976
The backend simply generates a forward declaration for every function (even nonrecursive ones) which also simplifies functor struct generation a bit.
Also needed to do something smarter for potentially cyclic eigen templates (#1228 heuristic has been broken for a while now because simple recursive functions don't actually need forward decls)
And also I've allowed variables to shadow user defined functions and not just stan math functions. The reason is shown here:
Release notes
Recursive user-defined functions no longer need forward declarations.
Copyright and Licensing
Copyright holder: Niko Huurre
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)