-
Notifications
You must be signed in to change notification settings - Fork 189
Fix nested lambda inference memory growth #5206 #5207
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
Open
martinfrancois
wants to merge
3
commits into
eclipse-jdt:master
Choose a base branch
from
martinfrancois:agent/issue-5206-nested-lambda-inference
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+170
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...ompiler/src/org/eclipse/jdt/core/tests/compiler/regression/NestedLambdaInferenceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 François Martin and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * François Martin - initial API and implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.jdt.core.tests.compiler.regression; | ||
|
|
||
| import junit.framework.Test; | ||
|
|
||
| public class NestedLambdaInferenceTest extends AbstractRegressionTest { | ||
| private static final int NESTING_DEPTH = 24; | ||
|
|
||
| public NestedLambdaInferenceTest(String name) { | ||
| super(name); | ||
| } | ||
|
|
||
| public static Test suite() { | ||
| return buildMinimalComplianceTestSuite(NestedLambdaInferenceTest.class, F_1_8); | ||
| } | ||
|
|
||
| // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/5206 | ||
| public void testIssue5206GenericRouteChain() { | ||
| runNestedLambdaTest("GenericRouteChain", """ | ||
| <V extends Red> V route(Red marker, Work<V> work) { return null; } | ||
| <V extends Blue> V route(Blue marker, Work<V> work) { return null; } | ||
| <V extends Green> V route(Green marker, Work<V> work) { return null; } | ||
| <V extends Gold> V route(Gold marker, Work<V> work) { return null; } | ||
| <V> V route(Object marker, Work<V> work) { return null; } | ||
|
|
||
| <V extends Red> V select(Red marker, Work<V> work) { return null; } | ||
| <V extends Blue> V select(Blue marker, Work<V> work) { return null; } | ||
| <V extends Green> V select(Green marker, Work<V> work) { return null; } | ||
| <V extends Gold> V select(Gold marker, Work<V> work) { return null; } | ||
| <V> V select(Object marker, Work<V> work) { return null; } | ||
| """); | ||
| } | ||
|
|
||
| // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/5206 | ||
| public void testIssue5206ConcreteRouteChain() { | ||
| runNestedLambdaTest("ConcreteRouteChain", """ | ||
| String route(Red marker, Work<Red> work) { return ""; } | ||
| String route(Blue marker, Work<Blue> work) { return ""; } | ||
| String route(Green marker, Work<Green> work) { return ""; } | ||
| String route(Gold marker, Work<Gold> work) { return ""; } | ||
| String route(Object marker, Work<String> work) { return ""; } | ||
|
|
||
| String select(Red marker, Work<Red> work) { return ""; } | ||
| String select(Blue marker, Work<Blue> work) { return ""; } | ||
| String select(Green marker, Work<Green> work) { return ""; } | ||
| String select(Gold marker, Work<Gold> work) { return ""; } | ||
| String select(Object marker, Work<String> work) { return ""; } | ||
| """); | ||
| } | ||
|
|
||
| // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/5206 | ||
| public void testIssue5206InterleavedParameterizedLambdas() { | ||
| this.runConformTest(new String[] { | ||
| "InterleavedLambdas.java", | ||
| """ | ||
| public class InterleavedLambdas { | ||
| interface Producer<T> { | ||
| T produce(); | ||
| } | ||
| interface Mapper<T, R> { | ||
| R map(T value); | ||
| } | ||
|
|
||
| static <T> T produce(Producer<T> producer) { | ||
| return producer.produce(); | ||
| } | ||
| static <T, R> R map(T value, Mapper<T, R> mapper) { | ||
| return mapper.map(value); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| String result = produce(() -> | ||
| map("left", left -> | ||
| produce(() -> | ||
| map(7, number -> left + number))) | ||
| + produce(() -> "!")); | ||
| System.out.print(result); | ||
| } | ||
| } | ||
| """ | ||
| }, | ||
| "left7!"); | ||
| } | ||
|
|
||
| private void runNestedLambdaTest(String className, String overloads) { | ||
| this.runConformTest(new String[] { | ||
| className + ".java", | ||
| """ | ||
| class %s { | ||
| interface Work<V> { | ||
| V perform(); | ||
| } | ||
| static final Work<String> TERMINAL = null; | ||
|
|
||
| void test() { | ||
| %s; | ||
| } | ||
| static class Red { } | ||
| static class Blue { } | ||
| static class Green { } | ||
| static class Gold { } | ||
| %s | ||
| } | ||
| """.formatted(className, createNestedInvocation(), overloads.indent(4).stripTrailing()) | ||
| }); | ||
| } | ||
|
|
||
| private static String createNestedInvocation() { | ||
| String invocation = "route(null, TERMINAL)"; | ||
| for (int level = 1; level < NESTING_DEPTH; level++) { | ||
| String selector = level % 2 == 0 ? "route" : "select"; | ||
| invocation = selector + "(null, () -> " + invocation + ")"; | ||
| } | ||
| return invocation; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.