Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Integrate splain – implicit resolution chains and type diffs in error messages#7785

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lrytz merged 4 commits intoscala:2.13.xfromtek:splain-2.13
Apr 21, 2021

Conversation

@tek
Copy link
Contributor

@tektek commentedFeb 22, 2019
edited by lrytz
Loading

This integrateshttps://github.com/tek/splain into the compiler

  • -Vimplicits makes the compiler print implicit resolution chains when no implicit value can be found
  • -Vtype-diffs turns type error messages (found: X, required: Y) into colored diffs between the two types

I copied most of splain's code into the directorysrc/compiler/scala/tools/nsc/typechecker/splain and changed its integration to be less intrusive. There are now compiler options like-Ysplain to control its behaviour. I kept the analyzer plugin method that allows consumers to override or amend output formatting, e.g. for providing more detailed messages about specific typeclasses with access to the typechecker and involved types.

(previous PR at#5958).

nafg, julianmichael, ashawley, nightscape, exoego, jhnsmth, svalaskevicius, lbialy, MateuszKubuszok, kubukoz, and 16 more reacted with hooray emojisake92, DavidGregory084, danslapman, psilospore, jatcwang, vikraman, He-Pin, tribbloid, mihaisoloi, joroKr21, and 6 more reacted with heart emoji
@scala-jenkinsscala-jenkins added this to the2.13.1 milestoneFeb 22, 2019
@som-snytt
Copy link
Contributor

som-snytt commentedFeb 23, 2019
edited
Loading

You might consider grouping the compiler flags,-Ysplain:no-color,trunc-refined etc.

tek and cosminci reacted with thumbs up emoji

@tek
Copy link
ContributorAuthor

tek commentedFeb 23, 2019

@som-snytt could you elaborate how that would work? The only tool I'm seeing that allows grouping like this isMultiChoiceSetting, but it doesn't seem very suitable for this specific case

@som-snytt
Copy link
Contributor

som-snytt commentedFeb 24, 2019
edited
Loading

That is, like-Xlint, except any flag would also enable-Ysplain; only the int-valued settings can't be grouped this way (although one could imagine supporting-Ysplain:myint=3 syntax).

The other possibility foravoiding a huge-Y help page would be to only show prefixes under-Y and then-Ysplain:help would show options with that prefix.

@som-snytt
Copy link
Contributor

Note that you could also provide a man page for:man splain.

som-snytt, SethTisue, sake92, NthPortal, kubukoz, jatcwang, tek, fommil, bl-ue, and DarrenBishop reacted with laugh emojifommil, bl-ue, and gontard reacted with heart emoji

@tek
Copy link
ContributorAuthor

tek commentedFeb 24, 2019

ok, got it!
I hoped that specifying only-Ysplain would makesetByUser true, but it's gonna have to be-Ysplain:enable.

@tek
Copy link
ContributorAuthor

tek commentedMar 1, 2019

any other suggestions?

@SethTisueSethTisue added the release-notesworth highlighting in next release notes labelJun 18, 2019
newSource1.scala:13: error: implicit error;
!I e: II
ImplicitChain.g invalid because
!I impPar3: I1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I find this message a bit hard to interpret. I have the impression that Dotty provides a more helpful error message (see an example here). Am I right, or are there limitations in what Dotty does that are addressed by splain?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the motivation for this notation is to be terse, concise and parsable in the face of implicit chains that are tens of levels deep. I haven't gotten any feedback on this by splain users so far, so I can't tell whether this is as useful to others as it is to me.
The test output with dummy names is certainly less readable than one where the involved names and types are recognizable, likecirce.Decoder andshapeless.Generic, which is the intended use case.

One solution would certainly be to offer both verbose and terse messages, to be configured by the user.

Are you suggesting that Dotty's messages would make splain obsolete? Would that imply that it wouldn't be needed in current Scala?
I haven't looked at Dotty's implicit messages yet, does it display whole chains?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Are you suggesting that Dotty's messages would make splain obsolete?
Would that imply that it wouldn't be needed in current Scala?

This is not clear yet. In any case, it’s definitely useful to work on improving error messages!

I haven't looked at Dotty's implicit messages yet, does it display whole chains?

I have posted a comparison of messages produced by Scala and Dottyhere

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I will have to investigate some test cases myself.

In any case, implicit conversions are not a feature that is handled by splain explicitly, just FYI.

My question now is: do you want to make this PR about how error messages should look? So far the mission was to make splain available as-is – if this should be different, we should make this an explicit statement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

My question now is: do you want to make this PR about how error messages should look? So far the mission was to make splain available as-is – if this should be different, we should make this an explicit statement.

That’s a good point. I agree that working on how error messages should look could be done in another PR.

tek reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

marking as "resolved" because although further improvement would be welcome, it's not a blocker

@szeigerszeiger modified the milestones:2.13.1,2.13.2Aug 30, 2019
@lrytzlrytz modified the milestones:2.13.2,2.13.3Feb 3, 2020
@kubukoz
Copy link

Hi, what's the state of this PR? It's been some time since the last update :)

