Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
5b68b92
quick wip
niloc132 Nov 25, 2025
262b13b
Vaguely functional implementation, except for switches
niloc132 Nov 26, 2025
95174ed
A little more clean up, all samples build cleanly
niloc132 Nov 26, 2025
6b603e7
Don't try to move {}s, better java gen, fix a js bug
niloc132 Nov 27, 2025
2938c74
Checkpoint, user tests pass but compiler fails
niloc132 Nov 27, 2025
de87228
More consistent output, still have a small size regression (inlining?)
niloc132 Nov 30, 2025
3f3c0f2
Try to restore ExpandBlocks, more problems found
niloc132 Nov 30, 2025
4a64133
Nearly correct impl of ExpandBlocks
niloc132 Dec 1, 2025
2786f4b
Cleanup dead code
niloc132 Jan 4, 2026
fdc0352
Remove the 'expand blocks' experiment
niloc132 Jan 28, 2026
bd9638b
break long line
niloc132 Jan 28, 2026
d3b0503
Update tests to drop extra braces when unnecessary
niloc132 Jan 29, 2026
b4cb9d5
Defensively add {}s to JS ifs
niloc132 Jan 30, 2026
c0fa094
Improved version of adding necessary braces
niloc132 Jan 30, 2026
48e32a9
checkstyle
niloc132 Jan 30, 2026
446049a
Drop Java 11 support
niloc132 Jan 30, 2026
8a8cf18
Compute total size of samples correctly
zbynek Jan 31, 2026
cb19126
Include deferred size in compilation report
zbynek Jan 31, 2026
0beeb84
Merge remote-tracking branch 'pr/10263' into 10239-if-child-blocks-test
niloc132 Feb 1, 2026
021fed8
Merge branch 'main' into 10239-if-child-blocks-test
niloc132 Feb 14, 2026
459f301
fix java ast dump to avoid dangling else
niloc132 Feb 15, 2026
6f26726
do/for/while support
niloc132 Feb 15, 2026
cb302b2
if's else can never be null, fixed other tests
niloc132 Feb 15, 2026
9b2de0d
Raise Java language level to 17, update errorprone
niloc132 Jun 8, 2026
1458a5d
temporarily use tools branch
niloc132 Jun 8, 2026
6bf7233
new apis to triage
niloc132 Jun 8, 2026
52acf3a
Rename missing emul files
niloc132 Jun 9, 2026
d2cea9a
Revert "temporarily use tools branch"
niloc132 Jun 9, 2026
54e5fd7
Update notes about what versions are required
niloc132 Jun 9, 2026
f27bcb7
Hardcode preview methods, support java 26 with an EP workaround
niloc132 Jun 10, 2026
67d99e3
Bump asm to support Java 27
niloc132 Jun 10, 2026
c70fb47
Temp tools branch
niloc132 Jun 10, 2026
470e637
Another errorprone bug
niloc132 Jun 10, 2026
14f91f1
Remove Java 26 again, seems to break DOMSuite
niloc132 Jun 10, 2026
b8e9479
quick wip
niloc132 Nov 25, 2025
790478d
Vaguely functional implementation, except for switches
niloc132 Nov 26, 2025
207a283
A little more clean up, all samples build cleanly
niloc132 Nov 26, 2025
ccdc74d
Don't try to move {}s, better java gen, fix a js bug
niloc132 Nov 27, 2025
073dd28
Checkpoint, user tests pass but compiler fails
niloc132 Nov 27, 2025
206198d
More consistent output, still have a small size regression (inlining?)
niloc132 Nov 30, 2025
279130a
Try to restore ExpandBlocks, more problems found
niloc132 Nov 30, 2025
c93bc4c
Nearly correct impl of ExpandBlocks
niloc132 Dec 1, 2025
382b730
Cleanup dead code
niloc132 Jan 4, 2026
4bee28a
Remove the 'expand blocks' experiment
niloc132 Jan 28, 2026
118bfbf
break long line
niloc132 Jan 28, 2026
96231ff
Update tests to drop extra braces when unnecessary
niloc132 Jan 29, 2026
38fb2bd
Defensively add {}s to JS ifs
niloc132 Jan 30, 2026
d53e77d
Improved version of adding necessary braces
niloc132 Jan 30, 2026
362537d
checkstyle
niloc132 Jan 30, 2026
ac18a98
fix java ast dump to avoid dangling else
niloc132 Feb 15, 2026
ac44bd1
do/for/while support
niloc132 Feb 15, 2026
42baabe
if's else can never be null, fixed other tests
niloc132 Feb 15, 2026
19a0aa5
Updated draft, trying to unify logic, avoid copy/paste
niloc132 Feb 24, 2026
3c6fa13
Also remove continue;s, add a simple test
niloc132 Mar 3, 2026
fafdf66
Support 17 for dev core too
niloc132 Mar 3, 2026
62b4cd4
checkstyle, revert unneeded java 17 changes
niloc132 Jun 10, 2026
d0f4b4c
Merge branch 'main' into min-java17
niloc132 Jun 24, 2026
8d5288e
Remove java 26 from list for now
niloc132 Jun 24, 2026
4cce622
Revert "Temp tools branch"
niloc132 Jun 24, 2026
9dd8107
Merge branch 'min-java17' into 10248-remove-pointless-returns
niloc132 Jun 24, 2026
4e476b9
Merge branch 'main' into 10248-remove-pointless-returns
niloc132 Jun 24, 2026
ad0946e
Revert do->while rewrite, unrelated
niloc132 Jun 24, 2026
955e3d5
Remove a comment that can't be handled in the java pass anyway
niloc132 Jun 24, 2026
ae4df09
Add more cases, exclude switch-expr, and write out more tests
niloc132 Jul 1, 2026
d82c4f4
More test
niloc132 Jul 8, 2026
64594ec
Merge branch 'main' into 10248-remove-pointless-returns
niloc132 Jul 8, 2026
a0b883c
More test, fix a bug
niloc132 Jul 8, 2026
ec0109f
checkstyle
niloc132 Jul 8, 2026
d549e2e
Support missing finally blocks
niloc132 Jul 8, 2026
378fb80
Merge branch '10248-remove-pointless-returns' into 10239-if-child-blo…
niloc132 Jul 9, 2026
6283b23
pick up changes from 10248, minus the point of that PR
niloc132 Jul 9, 2026
c141eec
Remove accidentally added files
niloc132 Jul 9, 2026
9dcd9bc
qsuash
niloc132 Jul 9, 2026
7d3b621
Review feedback, style
niloc132 Jul 22, 2026
768923f
Rigorously check for dangling else
niloc132 Jul 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions dev/core/src/com/google/gwt/dev/jjs/ast/JBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public JBlock(SourceInfo info, JStatement... statements) {
this.statements.addAll(Arrays.asList(statements));
}

