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 #159 - Use LinkedHashSet to store sets #161

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bbcd122
fix issue #159, also modified BoaJava.stg, passed all tests
CheShianHung Oct 11, 2017
970890b
Fixes #159 type updated
CheShianHung Oct 12, 2017
b3f0fb4
Fixed #159, change types to general set as much as possible
CheShianHung Oct 12, 2017
207cdc8
fix issue #159, change most LinkedHashSet to Set, change codegen
CheShianHung Jan 19, 2018
b263206
fix issue #159, toInterdaceJavaType and toParameterJavaType methods a…
CheShianHung Jan 22, 2018
081e731
fix #159, simplify setType and stackType in codegen
CheShianHung Jan 22, 2018
668fe6b
Merge branch 'master' of github.com:boalang/compiler into issue159
psybers Jan 22, 2018
1316b9e
fix #159, inhattr stack type added
CheShianHung Jan 22, 2018
1a582b6
fix #159, Map field type fixed
CheShianHung Jan 22, 2018
7521adb
fix #159, spacing and template fixed
CheShianHung Jan 22, 2018
6ecdbe6
merge master
psybers Aug 13, 2019
e3b1449
remove unneeded type templates
psybers Aug 13, 2019
af992b8
convert more HashSet to LinkedHashSet
psybers Aug 13, 2019
e6ec701
fix test errors and simplify some code
psybers Aug 15, 2019
683c817
code cleanup
psybers Aug 15, 2019
bf3e47e
Merge branch 'master' into issue159
psybers Aug 31, 2019
1c8a28a
Merge branch 'master' into issue159
psybers Sep 1, 2023
9961c74
fix bad merge that lost types2
psybers Sep 3, 2023
b73f2d8
fix compile error with template
psybers Sep 3, 2023
a240174
fix boxing issue with arrays
psybers Sep 3, 2023
6a2ccf9
make sure set aggregator sorts output
psybers Sep 3, 2023
e63b9b3
the set aggregator does not need to be a linked set, since we sort it
psybers Sep 3, 2023
cfe85ab
Merge branch 'master' into issue159
psybers Sep 5, 2023
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
2 changes: 1 addition & 1 deletion src/java/boa/aggregators/GraphAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class GraphAggregator extends Aggregator {
public void start(final EmitKey key) {
super.start(key);

this.neighbors = new HashSet<String>();
this.neighbors = new LinkedHashSet<String>();
this.weights = new HashMap<String,String>();
}

Expand Down
20 changes: 10 additions & 10 deletions src/java/boa/aggregators/PreconditionAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void aggregate(final String data, final String metadata) throws IOExcepti
final Expression precondition = parseexpression(precond);

if (!precondMethods.containsKey(precondition)) {
precondMethods.put(precondition, new HashSet<String>());
precondProjects.put(precondition, new HashSet<String>());
precondMethods.put(precondition, new LinkedHashSet<String>());
precondProjects.put(precondition, new LinkedHashSet<String>());
}

precondMethods.get(precondition).add(project + clientmethod);
Expand Down Expand Up @@ -103,7 +103,7 @@ private void doInference() {
*/
private Map<Expression, Set<String>> infer(Map<Expression, Set<String>> precondMP) {
final Map<Expression, Set<String>> infPreconditions = new HashMap<Expression, Set<String>>(precondMP);
final Set<Expression> preconds = new HashSet<Expression>(infPreconditions.keySet());
final Set<Expression> preconds = new LinkedHashSet<Expression>(infPreconditions.keySet());

for (final Expression eqPrecond : preconds) {
if (eqPrecond.getKind() == ExpressionKind.EQ) {
Expand All @@ -121,10 +121,10 @@ private Map<Expression, Set<String>> infer(Map<Expression, Set<String>> precondM
final Expression nsineqPrecond = builder.build();

if (!preconds.contains(nsineqPrecond))
infPreconditions.put(nsineqPrecond, new HashSet<String>());
infPreconditions.put(nsineqPrecond, new LinkedHashSet<String>());

if (infPreconditions.get(eqPrecond).size() == infPreconditions.get(sineqPrecond).size()) {
Set<String> tempSet = new HashSet<String>(infPreconditions.get(nsineqPrecond));
Set<String> tempSet = new LinkedHashSet<String>(infPreconditions.get(nsineqPrecond));
tempSet.addAll(infPreconditions.get(eqPrecond));
infPreconditions.get(nsineqPrecond).addAll(tempSet);
}
Expand All @@ -151,7 +151,7 @@ else if (infPreconditions.get(eqPrecond).size() > infPreconditions.get(sineqPrec

private Map<Expression, Set<String>> mergeConditionsWithImplication(final Map<Expression, Set<String>> precondMP) {
final Map<Expression, Set<String>> mergedPreconditions = new HashMap<Expression, Set<String>>(precondMP);
final Set<Expression> preconds = new HashSet<Expression>(mergedPreconditions.keySet());
final Set<Expression> preconds = new LinkedHashSet<Expression>(mergedPreconditions.keySet());

for (final Expression strongPrecond : preconds) {
for (final Expression weakPrecond : preconds) {
Expand Down Expand Up @@ -186,7 +186,7 @@ else if (strongPrecond.getKind() == ExpressionKind.LT && weakPrecond.getKind() =
*/
private Map<Expression, Set<String>> removeEquality(final Map<Expression, Set<String>> precondMP) {
final Map<Expression, Set<String>> filtPreconditions = new HashMap<Expression, Set<String>>(precondMP);
final Set<Expression> preconds = new HashSet<Expression>(filtPreconditions.keySet());
final Set<Expression> preconds = new LinkedHashSet<Expression>(filtPreconditions.keySet());

for (final Expression precond : preconds) {
if (precond.getKind() == ExpressionKind.OTHER) {
Expand Down Expand Up @@ -241,7 +241,7 @@ private Map<String, Double> calcConfidence(final Map<Expression, Set<String>> pr
final Map<String, Double> precondConf = new HashMap<String, Double>();
final Set<Expression> preconds = precondMP.keySet();

final Set<String> totalCalls = new HashSet<String>();
final Set<String> totalCalls = new LinkedHashSet<String>();
for (final Expression precond : preconds)
if (precondMP.get(precond).size() > 1)
totalCalls.addAll(precondMP.get(precond));
Expand Down Expand Up @@ -302,7 +302,7 @@ private List<Map.Entry<String, Double>> doRanking(final Map<String, Double> filt
* @return set of all combinations of arguments
*/
private Set<SortedSet<String>> kCombinations() {
final Set<SortedSet<String>> comb = new HashSet<SortedSet<String>>();
final Set<SortedSet<String>> comb = new LinkedHashSet<SortedSet<String>>();
final List<String> argList = new ArrayList<String>();
comb.add(new TreeSet<String>(Collections.singletonList("rcv$")));
argList.add("rcv$");
Expand All @@ -313,7 +313,7 @@ private Set<SortedSet<String>> kCombinations() {
}

for (final String arg : argList) {
final Set<SortedSet<String>> tempComb = new HashSet<SortedSet<String>>(comb);
final Set<SortedSet<String>> tempComb = new LinkedHashSet<SortedSet<String>>(comb);
for (final SortedSet<String> s : tempComb) {
final SortedSet<String> t = new TreeSet<String>(s);
t.add(arg);
Expand Down
7 changes: 4 additions & 3 deletions src/java/boa/aggregators/SetAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package boa.aggregators;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.LinkedHashSet;

import boa.io.EmitKey;

Expand All @@ -28,7 +29,7 @@
*/
@AggregatorSpec(name = "set", canCombine = true)
public class SetAggregator extends Aggregator {
private HashSet<String> set;
private Set<String> set;
private final long max;

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ public void start(final EmitKey key) {
super.start(key);

// the set of data to be collected
this.set = new HashSet<String>();
this.set = new LinkedHashSet<String>();
}

/** {@inheritDoc} */
Expand Down
4 changes: 2 additions & 2 deletions src/java/boa/compiler/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public class SymbolTable {
globalFunctions.addFunction("regex", new BoaFunction(new BoaString(), new BoaType[] { new BoaName(new BoaScalar()) }, "boa.functions.BoaSpecialIntrinsics.regex(\"${0}\")"));

// clone functions
globalFunctions.addFunction("clone", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] {new BoaSet(new BoaTypeVar("V"))},"(java.util.HashSet)${0}.clone()"));
globalFunctions.addFunction("clone", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] {new BoaSet(new BoaTypeVar("V"))},"(java.util.LinkedHashSet)${0}.clone()"));
globalFunctions.addFunction("clone", new BoaFunction(new BoaString(), new BoaType[] {new BoaString()},"new String(${0})"));

// visitors
Expand Down Expand Up @@ -247,7 +247,7 @@ public class SymbolTable {
globalFunctions.addFunction("remove", new BoaFunction(new BoaAny(), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaTypeVar("V") }, "${0}.remove(${1})"));
globalFunctions.addFunction("clear", new BoaFunction(new BoaAny(), new BoaType[] { new BoaSet(new BoaTypeVar("V")) }, "${0}.clear()"));
globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new ${V}[0]))"));
globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaSet(new BoaString())), new BoaType[] { new BoaSet(new BoaSet(new BoaString())) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new java.util.HashSet[0]))"));
globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaSet(new BoaString())), new BoaType[] { new BoaSet(new BoaSet(new BoaString())) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new java.util.LinkedHashSet[0]))"));

globalFunctions.addFunction("union", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.set_union(${0}, ${1})"));
globalFunctions.addFunction("intersect", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.set_intersect(${0}, ${1})"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -99,7 +99,7 @@ public void visit(final VisitorExpression n) {
* mapping from each type T found to a list of all uses in current(T).
*/
private class FindCurrentForVisitors extends AbstractVisitorNoArgNoRet{
protected final Set<BoaTuple> currents = new HashSet<BoaTuple>();
protected final Set<BoaTuple> currents = new LinkedHashSet<BoaTuple>();
protected final Map<BoaTuple,List<Factor>> factorMap = new HashMap<BoaTuple,List<Factor>>();

/** @{inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package boa.compiler.transforms;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.Stack;

Expand All @@ -39,7 +39,7 @@
* @author rdyer
*/
public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet {
protected final static Set<Class<? extends BoaType>> astTypes = new HashSet<Class<? extends BoaType>>();
protected final static Set<Class<? extends BoaType>> astTypes = new LinkedHashSet<Class<? extends BoaType>>();

static {
astTypes.addAll(new ASTRootProtoTuple().reachableTypes());
Expand All @@ -59,7 +59,7 @@ public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet {
/** {@inheritDoc} */
@Override
protected void initialize() {
types = new HashSet<Class<? extends BoaType>>();
types = new LinkedHashSet<Class<? extends BoaType>>();
beforeChangedFile = afterChangedFile = null;

typeStack.clear();
Expand All @@ -74,7 +74,7 @@ public void visit(final VisitorExpression n) {
beforeStack.push(beforeChangedFile);
afterStack.push(afterChangedFile);

types = new HashSet<Class<? extends BoaType>>();
types = new LinkedHashSet<Class<? extends BoaType>>();
beforeChangedFile = afterChangedFile = null;

n.getBody().accept(this);
Expand Down
63 changes: 12 additions & 51 deletions src/java/boa/compiler/visitors/CodeGeneratingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void visit(final VarDeclStatement n) {
final ST st = stg.getInstanceOf("VarDecl");

st.add("id", n.getId().getToken());
st.add("type", n.type.toJavaType());
st.add("type", n.type.toInterfaceJavaType());

if (n.isStatic())
st.add("isstatic", true);
Expand All @@ -202,7 +202,7 @@ public void visit(final VarDeclStatement n) {
* @author rdyer
*/
protected class FunctionDeclaratorCodeGeneratingVisitor extends AbstractCodeGeneratingVisitor {
protected final Set<String> funcs = new HashSet<String>();
protected final Set<String> funcs = new LinkedHashSet<String>();

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -232,7 +232,7 @@ public void visit(final FunctionType n) {

for (final Component c : params) {
args.add(c.getIdentifier().getToken());
types.add(c.getType().type.toJavaType());
types.add(c.getType().type.toInterfaceJavaType());
}

st.add("name", funcType.toJavaType());
Expand All @@ -253,7 +253,7 @@ public void visit(final FunctionType n) {
* @author ankuraga
*/
protected class TupleDeclaratorCodeGeneratingVisitor extends AbstractCodeGeneratingVisitor {
protected final Set<String> tuples = new HashSet<String>();
protected final Set<String> tuples = new LinkedHashSet<String>();

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -429,7 +429,7 @@ protected class IndexeeFindingVisitor extends AbstractVisitorNoReturn<String> {
protected Node lastFactor;

protected Map<Node, Node> lastFactors = new HashMap<Node, Node>();
protected final Set<Node> indexees = new HashSet<Node>();
protected final Set<Node> indexees = new LinkedHashSet<Node>();

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -1487,7 +1487,7 @@ public void visit(final TraverseStatement n) {
createNodeId.start(cfgBuilder);

final LocalMayAliasAnalysis localMayAliasAnalysis = new LocalMayAliasAnalysis();
final HashSet<Identifier> aliastSet = localMayAliasAnalysis.start(cfgBuilder, traversalId);
final Set<Identifier> aliastSet = localMayAliasAnalysis.start(cfgBuilder, traversalId);

final DataFlowSensitivityAnalysis dataFlowSensitivityAnalysis = new DataFlowSensitivityAnalysis();
dataFlowSensitivityAnalysis.start(cfgBuilder, aliastSet);
Expand Down Expand Up @@ -1566,7 +1566,7 @@ public void visit(final FunctionExpression n) {
if (!(c instanceof BoaName))
continue;
args.add(((BoaName)c).getId());
types.add(((BoaName)c).getType().toJavaType());
types.add(((BoaName)c).getType().toInterfaceJavaType());
}

this.varDecl.start(n);
Expand Down Expand Up @@ -1797,7 +1797,7 @@ public void visit(final FunctionType n) {

for (int i = 0; i < paramTypes.length; i++) {
args.add(((BoaName) paramTypes[i]).getId());
types.add(paramTypes[i].toJavaType());
types.add(paramTypes[i].toInterfaceJavaType());
}

st.add("name", funcType.toJavaType());
Expand Down Expand Up @@ -1829,19 +1829,7 @@ public void visit(final FixPType n) {
/** {@inheritDoc} */
@Override
public void visit(final MapType n) {
final ST st = stg.getInstanceOf("MapType");

n.env.setNeedsBoxing(true);

n.getIndex().accept(this);
st.add("key", code.removeLast());

n.getValue().accept(this);
st.add("value", code.removeLast());

n.env.setNeedsBoxing(false);

code.add(st.render());
code.add(n.type.toJavaType());
}

/** {@inheritDoc} */
Expand All @@ -1866,46 +1854,19 @@ public void visit(final OutputType n) {
/** {@inheritDoc} */
@Override
public void visit(final StackType n) {
final ST st = stg.getInstanceOf("StackType");

n.env.setNeedsBoxing(true);

n.getValue().accept(this);
st.add("value", code.removeLast());

n.env.setNeedsBoxing(false);

code.add(st.render());
code.add(n.type.toJavaType());
}

/** {@inheritDoc} */
@Override
public void visit(final QueueType n) {
final ST st = stg.getInstanceOf("QueueType");

n.env.setNeedsBoxing(true);

n.getValue().accept(this);
st.add("value", code.removeLast());

n.env.setNeedsBoxing(false);

code.add(st.render());
code.add(n.type.toJavaType());
}

/** {@inheritDoc} */
@Override
public void visit(final SetType n) {
final ST st = stg.getInstanceOf("SetType");

n.env.setNeedsBoxing(true);

n.getValue().accept(this);
st.add("value", code.removeLast());

n.env.setNeedsBoxing(false);

code.add(st.render());
code.add(n.type.toJavaType());
}

/** {@inheritDoc} */
Expand Down
4 changes: 2 additions & 2 deletions src/java/boa/compiler/visitors/IdentifierFindingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package boa.compiler.visitors;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import boa.compiler.ast.Identifier;
Expand All @@ -27,7 +27,7 @@
* @author rdyer
*/
public class IdentifierFindingVisitor extends AbstractVisitorNoArgNoRet {
protected final Set<String> names = new HashSet<String>();
protected final Set<String> names = new LinkedHashSet<String>();

public Set<String> getNames() {
return names;
Expand Down
6 changes: 3 additions & 3 deletions src/java/boa/compiler/visitors/TaskClassifyingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package boa.compiler.visitors;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import boa.compiler.ast.Call;
Expand All @@ -34,13 +34,13 @@
* @author rdyer
*/
public class TaskClassifyingVisitor extends AbstractVisitorNoArgNoRet {
protected final static Set<Class<? extends BoaType>> astTypes = new HashSet<Class<? extends BoaType>>();
protected final static Set<Class<? extends BoaType>> astTypes = new LinkedHashSet<Class<? extends BoaType>>();

static {
astTypes.addAll(new ASTRootProtoTuple().reachableTypes());
}

protected final Set<Class<? extends BoaType>> types = new HashSet<Class<? extends BoaType>>();
protected final Set<Class<? extends BoaType>> types = new LinkedHashSet<Class<? extends BoaType>>();

private boolean complex = false;

Expand Down
Loading