@tek
Copy link
ContributorAuthor

tek commentedFeb 25, 2020

I am waiting for activity!

@som-snytt
Copy link
Contributor

With the new github inbox for notifications, I'll never miss another review request.

I'll get up to speed. First, I'll get up.

kubukoz, psilospore, tek, BalmungSan, and bl-ue reacted with heart emoji

@SethTisue
Copy link
Member

@lrytz we're open to eventually merging this, right? I think you and I discussed it a few weeks ago but I admit that I forgot what we said. did we have any medium-sized-or-larger reservations about it?

@julienrf
Copy link
Contributor

FWIW, I haven’t had a look at the PR implementation but I think the feature itself is extremely valuable.

@lrytz
Copy link
Member

@lrytz we're open to eventually merging this, right? I think you and I discussed it a few weeks ago but I admit that I forgot what we said. did we have any medium-sized-or-larger reservations about it?

I also don't remember :-)

My only reservation here is that the improvements live behind new compiler flags, and that the implementation is separate from the ordinary error messages and type printing. Can we integrate this deeper and make more people benefit from the helpful messages?

  • for infix type printing, we have@showAsInfix - how does it relate?
  • type diffs would be really good to have by default, is there a reason against it? maybe not to break IDEs?
  • can the implementation of type printing be combined with what already exists in the compiler?
  • is there a drawback in adding compact implicit chains by default? compiler perfromance?

@SethTisue
Copy link
Member

My only reservation here is that the improvements live behind new compiler flags

Even if we decide that this style of output should remain under a flag, perhaps one or more normal error messages could mention the flag, to improve discoverability.

Regardless, I agree that deeper integration is better. Because passing flags is cumbersome; people tend to either turn a flag on all the time, or never.

@kubukoz
Copy link

Frankly I'd rather have it soon as a flag than wait months and get new behavior as a default in a 2.13.x version :)

@lrytz
Copy link
Member

@kubukoz that's understandable of course :-)

However, features we add to the compiler are shipped to the entire Scala community, so changing things (even compiler flags or the style of error messages) comes with a cost, that's why things often move a bit slower.

Also, from our perspective, it's a piece of code that we'll have to maintain for a long time, so it makes sense to integrate well into our codebase. For example,showType is re-implementing functionality that exists (to some degree) in the compiler.

@tek
Copy link
ContributorAuthor

tek commentedMar 2, 2020

I would suggest starting out with the flag, since the plugin has so far only been used by people intentionally looking for the provided functionality, and some of the edge cases in, e.g. the found/req type diffs can be slightly buggy – not to the point of significant impediment, but it could probably need a bit of bug reporting.

There's nothing keeping us from making it the default in the future, and it does feel like a lot of commitment to do it out of the gate.

