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

Fix bugs in name mangling #1816

Merged
merged 19 commits into from
Jun 5, 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
10 changes: 5 additions & 5 deletions .github/workflows/check-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
- id: do
run: |
wget https://raw.githubusercontent.com/lf-lang/lingua-franca/master/.github/scripts/check-diff.sh
source check-diff.sh "core/src/main/java/generator/c\|/home/peter/lingua-franca/core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C
source check-diff.sh "core/src/main/kotlin/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP
source check-diff.sh "core/src/main/java/generator/python\|core/src/main/resources/lib/py\|test/Python" PY
source check-diff.sh "core/src/main/kotlin/generator/rust\|core/src/main/java/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS
source check-diff.sh "core/src/main/kotlin/generator/ts\|core/src/main/java/generator/ts\|core/src/main/resources/lib/ts\|test/TypeScript" TS
source check-diff.sh "core/src/main/java/org/lflang/generator/c\|core/src/main/resources/lib/c\|core/src/main/resources/lib/platform\|test/C" C
source check-diff.sh "core/src/main/kotlin/org/lflang/generator/cpp\|core/src/main/resources/lib/cpp\|test/Cpp" CPP
source check-diff.sh "core/src/main/java/org/lflang/generator/python\|core/src/main/resources/lib/py\|test/Python" PY
source check-diff.sh "core/src/main/kotlin/org/lflang/generator/rust\|core/src/main/java/org/lflang/generator/rust\|core/src/main/resources/lib/rs\|test/Rust" RS
source check-diff.sh "core/src/main/kotlin/org/lflang/generator/ts\|core/src/main/java/org/lflang/generator/ts\|core/src/main/resources/lib/ts\|test/TypeScript" TS
source check-diff.sh "util/tracing" TRACING
shell: bash
27 changes: 13 additions & 14 deletions core/src/integrationTest/java/org/lflang/tests/RuntimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected boolean supportsFederatedExecution() {
return false;
}

/** Whether to enable {@link #runTypeParameterTests()}. */
/** Whether to enable {@link #runGenericsTests()}. */
protected boolean supportsGenericTypes() {
return false;
}
Expand All @@ -54,41 +54,40 @@ protected boolean supportsDockerOption() {
}

