Skip to content

Commit 9e89213

Browse files
Alexey AndreevAlexey Andreev
Alexey Andreev
authored and
Alexey Andreev
committed
Prototyping DCE tool for JS
1 parent d617b1d commit 9e89213

File tree

26 files changed

+1445
-22
lines changed

26 files changed

+1445
-22
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<include name="js/js.inliner/src"/>
113113
<include name="js/js.parser/src"/>
114114
<include name="js/js.serializer/src"/>
115+
<include name="js/js.dce/src"/>
115116
<include name="plugins/annotation-collector/src"/>
116117
</dirset>
117118

@@ -152,6 +153,7 @@
152153
<include name="js.inliner/**"/>
153154
<include name="js.parser/**"/>
154155
<include name="js.serializer/**"/>
156+
<include name="js.dce/**"/>
155157
</patternset>
156158

157159
<path id="compilerSources.path">
@@ -265,6 +267,7 @@
265267
<fileset dir="js/js.inliner/src"/>
266268
<fileset dir="js/js.parser/src"/>
267269
<fileset dir="js/js.serializer/src"/>
270+
<fileset dir="js/js.dce/src"/>
268271
<zipfileset file="${kotlin-home}/build.txt" prefix="META-INF"/>
269272

270273
<manifest>

compiler/cli/cli.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
<orderEntry type="module" module-name="builtins-serializer" />
2525
<orderEntry type="module" module-name="frontend.script" />
2626
<orderEntry type="module" module-name="javac-wrapper" />
27+
<orderEntry type="module" module-name="js.dce" />
2728
</component>
2829
</module>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2010-2017 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@file:JvmName("K2JSDce")
18+
package org.jetbrains.kotlin.cli.js.dce
19+
20+
import org.jetbrains.kotlin.js.dce.DeadCodeElimination
21+
import org.jetbrains.kotlin.js.dce.InputFile
22+
import org.jetbrains.kotlin.js.dce.extractRoots
23+
import org.jetbrains.kotlin.js.dce.printTree
24+
25+
fun main(args: Array<String>) {
26+
val files = args.map { InputFile(it) }
27+
val nodes = DeadCodeElimination.run(files, emptySet()) { println(it) }
28+
29+
println()
30+
for (node in nodes.extractRoots()) {
31+
printTree(node, { println(it) }, printNestedMembers = false, showLocations = true)
32+
}
33+
}

js/js.dce/js.dce.iml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
11+
<orderEntry type="module" module-name="js.ast" />
12+
<orderEntry type="module" module-name="js.inliner" />
13+
<orderEntry type="module" module-name="js.translator" />
14+
<orderEntry type="module" module-name="util" />
15+
</component>
16+
</module>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2010-2017 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jetbrains.kotlin.js.dce
18+
19+
import org.jetbrains.kotlin.js.backend.ast.JsFunction
20+
import org.jetbrains.kotlin.js.backend.ast.JsInvocation
21+
import org.jetbrains.kotlin.js.backend.ast.JsNode
22+
import org.jetbrains.kotlin.js.dce.Context.Node
23+
24+
interface AnalysisResult {
25+
val nodeMap: Map<JsNode, Node>
26+
27+
val astNodesToEliminate: Set<JsNode>
28+
29+
val astNodesToSkip: Set<JsNode>
30+
31+
val functionsToEnter: Set<JsFunction>
32+
33+
val invocationsToSkip: Set<JsInvocation>
34+
}

0 commit comments

Comments
 (0)