@lrytz
Copy link
Member

35% of the respondents inhttps://scalacenter.github.io/scala-developer-survey-2019/ say that "handling missing implicit errors" is a "main pain point in daily workflow".

SethTisue reacted with eyes emoji

@tek
Copy link
ContributorAuthor

tek commentedMar 3, 2020
edited
Loading

fair point 😸

regarding your concern about integrating it deeper: One benefit of having it separated, especially with Analyzer Plugin machinery involved, is that it would make it very simple to providehighly customized error message plugins for specific librarieswith access to the typer. One example of this is the builtin shapeless Record and Lazy support.

Of course there is some compromise in between. My only concern is that this PR and its predecessor have been going on for years and it would be nice to close the plugin repo and develop this in the compiler with some version already released, because it would make development significantly simpler. A flag seems a good approach, treating it as an experimental feature.

martijnhoekstra reacted with heart emoji

@tek
Copy link
ContributorAuthor

tek commentedMar 3, 2020

So my proposal would be 2.13.4 with-Vimplicits, 2.13.5 as default

@tek
Copy link
ContributorAuthor

tek commentedApr 1, 2021
edited
Loading

My suspicion is that both parameter messages and parent messages weren't around (or not at that location) when I initially wrote this five years ago.
The obvious solution is to copy the missing code over to splain, but I could also refactor it slightly so the annotation message is shared with the default printer.

Caveat: I noticed that the parameter message's assembly is a bit more complex.

@tek
Copy link
ContributorAuthor

tek commentedApr 1, 2021
edited
Loading

implemented the latter, please take a look. It's not complete though, this causes annotations to be ignored entirely for all but the first parameter in the chain.

Edit: fixed that as well.

@tek
Copy link
ContributorAuthor

tek commentedApr 1, 2021

@dwijnand I think that addresses all of the examples of information loss you quoted, do you have any others?

Sorry, I missed your question here,@tek! No, what I meant was why it was creating its own hook rather than reusing the existing hooks and having splain be an AnalysisPlugin. And, yeah, I don't think we should provide that plugin addition - at least not until it provides necessary.

The existing hooks didn't include the necessary information, iirc. If they had, the plugin would have been a lot simpler 😄

Necessity wouldn't be an argument for this feature – its intended purpose is to allow people to provide a AnalyzerPlugin for e.g.shapeless, that includes additional formatting, like theRecord rules that were part of the splain plugin and have now been removed. If you consider that to be not worth the addition of a new hook, I'll remove it.

Sadly there is that potential, but I'd rather let it crash and fix the root causes that slowly sprinkle these all over.

Removed!

I'm not 100% sure, but I think unless we're convinced the messages are pointless or misleading, I dislike just removing them. I'm also thinking we should keep-Xlog-implicits as an alias ("abbreviation") of-Vimplicits, so that means (1) and (3) clash. I agree with you integrating it shouldn't block, so I'm thinking either just-Vdebug or-Vimplicits -Vdebug.

ok!

dwijnand and bl-ue reacted with heart emoji

@dwijnand
Copy link
Member

@dwijnand I think that addresses all of the examples of information loss you quoted, do you have any others?

Thanks for the quick fix! I'll re-run all the tests with the option enabled again (and actually we should just have that commit run in the PR).

Necessity wouldn't be an argument for this feature – its intended purpose is to allow people to provide a AnalyzerPlugin for e.g.shapeless, that includes additional formatting, like theRecord rules that were part of the splain plugin and have now been removed. If you consider that to be not worth the addition of a new hook, I'll remove it.

As it's simple (and already implemented) I'm fine with keeping it, you've convinced me 😄

I have a patch on top of yours which applies a whole bunch of changes, which allowed me to understand the code, and try different things. I'll look to rebasing it onto your branch here and PRing your fork next week so you have a look.

@tek
Copy link
ContributorAuthor

