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

GROOVY-11263: Analyze dead code #2023

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,10 @@ public void call(final SourceUnit source, final GeneratorContext context, final
getErrorCollector().addError(new SyntaxException(rpe.getMessage(), rpe.getNode()), source);
}

visitor = new DeadCodeAnalyzer(source);
visitor.visitClass(classNode);
if (Boolean.TRUE.equals(configuration.getOptimizationOptions().get(CompilerConfiguration.ANALYZE_DEAD_CODE))) {
visitor = new DeadCodeAnalyzer(source);
visitor.visitClass(classNode);
}

visitor = new LabelVerifier(source);
visitor.visitClass(classNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class CompilerConfiguration {
/** Joint Compilation Option for enabling generating stubs in memory. */
public static final String MEM_STUB = "memStub";

/** Optimization Option for enabling dead code analysis */
public static final String ANALYZE_DEAD_CODE = "analyzeDeadCode";

Comment on lines +69 to +71
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this adjacent to the other optimization options and add an @since tag?

I'm partial to naming it DEAD_CODE_ANALYSIS and "deadCodeAnalysis".

/** This (<code>"1.4"</code>) is the value for targetBytecode to compile for a JDK 1.4. */
@Deprecated public static final String JDK4 = "1.4";
/** This (<code>"1.5"</code>) is the value for targetBytecode to compile for a JDK 1.5. */
Expand Down Expand Up @@ -469,6 +472,8 @@ public CompilerConfiguration() {
handleOptimizationOption(GROOVYDOC, getSystemPropertySafe("groovy.attach.groovydoc"));
handleOptimizationOption(RUNTIME_GROOVYDOC, getSystemPropertySafe("groovy.attach.runtime.groovydoc"));
handleOptimizationOption(PARALLEL_PARSE, getSystemPropertySafe("groovy.parallel.parse", "true"));
handleOptimizationOption(ANALYZE_DEAD_CODE, getSystemPropertySafe("groovy.analyze.deadcode", "true"));

Comment on lines +475 to +476
Copy link
Member

Choose a reason for hiding this comment

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

"groovy.branch.analysis" or "groovy.deadCode.analysis"? Are you sure we want to default to enabled right out the gate?

Spurious extra line added.


if (getBooleanSafe("groovy.mem.stub")) {
jointCompilationOptions = new HashMap<>(2);
Expand Down