Skip to content

Meta issue for constraint solver rewrite #1932

Description

@msridhar

This is a meta-issue for a constraint solver rewrite for generic method inference to encompass #1585 and #1291. Right now, our solve() method to solve constraints has signature:

Map<Element, InferredNullability> solve() throws UnsatisfiableConstraintsException;

This needs to change in (at least) two ways:

  1. The returned Map is currently key'd on Elements corresponding to generic type variables. But as shown in Generic method inference does not support inferring different nullability for multiple calls to same generic method #1291, the same generic method may be invoked more than once in the context of a particular inference problem. So, really this should be key'd on some record datatype that includes both the Element and also the MethodInvocationTree identifying the call to the generic method.
  2. Enhance generic method inference to compute mappings from type variables to full types? #1585 discusses how in various cases it would be better to infer a complete nullness-annotated type for each value in the map. Right now the values are InferredNullability, which only gives the top-level nullability of a type. Instead, the values in the map should be fully nullness-annotated Types, including nested annotations.

This may require other changes to the solver interface, e.g., addSubtypeConstraint may also need a MethodInvocationTree parameter to identify which call generated the constraint.

Clearly the internal vars map in ConstraintSolverImpl would have to change to track all this additional information. It too would also need to incorporate invocation trees into its keys and fully-annotated types into its values.

My hope is that with a fix here for #1585 we can remove some or all of the hacks from #1473 and #1574; I would hope that the entire NestedTypeVarSubstitutionRepairVisitor type and its related "repair" code could just go away.

Beyond keeping existing tests passing, the new test cases in #1291 and #1585 should also pass after the rewrite.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions