Skip to content

Commit

Permalink
Qute: disable optimization of generated ValueResolvers for native builds
Browse files Browse the repository at this point in the history
- fixes #33881
  • Loading branch information
mkouba committed Jun 12, 2023
1 parent 197c921 commit bad0ed1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ public boolean isUberJar() {
return type.equalsIgnoreCase(PackageConfig.BuiltInType.UBER_JAR.getValue());
}

public boolean isNativeOrNativeSources() {
return type.equalsIgnoreCase(PackageConfig.BuiltInType.NATIVE.getValue())
|| type.equalsIgnoreCase(PackageConfig.BuiltInType.NATIVE_SOURCES.getValue());
}

public String getRunnerSuffix() {
return addRunnerSuffix ? runnerSuffix : "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class NativeOrNativeSourcesBuild implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
return packageConfig.type.equalsIgnoreCase(PackageConfig.BuiltInType.NATIVE.getValue())
|| packageConfig.type.equalsIgnoreCase(PackageConfig.BuiltInType.NATIVE_SOURCES.getValue());
return packageConfig.isNativeOrNativeSources();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import io.quarkus.deployment.builditem.ServiceStartBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.fs.util.ZipUtils;
import io.quarkus.gizmo.ClassOutput;
Expand Down Expand Up @@ -830,7 +831,8 @@ void validateExpressions(TemplatesAnalysisBuildItem templatesAnalysis,
BeanDiscoveryFinishedBuildItem beanDiscovery,
List<CheckedTemplateBuildItem> checkedTemplates,
List<TemplateDataBuildItem> templateData,
QuteConfig config) {
QuteConfig config,
PackageConfig packageConfig) {

long start = System.nanoTime();

Expand Down Expand Up @@ -887,6 +889,14 @@ public String apply(String id) {
// Maps an expression generated id to the last match of an expression (i.e. the type of the last part)
Map<Integer, MatchResult> generatedIdsToMatches = new HashMap<>();

// Register all param declarations as targets of implicit value resolvers
for (ParameterDeclaration paramDeclaration : templateAnalysis.parameterDeclarations) {
Type type = TypeInfos.resolveTypeFromTypeInfo(paramDeclaration.getTypeInfo());
if (type != null) {
implicitClassToMembersUsed.put(type.name(), new HashSet<>());
}
}

// Iterate over all top-level expressions found in the template
for (Expression expression : templateAnalysis.expressions) {
if (expression.isLiteral()) {
Expand Down Expand Up @@ -916,15 +926,21 @@ public String apply(String id) {
// ==========================================================================
// Register implicit value resolvers for classes collected during validation
// ==========================================================================
boolean isNonNativeBuild = !packageConfig.isNativeOrNativeSources();
for (Entry<DotName, Set<String>> entry : implicitClassToMembersUsed.entrySet()) {
if (entry.getValue().isEmpty()) {
// No members
if (entry.getValue().isEmpty() && isNonNativeBuild) {
// No members used - skip the generation for non-native builds
continue;
}
ClassInfo clazz = index.getClassByName(entry.getKey());
if (clazz != null) {
implicitClasses.produce(new ImplicitValueResolverBuildItem(clazz,
new TemplateDataBuilder().addIgnore(buildIgnorePattern(entry.getValue())).build()));
TemplateDataBuilder builder = new TemplateDataBuilder();
if (isNonNativeBuild) {
// Optimize the generated value resolvers
// I.e. only fields/methods used in templates are considered and all other members are ignored
builder.addIgnore(buildIgnorePattern(entry.getValue()));
}
implicitClasses.produce(new ImplicitValueResolverBuildItem(clazz, builder.build()));
}
}
}
Expand Down Expand Up @@ -1784,7 +1800,8 @@ public Function<FieldInfo, String> apply(ClassInfo clazz) {
continue;
}
if (uncontrolled.containsKey(implicitClassName)) {
LOGGER.debugf("Implicit value resolver for %d ignored: %s declared on %s", uncontrolled.get(implicitClassName),
LOGGER.debugf("Implicit value resolver for %s ignored: %s declared on %s", implicitClassName,
uncontrolled.get(implicitClassName),
uncontrolled.get(implicitClassName).target());
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ static Info create(String typeInfo, Expression.Part part, IndexView index, Funct
}
}

static Type resolveTypeFromTypeInfo(String typeInfo) {
if (typeInfo.startsWith(TYPE_INFO_SEPARATOR)) {
int endIdx = typeInfo.substring(1, typeInfo.length()).indexOf(Expressions.TYPE_INFO_SEPARATOR);
if (endIdx < 1) {
throw new IllegalArgumentException("Invalid type info: " + typeInfo);
}
String typeInfoStr = typeInfo.substring(1, endIdx + 1);
if (!isArray(typeInfoStr)) {
Type primitiveType = decodePrimitive(typeInfoStr);
if (primitiveType == null) {
return resolveType(typeInfoStr);
}
}
}
return null;
}

static boolean isArray(String typeInfo) {
return typeInfo == null ? false : typeInfo.indexOf(ARRAY_DIM) > 0;
}

private static ClassInfo getClassInfo(String val, IndexView index, Function<String, String> templateIdToPathFun,
Origin expressionOrigin) {
DotName rawClassName = rawClassName(val);
Expand Down

0 comments on commit bad0ed1

Please sign in to comment.