Skip to content
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

Fix order that constraints/variables are resolved in type arg inference #6713

Merged
merged 12 commits into from
Jul 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,13 @@ private BoundSet getB4(BoundSet b3, ConstraintSet c) {
c.applyInstantiations();
}
c.remove(subset);
BoundSet newBounds = subset.reduce(context);
BoundSet newBounds = subset.reduceAdditionalArgOnce(context);
if (!subset.isEmpty()) {
// The subset is not empty at this point if an additional argument constraint was found.
// In this case, a new subset needs to be picked so that dependencies of the constraints
// from reducing the additional argument constraint can be taken into account.
c.addAll(subset);
}
b3.incorporateToFixedPoint(newBounds);
}
return b3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ public Dependencies getDependencies() {
* @return the dependencies between all variables in this bound set
*/
public Dependencies getDependencies(Collection<Variable> additionalVars) {
variables.addAll(additionalVars);
for (Theta t : context.maps.values()) {
variables.addAll(t.values());
}
// variables.addAll(additionalVars);
Dependencies dependencies = new Dependencies();

for (CaptureBound capture : captures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,32 @@ public BoundSet reduce(Java8InferenceContext context) {
if (this.list.size() > BoundSet.MAX_INCORPORATION_STEPS) {
throw new BugInCF("TO MANY CONSTRAINTS: %s", context.pathToExpression.getLeaf());
}
boundSet.merge(reduceOneStep(context));
BoundSet result = reduceOneStep(context);
boundSet.merge(result);
}
return boundSet;
}

/**
* Reduces all the constraints in this set. (See JLS 18.2) If an {@link AdditionalArgument} is
* found it is reduced one step and then this method is returns.
*
* @param context the context
* @return the bound set produced by reducing this constraint set
*/
public BoundSet reduceAdditionalArgOnce(Java8InferenceContext context) {
BoundSet boundSet = new BoundSet(context);
while (!this.isEmpty()) {
if (this.list.size() > BoundSet.MAX_INCORPORATION_STEPS) {
throw new BugInCF("TO MANY CONSTRAINTS: %s", context.pathToExpression.getLeaf());
smillst marked this conversation as resolved.
Show resolved Hide resolved
}
boolean foundAA = this.list.get(0).getKind() == Kind.ADDITIONAL_ARG;
BoundSet result = reduceOneStep(context);
if (foundAA) {
return boundSet;
}
boundSet.merge(result);
}
return boundSet;
}

Expand Down
13 changes: 10 additions & 3 deletions framework/tests/all-systems/DiamondMethodRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ void method(CharacterDisplay display) {
.boxed()
.collect(
Collectors.toMap(
Function.identity(), hitDie -> 1, Integer::sum, LinkedHashMap::new)))
Function.identity(),
hitDie -> 1,
DiamondMethodRef::sum,
LinkedHashMap::new)))
.mapToInt(hdMap -> hdMap.entrySet().stream().mapToInt(Map.Entry::getValue).sum());
}

static Integer sum(Integer a, Integer b) {
throw new RuntimeException();
}

public static class CharacterDisplay {
public Set<PCClass> getClassSet() {
throw new RuntimeException();
}

public final int getLevel(PCClass pcc) {
return 0;
throw new RuntimeException();
}

public HitDie getLevelHitDie(PCClass pcClass, final int classLevel) {
Expand All @@ -38,7 +45,7 @@ static class PCClass {}

static class HitDie {
int getDie() {
return 0;
throw new RuntimeException();
}
}
}
17 changes: 17 additions & 0 deletions framework/tests/all-systems/Issue6652.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.function.Supplier;

class Issue6652 {
interface Arbitrary<T> {}

Arbitrary<Supplier<String>> test() {
return lazyOf(() -> of(() -> "foo"));
}

static <T> Arbitrary<T> of(T value) {
throw new UnsupportedOperationException("implementation omitted");
}

static <T> Arbitrary<T> lazyOf(Supplier<Arbitrary<? extends T>> supplier) {
throw new UnsupportedOperationException("implementation omitted");
}
}
Loading