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

add memoization to agree type system #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -12,7 +12,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.console;bundle-version="3.5.100",
org.eclipse.core.expressions;bundle-version="3.4.401",
org.osate.aadl2;bundle-version="[2.0.0,3.0.0)",
org.osate.ui;bundle-version="[2.0.0,3.0.0)",
org.osate.ui;bundle-version="[2.0.0,4.0.0)",
org.osate.xtext.aadl2.properties;bundle-version="[1.1.0,2.0.0)",
com.rockwellcollins.atc.agree;bundle-version="1.0.0",
com.rockwellcollins.atc.agree.ui;bundle-version="1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public TypeTable() {
typeNameToLustreType = new HashMap<>();
}

private final AgreeTypeSystem ats = AgreeTypeSystem.make();


public Type updateLustreTypeMap(AgreeTypeSystem.TypeDef agreeType) {
Type lustreType = typeNameToLustreType.get(AgreeTypeSystem.nameOfTypeDef(agreeType));
Type lustreType = typeNameToLustreType.get(ats.nameOfTypeDef(agreeType));
if (lustreType == null) {
lustreType = getLustreType(agreeType);
if (lustreType != null) {
typeNameToLustreType.put(AgreeTypeSystem.nameOfTypeDef(agreeType), lustreType);
typeNameToLustreType.put(ats.nameOfTypeDef(agreeType), lustreType);
}
}
return lustreType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public class AgreeASTBuilder extends AgreeSwitch<Expr> {
// Symbol table to gather all the globalTypes
private static TypeTable symbolTable;

private static AgreeTypeSystem ats = AgreeTypeSystem.make();
// EGM: end-array-backend

private static Map<String, AgreeVar> timeOfVarMap;
Expand Down Expand Up @@ -757,7 +758,7 @@ private void portToAgreeVar(List<AgreeVar> outputs, List<AgreeVar> inputs, Featu
return;
}

AgreeTypeSystem.TypeDef td = AgreeTypeSystem.inferFromNamedElement(dataFeature);
AgreeTypeSystem.TypeDef td = ats.inferFromNamedElement(dataFeature);
Type type = symbolTable.updateLustreTypeMap(td);

if (type == null) {
Expand Down Expand Up @@ -909,7 +910,7 @@ private Type getConnectionEndType(ConnectionEnd port) {
}
// EGM: array-backend
// Type lustreType = AgreeTypeUtils.getType(dataClass, typeMap, globalTypes);
Type lustreType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromNE(dataClass));
Type lustreType = symbolTable.updateLustreTypeMap(ats.typeDefFromNE(dataClass));
return lustreType;
}

Expand Down Expand Up @@ -1146,7 +1147,7 @@ private List<Type> gatherLustreTypes(EList<SpecStatement> specs) {
// this will record them to the global types
// EGM: array-backend
// AgreeTypeUtils.getType((NamedElement) spec, typeMap, globalTypes);
symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromNE((NamedElement) spec));
symbolTable.updateLustreTypeMap(ats.typeDefFromNE((NamedElement) spec));
}
}
return types;
Expand All @@ -1163,7 +1164,7 @@ private List<Node> addLustreNodes(EList<SpecStatement> specs) {
}