public static JBlock ensureBlock(SourceInfo info, JStatement statement) {
if (statement == null) {
return new JBlock(info);
}
if (statement instanceof JBlock block) {
return block;
}

return new JBlock(statement.getSourceInfo(), statement);
}

/**
* Insert a statement into this block.
*/
Expand Down Expand Up @@ -105,4 +116,32 @@ public boolean unconditionalControlBreak() {
}
return false;
}

/**
* If possible, expresses this block as a single statement.
* <ul>
* <li>If the block is empty, return null</li>
* <li>If there are multiple items in this block, return the block</li>
* <li>If the only item is another block, invoke {@code singleStatement()} on it</li>
* <li>Otherwise, return the only item as is.</li>
* </ul>
*
* @return the contents of this block as a single nullable statement
*/
public JStatement singleStatement() {
if (statements.isEmpty()) {
return null;
}

if (statements.size() > 1) {
return this;
}

JStatement onlyStatement = statements.get(0);
if (onlyStatement instanceof JBlock block) {
return block.singleStatement();
}

return onlyStatement;
}
Comment thread
vegegoku marked this conversation as resolved.
}
10 changes: 4 additions & 6 deletions dev/core/src/com/google/gwt/dev/jjs/ast/JDoStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
*/
public class JDoStatement extends JStatement {

private JStatement body;
private JBlock body;
private JExpression testExpr;

public JDoStatement(SourceInfo info, JExpression testExpr, JStatement body) {
super(info);
this.testExpr = testExpr;
this.body = body;
this.body = JBlock.ensureBlock(info, body);
}

public JStatement getBody() {
public JBlock getBody() {
return body;
}

Expand All @@ -43,9 +43,7 @@ public JExpression getTestExpr() {
public void traverse(JVisitor visitor, Context ctx) {
if (visitor.visit(this, ctx)) {
testExpr = visitor.accept(testExpr);
if (body != null) {
body = visitor.accept(body, true);
}
body = JBlock.ensureBlock(getSourceInfo(), visitor.accept(body, false));
}
visitor.endVisit(this, ctx);
}
Expand Down
10 changes: 4 additions & 6 deletions dev/core/src/com/google/gwt/dev/jjs/ast/JForStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class JForStatement extends JStatement {

private JStatement body;
private JBlock body;
private List<JStatement> initializers;
private JExpression condition;
private JExpression increments;
Expand All @@ -40,13 +40,13 @@
this.initializers = Lists.newArrayList(initializers);
this.condition = condition;
this.increments = increments;
this.body = body;
this.body = JBlock.ensureBlock(info, body);
}

/**
* Returns the {@code for} statement body.
*/
public JStatement getBody() {
public JBlock getBody() {
return body;
}

Expand Down Expand Up @@ -81,9 +81,7 @@
if (increments != null) {
increments = visitor.accept(increments);
}
if (body != null) {
body = visitor.accept(body, true);
}
body = JBlock.ensureBlock(getSourceInfo(), visitor.accept(body, false));//TODO no tests fail without this change...

Check warning on line 84 in dev/core/src/com/google/gwt/dev/jjs/ast/JForStatement.java

View workflow job for this annotation

GitHub Actions / build (21)

[checkstyle] reported by reviewdog 🐶 Line is longer than 100 characters (found 121). Raw Output: /home/runner/work/gwt/gwt/gwt/dev/core/src/com/google/gwt/dev/jjs/ast/JForStatement.java:84:0: warning: Line is longer than 100 characters (found 121). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO after verifying with a test.

}
visitor.endVisit(this, ctx);
}
Expand Down
20 changes: 8 additions & 12 deletions dev/core/src/com/google/gwt/dev/jjs/ast/JIfStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,35 @@
*/
public class JIfStatement extends JStatement {

private JStatement elseStmt;
private JBlock elseStmt;
private JExpression ifExpr;
private JStatement thenStmt;
private JBlock thenStmt;

public JIfStatement(SourceInfo info, JExpression ifExpr, JStatement thenStmt, JStatement elseStmt) {

Check warning on line 29 in dev/core/src/com/google/gwt/dev/jjs/ast/JIfStatement.java

View workflow job for this annotation

GitHub Actions / build (21)

[checkstyle] reported by reviewdog 🐶 Line is longer than 100 characters (found 102). Raw Output: /home/runner/work/gwt/gwt/gwt/dev/core/src/com/google/gwt/dev/jjs/ast/JIfStatement.java:29:0: warning: Line is longer than 100 characters (found 102). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
super(info);
this.ifExpr = ifExpr;
this.thenStmt = thenStmt;
this.elseStmt = elseStmt;
this.thenStmt = JBlock.ensureBlock(info, thenStmt);
this.elseStmt = JBlock.ensureBlock(info, elseStmt);
}

public JStatement getElseStmt() {
public JBlock getElseStmt() {
return elseStmt;
}

public JExpression getIfExpr() {
return ifExpr;
}

public JStatement getThenStmt() {
public JBlock getThenStmt() {
return thenStmt;
}

@Override
public void traverse(JVisitor visitor, Context ctx) {
if (visitor.visit(this, ctx)) {
ifExpr = visitor.accept(ifExpr);
if (thenStmt != null) {
thenStmt = visitor.accept(thenStmt, true);
}
if (elseStmt != null) {
elseStmt = visitor.accept(elseStmt, true);
}
thenStmt = JBlock.ensureBlock(getSourceInfo(), visitor.accept(thenStmt, false));
elseStmt = JBlock.ensureBlock(getSourceInfo(), visitor.accept(elseStmt, false));
}
visitor.endVisit(this, ctx);
}
Expand Down
10 changes: 4 additions & 6 deletions dev/core/src/com/google/gwt/dev/jjs/ast/JWhileStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
*/
public class JWhileStatement extends JStatement {

private JStatement body;
private JBlock body;
private JExpression testExpr;

public JWhileStatement(SourceInfo info, JExpression testExpr, JStatement body) {
super(info);
this.testExpr = testExpr;
this.body = body;
this.body = JBlock.ensureBlock(info, body);
}

public JStatement getBody() {
public JBlock getBody() {
return body;
}

Expand All @@ -43,9 +43,7 @@
public void traverse(JVisitor visitor, Context ctx) {
if (visitor.visit(this, ctx)) {
testExpr = visitor.accept(testExpr);
if (body != null) {
body = visitor.accept(body, true);
}
body = JBlock.ensureBlock(getSourceInfo(), visitor.accept(body, false));//TODO no tests fail without this change...

Check warning on line 46 in dev/core/src/com/google/gwt/dev/jjs/ast/JWhileStatement.java

View workflow job for this annotation

GitHub Actions / build (21)

[checkstyle] reported by reviewdog 🐶 Line is longer than 100 characters (found 121). Raw Output: /home/runner/work/gwt/gwt/gwt/dev/core/src/com/google/gwt/dev/jjs/ast/JWhileStatement.java:46:0: warning: Line is longer than 100 characters (found 121). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
Comment thread
vegegoku marked this conversation as resolved.
}
visitor.endVisit(this, ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ public void endVisit(JDoStatement x, Context ctx) {
if (expression instanceof JBooleanLiteral) {
JBooleanLiteral booleanLiteral = (JBooleanLiteral) expression;

// If false, replace do with do's body
if (!booleanLiteral.getValue()) {
if (JjsUtils.isEmptyBlock(x.getBody())) {
// If false, replace do with do's body
if (x.getBody().isEmpty()) {
ctx.removeMe();
} else { // Unless it contains break/continue statements
FindBreakContinueStatementsVisitor visitor = new FindBreakContinueStatementsVisitor();
Expand Down Expand Up @@ -1964,10 +1964,8 @@ private void tryRemoveSwitch(JSwitchStatement x, Context ctx) {
} else {
// Create an if statement equivalent to the single-case switch.
JBinaryOperation compareOperation = caseStatement.convertToCompareExpression(x.getExpr());
JBlock block = new JBlock(x.getSourceInfo());
block.addStmt(statement);
JIfStatement ifStatement =
new JIfStatement(x.getSourceInfo(), compareOperation, block, null);
new JIfStatement(x.getSourceInfo(), compareOperation, statement, null);
replaceMe(ifStatement, ctx);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public JsExpression transformBinaryOperation(JBinaryOperation binaryOperation) {
}

@Override
public JsStatement transformBlock(JBlock block) {
public JsBlock transformBlock(JBlock block) {
JsBlock jsBlock = new JsBlock(block.getSourceInfo());
List<JsStatement> stmts = jsBlock.getStatements();

Expand Down Expand Up @@ -692,7 +692,8 @@ public JsNode transformDeclarationStatement(JDeclarationStatement declarationSta
public JsNode transformDoStatement(JDoStatement doStatement) {
JsDoWhile stmt = new JsDoWhile(doStatement.getSourceInfo());
stmt.setCondition(transform(doStatement.getTestExpr()));
stmt.setBody(jsEmptyIfNull(doStatement.getSourceInfo(), transform(doStatement.getBody())));
stmt.setBody(jsEmptyIfNull(doStatement.getSourceInfo(),
transform(doStatement.getBody().singleStatement())));
return stmt;
}

Expand Down Expand Up @@ -742,7 +743,8 @@ public JsNode transformForStatement(JForStatement forStatement) {
result.setInitExpr(initExpr);
result.setCondition(transform(forStatement.getCondition()));
result.setIncrExpr(transform(forStatement.getIncrements()));
result.setBody(jsEmptyIfNull(forStatement.getSourceInfo(), transform(forStatement.getBody())));
result.setBody(jsEmptyIfNull(forStatement.getSourceInfo(),
transform(forStatement.getBody().singleStatement())));

return result;
}
Expand All @@ -753,8 +755,8 @@ public JsNode transformIfStatement(JIfStatement ifStatement) {

result.setIfExpr(transform(ifStatement.getIfExpr()));
result.setThenStmt(jsEmptyIfNull(ifStatement.getSourceInfo(),
transform(ifStatement.getThenStmt())));
result.setElseStmt(transform(ifStatement.getElseStmt()));
transform(ifStatement.getThenStmt().singleStatement())));
result.setElseStmt(transform(ifStatement.getElseStmt().singleStatement()));

return result;
}
Expand Down Expand Up @@ -1168,7 +1170,7 @@ public JsNode transformWhileStatement(JWhileStatement whileStatement) {
SourceInfo info = whileStatement.getSourceInfo();
JsWhile stmt = new JsWhile(info);
stmt.setCondition(transform(whileStatement.getTestExpr()));
stmt.setBody(jsEmptyIfNull(info, transform(whileStatement.getBody())));
stmt.setBody(jsEmptyIfNull(info, transform(whileStatement.getBody().singleStatement())));
return stmt;
}

Expand Down
4 changes: 2 additions & 2 deletions dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,8 @@ public JExpression apply(JStatement statement) {
public void endVisit(IfStatement x, BlockScope scope) {
try {
SourceInfo info = makeSourceInfo(x);
JStatement elseStatement = pop(x.elseStatement);
JStatement thenStatement = pop(x.thenStatement);
JBlock elseStatement = popBlock(info, x.elseStatement);
JBlock thenStatement = popBlock(info, x.thenStatement);
JExpression condition = pop(x.condition);
push(new JIfStatement(info, condition, thenStatement, elseStatement));
} catch (Throwable e) {
Expand Down
33 changes: 9 additions & 24 deletions dev/core/src/com/google/gwt/dev/jjs/impl/Simplifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ public static JExpression simplifyConditional(JConditional expression) {
public static JStatement simplifyIfStatement(JIfStatement ifStatement, JType methodReturnType) {
SourceInfo info = ifStatement.getSourceInfo();
JExpression conditionExpression = ifStatement.getIfExpr();
JStatement thenStmt = ifStatement.getThenStmt();
JStatement elseStmt = ifStatement.getElseStmt();
final JBlock thenStmt = ifStatement.getThenStmt();
final JBlock elseStmt = ifStatement.getElseStmt();
if (conditionExpression instanceof JMultiExpression) {
// if(a,b,c) d else e -> {a; b; if(c) d else e; }
JMultiExpression condMulti = (JMultiExpression) conditionExpression;
Expand All @@ -258,10 +258,10 @@ public static JStatement simplifyIfStatement(JIfStatement ifStatement, JType met

if (conditionExpression instanceof JBooleanLiteral) {
boolean conditionValue = ((JBooleanLiteral) conditionExpression).getValue();
if (conditionValue && !JjsUtils.isEmptyBlock(thenStmt)) {
if (conditionValue && !thenStmt.isEmpty()) {
// If true, replace myself with then statement
return thenStmt;
} else if (!conditionValue && !JjsUtils.isEmptyBlock(elseStmt)) {
} else if (!conditionValue && !elseStmt.isEmpty()) {
// If false, replace myself with else statement
return elseStmt;
} else {
Expand All @@ -270,19 +270,15 @@ public static JStatement simplifyIfStatement(JIfStatement ifStatement, JType met
}
}

if (JjsUtils.isEmptyBlock(thenStmt) && JjsUtils.isEmptyBlock(elseStmt)) {
if (thenStmt.isEmpty() && elseStmt.isEmpty()) {
return conditionExpression.makeStatement();
}

if (!JjsUtils.isEmptyBlock(elseStmt)) {
if (!elseStmt.isEmpty()) {
// if (!cond) foo else bar -> if (cond) bar else foo
JExpression negationArugment =
Simplifier.maybeGetNegatedExpressionArgument(conditionExpression);
if (negationArugment != null) {
// Force sub-parts to blocks, otherwise we break else-if chains.
// TODO: this goes away when we normalize the Java AST properly.
thenStmt = ensureBlock(thenStmt);
elseStmt = ensureBlock(elseStmt);
return simplifyIfStatement(
new JIfStatement(info, negationArugment, elseStmt, thenStmt), methodReturnType);
}
Expand Down Expand Up @@ -520,22 +516,11 @@ private static JExpression extractExpression(JStatement statement) {
return null;
}

private static JStatement extractSingleStatement(JStatement statement) {
if (statement instanceof JBlock) {
JBlock block = (JBlock) statement;
if (block.getStatements().size() == 1) {
return extractSingleStatement(block.getStatements().get(0));
}
}

return statement;
}

private static JStatement rewriteIfStatementAsExpression(SourceInfo sourceInfo,
JExpression conditionExpression, JStatement thenStmt, JStatement elseStmt,
JExpression conditionExpression, JBlock thenBlock, JBlock elseBlock,
JType methodReturnType) {
thenStmt = extractSingleStatement(thenStmt);
elseStmt = extractSingleStatement(elseStmt);
JStatement thenStmt = thenBlock.singleStatement();
JStatement elseStmt = elseBlock.singleStatement();

if (thenStmt instanceof JReturnStatement && elseStmt instanceof JReturnStatement
&& methodReturnType != null) {
Expand Down
Loading
Loading