tek commentedApr 1, 2021

we should just have that commit run in the PR

sorry, don't understand what that means. do you need me to do something there?

As it's simple (and already implemented) I'm fine with keeping it, you've convinced me smile

🙂

I have a patch on top of yours which applies a whole bunch of changes, which allowed me to understand the code, and try different things. I'll look to rebasing it onto your branch here and PRing your fork next week so you have a look.

ok cool. do you want me to squash again now?

@dwijnand
Copy link
Member

we should just have that commit run in the PR

sorry, don't understand what that means. do you need me to do something there?

My bad, that was a quick self/team-reminder. See#9557 for an example: make a change with the flag default on, to get a CI-verified test pass commit, and then default it off in the next commit for the merge.

ok cool. do you want me to squash again now?

No, hopefully we can get my changes in and then we can squash it all up (I've been debating whether it's best to have my changes after or squashed with yours - I don't care about the commit credit, I'm just thinking if any of the two options are preferable.)

@tek
Copy link
ContributorAuthor

tek commentedApr 6, 2021

My bad, that was a quick self/team-reminder. See#9557 for an example: make a change with the flag default on, to get a CI-verified test pass commit, and then default it off in the next commit for the merge.

ahhh clever!

No, hopefully we can get my changes in and then we can squash it all up (I've been debating whether it's best to have my changes after or squashed with yours - I don't care about the commit credit, I'm just thinking if any of the two options are preferable.)

👍

@tek
Copy link
ContributorAuthor

tek commentedApr 6, 2021

so, we decided to remove the link to the docs.scala-lang.org link in favor of a better description for the option. what are the requirements for this?

@dwijnand
Copy link
Member

dwijnand commentedApr 6, 2021
edited
Loading

scala/docs.scala-lang#1840 is the docs page, which needs an update with how I've reworked the options. Previously everything was under a single "MultiChoiceSetting", while now is broken up, which gives more lines to give some basic description, and have that docs page provide more context and nice examples.

Personally I welcome suggestions on improved description, but I'm happy if we were to ship what we have currently in the PR.

@tek
Copy link
ContributorAuthor

tek commentedApr 6, 2021

updated the doc page, please let me know what's bad!

tekand others added4 commitsApril 16, 2021 17:28
… messagesThis error formatting framework displays a tree of implicit parametersthat correspond to the resolution chain between an error's call site andthe offending implicit.Several additional improvements for error formatting are provided aswell, like colored diffs of found/required error types, which are basedon a set of pure data types extracted from the compiler internals,available to plugin developers through the AnalyzerPlugin API.
Copy link
Member

@SethTisueSethTisue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

(final review/merge by@lrytz?)

dwijnand, tek, and bl-ue reacted with rocket emoji
Copy link
Member

@lrytzlrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM too!

The message formatting / wording can still be improved, that would be helpful. Basically what's discussed in these comments:https://github.com/scala/scala/pull/7785/files#diff-0d00a887e46a40735249285fb63ea04a8aa3de82943535fdfdbf86106cdcb88d

@lrytzlrytz merged commit52cdad9 intoscala:2.13.xApr 21, 2021
@tek
Copy link
ContributorAuthor

tek commentedApr 21, 2021

wooooo 🥳 🎉

julienrf, joroKr21, KadekM, SethTisue, gourlaysama, nightscape, som-snytt, lrytz, jatcwang, nafg, and 4 more reacted with hooray emojijoroKr21, nightscape, lrytz, nafg, lorandszakacs, martijnhoekstra, Philippus, and bl-ue reacted with heart emoji

@kubukoz
Copy link

WOOOOOOOOOOO!

tek, nafg, martijnhoekstra, and bl-ue reacted with laugh emojitek, nafg, lorandszakacs, martijnhoekstra, calvinlfer, and bl-ue reacted with rocket emoji

@bl-ue
Copy link

So does this closetek/splain#4?

