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

Reactor extending itself causes StackOverflowError #907

Closed
housengw opened this issue Jan 28, 2022 · 4 comments
Closed

Reactor extending itself causes StackOverflowError #907

housengw opened this issue Jan 28, 2022 · 4 comments
Labels
bug Something isn't working validation

Comments

@housengw
Copy link
Contributor

housengw commented Jan 28, 2022

minimal example

target C;
reactor A extends A {}

output

wonghouseng@beefy-desktop-linux:~/Desktop/lingua-franca/test/C$  lfc src/exp.lf
0    [main] ERROR text.validation.CompositeEValidator  - Error executing EValidator
java.lang.StackOverflowError
	at org.eclipse.emf.ecore.util.EcoreEList.resolveProxy(EcoreEList.java:206)
	at org.eclipse.emf.ecore.util.EcoreEList.resolve(EcoreEList.java:161)
	at org.eclipse.emf.ecore.util.EObjectResolvingEList.resolve(EObjectResolvingEList.java:60)
	at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:348)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.doNext(AbstractEList.java:698)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.next(AbstractEList.java:685)
	at org.lflang.ASTUtils.allParameters(ASTUtils.java:615)
	at org.lflang.ASTUtils.allParameters(ASTUtils.java:616)
...
	at org.lflang.ASTUtils.allParameters(ASTUtils.java:616)
lfc: fatal error: An unexpected error occurred:
java.lang.NullPointerException
	at org.lflang.FileConfig.toIPath(FileConfig.java:707)
	at org.lflang.FileConfig.toPath(FileConfig.java:690)
	at org.lflang.lfc.Main.getValidatedResource(Main.java:336)
	at org.lflang.lfc.Main.runGenerator(Main.java:271)
	at org.lflang.lfc.Main.main(Main.java:209)
@housengw housengw added bug Something isn't working validation labels Jan 28, 2022
@edwardalee
Copy link
Collaborator

This is because InstantiationGraph no longer detects cycles. Perhaps because of porting to Java?

@housengw
Copy link
Contributor Author

housengw commented Feb 10, 2022

ok, based on results gathered from inserting print statements, seems like ASTUtils.allParameters is called before LFValidator.checkReactor is called and InstantiationGraph is initialized, and since allParameters is recursive, it causes a stack overflow before any checks take place.

Below is the function allParameters.
definition.getSuperClasses() will always be the same reactor if the reactor extends itself.

public static List<Parameter> allParameters(Reactor definition) {
        List<Parameter> result = new ArrayList<>();
        List<ReactorDecl> superClasses = convertToEmptyListIfNull(definition.getSuperClasses());
        for (ReactorDecl base : superClasses) {
            result.addAll(allParameters(toDefinition(base)));
        }
        result.addAll(definition.getParameters());
        return result;
    }

@edwardalee
Copy link
Collaborator

The situation is even worse than this. Not only are circular extensions not detected, but when multiple extensions include duplicates, the result is invalid. For example, then following reactor foo ends up having 5 input ports, two of which have the same name, rather than the correct four inputs.

target C;

reactor D {
    input d:int;
}
reactor C extends D {
    input c:int;
}
reactor B extends D {
    input b:int;
}
reactor A extends B, C {
    input a:int;
}

main reactor {
    foo = new A();
}

I'm working on a fix.

@edwardalee
Copy link
Collaborator

These two problems should be solved with PR #962.

@lhstrh lhstrh changed the title reactor extends itself causes StackOverflowError Reactor extending itself causes StackOverflowError Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working validation
Projects
None yet
Development

No branches or pull requests

2 participants