Skip to content

Commit 46a9016

Browse files
concavelenzcopybara-github
authored andcommitted
Remove "runtime type check" support.
This feature of the compiler has long been under used and under maintained. At this time we believe our efforts would be better spent elsewhere. PiperOrigin-RevId: 485375148
1 parent 0192157 commit 46a9016

File tree

11 files changed

+13
-1884
lines changed

11 files changed

+13
-1884
lines changed

BUILD.bazel

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ load("//:bazel/typedast.bzl", "typedast")
1919
load("@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl", "jar_jar")
2020
load("@google_bazel_common//testing:test_defs.bzl", "gen_java_tests")
2121

22+
# Produce an unshaded export jar based on :compiler_lib
23+
load("@rules_jvm_external//:defs.bzl", "java_export")
24+
2225
package(licenses = ["notice"])
2326

2427
filegroup(
@@ -81,16 +84,15 @@ java_binary(
8184
runtime_deps = [":compiler_lib"],
8285
)
8386

84-
# Produce an unshaded export jar based on :compiler_lib
85-
load("@rules_jvm_external//:defs.bzl", "java_export")
8687
version = "$(COMPILER_VERSION)" or "1.0-SNAPSHOT"
88+
8789
java_export(
8890
name = "compiler_unshaded",
8991
maven_coordinates = "com.google.javascript:closure-compiler-unshaded:{0}".format(version),
92+
pom_template = "maven/closure-compiler-unshaded.pom.xml.tpl",
9093
runtime_deps = [
9194
"//:compiler_lib",
9295
],
93-
pom_template = "maven/closure-compiler-unshaded.pom.xml.tpl"
9496
)
9597

9698
java_binary(
@@ -114,7 +116,6 @@ java_library(
114116
name = "compiler_lib",
115117
resources = [
116118
"src/com/google/javascript/jscomp/js/polyfills.txt",
117-
"src/com/google/javascript/jscomp/js/runtime_type_check.js",
118119
":runtime_lib_typedast_srcs",
119120
":runtime_libs_typedast",
120121
],
@@ -132,7 +133,6 @@ filegroup(
132133
srcs = glob(
133134
["src/com/google/javascript/jscomp/js/**/*.js"],
134135
exclude = [
135-
"src/com/google/javascript/jscomp/js/runtime_type_check.js", # TODO(b/192503189) Add this when we can fix the compile errors.
136136
"src/com/google/javascript/jscomp/js/build_polyfill_table.js",
137137
],
138138
),
@@ -185,9 +185,9 @@ oss_java_library(
185185
"@com_google_errorprone_error_prone_annotations",
186186
"@com_google_guava_failureaccess//jar",
187187
"@com_google_guava_guava//jar",
188-
"@maven//:com_google_protobuf_protobuf_java",
189188
"@com_google_re2j_re2j",
190189
"@google_bazel_common//third_party/java/auto:value",
190+
"@maven//:com_google_protobuf_protobuf_java",
191191
"@org_apache_ant_ant",
192192
"@org_jspecify_jspecify",
193193
],
@@ -250,7 +250,6 @@ gen_java_tests(
250250
"@com_google_guava_guava//jar",
251251
"@com_google_guava_guava_testlib//jar",
252252
"@com_google_jimfs_jimfs",
253-
"@maven//:com_google_protobuf_protobuf_java",
254253
"@com_google_re2j_re2j",
255254
"@com_google_truth_extensions_truth_liteproto_extension",
256255
"@com_google_truth_extensions_truth_proto_extension",
@@ -259,6 +258,7 @@ gen_java_tests(
259258
"@google_bazel_common//third_party/java/mockito",
260259
"@google_bazel_common//third_party/java/truth",
261260
"@io_github_java_diff_utils_java_diff_utils",
261+
"@maven//:com_google_protobuf_protobuf_java",
262262
"@org_jspecify_jspecify",
263263
],
264264
)

src/com/google/javascript/jscomp/CommandLineRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ private static class Flags {
812812
usage =
813813
"Force injection of named runtime libraries. "
814814
+ "The format is <name> where <name> is the name of a runtime library. "
815-
+ "Possible libraries include: base, es6_runtime, runtime_type_check")
815+
+ "Possible libraries include: base, es6_runtime")
816816
private List<String> forceInjectLibraries = new ArrayList<>();
817817

818818
@Option(

src/com/google/javascript/jscomp/CompilerOptions.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,6 @@ public boolean shouldRunReplaceMessagesForChrome() {
702702
}
703703
}
704704

705-
/** Inserts run-time type assertions for debugging. */
706-
boolean runtimeTypeCheck;
707-
708-
/**
709-
* A JS function to be used for logging run-time type assertion failures. It will be passed the
710-
* warning as a string and the faulty expression as arguments.
711-
*/
712-
@Nullable String runtimeTypeCheckLogFunction;
713705

714706
/** A CodingConvention to use during the compile. */
715707
private CodingConvention codingConvention;
@@ -1365,8 +1357,7 @@ public CompilerOptions() {
13651357
nameGenerator = new DefaultNameGenerator();
13661358

13671359
// Alterations
1368-
runtimeTypeCheck = false;
1369-
runtimeTypeCheckLogFunction = null;
1360+
13701361
syntheticBlockStartMarker = null;
13711362
syntheticBlockEndMarker = null;
13721363
locale = null;
@@ -1657,20 +1648,6 @@ public boolean shouldColorizeErrorOutput() {
16571648
return colorizeErrorOutput;
16581649
}
16591650

1660-
/**
1661-
* Enable run-time type checking, which adds JS type assertions for debugging.
1662-
*
1663-
* @param logFunction A JS function to be used for logging run-time type assertion failures.
1664-
*/
1665-
public void enableRuntimeTypeCheck(String logFunction) {
1666-
this.runtimeTypeCheck = true;
1667-
this.runtimeTypeCheckLogFunction = logFunction;
1668-
}
1669-
1670-
public void disableRuntimeTypeCheck() {
1671-
this.runtimeTypeCheck = false;
1672-
}
1673-
16741651
public void setChecksOnly(boolean checksOnly) {
16751652
this.checksOnly = checksOnly;
16761653
}
@@ -2294,13 +2271,6 @@ public void setExportTestFunctions(boolean exportTestFunctions) {
22942271
this.exportTestFunctions = exportTestFunctions;
22952272
}
22962273

2297-
public void setRuntimeTypeCheck(boolean runtimeTypeCheck) {
2298-
this.runtimeTypeCheck = runtimeTypeCheck;
2299-
}
2300-
2301-
public void setRuntimeTypeCheckLogFunction(String runtimeTypeCheckLogFunction) {
2302-
this.runtimeTypeCheckLogFunction = runtimeTypeCheckLogFunction;
2303-
}
23042274

23052275
public void setSyntheticBlockStartMarker(String syntheticBlockStartMarker) {
23062276
this.syntheticBlockStartMarker = syntheticBlockStartMarker;
@@ -2947,8 +2917,6 @@ public String toString() {
29472917
.add("reserveRawExports", reserveRawExports)
29482918
.add("rewriteFunctionExpressions", rewriteFunctionExpressions)
29492919
.add("rewritePolyfills", rewritePolyfills)
2950-
.add("runtimeTypeCheckLogFunction", runtimeTypeCheckLogFunction)
2951-
.add("runtimeTypeCheck", runtimeTypeCheck)
29522920
.add("rewriteModulesBeforeTypechecking", rewriteModulesBeforeTypechecking)
29532921
.add("skipNonTranspilationPasses", skipNonTranspilationPasses)
29542922
.add("smartNameRemoval", smartNameRemoval)

src/com/google/javascript/jscomp/DefaultPassConfig.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,6 @@ protected PassListBuilder getChecks() {
490490
checks.maybeAdd(externExports);
491491
}
492492

493-
if (options.runtimeTypeCheck) {
494-
// RuntimeTypeCheck depends on the AST being normalized. We immediately mark the AST
495-
// unnormalized as subsequent passes may produce unnormalized code.
496-
// TODO(b/197349249): always run normalize here.
497-
checks.maybeAdd(normalize);
498-
checks.maybeAdd(runtimeTypeCheck);
499-
checks.maybeAdd(markUnnormalized);
500-
}
501-
502493
if (!options.checksOnly) {
503494
checks.maybeAdd(removeWeakSources);
504495
}
@@ -2070,16 +2061,6 @@ public void process(Node externs, Node jsRoot) {
20702061
.setInternalFactory(ConstParamCheck::new)
20712062
.build();
20722063

2073-
/** Inserts run-time type assertions for debugging. */
2074-
private final PassFactory runtimeTypeCheck =
2075-
PassFactory.builder()
2076-
.setName(PassNames.RUNTIME_TYPE_CHECK)
2077-
.setInternalFactory(
2078-
(compiler) -> new RuntimeTypeCheck(compiler, options.runtimeTypeCheckLogFunction))
2079-
// TODO(bradfordcsmith): Drop support for this pass.
2080-
// It's never been updated to handle ES2016+ code, because it isn't worth the effort.
2081-
.build();
2082-
20832064
/** Generates unique ids. */
20842065
private final PassFactory replaceIdGenerators =
20852066
PassFactory.builder()

src/com/google/javascript/jscomp/InjectRuntimeLibraries.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,14 @@
1818
import com.google.javascript.rhino.Node;
1919

2020
/**
21-
* Adds runtime libraries to the beginning of the AST. The libraries for runtime typechecking are
22-
* added, if needed, as well as any other libraries explicitly requested via the {@link
23-
* CompilerOptions#forceLibraryInjection} field.
21+
* Adds runtime libraries to the beginning of the AST. Any libraries explicitly requested via the
22+
* {@link CompilerOptions#forceLibraryInjection} field.
2423
*
2524
* <p>TODO(b/120486392): merge this pass with {@link InjectTranspilationRuntimeLibraries}.
2625
*/
2726
class InjectRuntimeLibraries implements CompilerPass {
2827
private final AbstractCompiler compiler;
2928
private final Stage stage;
30-
// The runtime type check library code is special in that it is the only library that should be
31-
// injected before typechecking. All other library code is expected to be injected during the
32-
// optimization phase. This is because runtime typechecking is incompatible with a binary reading
33-
// from precompiled TypedASTs.
34-
private static final String RUNTIME_TYPE_CHECK_LIB = "runtime_type_check";
3529

3630
private enum Stage {
3731
CHECKS,
@@ -49,7 +43,6 @@ public void process(Node externs, Node root) {
4943
CompilerOptions options = compiler.getOptions();
5044
switch (this.stage) {
5145
case CHECKS:
52-
injectCheckLibraries(options);
5346
return;
5447
case OPTIMIZATIONS:
5548
injectOptimizationsLibraries(options);
@@ -58,18 +51,9 @@ public void process(Node externs, Node root) {
5851
throw new AssertionError();
5952
}
6053

61-
private void injectCheckLibraries(CompilerOptions options) {
62-
if (options.runtimeTypeCheck
63-
|| options.forceLibraryInjection.contains(RUNTIME_TYPE_CHECK_LIB)) {
64-
compiler.ensureLibraryInjected(RUNTIME_TYPE_CHECK_LIB, true);
65-
}
66-
}
67-
6854
private void injectOptimizationsLibraries(CompilerOptions options) {
6955
for (String forced : options.forceLibraryInjection) {
70-
if (!forced.equals(RUNTIME_TYPE_CHECK_LIB)) {
71-
compiler.ensureLibraryInjected(forced, true);
72-
}
56+
compiler.ensureLibraryInjected(forced, true);
7357
}
7458
}
7559

src/com/google/javascript/jscomp/PassNames.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public final class PassNames {
8888
public static final String RESOLVE_TYPES = "resolveTypes";
8989
public static final String REWRITE_FUNCTION_EXPRESSIONS = "rewriteFunctionExpressions";
9090
public static final String RENAME_PROPERTIES = "renameProperties";
91-
public static final String RUNTIME_TYPE_CHECK = "runtimeTypeCheck";
9291
public static final String STRIP_SIDE_EFFECT_PROTECTION = "stripSideEffectProtection";
9392
public static final String WIZ_PASS = "wizPass";
9493
public static final String PARENTHESIZE_FUNCTIONS_IN_CHUNKS = "parenthesizeFunctionsInChunks";

0 commit comments

Comments
 (0)