@Test
public void runGenericTests() {
public void runBasicTests() {
runTestsForTargets(
Message.DESC_GENERIC,
TestCategory.GENERIC::equals,
Message.DESC_BASIC,
TestCategory.BASIC::equals,
Configurators::noChanges,
TestLevel.EXECUTION,
false);
}

@Test
public void runTargetSpecificTests() {
public void runGenericsTests() {
runTestsForTargets(
Message.DESC_TARGET_SPECIFIC,
TestCategory.TARGET::equals,
Message.DESC_GENERICS,
TestCategory.GENERICS::equals,
Configurators::noChanges,
TestLevel.EXECUTION,
false);
}

@Test
public void runMultiportTests() {
public void runTargetSpecificTests() {
runTestsForTargets(
Message.DESC_MULTIPORT,
TestCategory.MULTIPORT::equals,
Message.DESC_TARGET_SPECIFIC,
TestCategory.TARGET::equals,
Configurators::noChanges,
TestLevel.EXECUTION,
false);
}

@Test
public void runTypeParameterTests() {
Assumptions.assumeTrue(supportsGenericTypes(), Message.NO_GENERICS_SUPPORT);
public void runMultiportTests() {
runTestsForTargets(
Message.DESC_TYPE_PARMS,
TestCategory.GENERICS::equals,
Message.DESC_MULTIPORT,
TestCategory.MULTIPORT::equals,
Configurators::noChanges,
TestLevel.EXECUTION,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ protected boolean supportsDockerOption() {

@Test
@Override
public void runGenericTests() {
super.runGenericTests();
public void runBasicTests() {
super.runBasicTests();
}

@Test
@Override
public void runGenericsTests() {
super.runGenericsTests();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public void buildZephyrTests() {
}

@Test
public void buildGenericTests() {
public void buildBasicTests() {
Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux");
super.runTestsFor(
List.of(Target.C),
Message.DESC_GENERIC,
TestCategory.GENERIC::equals,
Message.DESC_BASIC,
TestCategory.BASIC::equals,
Configurators::makeZephyrCompatibleUnthreaded,
TestLevel.BUILD,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected boolean supportsEnclaves() {

@Test
@Override
public void runGenericTests() {
super.runGenericTests();
public void runBasicTests() {
super.runBasicTests();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected boolean supportsDockerOption() {

@Test
@Override
public void runGenericTests() {
super.runGenericTests();
public void runBasicTests() {
super.runBasicTests();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.lflang.tests.runtime;

import org.junit.jupiter.api.Test;
import org.lflang.Target;
import org.lflang.tests.RuntimeTest;

Expand All @@ -34,6 +35,12 @@ public RustTest() {
super(Target.Rust);
}

@Test
@Override
public void runGenericsTests() {
super.runGenericsTests();
}

@Override
protected boolean supportsGenericTypes() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected boolean supportsFederatedExecution() {

@Test
@Override
public void runGenericTests() {
super.runGenericTests();
public void runBasicTests() {
super.runBasicTests();
}

@Test
Expand Down
36 changes: 24 additions & 12 deletions core/src/main/java/org/lflang/generator/ReactorInstance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/** A data structure for a reactor instance. */

/*************
* Copyright (c) 2019-2022, The University of California at Berkeley.
*
Expand Down Expand Up @@ -85,14 +83,25 @@
*/
public class ReactorInstance extends NamedInstance<Instantiation> {

/**
* Create a new instantiation hierarchy that starts with the given top-level reactor.
*
* @param reactor The top-level reactor.
* @param reporter The error reporter.
*/
public ReactorInstance(Reactor reactor, ErrorReporter reporter, List<Reactor> reactors) {
this(ASTUtils.createInstantiation(reactor), null, reporter, -1, reactors);
assert !reactors.isEmpty();
}

/**
* Create a new instantiation hierarchy that starts with the given top-level reactor.
*
* @param reactor The top-level reactor.
* @param reporter The error reporter.
*/
public ReactorInstance(Reactor reactor, ErrorReporter reporter) {
this(ASTUtils.createInstantiation(reactor), null, reporter, -1);
this(ASTUtils.createInstantiation(reactor), null, reporter, -1, List.of());
}

/**
Expand All @@ -104,7 +113,7 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter) {
* @param desiredDepth The depth to which to go, or -1 to construct the full hierarchy.
*/
public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth) {
this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth);
this(ASTUtils.createInstantiation(reactor), null, reporter, desiredDepth, List.of());
}

/**
Expand All @@ -116,7 +125,7 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter, int desiredDepth
* @param reporter The error reporter.
*/
public ReactorInstance(Reactor reactor, ReactorInstance parent, ErrorReporter reporter) {
this(ASTUtils.createInstantiation(reactor), parent, reporter, -1);
this(ASTUtils.createInstantiation(reactor), parent, reporter, -1, List.of());
}

//////////////////////////////////////////////////////
Expand Down Expand Up @@ -790,12 +799,19 @@ protected void createWatchdogInstances() {
* @param desiredDepth The depth to which to expand the hierarchy.
*/
public ReactorInstance(
Instantiation definition, ReactorInstance parent, ErrorReporter reporter, int desiredDepth) {
Instantiation definition,
ReactorInstance parent,
ErrorReporter reporter,
int desiredDepth,
List<Reactor> reactors) {
super(definition, parent);
this.reporter = reporter;
this.reactorDeclaration = definition.getReactorClass();
this.reactorDefinition = ASTUtils.toDefinition(reactorDeclaration);
this.tpr = new TypeParameterizedReactor(definition, parent == null ? null : parent.tpr);
this.tpr =
parent == null
? new TypeParameterizedReactor(definition, reactors)
: new TypeParameterizedReactor(definition, parent.tpr);

// check for recursive instantiation
var currentParent = parent;
Expand Down Expand Up @@ -845,7 +861,7 @@ public ReactorInstance(
// Instantiate children for this reactor instance.
// While doing this, assign an index offset to each.
for (Instantiation child : ASTUtils.allInstantiations(reactorDefinition)) {
var childInstance = new ReactorInstance(child, this, reporter, desiredDepth);
var childInstance = new ReactorInstance(child, this, reporter, desiredDepth, reactors);
this.children.add(childInstance);
}

Expand Down Expand Up @@ -879,10 +895,6 @@ public ReactorInstance(
}
}

public TypeParameterizedReactor getTypeParameterizedReactor() {
return this.tpr;
}

//////////////////////////////////////////////////////
//// Private methods.

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ private void generateReactorDefinitions() throws IOException {
var generatedReactors = new LinkedHashSet<TypeParameterizedReactor>();
if (this.main != null) {
generateReactorChildren(this.main, generatedReactors);
generateReactorClass(this.main.getTypeParameterizedReactor());
generateReactorClass(new TypeParameterizedReactor(this.mainDef, reactors));
}
// do not generate code for reactors that are not instantiated
}
Expand Down Expand Up @@ -2095,7 +2095,8 @@ private void createMainReactorInstance() {
if (this.mainDef != null) {
if (this.main == null) {
// Recursively build instances.
this.main = new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter);
this.main =
new ReactorInstance(toDefinition(mainDef.getReactorClass()), errorReporter, reactors);
var reactionInstanceGraph = this.main.assignLevels();
if (reactionInstanceGraph.nodeCount() > 0) {
errorReporter.reportError("Main reactor has causality cycles. Skipping code generation.");
Expand Down
Loading