Repository navigation
Conversation
|
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
|
@lahodaj This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 608 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
| import com.sun.tools.javac.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class UnknownTypeTest extends TypeHarness { |
| @Override | ||
| public boolean isPartial() { | ||
| return true; | ||
| @Override @DefinedBy(Api.LANGUAGE_MODEL) |
There was a problem hiding this comment.
Modelling-wise, I'm not sure. It almost seems as if UnknownType should be subclassed by ErrorType and not the other way around. Is there a specific reason you went for this?
There was a problem hiding this comment.
I would see the UnknownType as a specific kind of an erroneous type (and hence UnknownType being a subtype or erroneous, as it is here).
But, even from a practical point of view - ErrorType basically must extend ClassType, I think, so implanting UnknownType in there seems difficult.
There was a problem hiding this comment.
I guess I'm a bit surprised by the typeKind - which is OTHER (you added the override to keep compatibility with what was there before). In that sense, it doesn't seem like UnknownType "is a" ErrorType, because its tag seems "less general" than the one in ErrorType.
mcimadamore
left a comment
There was a problem hiding this comment.
The approach seems good. I left some modelling questions. As you notice, I'm skeptical that just handling unknown types better is going to be the last time we see issues like this. E.g. the switch code in Attr seems to be doing way too much when we're in speculative mode.
I don't disagree. I think we need to see if we can move the completeness computation to a later point, and maybe even skip the exhaustiveness check during speculative attribution. But, having a type that crashes the compiler when sent to an innocuous method seemed relatively important to fix. |
| unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage); | ||
| unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol); | ||
| unknownSymbol.type = unknownType; | ||
| // Create the unknown type |
There was a problem hiding this comment.
More general question: is the distinction between unknown and erroneous even relevant? It seems that an unknown type is just an erroneous type whose "class" happens to be the unknown symbol class.
Can we just say:
unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
unknownType = unknownSymbol.type = new ErrorType(unknownSymbol);
Is the only difference what the public getTypeKind will report? Do we care if there's a difference there?
There was a problem hiding this comment.
Internally, after this patch, the distinction is minimal, and usually checked using == unknownType. Whether we can change the external behavior not sure. We can try.
I agree with Maurizio that we are probably doing too much in speculative mode in the switch. I wonder if this patch should be part of the code that will refactor what we are doing there. I would expect any refactoring of what it is done in the switch code to affect this current PR |
That depends on what the merit of this PR is. There's a type that is inherently unsafe in javac ( Note that even though we don't know about any usecase right now where the problem would happen outside of speculative attribution, as long as |
yep that makes sense to me we can revisit this issue later on if needed |
vicente-romero-oracle
left a comment
There was a problem hiding this comment.
looks good
|
/integrate |
|
Going to push as commit f0b130e.
Your commit was automatically rebased without conflicts. |
Consider code like this:
Compiling this fails with a
StackOverflowError, because:case R(String s)Attr.PostAttrAnalyzerfills in the missing types. In particular, theString sbinding will get theSymtab.unknownType.Flow.makePatternDescriptionwill eventually askTypes.isSubtype(..., unknownType). This is guaranteed to fail with theStackOverflowError, as:unknownType.isPartial()returnstrue, soTypes.isSubtype(t, s)(sis theunknownType) callsTypes.isSuperType(s, t), andTypes.isSuperType(s, t)does not contain any special handling for theunknownType, so it will delegate toTypes.isSubtype(t, s), leading to an infinite recursion.It may be possible to side-step the issue by not computing the completes normally property during speculative attribution, or move that computation outside of
Attr. It may be good to do, for performance reasons.But, that does not seem to solve the underlying issue with
unknownType. Many methods inTypesmisbehave in weird ways when theunknownTypeis passed to them.The proposal herein is to attempt to resolve that. In particular, the
UnknownTypeis proposed to extend theErrorType, dropping the (internal)UNKNOWNtype tag. The uses of theUNKNOWNtype tag appear to be equivalent to handling of theERRORtype tag anyway. And the special handling of theunknownTypeappear to usually use== syms.unknownType:jdk/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
Line 904 in 0c36177
After this change, the
unknownTypeshould behave as an erroneous type, unless specifically requested otherwise.The intent is that the public API behavior for the
unknownTypeshould remain the same.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20990/head:pull/20990$ git checkout pull/20990Update a local copy of the PR:
$ git checkout pull/20990$ git pull https://git.openjdk.org/jdk.git pull/20990/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20990View PR using the GUI difftool:
$ git pr show -t 20990Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20990.diff
Webrev
Link to Webrev Comment