Skip to content

Commit 982d9ba

Browse files
committed
Optimize inner configuration exclusion
Fixes spring-attic#190
1 parent a727ca4 commit 982d9ba

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

spring-graalvm-native-feature/src/main/java/org/springframework/graalvm/support/ResourcesHandler.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,15 @@ private boolean processType(Type type, Set<String> visited, int depth) {
983983
SpringFeature.log(spaces(depth) + "will follow " + t);
984984
toFollow.add(t);
985985
}
986-
} else if (hint.isSkipIfTypesMissing() && depth == 0) {
986+
} else if (hint.isSkipIfTypesMissing() && (depth == 0 || isNestedConfiguration(type))) {
987987
// TODO If processing secondary type (depth>0) we can't skip things as we don't
988988
// know if the top level type that refers to us is going to fail or not. Ideally we should
989989
// pass in the tar and accumulate types in secondary type processing and leave it to the
990990
// outermost processing to decide if they need registration.
991+
// Update: the isNestedConfiguration() clause allows us to discard nested configurations that are failing a COC check.
992+
// This works if they are simply included in a setup due to being lexically inside an outer configuration - if they
993+
// are being explicitly referenced via some other mechanism (e.g. @Import) this will need a bit of rework (the outer
994+
// call into here should tell us how this configuration is being made so we can make a smarter decision).
991995
passesTests = false;
992996
// Once failing, no need to process other hints
993997
if (ConfigOptions.shouldRemoveUnusedAutoconfig()) {
@@ -1242,6 +1246,14 @@ private boolean processType(Type type, Set<String> visited, int depth) {
12421246
return passesTests;
12431247
}
12441248

1249+
/**
1250+
* Crude guess at nested configuration.
1251+
*/
1252+
private boolean isNestedConfiguration(Type type) {
1253+
boolean b = type.isAtConfiguration() && type.getEnclosingType()!=null;
1254+
return b;
1255+
}
1256+
12451257
private void registerAnnotationChain(int depth, TypeAccessRequestor tar, List<Type> annotationChain) {
12461258
SpringFeature.log(spaces(depth) + "attempting registration of " + annotationChain.size()
12471259
+ " elements of annotation chain");

spring-graalvm-native-feature/src/main/java/org/springframework/graalvm/type/Type.java

+18
Original file line numberDiff line numberDiff line change
@@ -1862,4 +1862,22 @@ public boolean equals(Object that) {
18621862
public int hashCode() {
18631863
return node.hashCode() * 37;
18641864
}
1865+
1866+
/**
1867+
* TODO: This is a little crude, relying on patterns rather than classfile encoded data.
1868+
* @return the guessed enclosing type, if resolvable
1869+
*/
1870+
public Type getEnclosingType() {
1871+
String n = this.getDottedName();
1872+
int idx = n.lastIndexOf("$");
1873+
if (idx == -1) {
1874+
return null;
1875+
}
1876+
Type t = typeSystem.resolveDotted(n.substring(0,idx),true);
1877+
if (t == null) {
1878+
return null;
1879+
} else {
1880+
return t;
1881+
}
1882+
}
18651883
}

0 commit comments

Comments
 (0)