Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute: disable optimization of generated ValueResolvers for native builds #33984

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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