-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
RFC: highlighting type problems #9349
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
Conversation
this looks amazing. of course, regardless of where it goes, it needs documentation (e.g. "it's not useful if people don't know about it.") |
I would love to have something like this in base. |
💯 such awesomeness. |
Awesome! |
This is really great. I think this kind of thing is the biggest source of unpredictability in performance for Julia, so literally highlighting these things will be a huge help to people. |
@rfourquet, I totally agree and will change the name to Can you give me a concrete example of the spurious warning you're describing? It's definitely the case that this will warn about things that are only minimally a problem. For example: f() = ntuple(2, i->1)::(Int,Int)
g(x) = f()[2]+x in a sense, does not have a real type instability problem, but there's a transient type instability because the output of |
OK, I've done the name change and added some fairly extensive documentation. One thing I couldn't figure out was how to get reST to do the red highlighting, so I used all-caps. Any gurus out there know how to do better? |
This is really great, but I feel functionality like this should be in a package rather than in Base. I'm probably in the minority with that opinion though. The number of features getting packed into Base seems to be growing rapidly and seems counter to the goal of .#5155. |
+1 |
Sorry, that was missing several zeros. |
The one thing I worry about with putting it in a package is #265---I'm pretty sure that when I define this outside of julia, I sometimes get If true, we could keep just that portion in base and put the rest in a package. |
OK, I experimented again with taking it out of base. It seems to work fine, so presumably my original problems were due to transient bugs. The explicit votes are 1 in favor of having it in base, and 1 opposed. Everyone else who has commented seems to like the functionality, but hasn't expressed an opinion about where it should live. I suspect it's best to count those as mild votes in favor of keeping this in a package. I'll wait a bit to give folks a chance to weigh in on this specific topic; if no feedback, I'll go the package route. |
Hey Tim, I have not tested your patch but +1000 for having such functionality in base. Type stability is one of the most crucial things in Julia and IMHO Julias Achilles heel... |
I have to say, the visual effect is very nice. For the @code_warntype update!(particles, 1.e-3, velocityverlet) |
Nice example, @jiahao! |
Although I see at least one thing that needs fixing. I expect we'll find quite a few such things in the early days. |
That red annotation on
and it all works fine. So I don't understand. |
I'm a strong proponent for #5155, but I don't think putting this (temporary?) in base will be problematic. This will be used in interactive sessions and I can't really see when someone will write a program that uses this. Therefore we can deprecate this at any time and give instructions to users how to get the new tools. Adding a package is a barrier for some people, and this is one of the first things we should recommend everyone with a performance problem to use. |
It feels a bit too complicated to implement this by copying the AST. |
Looking forward to playing with this. +1 to having it in Base. |
The example I mentioned which seems safe to me is:
So the return value of |
There was a comment that appeared in my email in this thread that perhaps got deleted. But the comment raised some good points about "will this really be useful if I don't know how to interpret the output?" For the record, this is a very reasonable question; interpreting the output of But this will not be the case for most people using julia, nor is it reasonable to expect that will be the case. My first attempt at a solution to this was documentation; it's probably not as easy to read in the commits as it will be when formatted on the web page, but among them there's a lookup table "if you see X, it means Y, fix it by doing Z." But partially prompted by your comment, I agree we should think about doing even better. I just haven't even begun to think about that particular problem yet. I suspect @tonyhffong and @astrieanna might have some good ideas, since their packages already serve this niche. |
I confess to having written the now-deleted comment. I typed it and then realized three things: first, I didn't want to bring up an issue for which I didn't have a proposed solution; second, I didn't want my name associated with something that looked like a complaint or criticism when I'm just a week into this great language; and finally, I did what I should've done before typing: I browsed the commit source and found that wonderful documentation (as an aside, docstrings can't come soon enough). It gave me some insight, as a new Julia user, how I might use the macro (though I confess the whole type thing is still very confusing to me, since I got lazy with Python). I'm very pleased that someone saw and took the comment in the spirit in which it was intended. I'm still not sure I'm smart enough for this language, but I'm doing my best with it, and this macro looks like an great addition to the suite of tools I can use to write better (I'll settle for "working" at this point, though) code. Thanks for letting me get my $0.02 in. |
@sbromberger, I thought it was an extremely relevant comment. As @timholy said, a lot of us have gotten used to the |
type-unstable. However, at the next line, all type-instability ends: | ||
because ``sin`` converts integer inputs into ``Float64``, the final | ||
return value of ``f`` is a ``Float64``. So calls of the form | ||
``f(x::Float64)`` will not be type-unstable in their output, even in |
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.
"even if"
@sbromberger thank you for your perspective on this. I don't think this is a tool that we should encourage everybody to use all the time. Like most automated tools, it has a certain false-positive rate. It shows a lot of stuff you don't really need to know, and identifies "problems" that are not necessarily problems. |
064589d
to
22663ed
Compare
I accidentally pushed an unrelated commit to this branch and then force pushed it away, hopefully I didn't mess anything up here :-\ |
No worries, I'll be doing some force-pushing anyway when I get time to address the review comments. But thanks for letting me know, I really appreciate it. |
22663ed
to
7cd255b
Compare
RFC: highlighting type problems
💯 oh sweet |
This is fantastic! |
One of the major "services" that julia developers provide on the mailing lists is helping people solve performance problems due to type instability. It's pretty easy to make such errors (I've made more than a few in my own time), but personally, I'd like to spend less time on such support issues. As usual, my response is to say "we need easier/more powerful analysis tools." So, here's proposing a new macro,
which produces output like this:
In the course of testing this I discovered #9345, and might not have noticed it without the red highlighting.
I see two main paths for this facility: it goes in base (aka, this PR; note it's not a lot of code), or it goes in a package like TypeCheck.jl or Lint.jl. I was originally planning on submitting it to TypeCheck, but it occurred to me that if folks think this should belong in base, then I'd just be giving @astrieanna a support headache by putting it in the package and then migrating it out again. So I thought I'd start here and see what people say.
Warnings: this does nassty, wicked things to our hobbitses, erm, the printing of types. It's quite possible that using this will bork your julia session in much the same way as "convertalypse" or #9315. (It did once for me during testing, albeit before it was fully working.) I would also characterize the testing of this as "minimal," on perhaps 20 functions. Hence the RFC.