manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.42k stars 125 forks source link

javac error with manifold-exceptions #553

Closed DaMatrix closed 8 months ago

DaMatrix commented 8 months ago

Describe the bug While trying to add manifold-exceptions to my project, I found a piece of code which fails to compile in the presence of Manifold but compiles fine with plain javac. The code snippet below is the erroring code, after removing as much code as I could while still causing the error.

Running the compiler in a debugger, the exception is being thrown when creating a new com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$TranslationContext for the tree (next)->this.visit0(next)

To Reproduce Compile the following code:

@FunctionalInterface
interface InternalChildCallback<M extends StructLayout.Member<M, C>, C extends StructLayout.Component> {
    int visitChild(Callback<M, C> next);
}

interface Callback<M extends StructLayout.Member<M, C>, C extends StructLayout.Component> {
}

class AbstractSetter {
    protected <M extends StructLayout.Member<M, C>, C extends StructLayout.Component> int visitChildFixed(InternalChildCallback<M, C> childCallback, Callback<M, C> callback) {
        return 0;
    }
}

class BasicSetterImpl extends AbstractSetter {
    protected <M extends StructLayout.Member<M, C>, C extends StructLayout.Component> int visit0(Callback<M, C> callback) {
        return this.visitChildFixed(next -> this.visit0(next), callback);
    }
}

abstract class StructLayout<M extends StructLayout.Member<M, C>, C extends StructLayout.Component> {
    public interface Member<M extends Member<M, C>, C extends Component> {
    }

    public interface Component {
    }
}

Compile the above code with manifold-exceptions 2024.1.5.

Expected behavior The code should compile correctly, and does if you remove the manifold plugin.

Stack trace

java: An exception has occurred in the compiler (1.8.0_392). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java: com.sun.tools.javac.code.Types$FunctionDescriptorLookupError
java:   at com.sun.tools.javac.code.Types.<init>(Types.java:123)
java:   at manifold.internal.javac.ManTypes_8.<init>(ManTypes_8.java:73)
java:   at manifold.internal.javac.ManTypes_8.instance(ManTypes_8.java:65)
java:   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
java:   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
java:   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java:   at java.lang.reflect.Method.invoke(Method.java:498)
java:   at manifold.util.ReflectUtil$MethodRef.invokeStatic(ReflectUtil.java:962)
java:   at manifold.internal.javac.JavacPlugin.tailorJavaCompiler(JavacPlugin.java:447)
java:   at manifold.internal.javac.JavacPlugin.initialize(JavacPlugin.java:1030)
java:   at manifold.internal.javac.JavacPlugin.started(JavacPlugin.java:1051)
java:   at com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.started(ClientCodeWrapper.java:668)
java:   at com.sun.tools.javac.api.MultiTaskListener.started(MultiTaskListener.java:103)
java:   at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:978)
java:   at com.sun.tools.javac.main.JavaCompiler.enterTreesIfNeeded(JavaCompiler.java:965)
java:   at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1250)
java:   at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
java:   at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
java:   at com.sun.tools.javac.main.Main.compile(Main.java:523)
java:   at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
java:   at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)

Stack trace from debugger breakpoint at com.sun.tools.javac.code.Types$DescriptorCache#failure()`:

Breakpoint reached
    at com.sun.tools.javac.code.Types$DescriptorCache.failure(Types.java:549)
    at com.sun.tools.javac.code.Types$DescriptorCache$FunctionDescriptor.getType(Types.java:366)
    at com.sun.tools.javac.code.Types.findDescriptorType(Types.java:568)
    at com.sun.tools.javac.code.Types.makeFunctionalInterfaceClass(Types.java:639)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$TranslationContext.<init>(LambdaToMethod.java:1769)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor$LambdaTranslationContext.<init>(LambdaToMethod.java:1853)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.analyzeLambda(LambdaToMethod.java:1337)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitLambda(LambdaToMethod.java:1322)
    at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
    at com.sun.tools.javac.tree.TreeTranslator.visitApply(TreeTranslator.java:275)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitApply(LambdaToMethod.java:1208)
    at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
    at com.sun.tools.javac.tree.TreeTranslator.visitReturn(TreeTranslator.java:258)
    at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1384)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
    at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:162)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitBlock(LambdaToMethod.java:1231)
    at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
    at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:145)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitMethodDef(LambdaToMethod.java:1361)
    at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
    at com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:134)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.visitClassDef(LambdaToMethod.java:1270)
    at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.analyzeAndPreprocessClass(LambdaToMethod.java:1197)
    at com.sun.tools.javac.comp.LambdaToMethod$LambdaAnalyzerPreprocessor.access$300(LambdaToMethod.java:1148)
    at com.sun.tools.javac.comp.LambdaToMethod.visitClassDef(LambdaToMethod.java:232)
    at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
    at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:197)
    at com.sun.tools.javac.comp.LambdaToMethod.translate(LambdaToMethod.java:190)
    at com.sun.tools.javac.comp.LambdaToMethod.translateTopLevelClass(LambdaToMethod.java:217)
    at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1493)
    at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1356)
    at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
    at com.sun.tools.javac.main.Main.compile(Main.java:523)
    at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
DaMatrix commented 8 months ago

Possibly related to #462 ?

rsmckinney commented 8 months ago

In progress

rsmckinney commented 8 months ago

Fixed locally, will be available with next release by EOD March 11 2024.

rsmckinney commented 8 months ago

Fix available with release 2024.1.6

rsmckinney commented 8 months ago

By the way, Thanks for reporting this!

DaMatrix commented 8 months ago

Seems to work, thanks!