-
Notifications
You must be signed in to change notification settings - Fork 0
Support invocation inference across narrowing reference conversions #8
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
base: JDK-8372170
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -394,7 +394,8 @@ Type generateReturnConstraints(JCTree tree, Attr.ResultInfo resultInfo, | |
| } | ||
| } | ||
| Type qtype = inferenceContext.asUndetVar(from); | ||
| Type to = resultInfo.pt; | ||
| Type to = resultCompatibilityTarget(mt.getReturnType(), resultInfo.pt, | ||
| inferenceContext, rsInfoInfContext); | ||
|
|
||
| if (qtype.hasTag(VOID)) { | ||
| to = syms.voidType; | ||
|
|
@@ -416,6 +417,33 @@ Type generateReturnConstraints(JCTree tree, Attr.ResultInfo resultInfo, | |
| return from; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the target for invocation result constraints, lifting a proper | ||
| * target to the supertype corresponding to the generic return type. Targets | ||
| * free in an enclosing inference context are left unchanged. | ||
| */ | ||
| private Type resultCompatibilityTarget(Type returnType, Type targetType, | ||
| InferenceContext inferenceContext, InferenceContext targetInferenceContext) { | ||
| if (returnType.hasTag(CLASS) && | ||
| returnType.getTypeArguments().stream() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inferenceContext.free(returnType)? |
||
| .anyMatch(t -> t.containsAny(inferenceContext.inferencevars)) && | ||
| !targetType.hasTag(NONE) && | ||
| !targetType.hasTag(ERROR) && | ||
| targetType.isReference() && | ||
| !targetInferenceContext.free(targetType) && | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this can be replaced by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (e.g. the issue here is that a type variable might erase to a class type, which might lead you to lift more cases than needed. E.g. if we lift T to C<...> where T was an inference variable, we kind of lose T). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I follow, erasure during inference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the check in the line below -- which checks if |T| <: |R| where T is the target type and R is the return type. Basically, we're checking here if the relationship is "the wrong way around", and, if so, lift T to the same height as R. That's because with the new narrowing sealing conversion you can have legit cases of |T| <: |R| that are valid assignments. |
||
| types.isSubtype(types.erasure(targetType), types.erasure(returnType))) { | ||
| Type liftedTarget = lift(targetType, returnType); | ||
| if (liftedTarget != null) { | ||
| return liftedTarget; | ||
| } | ||
| } | ||
| return targetType; | ||
| } | ||
|
|
||
| private Type lift(Type targetType, Type returnType) { | ||
| return types.asSuper(targetType, returnType.tsym); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if we are dealing with arrays? better to use Infer::asSuper |
||
| } | ||
|
|
||
| private boolean needsEagerInstantiation(UndetVar from, Type to, InferenceContext inferenceContext) { | ||
| if (to.isPrimitive()) { | ||
| /* T is a primitive type, and one of the primitive wrapper classes is an instantiation, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
probably the highest risk of semantic change is when
qtypeis anUndetVar, we need to test that case and look for any possible semantic change