Skip to content

Commit

Permalink
Introduce TypeDeclaration.getAllSuperInterfaces().
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 620241524
  • Loading branch information
rluble authored and copybara-github committed Mar 29, 2024
1 parent b009ce1 commit c2ea38a
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 35 deletions.
7 changes: 4 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load("@rules_license//rules:license.bzl", "license")
load("//build_defs:rules.bzl", "j2cl_alias")

# Description:
# Public targets available externally. Also see build_defs/rules.bzl for the provided rules.
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("//build_defs:rules.bzl", "j2cl_alias")
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load("@rules_license//rules:license.bzl", "license")

package(
default_applicable_licenses = [":j2cl_license"],
Expand Down
2 changes: 1 addition & 1 deletion jre/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# j2cl/jre: JRE subset for transpilation.
#

load("//build_defs:rules.bzl", "j2cl_import", "j2cl_library", "j2wasm_library")
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load("//build_defs:rules.bzl", "j2cl_import", "j2cl_library", "j2wasm_library")
load(":j2cl_java_toolchain.bzl", "j2cl_java_toolchain")
load(":package_sources.bzl", "package_sources")

Expand Down
4 changes: 2 additions & 2 deletions jre/javatests/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Description:
# j2cl/jre: JRE subset for transpilation.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary")
load("//build_defs:rules.bzl", "j2cl_library", "j2cl_test", "j2kt_native_library")
load("//javascript/tools/jscompiler/builddefs:flags.bzl", "VERBOSE_WARNING_FLAGS_STRICT", "WHITESPACE_ONLY_FLAGS")
load("//third_party/bazel_rules/rules_closure/closure:defs.bzl", "closure_js_binary")
load("//build_defs:rules.bzl", "j2cl_library", "j2cl_test", "j2kt_native_library")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load(":j2cl_multi_test.bzl", "j2cl_multi_test")

package(
Expand Down
2 changes: 1 addition & 1 deletion junit/generator/java/com/google/j2cl/junit/runtime/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//build_defs:rules.bzl", "j2cl_library")
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load("//build_defs:rules.bzl", "j2cl_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load(
"//junit/generator/javatests/com/google/j2cl/junit/integration:j2cl_junit_integration_test.bzl",
"j2cl_test_integration_test_data",
"java_and_j2cl_library",
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
# for community experimentation and it doesn't reflect final workings of the product
# nor the Wasm spec.

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load(
"@com_google_j2cl//build_defs:rules.bzl",
"j2cl_application",
"j2wasm_application",
"j2wasm_library",
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")

package(
default_applicable_licenses = ["@com_google_j2cl//:j2cl_license"],
Expand Down
2 changes: 1 addition & 1 deletion tools/javatests/com/google/j2cl/tools/rta/proto/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("//third_party/java/j2cl_proto:j2cl_proto_library.bzl", "j2cl_proto_library")
load(
"//tools/javatests/com/google/j2cl/tools/rta:rta_test.bzl",
"rta_test",
)
load("//third_party/java/j2cl_proto:j2cl_proto_library.bzl", "j2cl_proto_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.util.stream.Collectors.joining;

import com.google.auto.value.AutoValue;
Expand Down Expand Up @@ -388,9 +389,8 @@ public boolean hasTypeParameters() {
return !getTypeParameterDescriptors().isEmpty();
}

@Memoized
public boolean implementsInterfaces() {
return getAllSuperTypesIncludingSelf().stream().anyMatch(TypeDeclaration::isInterface);
return !getAllSuperInterfaces().isEmpty();
}

@Memoized
Expand Down Expand Up @@ -734,6 +734,14 @@ public Set<TypeDeclaration> getAllSuperTypesIncludingSelf() {
return allSupertypesIncludingSelf;
}

@Memoized
public Set<TypeDeclaration> getAllSuperInterfaces() {
return getAllSuperTypesIncludingSelf().stream()
.filter(Predicate.not(Predicate.isEqual(this)))
.filter(TypeDeclaration::isInterface)
.collect(toImmutableSet());
}

/**
* The list of methods declared in the type. Note: this does not include methods synthetic methods
* (like bridge methods) nor supertype methods that are not overridden in the type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private void addType(Type type) {
typeHierarchyInfoBuilder.setExtendsType(getTypeId(superTypeDescriptor));
}

type.getDeclaration().getAllSuperTypesIncludingSelf().stream()
.filter(TypeDeclaration::isInterface)
type.getDeclaration().getAllSuperInterfaces().stream()
.filter(not(TypeDeclaration::isNative))
.forEach(
t ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
Expand Down Expand Up @@ -580,8 +581,8 @@ private void emitVtablesInitialization(TypeDeclaration typeDeclaration) {
builder.newLine();
builder.append(")");

typeDeclaration.getAllSuperTypesIncludingSelf().stream()
.filter(TypeDeclaration::isInterface)
typeDeclaration
.getAllSuperInterfaces()
.forEach(
i -> {
builder.newLine();
Expand Down Expand Up @@ -645,10 +646,7 @@ private void emitItableInitialization(TypeDeclaration typeDeclaration) {
}

private TypeDeclaration[] getInterfacesByItableIndex(TypeDeclaration typeDeclaration) {
ImmutableList<TypeDeclaration> superInterfaces =
typeDeclaration.getAllSuperTypesIncludingSelf().stream()
.filter(TypeDeclaration::isInterface)
.collect(toImmutableList());
Set<TypeDeclaration> superInterfaces = typeDeclaration.getAllSuperInterfaces();

// Compute the itable for this type.
int numSlots = environment.getItableSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ private void assignInterfaceSlots(Library library) {
.filter(Predicates.not(Type::isInterface))
.forEach(
t ->
t.getDeclaration().getAllSuperTypesIncludingSelf().stream()
.filter(TypeDeclaration::isInterface)
t.getDeclaration()
.getAllSuperInterfaces()
.forEach(i -> concreteTypesByInterface.put(i, t.getDeclaration())));

// Traverse and assign interfaces by most implemented to least implemented so that widely
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.j2cl.transpiler.ast.MethodDescriptor;
import com.google.j2cl.transpiler.ast.SuperReference;
import com.google.j2cl.transpiler.ast.Type;
import com.google.j2cl.transpiler.ast.TypeDeclaration;
import com.google.j2cl.transpiler.ast.TypeDescriptors;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -55,8 +54,7 @@ public void applyTo(Type type) {

Map<String, MethodDescriptor> requiredJavaLangObjectMethods =
type.getDeclaration().getInterfaceTypeDescriptors().stream()
.flatMap(t -> t.getTypeDeclaration().getAllSuperTypesIncludingSelf().stream())
.filter(TypeDeclaration::isInterface)
.flatMap(t -> t.getTypeDeclaration().getAllSuperInterfaces().stream())
// TODO(b/317299672): Remove JsType special casing since should preserve all of them for
// migration purposes.
.filter(t -> PRESERVE_EQUALS_FOR_JSTYPE_INTERFACE && t.isJsType())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("//build_defs:rules.bzl", "j2wasm_library")
load(
"//transpiler/javatests/com/google/j2cl/integration:integration_test.bzl",
"integration_test",
)
load("//build_defs:rules.bzl", "j2wasm_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load("//build_defs:rules.bzl", "j2cl_library")
load(
"//transpiler/javatests/com/google/j2cl/integration:integration_test.bzl",
"integration_test",
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("//build_defs:rules.bzl", "j2cl_import", "j2cl_library")
load(
"//transpiler/javatests/com/google/j2cl/readable:readable_example.bzl",
"readable_example",
)
load("//build_defs:rules.bzl", "j2cl_import", "j2cl_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load("//build_defs:rules.bzl", "j2kt_jvm_library")
load(
"//transpiler/javatests/com/google/j2cl/readable:readable_example.bzl",
"readable_example",
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("//build_defs:rules.bzl", "j2cl_library")
load(
"//transpiler/javatests/com/google/j2cl/readable:readable_example.bzl",
"readable_example",
)
load("//build_defs:rules.bzl", "j2cl_library")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("//testing/build_defs:junit_test_suites.bzl", "junit_test_suites")

package(
default_applicable_licenses = ["//:j2cl_license"],
Expand Down

0 comments on commit c2ea38a

Please sign in to comment.