@tektek deleted the splain-2.13 branchMay 22, 2021 21:29
@tek
Copy link
ContributorAuthor

tek commentedMay 22, 2021

fuck yeah!

bl-ue and SethTisue reacted with rocket emoji

@SethTisue
Copy link
Member

SethTisue commentedSep 1, 2021
edited
Loading

There is some (trigger warning: somewhat grouchy) negative feedback attypelevel/sbt-tpolecat#38 andtypelevel/sbt-tpolecat#45. Not sure if there's anything actionable in the sense that the feature could be improved, or if it's only actionable by telling people "this isn't intended to be enabled by default".

@tek
Copy link
ContributorAuthor

tek commentedSep 1, 2021

well, it isn't enabled by default, so not sure what else could be said 🙂 And the issue 38 talks about-explain-types, which isn't related to splain

SethTisue and som-snytt reacted with thumbs up emoji

@tribbloid
Copy link

tribbloid commentedSep 29, 2021
edited
Loading

At this moment (Sept 2021), who is the maintainer/reviewer of this feature?

There are a few hotfixes in splain 0.5.9 that wasn't included.

Unfortunately the first patch to scala compiler takes a lot of copy and paste. IMHO, we can't afford to do this repeatedly for hotfixes.

After consulting with@tek. I may have to rebase them on this repo

@SethTisue
Copy link
Member

who is the maintainer/reviewer of this feature?

any of us, all of us. PRs welcome

@tribbloid
Copy link

@SethTisue thanks a lot. I've talked to@tek and discovered that many config options are also omitted:

tek/splain#58

So I'll have to introduce them first. The following 2 PR should be ideally submitted in succession:

  1. add the following configurations that are ingested though-P:splain:<param>[:<value>] options:
valkeyAll="all"valkeyImplicits="implicits"valkeyFoundReq="foundreq"valkeyInfix="infix"valkeyBounds="bounds"valkeyColor="color"valkeyBreakInfix="breakinfix"valkeyCompact="compact"valkeyTree="tree"valkeyBoundsImplicits="boundsimplicits"valkeyTruncRefined="truncrefined"valkeyRewrite="rewrite"valkeyKeepModules="keepmodules"valanalyzer=new {valglobal=SplainPluginCompat.this.global }withAnalyzer {deffeatureImplicits= boolean(keyImplicits)deffeatureFoundReq= boolean(keyFoundReq)deffeatureInfix= boolean(keyInfix)deffeatureBounds= boolean(keyBounds)deffeatureColor= boolean(keyColor)deffeatureBreakInfix= int(keyBreakInfix).filterNot(_==0)deffeatureCompact= boolean(keyCompact)deffeatureTree= boolean(keyTree)deffeatureBoundsImplicits= boolean(keyBoundsImplicits)deffeatureTruncRefined= int(keyTruncRefined).filterNot(_==0)deffeatureRewrite= opt(keyRewrite,"")deffeatureKeepModules= int(keyKeepModules)    }

(feel free to suggest alternative names)

  1. backport the patch

Wonder if I can catch the 2.13.7 release deadline?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@julienrfjulienrfjulienrf left review comments

@lrytzlrytzlrytz approved these changes

@SethTisueSethTisueSethTisue approved these changes

@dwijnanddwijnanddwijnand approved these changes

@som-snyttsom-snyttsom-snytt approved these changes

+2 more reviewers

@martijnhoekstramartijnhoekstramartijnhoekstra left review comments

@kubukozkubukozkubukoz left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

release-notesworth highlighting in next release notes

Projects

None yet

Milestone

2.13.6

Development

Successfully merging this pull request may close these issues.

13 participants

@tek@som-snytt@kubukoz@SethTisue@julienrf@lrytz@dwijnand@retronym@bl-ue@tribbloid@martijnhoekstra@szeiger@scala-jenkins

[8]ページ先頭

©2009-2025 Movatter.jp