-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make sure messages are lazily evaluated until report
in Reporter
#1696
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
Make sure messages are lazily evaluated until report
in Reporter
#1696
Conversation
The PR also adds a |
Also @Blaisorblade - if you're interested in having a look I'd appreciate it :) |
I am afraid we should not evaluate on |
Sounds reasonable - I'll update the PR with your feedback - thanks Martin. |
override def report(d: => MessageContainer)(implicit ctx: Context) = () | ||
} | ||
|
||
case class LazyError() extends Message(1000) { |
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.
👍
* This is useful when we need to add additional information to an existing | ||
* message. | ||
*/ | ||
class ExtendMessage(_msg: () => Message)(f: String => String) { self => |
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.
Maybe MappedMessage
or TransformedMessage
would be even clearer.
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.
Sure :)
@@ -236,7 +240,7 @@ abstract class Reporter extends interfaces.ReporterResult { | |||
override def default(key: String) = 0 | |||
} | |||
|
|||
def report(d: MessageContainer)(implicit ctx: Context): Unit = | |||
def report(d: => MessageContainer)(implicit ctx: Context): Unit = |
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.
MessageContainer
still takes messages by-name so I doubt it needs to be by-name itself.- If there's some reason I'm missing (totally possible), other uses of
MessageContainer
would have to also become by-name—starting fromisHidden
. A test might be harder, so one would have to grep for uses ofMessageContainer
.
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 I'll investigate this with...more tests! 😮
IIUC To know I inspected overrides of
Conversely, This sort of complicated invariant is why I advocated dynamic checking via assertions, at least in some (existing?) debug mode (beyond the testcase, which are a good step): even with your new ScalaDocs on leaks, we need to trust reviewers to maintain a non-local invariant. Some other solution might work, but enforcing the invariant isn't.
EDIT: added some checkboxes so I remember what might still be open. |
Just to update this - I've been hacking on this throughout the day. But I'm not ready to update the PR yet, still have a few kinks to work out. |
e24be23
to
93d3f12
Compare
@@ -99,7 +99,7 @@ object Parsers { | |||
/** Issue an error at given offset if beyond last error offset | |||
* and update lastErrorOffset. | |||
*/ | |||
def syntaxError(msg: Message, offset: Int = in.offset): Unit = | |||
def syntaxError(msg: => Message, offset: Int = in.offset): Unit = |
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.
👍 to this whole commit (without having rechecked other occurrences of Message
).
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.
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.
(Note that questions on StoreReporter
and so on are still probably on, but all that commit does makes sense).
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.
Yes, the store reporter will force if debugging - but I think we can live with that :)
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.
FWIW, IMHO we can live with sharp edges as long as we document them when we notice them, and you already added some comments in this direction so 👍.
I'm just asking for a warning comment on the store reporter lest people use it in other scenarios, as I think Murphy's law applies to software evolution. Copy-pasting this would be enough, if drafting the text is the problem:
/** Beware this can leak memory, see https://github.com/lampepfl/dotty/pull/1696#issuecomment-259739205 */
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.
As soon as the restructuring repo PR is merged - I wanted to make the StoreReporter
private to the compiler - WDYT?
But sure, maybe it could use another comment :)
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.
But sure, maybe it could use another comment :)
👍 . "Private to the compiler" doesn't help compiler contributors, neither core ones nor contributors outside EPFL. I also had no clue StoreReporter
is for debugging only.
I'm also confused by the pushback — ideally one documents more pitfalls, not fewer (or even better, makes the comments unnecessary by removing them).
I'm aware there are bad comments, and double-checked checklists of comment downsides (on http://wiki.c2.com/?CommentCostsAndBenefits)—and I'm not sure I see a downside here (other than "time to write", which is why I offered text).
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.
Yeah, didn't mean to push back - but at home right now ^^. The PR has been updated to document this in a2354dd 👍
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.
but at home right now ^^
Oh sorry didn't mean to interrupt. Only time bound I care for: comments are best addressed before the issue/PR is closed, or they should be moved to a new issue lest they're forgot.
LGTM 👍 |
In this PR I make sure that messages are lazily evaluated to the same point in the code it was previously. Namely in
Reporter.scala
in the methodReporter#report
. The message is forced within this method, WDYT - should it be made lazy as well?Review by @odersky