public VarDecl agreeVarFromArg(Arg arg, ComponentInstance compInst) {
Type type = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(arg.getType()));
Type type = symbolTable.updateLustreTypeMap(ats.typeDefFromType(arg.getType()));
if (type != null) {
return new AgreeVar(arg.getName(), type, arg, compInst, null);
} else {
Expand Down Expand Up @@ -1452,7 +1453,7 @@ private List<Expr> getConstraintsFromTypeDef(String name, AgreeTypeSystem.TypeDe
private List<AgreeStatement> getConstraintsFromArgs(List<Arg> args, EObject reference) {
List<AgreeStatement> constraints = new ArrayList<>();
for (Arg arg : args) {
List<Expr> argConstraints = getConstraintsFromTypeDef(arg.getName(), AgreeTypeSystem.typeDefFromType(arg.getType()));
List<Expr> argConstraints = getConstraintsFromTypeDef(arg.getName(), ats.typeDefFromType(arg.getType()));
if (!argConstraints.isEmpty()) {
constraints.add(new AgreeStatement("Type predicate on '" + arg.getName() + "'", argConstraints.stream()
.reduce(new BoolExpr(true), (a, b) -> new BinaryExpr(a, BinaryOp.AND, b)), reference));
Expand Down Expand Up @@ -1809,7 +1810,7 @@ public Expr caseFnDef(FnDef fnDef) {

// EGM: array-backend
// Type outType = getNamedType(AgreeTypeUtils.getTypeName(fnDef.getType(), typeMap, globalTypes));
Type outType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(fnDef.getType()));
Type outType = symbolTable.updateLustreTypeMap(ats.typeDefFromType(fnDef.getType()));

if (outType != null) {

Expand Down Expand Up @@ -2167,7 +2168,7 @@ public Expr caseArraySubExpr(ArraySubExpr expr) {

@Override
public Expr caseIndicesExpr(IndicesExpr expr) {
AgreeTypeSystem.TypeDef arrayTypeDef = AgreeTypeSystem.infer(expr.getArray());
AgreeTypeSystem.TypeDef arrayTypeDef = ats.infer(expr.getArray());

if (arrayTypeDef instanceof AgreeTypeSystem.ArrayTypeDef) {
int size = ((AgreeTypeSystem.ArrayTypeDef) arrayTypeDef).size;
Expand Down Expand Up @@ -2313,7 +2314,7 @@ public Expr caseForallExpr(ForallExpr expr) {
com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
Expr array = doSwitch(arrayExpr);

AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
AgreeTypeSystem.TypeDef agreeType = ats.infer(arrayExpr);
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
Expand All @@ -2337,7 +2338,7 @@ public Expr caseExistsExpr(ExistsExpr expr) {
com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
Expr array = doSwitch(arrayExpr);

AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
AgreeTypeSystem.TypeDef agreeType = ats.infer(arrayExpr);
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
Expand All @@ -2358,7 +2359,7 @@ public Expr caseExistsExpr(ExistsExpr expr) {

@Override
public Expr caseFlatmapExpr(FlatmapExpr expr) {
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
AgreeTypeSystem.TypeDef agreeType = ats.infer(expr.getArray());
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
Expand All @@ -2372,7 +2373,7 @@ public Expr caseFlatmapExpr(FlatmapExpr expr) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
Expr body = substitute(doSwitch(expr.getExpr()), binding.getName(), arrayAccess);

AgreeTypeSystem.TypeDef innerArrType = AgreeTypeSystem.infer(expr.getExpr());
AgreeTypeSystem.TypeDef innerArrType = ats.infer(expr.getExpr());
if (innerArrType instanceof AgreeTypeSystem.ArrayTypeDef) {
int innerSize = ((AgreeTypeSystem.ArrayTypeDef) innerArrType).size;
for (int j = 0; j < innerSize; j++) {
Expand All @@ -2388,7 +2389,7 @@ public Expr caseFlatmapExpr(FlatmapExpr expr) {

@Override
public Expr caseFoldLeftExpr(FoldLeftExpr expr) {
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
AgreeTypeSystem.TypeDef agreeType = ats.infer(expr.getArray());

int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
Expand All @@ -2410,7 +2411,7 @@ public Expr caseFoldLeftExpr(FoldLeftExpr expr) {

@Override
public Expr caseFoldRightExpr(FoldRightExpr expr) {
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
AgreeTypeSystem.TypeDef agreeType = ats.infer(expr.getArray());

int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
Expand Down
2 changes: 1 addition & 1 deletion com.rockwellcollins.atc.agree.codegen/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.swt,
org.osate.aadl2.modelsupport;bundle-version="[2.0.0,3.0.0)",
org.osate.aadl2.instantiation;bundle-version="[1.0.1,2.0.0)",
org.osate.ui;bundle-version="[2.0.0,3.0.0)"
org.osate.ui;bundle-version="[2.0.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: com.rockwellcollins.atc.agree.analysis.handlers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AgreeTypeInferenceTest extends XtextTest {

val testResult = issues = testHelper.testString(model)
val issueCollection = new FluentIssueCollection(testResult.resource, newArrayList, newArrayList)
val ats = AgreeTypeSystem.make();

// parseResult => [
testResult.resource.contents.head as AadlPackage => [
Expand All @@ -85,7 +86,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertTrue(elm instanceof DataPort)
Assert.assertEquals(port1, elm)
]
Assert.assertEquals(AgreeTypeSystem.Prim.BoolTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.BoolTypeDef, ats.infer(expr))
]
specs.filter(EqStatement).tail.head => [
Assert.assertEquals(1, lhs.size)
Expand All @@ -95,7 +96,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertTrue(elm instanceof DataPort)
Assert.assertEquals(port2, elm)
]
Assert.assertEquals(AgreeTypeSystem.Prim.IntTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.IntTypeDef, ats.infer(expr))
]
specs.filter(EqStatement).tail.tail.head => [
Assert.assertEquals(1, lhs.size)
Expand All @@ -105,7 +106,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertTrue(elm instanceof DataPort)
Assert.assertEquals(port3, elm)
]
Assert.assertEquals(AgreeTypeSystem.Prim.RealTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.RealTypeDef, ats.infer(expr))
]
]
]
Expand Down Expand Up @@ -149,6 +150,7 @@ class AgreeTypeInferenceTest extends XtextTest {

val testResult = issues = testHelper.testString(model)
val issueCollection = new FluentIssueCollection(testResult.resource, newArrayList, newArrayList)
val ats = AgreeTypeSystem.make()

// parseResult => [
testResult.resource.contents.head as AadlPackage => [
Expand Down Expand Up @@ -182,7 +184,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertEquals(boolDataType, dataFeatureClassifier)
]
]
Assert.assertEquals(AgreeTypeSystem.Prim.BoolTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.BoolTypeDef, ats.infer(expr))
]
specs.filter(EqStatement).tail.head => [
Assert.assertEquals(1, lhs.size)
Expand All @@ -195,7 +197,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertEquals(intDataType, dataFeatureClassifier)
]
]
Assert.assertEquals(AgreeTypeSystem.Prim.IntTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.IntTypeDef, ats.infer(expr))
]
specs.filter(EqStatement).tail.tail.head => [
Assert.assertEquals(1, lhs.size)
Expand All @@ -208,7 +210,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertEquals(realDataType, dataFeatureClassifier)
]
]
Assert.assertEquals(AgreeTypeSystem.Prim.RealTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.RealTypeDef, ats.infer(expr))
]
]
]
Expand Down Expand Up @@ -244,7 +246,8 @@ class AgreeTypeInferenceTest extends XtextTest {

val testResult = issues = testHelper.testString(model)
val issueCollection = new FluentIssueCollection(testResult.resource, newArrayList, newArrayList)

val ats = AgreeTypeSystem.make();

// parseResult => [
testResult.resource.contents.head as AadlPackage => [
Assert.assertEquals(1, publicSection.ownedClassifiers.filter(SystemType).size);
Expand Down Expand Up @@ -274,7 +277,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertEquals(boolPropType, type)
]
]
Assert.assertEquals(AgreeTypeSystem.Prim.BoolTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.BoolTypeDef, ats.infer(expr))
]
specs.filter(EqStatement).tail.head => [
Assert.assertEquals(1, lhs.size)
Expand All @@ -286,7 +289,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertEquals(intPropType, type)
]
]
Assert.assertEquals(AgreeTypeSystem.Prim.IntTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.IntTypeDef, ats.infer(expr))
]
specs.filter(EqStatement).tail.tail.head => [
Assert.assertEquals(1, lhs.size)
Expand All @@ -298,7 +301,7 @@ class AgreeTypeInferenceTest extends XtextTest {
Assert.assertEquals(realPropType, type)
]
]
Assert.assertEquals(AgreeTypeSystem.Prim.RealTypeDef, AgreeTypeSystem.infer(expr))
Assert.assertEquals(AgreeTypeSystem.Prim.RealTypeDef, ats.infer(expr))
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ class Issue17Test extends XtextTest {
val testFileResult = issues = testHelper.testString(
com.rockwellcollins.atc.agree.tests.issues.Issue17Test.deltaCharlieModel)
val systemScratchSys = EcoreUtil2.getAllContentsOfType(testFileResult.resource.contents.head, SystemType).head;

val ats = AgreeTypeSystem.make();
((systemScratchSys.ownedAnnexSubclauses.head as DefaultAnnexSubclause).
parsedAnnexSubclause as AgreeContractSubclause).contract as AgreeContract => [
specs.filter(ConstStatement).head => [
val declaredType = AgreeTypeSystem.typeDefFromType(type)
val declaredType = ats.typeDefFromType(type)
Assert.assertTrue(declaredType instanceof Prim)
declaredType as Prim => [
Assert.assertEquals('int', name)
Expand All @@ -186,13 +186,13 @@ class Issue17Test extends XtextTest {
val testFileResult = issues = testHelper.testString(
com.rockwellcollins.atc.agree.tests.issues.Issue17Test.deltaCharlieModel)
val systemScratchSys = EcoreUtil2.getAllContentsOfType(testFileResult.resource.contents.head, SystemType).head;

val ats = AgreeTypeSystem.make();
((systemScratchSys.ownedAnnexSubclauses.head as DefaultAnnexSubclause).
parsedAnnexSubclause as AgreeContractSubclause).contract as AgreeContract => [
specs.filter(GuaranteeStatement).head => [
Assert.assertTrue(expr instanceof BinaryExpr)
expr as BinaryExpr => [
val inferredType = AgreeTypeSystem.infer(right)
val inferredType = ats.infer(right)
Assert.assertTrue(inferredType instanceof Prim)
inferredType as Prim => [
Assert.assertEquals('int', name)
Expand All @@ -208,14 +208,15 @@ class Issue17Test extends XtextTest {
com.rockwellcollins.atc.agree.tests.issues.Issue17Test.deltaCharlieModel)

val systemScratchSys = EcoreUtil2.getAllContentsOfType(testFileResult.resource.contents.head, SystemType).head;

val ats = AgreeTypeSystem.make();

((systemScratchSys.ownedAnnexSubclauses.head as DefaultAnnexSubclause).
parsedAnnexSubclause as AgreeContractSubclause).contract as AgreeContract => [
specs.filter(GuaranteeStatement).head => [
Assert.assertTrue(expr instanceof BinaryExpr)
expr as BinaryExpr => [
Assert.assertTrue(left instanceof SelectionExpr)
val inferredType = AgreeTypeSystem.infer(left)
val inferredType = ats.infer(left)
Assert.assertTrue(inferredType instanceof Prim)
inferredType as Prim => [
Assert.assertEquals('int', name)
Expand Down
Loading