Fix RichDiagnosticFormatter not to strip metadata when computing where clauses #1921
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The rich diagnostic formatter computes a list of "where clauses" -- that is, extra diagnostics that are meant to explain what the types in the main diagnostic are.
At some point it was decided to strip type annotations from the types in the diagnostics, to eliminate some noise. This created some issues:
In addition to these general issues, calling
stripMetadataunconditionally inAbstractDiagnosticFormatter, also means that we cannot correctly render null-restricted types. While we could do something to re-add the null-restriction after stripping, this silent coupling betweenAbstractDiagnosticFormatterand pre-processing of where clauses inRichDiagnosticFormatteris problematic, and an obstable to improve the treatment of null-restricted types.The solution is to avoid string-y comparison when populating where clauses. All comparison should occur either by symbol (e.g. type variables, captured types), or by
Types::isSameType(for intersection type). Note that, since symbols are more stable, and sinceisSameTypeignores metadata, we no longer need metadata stripping when computing and/or searching for where clauses.To make the code more robust I've centralized all the logic corresponding to populating and searching where clauses inside the already-existing
WhereClausesclass. This allows the code to control how de-duplication of similarly named (but different) type-variables should occur, etc. It also leads to slightly improved client code.This means we can now tweak
AbstractDiagnosticFormatterto restore null-restriction after stripping. And this will now have no effect on the correctness of the rich formatter.I've also added a separate regression test to make sure that there's only one intersection where clause generated in cases where we have two intersection types with the same component types, but different annotations. Since the annotations are stripped, this leads (before this PR) to redundant where clauses with same content.
Progress
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/1921/head:pull/1921$ git checkout pull/1921Update a local copy of the PR:
$ git checkout pull/1921$ git pull https://git.openjdk.org/valhalla.git pull/1921/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1921View PR using the GUI difftool:
$ git pr show -t 1921Using diff file
Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/1921.diff
Using Webrev
Link to Webrev Comment