From: <vj...@us...> - 2010-09-18 12:29:17
|
Revision: 16554 http://x10.svn.sourceforge.net/x10/?rev=16554&view=rev Author: vj0 Date: 2010-09-18 12:29:09 +0000 (Sat, 18 Sep 2010) Log Message: ----------- When a CConstraint was copied, it did not copy over validity and consistency status. Now fixed. Modified Paths: -------------- trunk/x10.compiler/src/x10/types/constraints/CConstraint.java trunk/x10.constraints/src/x10/constraint/XConstraint.java Modified: trunk/x10.compiler/src/x10/types/constraints/CConstraint.java =================================================================== --- trunk/x10.compiler/src/x10/types/constraints/CConstraint.java 2010-09-18 11:13:57 UTC (rev 16553) +++ trunk/x10.compiler/src/x10/types/constraints/CConstraint.java 2010-09-18 12:29:09 UTC (rev 16554) @@ -114,15 +114,8 @@ */ public CConstraint copy() { CConstraint c = new CConstraint(); - try { - c.thisVar = thisVar(); - c.self = self(); - return (CConstraint) copyInto(c); - } - catch (XFailure f) { - c.setInconsistent(); - return c; - } + c.init(this); + return c; } /** @@ -489,6 +482,12 @@ XTerm subst = term.subst(self(), self); return entails(subst); } + + protected void init(CConstraint from) { + thisVar = from.thisVar(); + self = from.self(); + super.init(from); + } /** * Return the result of copying this into c. Assume that c will be * the depclause of the same base type as this, hence it is ok to Modified: trunk/x10.constraints/src/x10/constraint/XConstraint.java =================================================================== --- trunk/x10.constraints/src/x10/constraint/XConstraint.java 2010-09-18 11:13:57 UTC (rev 16553) +++ trunk/x10.constraints/src/x10/constraint/XConstraint.java 2010-09-18 12:29:09 UTC (rev 16554) @@ -15,7 +15,6 @@ import java.util.HashMap; import java.util.List; import java.util.ArrayList; -import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; @@ -45,12 +44,12 @@ * <li> <code>s equals t</code> and <code>t equals u</code> implies <code> s equals u</code> * <li> it is always the case that <code>s equals s</code> * </uline> - * Terms are created using the static API in XTerms. The <code>==</code> relation on terms at the level of the + * <p>Terms are created using the static API in XTerms. The <code>==</code> relation on terms at the level of the * constraint system is translated into the <code>equals</code> relation on the Java representation of the terms. * * <p>A constraint is implemented as a graph whose nodes are XPromises. Two different constraints will * not share @link{XPromise}. See the description of @link{XPromise} for more information about the - * internal representation of a constraint. + * structure of a promise. * * <p>This representation is a bit different from the Nelson-Oppen and Shostak congruence closure * algorithms described, e.g. in Cyrluk, Lincoln and Shankar "On Shostak's Decision Procedure @@ -71,11 +70,9 @@ * */ public class XConstraint implements Cloneable { - - private static final boolean DEBUG = false; protected HashMap<XTerm, XPromise> roots; protected boolean consistent = true; - boolean valid = true; + protected boolean valid = true; public XConstraint() {} @@ -111,16 +108,8 @@ */ public XConstraint copy() { XConstraint c = new XConstraint(); - try { - - c.consistent = consistent; - c.valid = valid; - return copyInto(c); - } - catch (XFailure f) { - c.setInconsistent(); - return c; - } + c.init(this); + return c; } /** @@ -928,7 +917,8 @@ } } - protected void applySubstitution(XTerm y, XVar x) throws XFailure { + @SuppressWarnings({ "unchecked"}) + protected void applySubstitution(XTerm y, XVar x) throws XFailure { if (roots == null) { // nothing to substitute return; @@ -967,7 +957,7 @@ // Substitute y for x in the promise terms. { - Collection<XPromise> rootPs = roots.values(); + // Collection<XPromise> rootPs = roots.values(); for (Map.Entry<XTerm, XPromise> e : ((Map<XTerm,XPromise>) roots.clone()).entrySet()) { if (!e.getKey().equals(p.term())) { XPromise px = e.getValue(); @@ -993,7 +983,7 @@ renaming.put(q, new XPromise_c(v)); for (Map.Entry<XTerm, XPromise> m : roots.entrySet()) { - XTerm var = m.getKey(); + // XTerm var = m.getKey(); XPromise p2 = m.getValue(); XPromise q2 = p2.cloneRecursively(renaming); m.setValue(q2); @@ -1081,7 +1071,7 @@ // m.setValue(q2); // } - Collection<XPromise> rootPs = roots.values(); + // Collection<XPromise> rootPs = roots.values(); for (Map.Entry<XTerm, XPromise> e : roots.entrySet()) { if (!e.getKey().equals(x.term())) { XPromise p = e.getValue(); @@ -1089,7 +1079,20 @@ } } } - + /** + * Initialize this constraint from the given constraint + * @param from -- the constraint whose state is used to initialize this. + */ + protected void init(XConstraint from) { + try { + consistent = from.consistent; + valid = from.valid; + from.copyInto(this); + } + catch (XFailure f) { + setInconsistent(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mt...@us...> - 2010-09-19 04:45:57
|
Revision: 16564 http://x10.svn.sourceforge.net/x10/?rev=16564&view=rev Author: mtake Date: 2010-09-19 04:45:51 +0000 (Sun, 19 Sep 2010) Log Message: ----------- Add Types.isNativeStruct(Object o) Modified Paths: -------------- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java trunk/x10.runtime/src-java/x10/rtt/Types.java Modified: trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-19 02:08:32 UTC (rev 16563) +++ trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-19 04:45:51 UTC (rev 16564) @@ -1133,6 +1133,11 @@ w.write(")"); w.write(" || "); + w.write("x10.rtt.Types.isNativeStruct("); + tr.print(c, c.expr(), w); + w.write(")"); + /* + w.write(" || "); new RuntimeTypeExpander(er, xts.Byte()).expand(tr); w.write("."); w.write("instanceof$("); @@ -1187,6 +1192,7 @@ w.write("instanceof$("); tr.print(c, c.expr(), w); w.write(")"); + */ // Java representation of unsigned types are same as signed ones. /* Modified: trunk/x10.runtime/src-java/x10/rtt/Types.java =================================================================== --- trunk/x10.runtime/src-java/x10/rtt/Types.java 2010-09-19 02:08:32 UTC (rev 16563) +++ trunk/x10.runtime/src-java/x10/rtt/Types.java 2010-09-19 04:45:51 UTC (rev 16564) @@ -200,6 +200,11 @@ return false; } + public static boolean isNativeStruct(Object o) { + return BYTE.instanceof$(o) || SHORT.instanceof$(o) || INT.instanceof$(o) || LONG.instanceof$(o) + || FLOAT.instanceof$(o) || DOUBLE.instanceof$(o) || CHAR.instanceof$(o) || BOOLEAN.instanceof$(o); + } + public static boolean asboolean(Object typeParamOrAny) { if (typeParamOrAny == null) {nullIsCastedToStruct();} if (typeParamOrAny instanceof java.lang.Boolean) {return (java.lang.Boolean) typeParamOrAny;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mt...@us...> - 2010-09-19 16:34:50
|
Revision: 16567 http://x10.svn.sourceforge.net/x10/?rev=16567&view=rev Author: mtake Date: 2010-09-19 16:34:43 +0000 (Sun, 19 Sep 2010) Log Message: ----------- Implement RTT of Any. Simplify codegen of "instanceof Object" Modified Paths: -------------- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java trunk/x10.runtime/src-java/x10/rtt/Types.java trunk/x10.runtime/src-x10/x10/lang/Any.x10 Modified: trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-19 14:52:02 UTC (rev 16566) +++ trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-19 16:34:43 UTC (rev 16567) @@ -1126,6 +1126,11 @@ w.write(")"); w.write(" || "); + w.write("x10.rtt.Types.isStruct("); + tr.print(c, c.expr(), w); + w.write(")"); + /* + w.write(" || "); w.write("x10.rtt.Types.runtimeType(x10.core.Struct.class)"); // new RuntimeTypeExpander(er, xts.Struct()).expand(tr); w.write("."); w.write("instanceof$("); @@ -1133,11 +1138,6 @@ w.write(")"); w.write(" || "); - w.write("x10.rtt.Types.isNativeStruct("); - tr.print(c, c.expr(), w); - w.write(")"); - /* - w.write(" || "); new RuntimeTypeExpander(er, xts.Byte()).expand(tr); w.write("."); w.write("instanceof$("); Modified: trunk/x10.runtime/src-java/x10/rtt/Types.java =================================================================== --- trunk/x10.runtime/src-java/x10/rtt/Types.java 2010-09-19 14:52:02 UTC (rev 16566) +++ trunk/x10.runtime/src-java/x10/rtt/Types.java 2010-09-19 16:34:43 UTC (rev 16567) @@ -159,6 +159,7 @@ return "x10.lang.Object"; } }; + public static Type<Object> ANY = new RuntimeType<Object>(Object.class); public static Type<?> UBYTE; // instance created and set in UByte static initializer public static Type<?> USHORT; // instance created and set in UShort static initializer @@ -189,7 +190,7 @@ return null; } - private static boolean isStruct(Type<?> rtt) { + private static boolean isStructType(Type<?> rtt) { if ( rtt == BOOLEAN || rtt == BYTE || rtt == SHORT || rtt == CHAR || rtt == INT || rtt == LONG @@ -201,9 +202,10 @@ return false; } - public static boolean isNativeStruct(Object o) { - return BYTE.instanceof$(o) || SHORT.instanceof$(o) || INT.instanceof$(o) || LONG.instanceof$(o) - || FLOAT.instanceof$(o) || DOUBLE.instanceof$(o) || CHAR.instanceof$(o) || BOOLEAN.instanceof$(o); + public static boolean isStruct(Object o) { + return x10.core.Struct._RTT.instanceof$(o) || + BYTE.instanceof$(o) || SHORT.instanceof$(o) || INT.instanceof$(o) || LONG.instanceof$(o) || + FLOAT.instanceof$(o) || DOUBLE.instanceof$(o) || CHAR.instanceof$(o) || BOOLEAN.instanceof$(o); } public static boolean asboolean(Object typeParamOrAny) { @@ -256,7 +258,7 @@ public static Object conversion(Type<?> rtt, Object primOrTypeParam) { - if (primOrTypeParam == null && isStruct(rtt)) {nullIsCastedToStruct();} + if (primOrTypeParam == null && isStructType(rtt)) {nullIsCastedToStruct();} if (rtt == BYTE) { if (primOrTypeParam instanceof java.lang.Number) return ((java.lang.Number) primOrTypeParam).byteValue(); Modified: trunk/x10.runtime/src-x10/x10/lang/Any.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-09-19 14:52:02 UTC (rev 16566) +++ trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-09-19 16:34:43 UTC (rev 16567) @@ -24,7 +24,7 @@ * * @author vj 12/14/09 */ -@NativeRep("java", "java.lang.Object", null, null) +@NativeRep("java", "java.lang.Object", null, "x10.rtt.Types.ANY") @NativeRep("c++", "x10aux::ref<x10::lang::Any>", "x10::lang::Any", null) public interface Any { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-20 00:53:07
|
Revision: 16570 http://x10.svn.sourceforge.net/x10/?rev=16570&view=rev Author: yzibin Date: 2010-09-20 00:52:58 +0000 (Mon, 20 Sep 2010) Log Message: ----------- * added stack trace for a failed X10 assertion. * added @NonEscaping(readFields) that allows dynamic dispatching in a CTOR * now we can call typeName() because it is @NonEscaping(""). Added this annotation to Struct as well. * GlobalRef[...](this) fields must be private. Changed X10 files to conform to it. * optimization for the initialization data flow: ctors are treated specially (only analyzed once since they cannot be called) * fixed anonymous class bug (XTENLANG-1827) Modified Paths: -------------- trunk/x10.compiler/src/polyglot/ast/New_c.java trunk/x10.compiler/src/x10/ast/X10New_c.java trunk/x10.compiler/src/x10/types/X10TypeMixin.java trunk/x10.compiler/src/x10/util/RunTestSuite.java trunk/x10.compiler/src/x10/util/Struct.java trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java trunk/x10.runtime/src-java/x10/runtime/impl/java/X10Throwable.java trunk/x10.runtime/src-x10/x10/compiler/NonEscaping.x10 trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 trunk/x10.runtime/src-x10/x10/io/StringWriter.x10 trunk/x10.runtime/src-x10/x10/lang/Activity.x10 trunk/x10.runtime/src-x10/x10/lang/Any.x10 trunk/x10.runtime/src-x10/x10/lang/Clock.x10 trunk/x10.runtime/src-x10/x10/lang/Object.x10 trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 trunk/x10.runtime/src-x10/x10/util/Future.x10 trunk/x10.tests/examples/Constructs/Array/FlattenPlaceCast.x10 trunk/x10.tests/examples/Constructs/Array/TestArray.x10 trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 trunk/x10.tests/examples/Constructs/Async/AsyncFieldAccess.x10 trunk/x10.tests/examples/Constructs/Async/AsyncNext.x10 trunk/x10.tests/examples/Constructs/Async/AsyncReturn.x10 trunk/x10.tests/examples/Constructs/At/AtFieldAccess.x10 trunk/x10.tests/examples/Constructs/At/AtFieldWrite.x10 trunk/x10.tests/examples/Constructs/At/AtFieldWrite_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/At/AtNext.x10 trunk/x10.tests/examples/Constructs/AtEach/AtEach.x10 trunk/x10.tests/examples/Constructs/AtEach/AtEach2.x10 trunk/x10.tests/examples/Constructs/AtEach/AtEachLoopOnArray.x10 trunk/x10.tests/examples/Constructs/Atomic/Atomic1.x10 trunk/x10.tests/examples/Constructs/Atomic/Atomic1a.x10 trunk/x10.tests/examples/Constructs/Atomic/ConditionalAtomicQueue.x10 trunk/x10.tests/examples/Constructs/Call/ConInstanceHere_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Place/AtCheck.x10 trunk/x10.tests/examples/Constructs/Place/AtCheck2.x10 trunk/x10.tests/examples/Constructs/Place/AtCheck3_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Place/AtCheck3a_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Place/AtThisIntoAtHere.x10 trunk/x10.tests/examples/Constructs/Place/AtThisIntoAtHere1_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Place/At_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Place/B_AtThisIntoAtHere.x10 trunk/x10.tests/examples/Constructs/Place/B_AtThisIntoAtHere_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/PlaceCast/PlaceCast.x10 Modified: trunk/x10.compiler/src/polyglot/ast/New_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/New_c.java 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.compiler/src/polyglot/ast/New_c.java 2010-09-20 00:52:58 UTC (rev 16570) @@ -418,6 +418,7 @@ // According to JLS2 15.9.1, the class type being // instantiated must be inner. if (! ct.isInnerClass()) { + if (!(qualifier instanceof Special)) // Yoav added "this" qualifier for non-static anonymous classes throw new SemanticException( "Cannot provide a containing instance for non-inner class " + ct.fullName() + ".", qualifier.position()); Modified: trunk/x10.compiler/src/x10/ast/X10New_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10New_c.java 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.compiler/src/x10/ast/X10New_c.java 2010-09-20 00:52:58 UTC (rev 16570) @@ -198,6 +198,10 @@ if (t == anonType) { t = t.outer(); } + if (anonType!=null) { + outer = t; + t = null; + } // Search all enclosing classes for the type. while (t != null) { @@ -286,8 +290,10 @@ X10ClassType ct = (X10ClassType) t; - if (ct.isMember() && !ct.flags().isStatic()) { - New k = ((X10New_c) n.objectType(tn)).findQualifier(childtc, ct); + if ((ct.isMember()&& !ct.flags().isStatic()) + || (anonType!=null && !childtc.context().inStaticContext())) { // the receiver/target of X10New_c for anonymous classes should be "this" (for CheckEscapingThis) + final X10New_c newC = (X10New_c) n.objectType(tn); + New k = newC.findQualifier(childtc, ct); tn = k.objectType(); qualifier = (Expr) k.visitChild(k.qualifier(), childtc); } @@ -437,6 +443,7 @@ } X10ParsedClassType container = (X10ParsedClassType) ci.container(); + // todo: "t" might be a ConstrainedType_c (C:\cygwin\home\Yoav\intellij\sourceforge\x10.tests\examples\Constructs\Typedefs\TypedefNew01.x10:44,31-38) if (((X10ParsedClassType) t).typeArguments().equals(container.x10Def().typeParameters())) { t = ((X10ParsedClassType) t).typeArguments(container.typeArguments()); result = (X10New_c) result.objectType(result.objectType().typeRef(Types.ref(t))); Modified: trunk/x10.compiler/src/x10/types/X10TypeMixin.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-20 00:52:58 UTC (rev 16570) @@ -55,6 +55,7 @@ import x10.ast.SubtypeTest; import x10.ast.X10NodeFactory; import x10.ast.X10IntLit_c; +import x10.ast.X10StringLit_c; import x10.constraint.XFailure; import x10.constraint.XNameWrapper; import x10.constraint.XVar; @@ -975,8 +976,22 @@ public static boolean isUninitializedField(X10FieldDef def,X10TypeSystem ts) { return isDefAnnotated(def,ts,"x10.compiler.Uninitialized"); } - public static boolean isNonEscapingMethod(X10ProcedureDef def,X10TypeSystem ts) { - return isDefAnnotated(def,ts,"x10.compiler.NonEscaping"); + public static String getNonEscapingReadsFrom(X10ProcedureDef def,X10TypeSystem ts) { + try { + Type at = (Type) ts.systemResolver().find(QName.make("x10.compiler.NonEscaping")); + final List<Type> annotations = def.annotationsMatching(at); + if (annotations.isEmpty()) return null; + Type first = annotations.get(0); + if (!(first instanceof X10ParsedClassType_c)) return null; + X10ParsedClassType_c nonEscaping = (X10ParsedClassType_c) first; + final List<Expr> list = nonEscaping.propertyInitializers(); + if (list.size()!=1) return ""; // @NonEscaping is like @NonEscaping("") + Expr arg = list.get(0); + if (arg==null || !(arg instanceof X10StringLit_c)) return ""; // @NonEscaping(null) is like @NonEscaping("") + return ((X10StringLit_c) arg).stringValue(); + } catch (SemanticException e) { + return null; + } } public static boolean isDefAnnotated(X10Def def,X10TypeSystem ts, String name) { try { Modified: trunk/x10.compiler/src/x10/util/RunTestSuite.java =================================================================== --- trunk/x10.compiler/src/x10/util/RunTestSuite.java 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.compiler/src/x10/util/RunTestSuite.java 2010-09-20 00:52:58 UTC (rev 16570) @@ -141,7 +141,6 @@ // Now checking the errors reported are correct and match ERR markers // 1. find all ERR markers that don't have a corresponding error for (File file : files) { - if (!file.getName().endsWith("_MustFailCompile.x10")) continue; if (Report.should_report("TestSuite", 3)) Report.report(3, "Looking for ERR markers in file "+ file); BufferedReader in = new BufferedReader(new FileReader(file)); @@ -150,7 +149,8 @@ String line; while ((line=in.readLine())!=null) { lineNum++; - if (line.contains("ERR")) { + if (line.contains("ERR") && + !file.getName().contains("Console.x10")) { // Console defines "static ERR:Printer" foundErr = true; // try to find the matching error boolean foundMatch = false; @@ -169,7 +169,7 @@ System.err.println("File "+file+" has an ERR marker on line "+lineNum+", but the compiler didn't report an error on that line!"); } } - if (!foundErr) { + if (!foundErr && file.getName().endsWith("_MustFailCompile.x10")) { System.err.println("File "+file+" ends in _MustFailCompile.x10 but it doesn't contain any 'ERR' markers!"); } } Modified: trunk/x10.compiler/src/x10/util/Struct.java =================================================================== --- trunk/x10.compiler/src/x10/util/Struct.java 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.compiler/src/x10/util/Struct.java 2010-09-20 00:52:58 UTC (rev 16570) @@ -209,6 +209,8 @@ //@Native("c++", "x10aux::type_name(#0)") //global safe def typeName():String; natives = createNative(nf, pos, "x10.rtt.Types.typeName(#0)", "x10aux::type_name(#0)"); + AnnotationNode nonEscaping = nf.AnnotationNode(pos, nf.AmbMacroTypeNode(pos, nf.PrefixFromQualifiedName(pos,QName.make("x10.compiler")), nf.Id(pos, "NonEscaping"), Collections.EMPTY_LIST, Collections.<Expr>singletonList(nf.StringLit(pos,"")))); + natives.add(nonEscaping); methodName = "typeName"; md = nf.MethodDecl(pos,nf.FlagsNode(pos,nativeFlags),stringTypeNode,nf.Id(pos,Name.make(methodName)),Collections.EMPTY_LIST,Collections.EMPTY_LIST,null); md = (X10MethodDecl) ((X10Ext) md.ext()).annotations(natives); Modified: trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java =================================================================== --- trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java 2010-09-20 00:52:58 UTC (rev 16570) @@ -9,12 +9,17 @@ import polyglot.frontend.Job; import polyglot.types.Type; import polyglot.types.FieldDef; -import polyglot.types.Flags; import polyglot.types.MethodInstance; import polyglot.types.MethodDef; import polyglot.types.FieldInstance; import polyglot.types.ProcedureDef; import polyglot.types.QName; +import polyglot.types.ClassDef; +import polyglot.types.Ref; +import polyglot.types.SemanticException; +import polyglot.types.Name; +import polyglot.types.Context; +import polyglot.types.ProcedureDef_c; import x10.ast.*; import x10.types.X10TypeMixin; import x10.types.X10Flags; @@ -22,6 +27,7 @@ import x10.types.X10FieldDef; import x10.types.X10ParsedClassType_c; import x10.types.X10ProcedureDef; +import x10.types.X10MethodDef; import java.util.HashMap; import java.util.Set; @@ -30,6 +36,7 @@ import java.util.Map; import java.util.LinkedHashMap; import java.util.ArrayList; +import java.util.Collections; public class CheckEscapingThis extends NodeVisitor { @@ -52,10 +59,10 @@ private class DataFlowItem extends DataFlow.Item { - private final Map<X10FieldDecl_c, Integer> initStatus = new HashMap<X10FieldDecl_c, Integer>(); // immutable map of fields to 3flags + private final Map<FieldDef, Integer> initStatus = new HashMap<FieldDef, Integer>(); // immutable map of fields to 3flags private DataFlowItem() { - for (X10FieldDecl_c f : fields) + for (FieldDef f : fields) initStatus.put(f,0); } public boolean equals(Object o) { @@ -71,7 +78,7 @@ @Override public String toString() { StringBuilder res = new StringBuilder(); - for (Map.Entry<X10FieldDecl_c, Integer> pair : initStatus.entrySet()) { + for (Map.Entry<FieldDef, Integer> pair : initStatus.entrySet()) { res.append(pair.getKey().name()).append(":").append(flagsToString(pair.getValue())).append(" "); } return res.toString(); @@ -79,16 +86,19 @@ } class FieldChecker extends DataFlow { private final DataFlowItem INIT = new DataFlowItem(); + private final DataFlowItem CTOR_INIT = new DataFlowItem(); private ProcedureDecl currDecl; public FieldChecker() { super(CheckEscapingThis.this.job, CheckEscapingThis.this.ts, CheckEscapingThis.this.nf, true /* forward analysis */, false /* perform dataflow when leaving CodeDecls, not when entering */); - for (X10FieldDecl_c f : fields) - INIT.initStatus.put(f,0); + + for (FieldDef field : superFields) { + CTOR_INIT.initStatus.put(field, build(false, true,true)); + } } protected Item createInitialItem(FlowGraph graph, Term node, boolean entry) { - return INIT; + return isCtor() ? CTOR_INIT : INIT; } protected Item confluence(List items, List itemKeys, Term node, boolean entry, FlowGraph graph) { @@ -117,8 +127,8 @@ for (int i=1; i<items.size(); i++) { DataFlowItem item = (DataFlowItem) items.get(i); - for (Map.Entry<X10FieldDecl_c, Integer> pair : item.initStatus.entrySet()) { - final X10FieldDecl_c key = pair.getKey(); + for (Map.Entry<FieldDef, Integer> pair : item.initStatus.entrySet()) { + final FieldDef key = pair.getKey(); int i1 = res.initStatus.get(key); int i2 = pair.getValue(); // Async must be handled here, because DataFlow first calls safeConfluence, and only then it calls flow: @@ -154,10 +164,11 @@ } boolean isAssign = n instanceof FieldAssign; + // todo: closure call: check that all field access are legal if (isAssign || n instanceof Field) { final Receiver target = isAssign ? ((FieldAssign) n).target() : ((Field) n).target(); final FieldInstance fi = isAssign ? ((FieldAssign) n).fieldInstance() : ((Field) n).fieldInstance(); - X10FieldDecl_c field = findField(fi.def()); + FieldDef field = findField(fi.def()); if (field!=null && isThis(target)) { res = new DataFlowItem(); res.initStatus.putAll(inItem.initStatus); @@ -166,21 +177,30 @@ res.initStatus.put(field,valueAfter); } + } else if (n instanceof ConstructorCall) { + ConstructorCall ctorCall = (ConstructorCall) n; + assert (ctorCall.kind()==ConstructorCall.SUPER) : "We do not analyze ctors with 'this()' calls, because they're always correct - everything must be initialized after the 'this()' call"; + //assert res==INIT : "It must be the first statement in the ctor"; + // Note that the super call should be the first statement, but I inline the field-inits before it. + } else if (n instanceof X10Call) { X10Call call = (X10Call) n; Receiver receiver = call.target(); if (isThis(receiver)) { X10MethodDecl_c methodDecl = findMethod(call); if (methodDecl!=null) { - res = new DataFlowItem(); - res.initStatus.putAll(inItem.initStatus); - MethodInfo info = allMethods.get(methodDecl.procedureInstance()); - if (info !=null) - for (X10FieldDecl_c field : fields) { - boolean isRead = info.read.contains(field); - boolean isWrite = info.write.contains(field); - boolean isWriteSeq = info.seqWrite.contains(field); - res.initStatus.put(field, afterSeqBlock(res.initStatus.get(field),build(isRead,isWrite, isWriteSeq))); + final ProcedureDef procDef = methodDecl.procedureInstance(); + if (!isProperty(procDef)) { + res = new DataFlowItem(); + res.initStatus.putAll(inItem.initStatus); + MethodInfo info = allMethods.get(procDef); + assert info !=null : methodDecl; + for (FieldDef field : fields) { + boolean isRead = info.read.contains(field); + boolean isWrite = info.write.contains(field); + boolean isWriteSeq = info.seqWrite.contains(field); + res.initStatus.put(field, afterSeqBlock(res.initStatus.get(field),build(isRead,isWrite, isWriteSeq))); + } } } } @@ -192,18 +212,27 @@ return itemsToMap(trueItem, falseItem, inItem, succEdgeKeys); } else if (n instanceof Finish) { res = new DataFlowItem(); - for (Map.Entry<X10FieldDecl_c, Integer> pair : inItem.initStatus.entrySet()) { + for (Map.Entry<FieldDef, Integer> pair : inItem.initStatus.entrySet()) { res.initStatus.put(pair.getKey(),afterFinish(pair.getValue())); } } - if (res!=inItem && isCtor()) { + if (res!=inItem) { + MethodInfo info = allMethods.get(currDecl.procedureInstance()); + final boolean ctor = isCtor(); + if (!ctor) assert info!=null : currDecl; + final Set<FieldDef> canReadFrom = ctor ? Collections.EMPTY_SET : info.canReadFrom; // can't read from an un-init var in the ctors (I want to catch it here, so I can give the exact position info) - for (X10FieldDecl_c f : fields) { - boolean readBefore = isRead(inItem.initStatus.get(f)); - if (!readBefore && isRead(res.initStatus.get(f))) { - // wasn't read before, and we read it now (either because of Field access, or X10Call) - reportError("Cannot read from field '"+f.name()+"' before it is definitely assigned.",n.position()); - wasError = true; + // can't read from any var not in @NonEscaping(...) + if (canReadFrom!=null) { + for (FieldDef f : fields) { + boolean readBefore = isRead(inItem.initStatus.get(f)); + if (!readBefore && isRead(res.initStatus.get(f))) { + if (!canReadFrom.contains(f)) { + // wasn't read before, and we read it now (either because of Field access, or X10Call) + reportError("Cannot read from field '"+f.name()+"' before it is definitely assigned.",n.position()); + wasError = true; + } + } } } } @@ -220,30 +249,15 @@ ProcedureDecl decl = (ProcedureDecl)n; assert decl!=null; final ProcedureDef procDef = decl.procedureInstance(); - MethodInfo oldInfo = allMethods.get(procDef); MethodInfo newInfo = new MethodInfo(); - for (Map.Entry<X10FieldDecl_c, Integer> pair : dfIn.initStatus.entrySet()) { + for (Map.Entry<FieldDef, Integer> pair : dfIn.initStatus.entrySet()) { int val = pair.getValue(); - final X10FieldDecl_c f = pair.getKey(); + final FieldDef f = pair.getKey(); if (isRead(val)) newInfo.read.add(f); if (isWrite(val)) newInfo.write.add(f); if (isSeqWrite(val)) newInfo.seqWrite.add(f); } - // proof that the fix-point terminates: write set decreases while the read set increases - assert oldInfo.write.containsAll(newInfo.write); - assert oldInfo.seqWrite.containsAll(newInfo.seqWrite); - assert newInfo.read.containsAll(oldInfo.read); - // fixed-point reached? - if (newInfo.read.equals(oldInfo.read) && - newInfo.write.equals(oldInfo.write) && - newInfo.seqWrite.equals(oldInfo.seqWrite)) { - // no change! - } else { - wasChange = true; - allMethods.put(procDef,newInfo); - } - // everything must be assigned in a ctor (and nothing read) if (isCtor()) { int size = fields.size(); @@ -252,16 +266,61 @@ if (newInfo.seqWrite.size()!=size) { wasError = true; // report the field that wasn't written to - for (X10FieldDecl_c f : fields) + for (FieldDef f : fields) if (!newInfo.seqWrite.contains(f)) { reportError("Field '"+f.name()+"' was not definitely assigned.",f.position()); } } + } else { + MethodInfo oldInfo = allMethods.get(procDef); + assert oldInfo!=null : n; + if (hasNonEscapingAnnot(procDef)) { + // the read-set should not change (we already reported an error if it did change) + newInfo.read.clear(); + newInfo.read.addAll(oldInfo.read); + } + if (noWrites(procDef)) { + newInfo.write.clear(); + newInfo.seqWrite.clear(); + } + // proof that the fix-point terminates: write set decreases while the read set increases + assert oldInfo.write.containsAll(newInfo.write); + assert oldInfo.seqWrite.containsAll(newInfo.seqWrite); + assert newInfo.read.containsAll(oldInfo.read); + + + // fixed-point reached? + if (newInfo.read.equals(oldInfo.read) && + newInfo.write.equals(oldInfo.write) && + newInfo.seqWrite.equals(oldInfo.seqWrite)) { + // no change! + } else { + wasChange = true; + newInfo.canReadFrom = oldInfo.canReadFrom; + allMethods.put(procDef,newInfo); + } } } } } + private boolean hasNonEscapingAnnot(ProcedureDef def) { + return X10TypeMixin.getNonEscapingReadsFrom((X10ProcedureDef) def, ts) != null; + } + private boolean noWrites(ProcedureDef def) { + // if it is not a final/private method (which can be the case for @NonEscaping), + // then the write-set must be empty (because it might be overriden and then the write doesn't happen) + final boolean hasNonEscapingAnnot = hasNonEscapingAnnot(def); + return hasNonEscapingAnnot && !isPrivateOrFinal(def); + } + private boolean isProperty(ProcedureDef def) { + final X10Flags flags = X10Flags.toX10Flags(((ProcedureDef_c)def).flags()); + return flags.isProperty(); + } + private boolean isPrivateOrFinal(ProcedureDef def) { + final X10Flags flags = X10Flags.toX10Flags(((ProcedureDef_c)def).flags()); + return flags.isPrivate() || flags.isFinal(); + } // Main visits all the classes, and type-checks them (verify that "this" doesn't escape, etc) public static class Main extends NodeVisitor { @@ -278,11 +337,12 @@ } - // we gather info on every private/final method + // we gather info on every private/final/@NonEscaping method private static class MethodInfo { - private final Set<X10FieldDecl_c> read = new HashSet<X10FieldDecl_c>(); - private final Set<X10FieldDecl_c> write = new HashSet<X10FieldDecl_c>(); - private final Set<X10FieldDecl_c> seqWrite = new HashSet<X10FieldDecl_c>(); + private Set<FieldDef> canReadFrom = null; + private final Set<FieldDef> read = new HashSet<FieldDef>(); + private final Set<FieldDef> write = new HashSet<FieldDef>(); + private final Set<FieldDef> seqWrite = new HashSet<FieldDef>(); } private final Job job; private final X10NodeFactory nf; @@ -292,28 +352,22 @@ // the keys are either X10ConstructorDecl_c or X10MethodDecl_c private final HashMap<ProcedureDef,MethodInfo> allMethods = new LinkedHashMap<ProcedureDef, MethodInfo>(); // all ctors and methods recursively called from allMethods on receiver "this" private final ArrayList<ProcedureDecl> dfsMethods = new ArrayList<ProcedureDecl>(); // to accelerate the fix-point alg - private final HashSet<X10ConstructorDecl_c> allCtors = new HashSet<X10ConstructorDecl_c>(); - // the set of VAR and VAL without initializers (we need to check that VAL are read properly, and that VAR are written and read properly.) + // the set of all VAR and VAL fields, including those in the superclass due to @NonEscaping (we need to check that VAL are read properly, and that VAR are written and read properly.) // InitChecker already checks that VAL are assigned in every ctor exactly once (and never assigned in other methods) // Therefore we can now treat both VAL and VAR identically. - private final HashSet<X10FieldDecl_c> fields = new HashSet<X10FieldDecl_c>(); + private final HashSet<FieldDef> fields = new HashSet<FieldDef>(); + private final HashSet<FieldDef> superFields = new HashSet<FieldDef>(); // after the "super()" call, these fields are initialized private boolean wasChange = true, wasError = false; // for fixed point alg private HashSet<FieldDef> globalRef = new HashSet<FieldDef>();// There is one exception to the "this cannot escape" rule: val root = GlobalRef[...](this) private void checkGlobalRef(Node n) { - boolean err = false; - FieldDef def = null; + // you cannot access a globalRef field via this (but you can assign to them) if (n instanceof Field) { Field f = (Field) n; - def = f.fieldInstance().def(); - err = (isThis(f.target())); - } - if (n instanceof FieldAssign) { - FieldAssign assign = (FieldAssign) n; - def = assign.fieldInstance().def(); - err = (isThis(assign.target())); - } - if (err && globalRef.contains(def)) reportError("Cannot use '"+def.name()+"' because a GlobalRef[...](this) cannot be used in a field initializer, constructor, or methods called from a constructor.",n.position()); + FieldDef def = f.fieldInstance().def(); + if (isThis(f.target()) && globalRef.contains(def)) + reportError("Cannot use '"+def.name()+"' because a GlobalRef[...](this) cannot be used in a field initializer, constructor, or methods called from a constructor.",n.position()); + } } public CheckEscapingThis(X10ClassDecl_c xlass, Job job, X10TypeSystem ts) { this.job = job; @@ -323,18 +377,28 @@ this.xlassType = X10TypeMixin.baseType(xlass.classDef().asType()); typeCheck(); } - private void typeCheck() { - final X10ClassBody_c body = (X10ClassBody_c)xlass.body(); - // visit all (non-static) field initializers and check that they do not have forward references nor that "this" escapes - ArrayList<X10FieldDecl_c> nonStaticFields = new ArrayList<X10FieldDecl_c>(); - for (ClassMember classMember : body.members()) { - if (classMember instanceof X10FieldDecl_c) { - X10FieldDecl_c field = (X10FieldDecl_c) classMember; - if (field.flags().flags().isStatic()) continue; - nonStaticFields.add(field); + private void calcFields() { + final ClassDef myClassDef = xlass.classDef(); + ClassDef currClass = myClassDef; + while (currClass!=null) { + List<FieldDef> list = currClass.fields(); + // a VAR marked with @Uninitialized is not tracked + List<FieldDef> init = new ArrayList<FieldDef>(list.size()); + for (FieldDef f : list) { + if (!X10TypeMixin.isUninitializedField((X10FieldDef)f,ts) && + !((X10FieldDef)f).isProperty() && // not tracking property fields (checking property() call was done elsewhere) + !f.flags().isStatic()) { // static fields are checked in FwdReferenceChecker + init.add(f); + } } + fields.addAll(init); + if (myClassDef!=currClass) superFields.addAll(init); + final Ref<? extends Type> superType = currClass.superType(); + if (superType==null) break; + currClass = superType.get().toClass().def(); } - // Find globalRef + } + private void calcGlobalRefs(ArrayList<X10FieldDecl_c> nonStaticFields) { for (X10FieldDecl_c field : nonStaticFields) { final Expr init = field.init(); // check for the pattern: val/var someField = GlobalRef[...](this) @@ -351,23 +415,39 @@ final QName qName = classType_c.def().fullName(); if (qName.equals(QName.make("x10.lang","GlobalRef"))) { // found the pattern! + // must be private + if (!field.flags().flags().isPrivate()) + reportError("In order to use the pattern GlobalRef[...](this) the field must be private.",field.position()); globalRef.add(field.fieldDef()); } } } } } - // checking "this" doesn't escape from field init + } + private void typeCheck() { + final X10ClassBody_c body = (X10ClassBody_c)xlass.body(); + // visit all (non-static) field initializers and check that they do not have forward references nor that "this" escapes + ArrayList<X10FieldDecl_c> nonStaticFields = new ArrayList<X10FieldDecl_c>(); + for (ClassMember classMember : body.members()) { + if (classMember instanceof X10FieldDecl_c) { + X10FieldDecl_c field = (X10FieldDecl_c) classMember; + if (field.flags().flags().isStatic()) continue; + nonStaticFields.add(field); + } + } + // Find globalRefs + calcGlobalRefs(nonStaticFields); + + // calculate the set of all fields (including inherited fields) + calcFields(); + + // inline the field-initializers in every ctor ArrayList<Stmt> fieldInits = new ArrayList<Stmt>(); final Position pos = Position.COMPILER_GENERATED; for (X10FieldDecl_c field : nonStaticFields) { final Expr init = field.init(); final X10FieldDef def = (X10FieldDef) field.fieldDef(); - // even if the field has an init, we still need to track it (because field-init are inlined in all ctors) - if (!X10TypeMixin.isUninitializedField(def,ts)) { - // if a VAR has a default value, then we already created an init() expr in X10FieldDecl_c.typeCheck - fields.add(field); - } if (init==null) continue; final Special This = (Special) nf.Special(pos, Special_c.THIS).type(def.container().get().toType()); final FieldAssign fieldAssign = (FieldAssign) nf.FieldAssign(pos, This, field.name(), Assign_c.ASSIGN, init). @@ -376,74 +456,130 @@ fieldInits.add(nf.Eval(pos, fieldAssign)); if (!globalRef.contains(def)) init.visit(this); // field init are implicitly NonEscaping } + Block newInit = nf.Block(pos,fieldInits); + + // visit every ctor, every @NonEscaping method, and every method recursively called from them, and check that this and super do not escape + ArrayList<X10ConstructorDecl_c> ctorsForDataFlow = new ArrayList<X10ConstructorDecl_c>(); for (ClassMember classMember : body.members()) { if (classMember instanceof ProcedureDecl) { final ProcedureDecl proc = (ProcedureDecl) classMember; final X10ProcedureDef def = (X10ProcedureDef)proc.procedureInstance(); - boolean shouldVisit = X10TypeMixin.isNonEscapingMethod(def,ts); + final Block procBody = proc.body(); - final Block ctorBody = proc.body(); - // for native methods/ctors, we don't have a body - if (ctorBody!=null) { - if (proc instanceof X10ConstructorDecl_c) { // ctors are implicitly NonEscaping - allCtors.add((X10ConstructorDecl_c)proc); - shouldVisit = true; + if (def instanceof X10MethodDef) { + String readsFrom = X10TypeMixin.getNonEscapingReadsFrom(def,ts); + + // check that overriding perserves the exact @NonEscaping annotation + X10MethodDef x10def = (X10MethodDef) def; + final MethodInstance instance = x10def.asInstance(); + final Context emptyContext = ts.emptyContext(); + final List<MethodInstance> overriddenMethods = ts.overrides(instance, emptyContext); + for (MethodInstance overriddenMI : overriddenMethods) { + MethodDef overriddenDef = overriddenMI.def(); + if (overriddenDef==def) continue; // me + String overriddenReadsFrom = X10TypeMixin.getNonEscapingReadsFrom((X10MethodDef)overriddenDef,ts); + if (overriddenReadsFrom!=null) { + if (readsFrom==null || !overriddenReadsFrom.equals(readsFrom)) { + reportError("You must annotate "+proc+" with @NonEscaping(\""+overriddenReadsFrom+"\") because it overrides a method annotated with that.", proc.position()); + break; // one such error msg is enough + } + } } - if (shouldVisit) ctorBody.visit(this); - } - } - } - if (fields.size()==0) return; // done! all fields have an init, thus all reads are legal. + + if (readsFrom==null) continue; - // ignore ctors that call other ctors (using "this(...)"). We can reuse ConstructorCallChecker, but for better efficiency, we just check it directly - Block newInit = nf.Block(pos,fieldInits); - for (X10ConstructorDecl_c ctor: allCtors) { - boolean callThis = false; - final Block ctorBody = ctor.body(); - assert ctorBody!=null; - final List<Stmt> stmts = ctorBody.statements(); - for (Stmt s : stmts) { - if (s instanceof ConstructorCall) { - ConstructorCall cc = (ConstructorCall) s; - if (cc.kind() == ConstructorCall.THIS) { - callThis = true; - break; + // check all the fields in the annotation are found + final MethodInfo info = new MethodInfo(); + info.canReadFrom = new HashSet<FieldDef>(); + String[] fieldNames = readsFrom.split(","); + for (String fieldName : fieldNames) { + String trimmed = fieldName.trim(); + if (trimmed.equals("")) continue; + FieldDef field = findField(trimmed); + if (field==null) reportError("Could not find field '"+trimmed+"' used in the annotation @NonEscaping.", proc.position()); + info.canReadFrom.add(field); + info.read.add(field); } + if (procBody==null) continue; // for native methods/ctors, we don't have a body + + allMethods.put(proc.procedureInstance(), info); + dfsMethods.add(proc); + + } else { + if (procBody==null) continue; + assert proc instanceof X10ConstructorDecl_c : proc; + final X10ConstructorDecl_c ctor = (X10ConstructorDecl_c) proc; + // ctors are implicitly NonEscaping + if (isCallingOtherCtor(ctor)) { + // ignore in dataflow ctors that call other ctors (using "this(...)"). We can reuse ConstructorCallChecker, but for better efficiency, we just check it directly + } else { + // add field initializers to all ctors + ctorsForDataFlow.add(ctor); + } } + procBody.visit(this); + } - if (!callThis) { - // add field init to all ctors - X10ConstructorDecl_c newCtor = (X10ConstructorDecl_c) ctor.body( nf.Block(pos,newInit,ctorBody) ); - allMethods.put(newCtor.procedureInstance(), new MethodInfo()); - dfsMethods.add(newCtor); - } } + if (fields.size()==0) return; // done! all fields have an init, thus all reads are legal (and no writes must be done). + // do init for the fixed point alg - for (MethodInfo info : allMethods.values()) { - info.write.addAll(fields); - info.seqWrite.addAll(fields); + for (Map.Entry<ProcedureDef, MethodInfo> entry : allMethods.entrySet()) { + MethodInfo info = entry.getValue(); + if (!noWrites(entry.getKey())) { + info.write.addAll(fields); + info.seqWrite.addAll(fields); + } } - // run fix point alg + // run fix point alg: ctors do not need to be in the fixed point alg because nobody can call them directly final FieldChecker fieldChecker = new FieldChecker(); while (wasChange && !wasError) { - wasChange = false; + wasChange =false; // do a DFS: starting from private/final methods, and then the ctors (this will reach a fixed-point fastest) for (ProcedureDecl p : dfsMethods) fieldChecker.dataflow(p); } + // handle ctors and field initializers + //fieldChecker.dataflow(newInit); // todo: make a new method for field-init, and the ctors will call it at the begining + for (X10ConstructorDecl_c ctor : ctorsForDataFlow) { + X10ConstructorDecl_c newCtor = (X10ConstructorDecl_c) ctor.body( nf.Block(pos,newInit,ctor.body()) ); + fieldChecker.dataflow(newCtor); + } } - private X10FieldDecl_c findField(FieldDef def) { - for (X10FieldDecl_c f : fields) - if (f.fieldDef().equalsImpl(def)) return f; + private FieldDef findField(String name) { + for (FieldDef fieldDef : fields) + if (fieldDef.name().toString().equals(name)) { + return fieldDef; + } return null; } + private static boolean isCallingOtherCtor(X10ConstructorDecl_c ctor) { + final Block ctorBody = ctor.body(); + assert ctorBody!=null; + final List<Stmt> stmts = ctorBody.statements(); + for (Stmt s : stmts) { + if (s instanceof ConstructorCall) { + ConstructorCall cc = (ConstructorCall) s; + if (cc.kind() == ConstructorCall.THIS) { + return true; + } + } + } + return false; + } + private FieldDef findField(FieldDef def) { + for (FieldDef f : fields) + if (f.equalsImpl(def)) return f; + return null; + } private X10MethodDecl_c findMethod(X10Call call) { MethodInstance mi2 = call.methodInstance(); final X10ClassBody_c body = (X10ClassBody_c)xlass.body(); for (ClassMember classMember : body.members()) { if (classMember instanceof X10MethodDecl_c) { X10MethodDecl_c mdecl = (X10MethodDecl_c) classMember; + if (mdecl.body()==null) continue; // for native methods (like typeName in structs) final MethodDef md = mdecl.methodDef(); if (mi2.def().equals(md)) return mdecl; } @@ -451,17 +587,10 @@ return null; } - private int closureCount = 0; - private boolean isInClosure() { return closureCount>0; } @Override public Node visitEdgeNoOverride(Node parent, Node n) { checkGlobalRef(n); // check globalRef usage in ctors and methods called from ctors - boolean isClosure = n instanceof Closure; - if (isClosure) closureCount++; - - if (!isInClosure()) { - - // You can access "this" for field access and field assignment (if not in a closure). + // You can access "this" for field access and field assignment. // field assignment: if (n instanceof FieldAssign) { FieldAssign f = (FieldAssign) n; @@ -480,18 +609,18 @@ if (n instanceof X10Call) { final X10Call call = (X10Call) n; final MethodInstance methodInstance = call.methodInstance(); - final X10Flags flags = X10Flags.toX10Flags(methodInstance.flags()); + final X10ProcedureDef procDef = (X10ProcedureDef) methodInstance.def(); if (isThis(call.target())) { - if (flags.isProperty()) { + if (isProperty(procDef)) { // property-method calls are ok } else { - // the method must be final or private - if (!flags.isFinal() && !flags.isPrivate()) { - reportError("The call "+call+" is illegal because you can only call private or final methods from a constructor or from methods called from a constructor",call.position()); - } + // the method must be final or private or NonEscaping + String readsFrom = X10TypeMixin.getNonEscapingReadsFrom(procDef,ts); + if (readsFrom==null && !isPrivateOrFinal(procDef)) + reportError("The call "+call+" is illegal because you can only call private/final/@NonEscaping methods from a NonEscaping method (such as a constructor, a field initializer, or a @NonEscaping method)", call.position()); X10MethodDecl_c method = findMethod(call); if (method==null) { - if (!X10TypeMixin.isNonEscapingMethod((X10ProcedureDef)methodInstance.def(),ts)) + if (readsFrom==null) reportError("The call "+call+" is illegal because you can only call @NonEscaping methods of a superclass from a constructor or from methods called from a constructor",call.position()); } else { ProcedureDef pd = method.procedureInstance(); @@ -514,14 +643,12 @@ return n; } } - - } + // You cannot use "this" for anything else! if (isThis(n)) { reportError("'this' and 'super' cannot escape from a constructor or from methods called from a constructor",n.position()); } n.del().visitChildren(this); - if (isClosure) closureCount--; return n; } private void reportError(String s, Position p) { Modified: trunk/x10.runtime/src-java/x10/runtime/impl/java/X10Throwable.java =================================================================== --- trunk/x10.runtime/src-java/x10/runtime/impl/java/X10Throwable.java 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-java/x10/runtime/impl/java/X10Throwable.java 2010-09-20 00:52:58 UTC (rev 16570) @@ -60,7 +60,9 @@ } try { - return (X10Throwable)(Class.forName(newExcName).newInstance()); + X10Throwable t = (X10Throwable)(Class.forName(newExcName).newInstance()); + t.setStackTrace(e.getStackTrace()); + return t; } catch (java.lang.ClassNotFoundException e1) { } catch (java.lang.InstantiationException e2) { } catch (java.lang.IllegalAccessException e3) { Modified: trunk/x10.runtime/src-x10/x10/compiler/NonEscaping.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/compiler/NonEscaping.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/compiler/NonEscaping.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -14,19 +14,34 @@ import x10.lang.annotations.MethodAnnotation; /** - * NonEscaping is an annotation that can be used on final or private methods. + * NonEscaping is an annotation that can be used on methods for two purposes: + * 1) for calling a super method during construction, and + * 2) for doing dynamic dispatching during construction. * - * <p>It marks the fact that "this" does not escape (also called leak) from the method. - * A method is explicitly-NonEscaping if it is annotated with @NonEscaping and it is implicitly-NonEscaping. - * A method is implicitly-NonEscaping if: - * 1) "this" is only used in field access, field assignment, - * and as the reciever of implicitly-NonEscaping method invocation. - * 2) "super" is only used in field access, field assignment, - * and as the reciever of explicitly-NonEscaping method invocation. - * All constructors and field initializers in X10 must be implicitly-NonEscaping. + * Object construction (or initialization) in X10 is more strict than Java: + * X10 has restricting rules that prevent seeing the default value of val fields + * (as opposed to final fields in Java, because it is possible to see the default value of final fields in Java) + * You can read the value of a val field only after it is definitely been assigned. * - * <p>It is considered good practice to mark all methods called from a constructor as NonEscaping. + * + * <p>@NonEscaping marks the fact that "this" does not escape (also called leak) from the method. + * A method is NonEscaping if: + * 1) the method is either final, private or annotated with @NonEscaping. + * 2) in the method body, "this" is only used in field access, field assignment, + * and as the reciever of NonEscaping methods. + * 2) in the method body, "super" is only used in field access, field assignment, + * and as the reciever of methods annotated with @NonEscaping. + * + * The compiler checks @NonEscaping as follows: + * 1) @NonEscaping must be preserved by overriding, i.e., when overriding a method annotated with + * @NonEscaping(readFromFields) then the overriding method must be annotated with exactly the same annotation. + * 2) The fields in readFromFields must be declared in the class (and cannot include fields of the superclass). + * 3) The method can read only from fields in readFromFields. + * NonEscaping is of course not checked on native methods because they do not have a body. + * + * All constructors and field initializers in X10 must be NonEscaping. + * + * <p>It is considered good practice to mark all methods called from a constructor as @NonEscaping. * - * <p>NonEscaping is not checked on native methods. */ -public interface NonEscaping extends MethodAnnotation { } +public interface NonEscaping(readFromFields:String) extends MethodAnnotation { } Modified: trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -17,7 +17,7 @@ import x10.compiler.Incomplete; public class ByteWriter[T] /*extends Writer*/ { - val root = GlobalRef[ByteWriter[T]](this); + private val root = GlobalRef[ByteWriter[T]](this); transient val b:Builder[Byte,T]; public def this(b: Builder[Byte,T]) { this.b = b; } Modified: trunk/x10.runtime/src-x10/x10/io/StringWriter.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/io/StringWriter.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/io/StringWriter.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -16,7 +16,7 @@ import x10.compiler.Pinned; public class StringWriter extends Writer { - val root = GlobalRef[StringWriter](this); + private val root = GlobalRef[StringWriter](this); transient val b:StringBuilder; public def this() { this.b = new StringBuilder(); Modified: trunk/x10.runtime/src-x10/x10/lang/Activity.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Activity.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/lang/Activity.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -21,7 +21,7 @@ public class Activity { // Useful for the Java runtime? - val root = GlobalRef[Activity](this); + private val root = GlobalRef[Activity](this); def home():Place=root.home(); /** * Sleep for the specified number of milliseconds. Modified: trunk/x10.runtime/src-x10/x10/lang/Any.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -13,6 +13,7 @@ import x10.compiler.Native; import x10.compiler.NativeRep; +import x10.compiler.NonEscaping; /** * The top of the type hierarchy. @@ -51,6 +52,7 @@ */ @Native("java", "x10.rtt.Types.typeName(#0)") @Native("c++", "x10aux::type_name(#0)") + @NonEscaping("") safe def typeName():String; /** Modified: trunk/x10.runtime/src-x10/x10/lang/Clock.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Clock.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/lang/Clock.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -25,7 +25,7 @@ */ public class Clock(name:String) { - protected val root = GlobalRef[Clock](this); + private val root = GlobalRef[Clock](this); public safe def equals(a:Any) { if (a == null || ! (a instanceof Clock)) return false; Modified: trunk/x10.runtime/src-x10/x10/lang/Object.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Object.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/lang/Object.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -13,6 +13,7 @@ import x10.compiler.Native; import x10.compiler.NativeRep; +import x10.compiler.NonEscaping; /** * The base class for all reference classes. @@ -88,5 +89,6 @@ */ @Native("java", "x10.rtt.Types.typeName(#0)") @Native("c++", "x10aux::type_name(#0)") + @NonEscaping("") public safe native final def typeName():String; } Modified: trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -282,7 +282,7 @@ // Single class translation of an X10 2.0 class static class RootCollectingFinish[T] extends RootFinish { - protected val root = GlobalRef[RootCollectingFinish[T]](this); + private val root = GlobalRef[RootCollectingFinish[T]](this); transient val sr:StatefulReducer[T]; val reducer:Reducible[T]; def this(r:Reducible[T]) { @@ -344,7 +344,7 @@ } static class RootFinish implements FinishState, Mortal { - protected val root = GlobalRef[RootFinish](this); + private val root = GlobalRef[RootFinish](this); transient protected val counts:Rail[Int]; transient protected val seen:Rail[Boolean]; transient protected var exceptions:Stack[Throwable]; @@ -1008,7 +1008,7 @@ static class SimpleRootFinish extends Latch implements FinishState, Mortal { - protected val root = GlobalRef[SimpleRootFinish](this); + private val root = GlobalRef[SimpleRootFinish](this); transient protected var counts:int; transient protected var exceptions:Stack[Throwable]; transient protected val latch = new Latch(); @@ -1572,7 +1572,7 @@ * Run at statement */ static class RemoteControl { - val root = GlobalRef[RemoteControl](this); + private val root = GlobalRef[RemoteControl](this); transient var e:Box[Throwable] = null; transient val latch = new Latch(); @Global public safe def equals(a:Any) = @@ -1618,7 +1618,7 @@ transient var t:Box[T] = null; transient var e:Box[Throwable] = null; transient val latch = new Latch(); - val root = GlobalRef[Remote](this); + private val root = GlobalRef[Remote](this); @Global public safe def equals(a:Any)= (a instanceof Remote[T]) && this.root.equals((a as Remote[T]).root); @Global public safe def hashCode()=root.hashCode(); Modified: trunk/x10.runtime/src-x10/x10/util/Future.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/util/Future.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.runtime/src-x10/x10/util/Future.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -24,7 +24,7 @@ * */ public class Future[+T] implements ()=>T { - val root = GlobalRef[Future[T]](this); + private val root = GlobalRef[Future[T]](this); /** * Latch for signaling and wait */ Modified: trunk/x10.tests/examples/Constructs/Array/FlattenPlaceCast.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Array/FlattenPlaceCast.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/Array/FlattenPlaceCast.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -25,7 +25,7 @@ } static class Test { - val root = GlobalRef[Test](this); + private val root = GlobalRef[Test](this); }; public def run():boolean = { Modified: trunk/x10.tests/examples/Constructs/Array/TestArray.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Array/TestArray.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/Array/TestArray.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -20,7 +20,7 @@ import x10.compiler.Global; abstract public class TestArray extends x10Test { - val root = GlobalRef[TestArray](this); + private val root = GlobalRef[TestArray](this); val os: StringWriter; val out: Printer; @@ -65,7 +65,7 @@ } class Grid { - val root = GlobalRef[Grid](this); + private val root = GlobalRef[Grid](this); transient var os: Rail[Object] = Rail.make[Object](10); @Pinned def set(i0: int, vue: double): void = { Modified: trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -68,7 +68,7 @@ } static class E { - val root = GlobalRef[E](this); + private val root = GlobalRef[E](this); def home() = root.home; var v: int; def this(var i: int): E = { v = i; } Modified: trunk/x10.tests/examples/Constructs/Async/AsyncFieldAccess.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Async/AsyncFieldAccess.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/Async/AsyncFieldAccess.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -16,7 +16,7 @@ * Testing an async spawned to a field access. */ public class AsyncFieldAccess extends x10Test { - val root = GlobalRef[AsyncFieldAccess](this); + private val root = GlobalRef[AsyncFieldAccess](this); transient var t: GlobalRef[T] = GlobalRef[T](null); public def run(): boolean = { var Second: Place = Place.FIRST_PLACE.next(); @@ -37,7 +37,7 @@ } static class T { - val root = GlobalRef[T](this); + private val root = GlobalRef[T](this); transient public var i: int; } } Modified: trunk/x10.tests/examples/Constructs/Async/AsyncNext.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Async/AsyncNext.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/Async/AsyncNext.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -35,7 +35,7 @@ } static class T { - val root = GlobalRef[T](this); + private val root = GlobalRef[T](this); transient var val_:Object; } } Modified: trunk/x10.tests/examples/Constructs/Async/AsyncReturn.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Async/AsyncReturn.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/Async/AsyncReturn.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -20,7 +20,7 @@ public def run(): boolean = { class T { - val root = GlobalRef[T](this); + private val root = GlobalRef[T](this); transient var t: int; } val f = new T(); Modified: trunk/x10.tests/examples/Constructs/At/AtFieldAccess.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/At/AtFieldAccess.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/At/AtFieldAccess.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -35,7 +35,7 @@ } static class T { - val root = GlobalRef[T](this); + private val root = GlobalRef[T](this); transient public var i: int; } } Modified: trunk/x10.tests/examples/Constructs/At/AtFieldWrite.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/At/AtFieldWrite.x10 2010-09-20 00:32:47 UTC (rev 16569) +++ trunk/x10.tests/examples/Constructs/At/AtFieldWrite.x10 2010-09-20 00:52:58 UTC (rev 16570) @@ -30,7 +30,7 @@ } static class T { - val root = GlobalRef[T](this); + private val root = GlobalRef[T](this); transient public var i: int; } } Modified: trunk/x10.tests/examples/Constructs/At/AtFieldWrite_MustFailCompile.x10 ========... [truncated message content] |
From: <ipe...@us...> - 2010-09-20 03:29:24
|
Revision: 16571 http://x10.svn.sourceforge.net/x10/?rev=16571&view=rev Author: ipeshansky Date: 2010-09-20 03:29:13 +0000 (Mon, 20 Sep 2010) Log Message: ----------- War on warnings. Genericize most of the code; add missing serialization ids; access static methods through the class. Remove duplicate code in X10TypeSystem_c.findAcceptableTypeDefs() -- delegate to the copy in X10TypeEnv_c. Update return type of procedureInstance() in Call, ConstructorCall, and New. Add procedureInstance(ProcedureInstance) setter to all ProcedureCall subtypes. Update return type of varInstance() in Local and Field. Update return type of Call.arguments(List<Expr>). Add a FIXME in NodeList and NodeList_c. Make data access methods in X10CPPContext_c generic. Modified Paths: -------------- trunk/x10.compiler/src/polyglot/ast/AbstractBlock_c.java trunk/x10.compiler/src/polyglot/ast/AmbQualifierNode_c.java trunk/x10.compiler/src/polyglot/ast/ArrayInit_c.java trunk/x10.compiler/src/polyglot/ast/Assign.java trunk/x10.compiler/src/polyglot/ast/Binary.java trunk/x10.compiler/src/polyglot/ast/Block_c.java trunk/x10.compiler/src/polyglot/ast/Branch.java trunk/x10.compiler/src/polyglot/ast/Call.java trunk/x10.compiler/src/polyglot/ast/Call_c.java trunk/x10.compiler/src/polyglot/ast/ClassDecl_c.java trunk/x10.compiler/src/polyglot/ast/ConstructorCall.java trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java trunk/x10.compiler/src/polyglot/ast/ConstructorDecl_c.java trunk/x10.compiler/src/polyglot/ast/Disamb_c.java trunk/x10.compiler/src/polyglot/ast/FieldDecl_c.java trunk/x10.compiler/src/polyglot/ast/Field_c.java trunk/x10.compiler/src/polyglot/ast/FloatLit.java trunk/x10.compiler/src/polyglot/ast/For_c.java trunk/x10.compiler/src/polyglot/ast/Import.java trunk/x10.compiler/src/polyglot/ast/IntLit.java trunk/x10.compiler/src/polyglot/ast/Local_c.java trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java trunk/x10.compiler/src/polyglot/ast/NamedVariable.java trunk/x10.compiler/src/polyglot/ast/NewArray_c.java trunk/x10.compiler/src/polyglot/ast/New_c.java trunk/x10.compiler/src/polyglot/ast/Node.java trunk/x10.compiler/src/polyglot/ast/NodeFactory_c.java trunk/x10.compiler/src/polyglot/ast/NodeList.java trunk/x10.compiler/src/polyglot/ast/NodeList_c.java trunk/x10.compiler/src/polyglot/ast/Node_c.java trunk/x10.compiler/src/polyglot/ast/Precedence.java trunk/x10.compiler/src/polyglot/ast/ProcedureCall.java trunk/x10.compiler/src/polyglot/ast/SourceCollection_c.java trunk/x10.compiler/src/polyglot/ast/SourceFile_c.java trunk/x10.compiler/src/polyglot/ast/Special.java trunk/x10.compiler/src/polyglot/ast/StringLit_c.java trunk/x10.compiler/src/polyglot/ast/SwitchBlock_c.java trunk/x10.compiler/src/polyglot/ast/TypeCheckFragmentGoal.java trunk/x10.compiler/src/polyglot/ast/TypeCheckTypeGoal.java trunk/x10.compiler/src/polyglot/ast/TypeNode_c.java trunk/x10.compiler/src/polyglot/ast/Unary.java trunk/x10.compiler/src/polyglot/dispatch/Dispatch.java trunk/x10.compiler/src/polyglot/dispatch/PassthruError.java trunk/x10.compiler/src/polyglot/frontend/AbstractGoal_c.java trunk/x10.compiler/src/polyglot/frontend/AllBarrierGoal.java trunk/x10.compiler/src/polyglot/frontend/BarrierGoal.java trunk/x10.compiler/src/polyglot/frontend/ClassPathResourceLoader.java trunk/x10.compiler/src/polyglot/frontend/Compiler.java trunk/x10.compiler/src/polyglot/frontend/CyclicDependencyException.java trunk/x10.compiler/src/polyglot/frontend/ForgivingVisitorGoal.java trunk/x10.compiler/src/polyglot/frontend/JLScheduler.java trunk/x10.compiler/src/polyglot/frontend/OutputGoal.java trunk/x10.compiler/src/polyglot/frontend/ParserGoal.java trunk/x10.compiler/src/polyglot/frontend/ResourceLoader.java trunk/x10.compiler/src/polyglot/frontend/Scheduler.java trunk/x10.compiler/src/polyglot/frontend/SchedulerException.java trunk/x10.compiler/src/polyglot/frontend/SetResolverGoal.java trunk/x10.compiler/src/polyglot/frontend/SourceGoal_c.java trunk/x10.compiler/src/polyglot/frontend/TypeObjectGoal_c.java trunk/x10.compiler/src/polyglot/frontend/VisitorGoal.java trunk/x10.compiler/src/polyglot/main/Main.java trunk/x10.compiler/src/polyglot/main/Options.java trunk/x10.compiler/src/polyglot/main/Report.java trunk/x10.compiler/src/polyglot/main/UsageError.java trunk/x10.compiler/src/polyglot/types/AbstractRef_c.java trunk/x10.compiler/src/polyglot/types/AnotherCachingResolver.java trunk/x10.compiler/src/polyglot/types/ArrayType_c.java trunk/x10.compiler/src/polyglot/types/BadSerializationException.java trunk/x10.compiler/src/polyglot/types/CachingResolver.java trunk/x10.compiler/src/polyglot/types/ClassContextResolver.java trunk/x10.compiler/src/polyglot/types/ClassDef.java trunk/x10.compiler/src/polyglot/types/ClassDef_c.java trunk/x10.compiler/src/polyglot/types/ClassType_c.java trunk/x10.compiler/src/polyglot/types/ConstructorDef_c.java trunk/x10.compiler/src/polyglot/types/ConstructorInstance_c.java trunk/x10.compiler/src/polyglot/types/Context.java trunk/x10.compiler/src/polyglot/types/Context_c.java trunk/x10.compiler/src/polyglot/types/Def_c.java trunk/x10.compiler/src/polyglot/types/ErrorRef_c.java trunk/x10.compiler/src/polyglot/types/FieldDef_c.java trunk/x10.compiler/src/polyglot/types/FieldInstance_c.java trunk/x10.compiler/src/polyglot/types/Flags.java trunk/x10.compiler/src/polyglot/types/FunctionInstance_c.java trunk/x10.compiler/src/polyglot/types/InitializerDef_c.java trunk/x10.compiler/src/polyglot/types/InitializerInstance_c.java trunk/x10.compiler/src/polyglot/types/LazyRef_c.java trunk/x10.compiler/src/polyglot/types/LocalDef_c.java trunk/x10.compiler/src/polyglot/types/LocalInstance_c.java trunk/x10.compiler/src/polyglot/types/MemberClassResolver.java trunk/x10.compiler/src/polyglot/types/MethodDef_c.java trunk/x10.compiler/src/polyglot/types/MethodInstance_c.java trunk/x10.compiler/src/polyglot/types/NoClassException.java trunk/x10.compiler/src/polyglot/types/NoMemberException.java trunk/x10.compiler/src/polyglot/types/NullType_c.java trunk/x10.compiler/src/polyglot/types/Package_c.java trunk/x10.compiler/src/polyglot/types/ParsedClassType_c.java trunk/x10.compiler/src/polyglot/types/PrimitiveType_c.java trunk/x10.compiler/src/polyglot/types/ProcedureDef_c.java trunk/x10.compiler/src/polyglot/types/ProcedureInstance_c.java trunk/x10.compiler/src/polyglot/types/Ref_c.java trunk/x10.compiler/src/polyglot/types/ReferenceType_c.java trunk/x10.compiler/src/polyglot/types/SemanticException.java trunk/x10.compiler/src/polyglot/types/SourceLoadException.java trunk/x10.compiler/src/polyglot/types/SystemResolver.java trunk/x10.compiler/src/polyglot/types/TypeEnv.java trunk/x10.compiler/src/polyglot/types/TypeEnv_c.java trunk/x10.compiler/src/polyglot/types/TypeObject_c.java trunk/x10.compiler/src/polyglot/types/TypeSystem.java trunk/x10.compiler/src/polyglot/types/TypeSystem_c.java trunk/x10.compiler/src/polyglot/types/Type_c.java trunk/x10.compiler/src/polyglot/types/Types.java trunk/x10.compiler/src/polyglot/types/UnknownPackage_c.java trunk/x10.compiler/src/polyglot/types/UnknownQualifier_c.java trunk/x10.compiler/src/polyglot/types/UnknownType_c.java trunk/x10.compiler/src/polyglot/types/Use_c.java trunk/x10.compiler/src/polyglot/types/VarDef_c.java trunk/x10.compiler/src/polyglot/types/VarInstance_c.java trunk/x10.compiler/src/polyglot/types/reflect/ClassFile.java trunk/x10.compiler/src/polyglot/types/reflect/ClassFileLazyClassInitializer.java trunk/x10.compiler/src/polyglot/types/reflect/ClassFileLoader.java trunk/x10.compiler/src/polyglot/util/CannotResolvePlaceHolderException.java trunk/x10.compiler/src/polyglot/util/CollectionUtil.java trunk/x10.compiler/src/polyglot/util/ConcatenatedIterator.java trunk/x10.compiler/src/polyglot/util/Enum.java trunk/x10.compiler/src/polyglot/util/ErrorLimitError.java trunk/x10.compiler/src/polyglot/util/InternalCompilerError.java trunk/x10.compiler/src/polyglot/util/NestedMap.java trunk/x10.compiler/src/polyglot/util/ObjectDumper.java trunk/x10.compiler/src/polyglot/util/OptimalCodeWriter.java trunk/x10.compiler/src/polyglot/util/Option.java trunk/x10.compiler/src/polyglot/util/Pair.java trunk/x10.compiler/src/polyglot/util/SilentErrorQueue.java trunk/x10.compiler/src/polyglot/util/SimpleCodeWriter.java trunk/x10.compiler/src/polyglot/util/TransformingIterator.java trunk/x10.compiler/src/polyglot/util/TypeEncoder.java trunk/x10.compiler/src/polyglot/util/TypeInputStream.java trunk/x10.compiler/src/polyglot/util/TypeOutputStream.java trunk/x10.compiler/src/polyglot/util/TypedList.java trunk/x10.compiler/src/polyglot/util/WorkList.java trunk/x10.compiler/src/polyglot/util/typedump/Main.java trunk/x10.compiler/src/polyglot/util/typedump/TypeDumper.java trunk/x10.compiler/src/polyglot/visit/CFGBuildError.java trunk/x10.compiler/src/polyglot/visit/ClassSerializer.java trunk/x10.compiler/src/polyglot/visit/CodeCleaner.java trunk/x10.compiler/src/polyglot/visit/CopyPropagator.java trunk/x10.compiler/src/polyglot/visit/DeadCodeEliminator.java trunk/x10.compiler/src/polyglot/visit/ExitChecker.java trunk/x10.compiler/src/polyglot/visit/FinalLocalExtractor.java trunk/x10.compiler/src/polyglot/visit/FlattenVisitor.java trunk/x10.compiler/src/polyglot/visit/InnerClassRemover.java trunk/x10.compiler/src/polyglot/visit/LocalClassRemover.java trunk/x10.compiler/src/polyglot/visit/NodeScrambler.java trunk/x10.compiler/src/polyglot/visit/PostCompiled.java trunk/x10.compiler/src/polyglot/visit/ReachChecker.java trunk/x10.compiler/src/polyglot/visit/RedundantCastRemover.java trunk/x10.compiler/src/polyglot/visit/Translator.java trunk/x10.compiler/src/x10/ExtensionInfo.java trunk/x10.compiler/src/x10/X10CompilerOptions.java trunk/x10.compiler/src/x10/ast/AmbDepTypeNode_c.java trunk/x10.compiler/src/x10/ast/AmbMacroTypeNode_c.java trunk/x10.compiler/src/x10/ast/Async_c.java trunk/x10.compiler/src/x10/ast/AtEach_c.java trunk/x10.compiler/src/x10/ast/ClosureCall_c.java trunk/x10.compiler/src/x10/ast/Closure_c.java trunk/x10.compiler/src/x10/ast/DepParameterExpr_c.java trunk/x10.compiler/src/x10/ast/ForEach_c.java trunk/x10.compiler/src/x10/ast/FunctionTypeNode_c.java trunk/x10.compiler/src/x10/ast/Region_c.java trunk/x10.compiler/src/x10/ast/SemanticError.java trunk/x10.compiler/src/x10/ast/TypeCheckExprGoal.java trunk/x10.compiler/src/x10/ast/TypeCheckFragmentGoal.java trunk/x10.compiler/src/x10/ast/TypeCheckReturnTypeGoal.java trunk/x10.compiler/src/x10/ast/TypeCheckTypeGoal.java trunk/x10.compiler/src/x10/ast/UnknownTypeNode_c.java trunk/x10.compiler/src/x10/ast/When.java trunk/x10.compiler/src/x10/ast/When_c.java trunk/x10.compiler/src/x10/ast/X10AmbQualifierNode_c.java trunk/x10.compiler/src/x10/ast/X10AmbTypeNode_c.java trunk/x10.compiler/src/x10/ast/X10Binary_c.java trunk/x10.compiler/src/x10/ast/X10CanonicalTypeNode_c.java trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java trunk/x10.compiler/src/x10/ast/X10ClockedLoop_c.java trunk/x10.compiler/src/x10/ast/X10Conditional_c.java trunk/x10.compiler/src/x10/ast/X10ConstructorCall_c.java trunk/x10.compiler/src/x10/ast/X10ConstructorDecl_c.java trunk/x10.compiler/src/x10/ast/X10Disamb_c.java trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java trunk/x10.compiler/src/x10/ast/X10Formal_c.java trunk/x10.compiler/src/x10/ast/X10IntLit_c.java trunk/x10.compiler/src/x10/ast/X10Loop_c.java trunk/x10.compiler/src/x10/ast/X10MLSourceFile_c.java trunk/x10.compiler/src/x10/ast/X10MethodDecl_c.java trunk/x10.compiler/src/x10/ast/X10New_c.java trunk/x10.compiler/src/x10/ast/X10SourceFile_c.java trunk/x10.compiler/src/x10/emitter/Join.java trunk/x10.compiler/src/x10/emitter/Loop.java trunk/x10.compiler/src/x10/extension/X10ClassBodyExt_c.java trunk/x10.compiler/src/x10/extension/X10Del_c.java trunk/x10.compiler/src/x10/extension/X10Ext_c.java trunk/x10.compiler/src/x10/finish/table/CallTableUtil.java trunk/x10.compiler/src/x10/finish/table/HprofParser.java trunk/x10.compiler/src/x10/finish/table/OutputUtil.java trunk/x10.compiler/src/x10/optimizations/LoopUnroller.java trunk/x10.compiler/src/x10/types/AnnotatedType_c.java trunk/x10.compiler/src/x10/types/ClosureDef_c.java trunk/x10.compiler/src/x10/types/ClosureInstance_c.java trunk/x10.compiler/src/x10/types/ConstrainedType_c.java trunk/x10.compiler/src/x10/types/MacroType_c.java trunk/x10.compiler/src/x10/types/ParameterType_c.java trunk/x10.compiler/src/x10/types/ParametrizedType_c.java trunk/x10.compiler/src/x10/types/ReinstantiatedClosureInstance_c.java trunk/x10.compiler/src/x10/types/ReinstantiatedConstructorInstance.java trunk/x10.compiler/src/x10/types/ReinstantiatedFieldInstance.java trunk/x10.compiler/src/x10/types/ReinstantiatedLocalInstance.java trunk/x10.compiler/src/x10/types/ReinstantiatedMacroType.java trunk/x10.compiler/src/x10/types/ReinstantiatedMethodInstance.java trunk/x10.compiler/src/x10/types/TypeDefMatcher.java trunk/x10.compiler/src/x10/types/TypeDef_c.java trunk/x10.compiler/src/x10/types/TypeParamSubst.java trunk/x10.compiler/src/x10/types/X10ClassDef_c.java trunk/x10.compiler/src/x10/types/X10ConstructorDef_c.java trunk/x10.compiler/src/x10/types/X10ConstructorInstance_c.java trunk/x10.compiler/src/x10/types/X10Context_c.java trunk/x10.compiler/src/x10/types/X10FieldDef_c.java trunk/x10.compiler/src/x10/types/X10FieldInstance_c.java trunk/x10.compiler/src/x10/types/X10Flags.java trunk/x10.compiler/src/x10/types/X10InitializerDef_c.java trunk/x10.compiler/src/x10/types/X10LocalDef_c.java trunk/x10.compiler/src/x10/types/X10LocalInstance_c.java trunk/x10.compiler/src/x10/types/X10MethodDef_c.java trunk/x10.compiler/src/x10/types/X10MethodInstance_c.java trunk/x10.compiler/src/x10/types/X10NullType_c.java trunk/x10.compiler/src/x10/types/X10ParsedClassType_c.java trunk/x10.compiler/src/x10/types/X10PrimitiveType_c.java trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java trunk/x10.compiler/src/x10/types/X10TypeMixin.java trunk/x10.compiler/src/x10/types/X10TypeSystem.java trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java trunk/x10.compiler/src/x10/types/X10UnknownType_c.java trunk/x10.compiler/src/x10/types/XTypeTranslator.java trunk/x10.compiler/src/x10/types/constraints/CConstraint.java trunk/x10.compiler/src/x10/types/constraints/SubtypeConstraint.java trunk/x10.compiler/src/x10/types/constraints/TypeConstraint.java trunk/x10.compiler/src/x10/types/matcher/X10MethodMatcher.java trunk/x10.compiler/src/x10/util/ClosureSynthesizer.java trunk/x10.compiler/src/x10/visit/AssignPropertyChecker.java trunk/x10.compiler/src/x10/visit/AtomicElimination.java trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java trunk/x10.compiler/src/x10/visit/Desugarer.java trunk/x10.compiler/src/x10/visit/ExprFlattener.java trunk/x10.compiler/src/x10/visit/FinishAsyncVisitor.java trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java trunk/x10.compiler/src/x10c/types/BackingArrayType.java trunk/x10.compiler/src/x10cpp/ExtensionInfo.java trunk/x10.compiler/src/x10cpp/X10CPPCompilerOptions.java trunk/x10.compiler/src/x10cpp/types/X10CPPContext_c.java trunk/x10.compiler/src/x10cpp/visit/ASTQuery.java trunk/x10.compiler/src/x10cpp/visit/Emitter.java trunk/x10.compiler/src/x10cpp/visit/ITable.java trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.compiler/src/x10cpp/visit/SharedVarsMethods.java trunk/x10.compiler/src/x10cpp/visit/X10CPPTranslator.java trunk/x10.compiler/src/x10cpp/visit/X10SearchVisitor.java trunk/x10.compiler/src/x10cuda/ExtensionInfo.java trunk/x10.compiler/src/x10cuda/types/X10CUDAContext_c.java trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java trunk/x10.constraints/src/x10/constraint/XConstraint.java trunk/x10.constraints/src/x10/constraint/XFormula.java Modified: trunk/x10.compiler/src/polyglot/ast/AbstractBlock_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/AbstractBlock_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/AbstractBlock_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -70,7 +70,7 @@ /** Visit the children of the block. */ public Node visitChildren(NodeVisitor v) { List<Stmt> statements = visitList(this.statements, v); - return reconstruct(statements); + return reconstruct(statements); } public Context enterScope(Context c) { @@ -81,9 +81,9 @@ public void prettyPrint(CodeWriter w, PrettyPrinter tr) { w.begin(0); - for (Iterator<Stmt> i = statements.iterator(); i.hasNext(); ) { + for (Iterator<Stmt> i = statements.iterator(); i.hasNext();) { Stmt n = i.next(); - + printBlock(n, w, tr); if (i.hasNext()) { @@ -109,13 +109,11 @@ int count = 0; - for (Iterator<Stmt> i = statements.iterator(); i.hasNext(); ) { + for (Stmt n : statements) { if (count++ > 2) { sb.append(" ..."); break; } - - Stmt n = i.next(); sb.append(" "); sb.append(n.toString()); } Modified: trunk/x10.compiler/src/polyglot/ast/AmbQualifierNode_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/AmbQualifierNode_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/AmbQualifierNode_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -93,7 +93,7 @@ final LazyRef<Qualifier> r = (LazyRef<Qualifier>) qualifierRef(); TypeChecker tc = new TypeChecker(v.job(), v.typeSystem(), v.nodeFactory(), v.getMemo()); tc = (TypeChecker) tc.context(v.context().freeze()); - r.setResolver(new TypeCheckTypeGoal(parent, this, tc, r, false)); + r.setResolver(new TypeCheckFragmentGoal<Qualifier>(parent, this, tc, r, false)); } public Node disambiguate(ContextVisitor ar) throws SemanticException { Modified: trunk/x10.compiler/src/polyglot/ast/ArrayInit_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/ArrayInit_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/ArrayInit_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -99,9 +99,7 @@ TypeSystem ts = av.typeSystem(); - for (Iterator i = elements.iterator(); i.hasNext(); ) { - Expr e = (Expr) i.next(); - + for (Expr e : elements) { if (e == child) { if (ts.numericConversionValid(t, e.constantValue(), av.context())) { return child.type(); Modified: trunk/x10.compiler/src/polyglot/ast/Assign.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Assign.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Assign.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -17,6 +17,7 @@ { /** Assignment operator. */ public static class Operator extends Enum { + private static final long serialVersionUID = 574369171510341962L; private final Binary.Operator binOp; public Operator(String name, Binary.Operator binOp) { super(name); Modified: trunk/x10.compiler/src/polyglot/ast/Binary.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Binary.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Binary.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -17,9 +17,10 @@ { /** Binary expression operator. */ public static class Operator extends Enum { + private static final long serialVersionUID = 4475208101698678242L; protected Precedence prec; - public Operator(String name, Precedence prec) { + public Operator(String name, Precedence prec) { super(name); this.prec = prec; } Modified: trunk/x10.compiler/src/polyglot/ast/Block_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Block_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Block_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -20,7 +20,7 @@ */ public class Block_c extends AbstractBlock_c implements Block { - public Block_c(Position pos, List statements) { + public Block_c(Position pos, List<Stmt> statements) { super(pos, statements); } Modified: trunk/x10.compiler/src/polyglot/ast/Branch.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Branch.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Branch.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -17,6 +17,7 @@ { /** Branch kind: either break or continue. */ public static class Kind extends Enum { + private static final long serialVersionUID = 7666190675942868358L; public Kind(String name) { super(name); } } Modified: trunk/x10.compiler/src/polyglot/ast/Call.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Call.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Call.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -61,7 +61,7 @@ * Set the call's actual arguments. * @param arguments A list of {@link polyglot.ast.Expr Expr}. */ - ProcedureCall arguments(List<Expr> arguments); + Call arguments(List<Expr> arguments); /** * The type object of the method we are calling. This is, generally, only Modified: trunk/x10.compiler/src/polyglot/ast/Call_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Call_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Call_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -67,7 +67,7 @@ return n; } - public ProcedureInstance procedureInstance() { + public MethodInstance procedureInstance() { return methodInstance(); } @@ -76,6 +76,10 @@ return this.mi; } + public Call procedureInstance(ProcedureInstance<? extends ProcedureDef> pi) { + return methodInstance((MethodInstance) pi); + } + /** Set the method instance of the call. */ public Call methodInstance(MethodInstance mi) { if (mi == this.mi) return this; @@ -104,7 +108,7 @@ } /** Set the actual arguments of the call. */ - public ProcedureCall arguments(List<Expr> arguments) { + public Call arguments(List<Expr> arguments) { Call_c n = (Call_c) copy(); n.arguments = TypedList.copyAndCheck(arguments, Expr.class, true); return n; @@ -253,8 +257,8 @@ return mi.container(); } - Iterator i = this.arguments.iterator(); - Iterator j = mi.formalTypes().iterator(); + Iterator<Expr> i = this.arguments.iterator(); + Iterator<Type> j = mi.formalTypes().iterator(); while (i.hasNext() && j.hasNext()) { Expr e = (Expr) i.next(); @@ -276,7 +280,7 @@ int count = 0; - for (Iterator i = arguments.iterator(); i.hasNext(); ) { + for (Iterator<Expr> i = arguments.iterator(); i.hasNext(); ) { if (count++ > 2) { sb.append("..."); break; Modified: trunk/x10.compiler/src/polyglot/ast/ClassDecl_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/ClassDecl_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/ClassDecl_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -32,7 +32,7 @@ protected ClassDef type; public ClassDecl_c(Position pos, FlagsNode flags, Id name, - TypeNode superClass, List interfaces, ClassBody body) { + TypeNode superClass, List<TypeNode> interfaces, ClassBody body) { super(pos); // superClass may be null, interfaces may be empty assert(flags != null && name != null && interfaces != null && body != null); @@ -343,7 +343,7 @@ Ref<? extends Type> superType = thisType.superType(); if (superType != null) { - ConstructorCall cc = nf.SuperCall(pos, Collections.EMPTY_LIST); + ConstructorCall cc = nf.SuperCall(pos, Collections.<Expr>emptyList()); block = nf.Block(pos, cc); } else { @@ -352,8 +352,8 @@ ConstructorDecl cd = nf.ConstructorDecl(pos, nf.FlagsNode(pos, Flags.PUBLIC), - name, Collections.EMPTY_LIST, - Collections.EMPTY_LIST, + name, Collections.<Formal>emptyList(), + Collections.<TypeNode>emptyList(), block); return cd; } Modified: trunk/x10.compiler/src/polyglot/ast/ConstructorCall.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/ConstructorCall.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/ConstructorCall.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -20,6 +20,7 @@ { /** Constructor call kind: either "super" or "this". */ public static class Kind extends Enum { + private static final long serialVersionUID = -6862343120050782664L; public Kind(String name) { super(name); } } Modified: trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -22,10 +22,10 @@ { protected Kind kind; protected Expr qualifier; - protected List arguments; + protected List<Expr> arguments; protected ConstructorInstance ci; - public ConstructorCall_c(Position pos, Kind kind, Expr qualifier, List arguments) { + public ConstructorCall_c(Position pos, Kind kind, Expr qualifier, List<Expr> arguments) { super(pos); assert(kind != null && arguments != null); // qualifier may be null this.kind = kind; @@ -69,7 +69,7 @@ return n; } - public ProcedureInstance procedureInstance() { + public ConstructorInstance procedureInstance() { return constructorInstance(); } @@ -78,6 +78,10 @@ return ci; } + public ConstructorCall procedureInstance(ProcedureInstance<? extends ProcedureDef> pi) { + return constructorInstance((ConstructorInstance) pi); + } + /** Set the constructor we are calling. */ public ConstructorCall constructorInstance(ConstructorInstance ci) { if (ci == this.ci) return this; @@ -95,7 +99,7 @@ } /** Reconstruct the constructor call. */ - protected ConstructorCall_c reconstruct(Expr qualifier, List arguments) { + protected ConstructorCall_c reconstruct(Expr qualifier, List<Expr> arguments) { if (qualifier != this.qualifier || ! CollectionUtil.allEqual(arguments, this.arguments)) { ConstructorCall_c n = (ConstructorCall_c) copy(); n.qualifier = qualifier; @@ -109,7 +113,7 @@ /** Visit the children of the call. */ public Node visitChildren(NodeVisitor v) { Expr qualifier = (Expr) visitChild(this.qualifier, v); - List arguments = visitList(this.arguments, v); + List<Expr> arguments = visitList(this.arguments, v); return reconstruct(qualifier, arguments); } @@ -242,12 +246,12 @@ return ts.Object(); } - Iterator i = this.arguments.iterator(); - Iterator j = ci.formalTypes().iterator(); + Iterator<Expr> i = this.arguments.iterator(); + Iterator<Type> j = ci.formalTypes().iterator(); while (i.hasNext() && j.hasNext()) { - Expr e = (Expr) i.next(); - Type t = (Type) j.next(); + Expr e = i.next(); + Type t = j.next(); if (e == child) { return t; @@ -272,8 +276,8 @@ w.begin(0); - for (Iterator i = arguments.iterator(); i.hasNext(); ) { - Expr e = (Expr) i.next(); + for (Iterator<Expr> i = arguments.iterator(); i.hasNext(); ) { + Expr e = i.next(); print(e, w, tr); if (i.hasNext()) { Modified: trunk/x10.compiler/src/polyglot/ast/ConstructorDecl_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/ConstructorDecl_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/ConstructorDecl_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -305,8 +305,8 @@ w.begin(0); - for (Iterator i = formals.iterator(); i.hasNext(); ) { - Formal f = (Formal) i.next(); + for (Iterator<Formal> i = formals.iterator(); i.hasNext(); ) { + Formal f = i.next(); print(f, w, tr); if (i.hasNext()) { @@ -322,8 +322,8 @@ w.allowBreak(6); w.write("throws "); - for (Iterator i = throwTypes().iterator(); i.hasNext(); ) { - TypeNode tn = (TypeNode) i.next(); + for (Iterator<TypeNode> i = throwTypes().iterator(); i.hasNext(); ) { + TypeNode tn = i.next(); print(tn, w, tr); if (i.hasNext()) { Modified: trunk/x10.compiler/src/polyglot/ast/Disamb_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Disamb_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Disamb_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -173,7 +173,7 @@ protected Node disambiguateNoPrefix() throws SemanticException { if (exprOK()) { // First try local variables and fields. - VarInstance vi = c.findVariableSilent(name.id()); + VarInstance<?> vi = c.findVariableSilent(name.id()); if (vi != null) { Node n = disambiguateVarInstance(vi); @@ -216,7 +216,7 @@ return null; } - protected Node disambiguateVarInstance(VarInstance vi) throws SemanticException { + protected Node disambiguateVarInstance(VarInstance<?> vi) throws SemanticException { if (vi instanceof FieldInstance) { FieldInstance fi = (FieldInstance) vi; Receiver r = makeMissingFieldTarget(fi); @@ -304,7 +304,7 @@ protected Node makeTypeNode(Type t) { if (amb instanceof TypeNode) { TypeNode tn = (TypeNode) amb; - if (tn.typeRef() instanceof LazyRef) { + if (tn.typeRef() instanceof LazyRef<?>) { LazyRef<Type> sym = (LazyRef<Type>) tn.typeRef(); sym.update(t); Modified: trunk/x10.compiler/src/polyglot/ast/FieldDecl_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/FieldDecl_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/FieldDecl_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -236,32 +236,33 @@ public void setResolver(final Node parent, TypeCheckPreparer v) { final FieldDef def = fieldDef(); Ref<ConstantValue> rx = def.constantValueRef(); - if (rx instanceof LazyRef) { + if (rx instanceof LazyRef<?>) { LazyRef<ConstantValue> r = (LazyRef<ConstantValue>) rx; TypeChecker tc0 = new TypeChecker(v.job(), v.typeSystem(), v.nodeFactory(), v.getMemo()); final TypeChecker tc = (TypeChecker) tc0.context(v.context().freeze()); final Node n = this; r.setResolver(new AbstractGoal_c("ConstantValue") { - public boolean runTask() { - if (state() == Goal.Status.RUNNING_RECURSIVE || state() == Goal.Status.RUNNING_WILL_FAIL) { - // The field is not constant if the initializer is recursive. - // - // But, we could be checking if the field is constant for another - // reference in the same file: - // - // m() { use x; } - // final int x = 1; - // - // So this is incorrect. The goal below needs to be refined to only visit the initializer. - def.setNotConstant(); - } - else { - Node m = parent.visitChild(n, tc); - tc.job().nodeMemo().put(n, m); - tc.job().nodeMemo().put(m, m); - } - return true; - } + private static final long serialVersionUID = 3729582427435523873L; + public boolean runTask() { + if (state() == Goal.Status.RUNNING_RECURSIVE || state() == Goal.Status.RUNNING_WILL_FAIL) { + // The field is not constant if the initializer is recursive. + // + // But, we could be checking if the field is constant for another + // reference in the same file: + // + // m() { use x; } + // final int x = 1; + // + // So this is incorrect. The goal below needs to be refined to only visit the initializer. + def.setNotConstant(); + } + else { + Node m = parent.visitChild(n, tc); + tc.job().nodeMemo().put(n, m); + tc.job().nodeMemo().put(m, m); + } + return true; + } }); } } Modified: trunk/x10.compiler/src/polyglot/ast/Field_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Field_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Field_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -73,7 +73,7 @@ } /** Get the field instance of the field. */ - public VarInstance varInstance() { + public FieldInstance varInstance() { return fi; } @@ -125,8 +125,10 @@ TypeSystem ts = tb.typeSystem(); - FieldInstance fi = ts.createFieldInstance(position(), new ErrorRef_c<FieldDef>(ts, position(), "Cannot get FieldDef before type-checking field access.") { - public String toString() { e.printStackTrace(); return super.toString(); } }); + FieldInstance fi = ts.createFieldInstance(position(), + new ErrorRef_c<FieldDef>(ts, position(), "Cannot get FieldDef before type-checking field access.") { + private static final long serialVersionUID = 7823901508583320051L; + public String toString() { e.printStackTrace(); return super.toString(); } }); return n.fieldInstance(fi); } @@ -254,7 +256,7 @@ */ protected void checkConsistency(Context c) { if (targetImplicit) { - VarInstance vi = c.findVariableSilent(name.id()); + VarInstance<?> vi = c.findVariableSilent(name.id()); if (vi instanceof FieldInstance) { FieldInstance rfi = (FieldInstance) vi; // Compare the original (declaration) fis, not the actuals. Modified: trunk/x10.compiler/src/polyglot/ast/FloatLit.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/FloatLit.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/FloatLit.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -17,6 +17,7 @@ { /** Integer literal kinds: float (e.g., 0.0F) or double (e.g., 0.0). */ public static class Kind extends Enum { + private static final long serialVersionUID = -3253935710240131093L; public Kind(String name) { super(name); } } Modified: trunk/x10.compiler/src/polyglot/ast/For_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/For_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/For_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -26,7 +26,7 @@ protected List<ForUpdate> iters; protected Stmt body; - public For_c(Position pos, List inits, Expr cond, List iters, Stmt body) { + public For_c(Position pos, List<ForInit> inits, Expr cond, List<ForUpdate> iters, Stmt body) { super(pos); assert(inits != null && iters != null && body != null); // cond may be null, inits and iters may be empty this.inits = TypedList.copyAndCheck(inits, ForInit.class, true); @@ -41,7 +41,7 @@ } /** Set the inits of the statement. */ - public For inits(List inits) { + public For inits(List<ForInit> inits) { For_c n = (For_c) copy(); n.inits = TypedList.copyAndCheck(inits, ForInit.class, true); return n; @@ -84,7 +84,7 @@ } /** Reconstruct the statement. */ - protected For_c reconstruct(List inits, Expr cond, List iters, Stmt body) { + protected For_c reconstruct(List<ForInit> inits, Expr cond, List<ForUpdate> iters, Stmt body) { if (! CollectionUtil.allEqual(inits, this.inits) || cond != this.cond || ! CollectionUtil.allEqual(iters, this.iters) || body != this.body) { For_c n = (For_c) copy(); n.inits = TypedList.copyAndCheck(inits, ForInit.class, true); @@ -99,9 +99,9 @@ /** Visit the children of the statement. */ public Node visitChildren(NodeVisitor v) { - List inits = visitList(this.inits, v); + List<ForInit> inits = visitList(this.inits, v); Expr cond = (Expr) visitChild(this.cond, v); - List iters = visitList(this.iters, v); + List<ForUpdate> iters = visitList(this.iters, v); Node body = visitChild(this.body, v); if (body instanceof NodeList) body = ((NodeList) body).toBlock(); return reconstruct(inits, cond, iters, (Stmt) body); @@ -120,9 +120,7 @@ // just to be sure. Type t = null; - for (Iterator i = inits.iterator(); i.hasNext(); ) { - ForInit s = (ForInit) i.next(); - + for (ForInit s : inits) { if (s instanceof LocalDecl) { LocalDecl d = (LocalDecl) s; Type dt = d.type().type(); @@ -164,16 +162,14 @@ w.begin(0); if (inits != null) { - boolean first = true; - for (Iterator i = inits.iterator(); i.hasNext(); ) { - ForInit s = (ForInit) i.next(); + boolean first = true; + for (ForInit s : inits) { + if (!first) { + w.write(","); + w.allowBreak(2, " "); + } printForInit(s, w, tr, first); - first = false; - - if (i.hasNext()) { - w.write(","); - w.allowBreak(2, " "); - } + first = false; } } @@ -188,8 +184,8 @@ w.allowBreak(0); if (iters != null) { - for (Iterator i = iters.iterator(); i.hasNext();) { - ForUpdate s = (ForUpdate) i.next(); + for (Iterator<ForUpdate> i = iters.iterator(); i.hasNext();) { + ForUpdate s = i.next(); printForUpdate(s, w, tr); if (i.hasNext()) { Modified: trunk/x10.compiler/src/polyglot/ast/Import.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Import.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Import.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -25,6 +25,7 @@ * is a class. This puts the nested classes of p.C in scope. */ public static class Kind extends Enum { + private static final long serialVersionUID = 167043594626583539L; public Kind(String name) { super(name); } } Modified: trunk/x10.compiler/src/polyglot/ast/IntLit.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/IntLit.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/IntLit.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -17,6 +17,7 @@ { /** Integer literal kinds: int (e.g., 0) or long (e.g., 0L). */ public static class Kind extends Enum { + private static final long serialVersionUID = 2490235381600621044L; public Kind(String name) { super(name); } } Modified: trunk/x10.compiler/src/polyglot/ast/Local_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Local_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Local_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -52,7 +52,7 @@ } /** Get the local instance of the local. */ - public VarInstance varInstance() { + public LocalInstance varInstance() { return li; } Modified: trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -376,7 +376,7 @@ w.allowBreak(6); w.write("throws "); - for (Iterator i = throwTypes().iterator(); i.hasNext(); ) { + for (Iterator<TypeNode> i = throwTypes().iterator(); i.hasNext(); ) { TypeNode tn = (TypeNode) i.next(); print(tn, w, tr); @@ -435,6 +435,6 @@ return succs; } - private static final Collection TOPICS = + private static final Collection<String> TOPICS = CollectionUtil.list(Report.types, Report.context); } Modified: trunk/x10.compiler/src/polyglot/ast/NamedVariable.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/NamedVariable.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/NamedVariable.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -8,6 +8,7 @@ package polyglot.ast; import polyglot.types.Flags; +import polyglot.types.VarDef; import polyglot.types.VarInstance; /** @@ -20,7 +21,7 @@ public Flags flags(); /** Return the type object for the variable. */ - public VarInstance varInstance(); + public VarInstance<? extends VarDef> varInstance(); /** Return the name of the variable. */ public Id name(); Modified: trunk/x10.compiler/src/polyglot/ast/NewArray_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/NewArray_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/NewArray_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -25,11 +25,11 @@ public class NewArray_c extends Expr_c implements NewArray { protected TypeNode baseType; - protected List dims; + protected List<Expr> dims; protected int addDims; protected ArrayInit init; - public NewArray_c(Position pos, TypeNode baseType, List dims, int addDims, ArrayInit init) { + public NewArray_c(Position pos, TypeNode baseType, List<Expr> dims, int addDims, ArrayInit init) { super(pos); assert(baseType != null && dims != null); // init may be null assert(addDims >= 0); @@ -56,12 +56,12 @@ } /** Get the dimension expressions of the expression. */ - public List dims() { + public List<Expr> dims() { return Collections.unmodifiableList(this.dims); } /** Set the dimension expressions of the expression. */ - public NewArray dims(List dims) { + public NewArray dims(List<Expr> dims) { NewArray_c n = (NewArray_c) copy(); n.dims = TypedList.copyAndCheck(dims, Expr.class, true); return n; @@ -97,7 +97,7 @@ } /** Reconstruct the expression. */ - protected NewArray_c reconstruct(TypeNode baseType, List dims, ArrayInit init) { + protected NewArray_c reconstruct(TypeNode baseType, List<Expr> dims, ArrayInit init) { if (baseType != this.baseType || ! CollectionUtil.allEqual(dims, this.dims) || init != this.init) { NewArray_c n = (NewArray_c) copy(); n.baseType = baseType; @@ -112,7 +112,7 @@ /** Visit the children of the expression. */ public Node visitChildren(NodeVisitor v) { TypeNode baseType = (TypeNode) visitChild(this.baseType, v); - List dims = visitList(this.dims, v); + List<Expr> dims = visitList(this.dims, v); ArrayInit init = (ArrayInit) visitChild(this.init, v); return reconstruct(baseType, dims, init); } @@ -121,8 +121,7 @@ public Node typeCheck(ContextVisitor tc) throws SemanticException { TypeSystem ts = tc.typeSystem(); - for (Iterator<Expr> i = dims.iterator(); i.hasNext(); ) { - Expr expr = (Expr) i.next(); + for (Expr expr : dims) { if (! ts.isImplicitCastValid(expr.type(), ts.Int(), tc.context())) { throw new SemanticException("Array dimension must be an integer.", expr.position()); @@ -155,11 +154,10 @@ w.write("new "); print(baseType, w, tr); - for (Iterator i = dims.iterator(); i.hasNext();) { - Expr e = (Expr) i.next(); - w.write("["); - printBlock(e, w, tr); - w.write("]"); + for (Expr e : dims) { + w.write("["); + printBlock(e, w, tr); + w.write("]"); } for (int i = 0; i < addDims; i++) { Modified: trunk/x10.compiler/src/polyglot/ast/New_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/New_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/New_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -83,7 +83,7 @@ return n; } - public ProcedureInstance procedureInstance() { + public ConstructorInstance procedureInstance() { return constructorInstance(); } @@ -91,6 +91,10 @@ return this.ci; } + public New procedureInstance(ProcedureInstance<? extends ProcedureDef> pi) { + return constructorInstance((ConstructorInstance) pi); + } + public New constructorInstance(ConstructorInstance ci) { if (ci == this.ci) return this; New_c n = (New_c) copy(); @@ -160,7 +164,7 @@ Expr qual = (Expr) n.visitChild(n.qualifier(), tb); TypeNode objectType = (TypeNode) n.visitChild(n.objectType(), tb); - List<Expr> arguments = (List<Expr>) n.visitList(n.arguments(), tb); + List<Expr> arguments = n.visitList(n.arguments(), tb); ClassBody body = null; @@ -503,8 +507,7 @@ "Null constructor instance after type check."); } - for (Iterator i = ci.throwTypes().iterator(); i.hasNext(); ) { - Type t = (Type) i.next(); + for (Type t : ci.throwTypes()) { ec.throwsException(t, position()); } Modified: trunk/x10.compiler/src/polyglot/ast/Node.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Node.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Node.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -110,7 +110,7 @@ * <code>l</code>. If <code>l</code> is <code>null</code>, * <code>null</code> is returned. */ - public List visitList(List l, NodeVisitor v); + public List visitList(List<? extends Node> l, NodeVisitor v); /** * Get the expected type of a child expression of <code>this</code>. Modified: trunk/x10.compiler/src/polyglot/ast/NodeFactory_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/NodeFactory_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/NodeFactory_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -54,7 +54,7 @@ /** * Utility method to find an instance of an Extension Factory */ - protected final ExtFactory findExtFactInstance(Class c) { + protected final ExtFactory findExtFactInstance(Class<?> c) { ExtFactory e = extFactory(); while (e != null) { if (c.isInstance(e)) { @@ -185,14 +185,14 @@ return n; } - public Block Block(Position pos, List statements) { + public Block Block(Position pos, List<Stmt> statements) { Block n = new Block_c(pos, CollectionUtil.nonNullList(statements)); n = (Block)n.ext(extFactory.extBlock()); n = (Block)n.del(delFactory.delBlock()); return n; } - public SwitchBlock SwitchBlock(Position pos, List statements) { + public SwitchBlock SwitchBlock(Position pos, List<Stmt> statements) { SwitchBlock n = new SwitchBlock_c(pos, CollectionUtil.nonNullList(statements)); n = (SwitchBlock)n.ext(extFactory.extSwitchBlock()); n = (SwitchBlock)n.del(delFactory.delSwitchBlock()); @@ -423,14 +423,14 @@ return n; } - public NewArray NewArray(Position pos, TypeNode base, List dims, int addDims, ArrayInit init) { + public NewArray NewArray(Position pos, TypeNode base, List<Expr> dims, int addDims, ArrayInit init) { NewArray n = new NewArray_c(pos, base, CollectionUtil.nonNullList(dims), addDims, init); n = (NewArray)n.ext(extFactory.extNewArray()); n = (NewArray)n.del(delFactory.delNewArray()); return n; } - public NodeList NodeList(Position pos, NodeFactory nf, List nodes) { + public NodeList NodeList(Position pos, NodeFactory nf, List<Node> nodes) { NodeList n = new NodeList_c(pos, nf, nodes); n = (NodeList) n.ext(extFactory.extNodeList()); n = (NodeList) n.del(delFactory.delNodeList()); @@ -451,7 +451,7 @@ return n; } - public SourceCollection SourceCollection(Position pos, List sources) { + public SourceCollection SourceCollection(Position pos, List<SourceFile> sources) { SourceCollection n = new SourceCollection_c(pos, CollectionUtil.nonNullList(sources)); n = (SourceCollection)n.ext(extFactory.extSourceCollection()); n = (SourceCollection)n.del(delFactory.delSourceCollection()); @@ -479,7 +479,7 @@ return n; } - public Switch Switch(Position pos, Expr expr, List elements) { + public Switch Switch(Position pos, Expr expr, List<SwitchElement> elements) { Switch n = new Switch_c(pos, expr, CollectionUtil.nonNullList(elements)); n = (Switch)n.ext(extFactory.extSwitch()); n = (Switch)n.del(delFactory.delSwitch()); @@ -500,7 +500,7 @@ return n; } - public Try Try(Position pos, Block tryBlock, List catchBlocks, Block finallyBlock) { + public Try Try(Position pos, Block tryBlock, List<Catch> catchBlocks, Block finallyBlock) { Try n = new Try_c(pos, tryBlock, CollectionUtil.nonNullList(catchBlocks), finallyBlock); n = (Try)n.ext(extFactory.extTry()); n = (Try)n.del(delFactory.delTry()); Modified: trunk/x10.compiler/src/polyglot/ast/NodeList.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/NodeList.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/NodeList.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -14,6 +14,7 @@ * a node is visited, it may replace itself with multiple nodes by returning a * <code>NodeList</code> to the visitor. The rewritten node's parent would * then be responsible for properly splicing those nodes into the AST. + * FIXME: make generic */ public interface NodeList extends Node { /** Modified: trunk/x10.compiler/src/polyglot/ast/NodeList_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/NodeList_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/NodeList_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -6,7 +6,6 @@ package polyglot.ast; -import java.util.Iterator; import java.util.List; import polyglot.types.Context; @@ -19,12 +18,13 @@ * a node is visited, it may replace itself with multiple nodes by returning a * <code>NodeList</code> to the visitor. The rewritten node's parent would * then be responsible for properly splicing those nodes into the AST. + * FIXME: make generic */ public class NodeList_c extends Node_c implements NodeList { protected NodeFactory nf; protected List<Node> nodes; - public NodeList_c(Position pos, NodeFactory nf, List nodes) { + public NodeList_c(Position pos, NodeFactory nf, List<Node> nodes) { super(pos); assert (nodes != null); this.nf = nf; @@ -36,7 +36,7 @@ * * @see polyglot.ast.NodeList#nodes() */ - public List nodes() { + public List<Node> nodes() { return nodes; } @@ -45,7 +45,7 @@ * * @see polyglot.ast.NodeList#nodes(java.util.List) */ - public NodeList nodes(List nodes) { + public NodeList nodes(List<Node> nodes) { NodeList_c result = (NodeList_c) copy(); result.nodes = TypedList.copyAndCheck(nodes, Node.class, true); return result; @@ -66,7 +66,7 @@ * @see polyglot.ast.NodeList#toBlock() */ public Block toBlock() { - return nf.Block(position, (List) nodes); + return nf.Block(position, (List<Stmt>)(List) nodes); } public String toString() { @@ -74,13 +74,12 @@ int count = 0; - for (Iterator i = nodes.iterator(); i.hasNext(); ) { + for (Node n : nodes) { if (count++ > 2) { sb.append(" ..."); break; } - Node n = (Node) i.next(); sb.append(" "); sb.append(n.toString()); } @@ -97,7 +96,7 @@ @Override public Node visitChildren(NodeVisitor v) { - List l = visitList(nodes, v); + List<Node> l = visitList(nodes, v); if (CollectionUtil.allEqual(l, nodes)) return this; return nodes(l); Modified: trunk/x10.compiler/src/polyglot/ast/Node_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Node_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Node_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -226,15 +226,15 @@ * <code>l</code>. If <code>l</code> is <code>null</code>, * <code>null</code> is returned. */ - public List visitList(List l, NodeVisitor v) { + public List visitList(List<? extends Node> l, NodeVisitor v) { if (l == null) { return null; } - List result = l; - List vl = new ArrayList(l.size()); + List<? extends Node> result = l; + List<Node> vl = new ArrayList<Node>(l.size()); - for (Iterator i = l.iterator(); i.hasNext(); ) { + for (Iterator<? extends Node> i = l.iterator(); i.hasNext(); ) { Node n = (Node) i.next(); Node m = visitChild(n, v); if (n != m) { @@ -331,15 +331,15 @@ } public Node exceptionCheck(ExceptionChecker ec) throws SemanticException { - List l = this.del().throwTypes(ec.typeSystem()); - for (Iterator i = l.iterator(); i.hasNext(); ) { - ec.throwsException((Type)i.next(), position()); + List<Type> l = this.del().throwTypes(ec.typeSystem()); + for (Type t : l) { + ec.throwsException(t, position()); } return this; } public List<Type> throwTypes(TypeSystem ts) { - return Collections.EMPTY_LIST; + return Collections.<Type>emptyList(); } /** Dump the AST for debugging. */ Modified: trunk/x10.compiler/src/polyglot/ast/Precedence.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Precedence.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Precedence.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -15,6 +15,8 @@ * values denote higher precedence (i.e., tighter binding). */ public class Precedence extends Enum { + private static final long serialVersionUID = 2930131912223765591L; + private int value; public Precedence(String name, int value) { Modified: trunk/x10.compiler/src/polyglot/ast/ProcedureCall.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/ProcedureCall.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/ProcedureCall.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -9,6 +9,7 @@ import java.util.List; +import polyglot.types.ProcedureDef; import polyglot.types.ProcedureInstance; /** @@ -26,6 +27,7 @@ /** * Set the call's actual arguments. * @param arguments A list of {@link polyglot.ast.Expr Expr}. + * @return a copy of this ProcedureCall with the new arguments. */ ProcedureCall arguments(List<Expr> arguments); @@ -33,5 +35,11 @@ * The type object of the method we are calling. This is, generally, only * valid after the type-checking pass. */ - ProcedureInstance procedureInstance(); + ProcedureInstance<? extends ProcedureDef> procedureInstance(); + + /** + * Set the type object for instance being called. + * @return a copy of this ProcedureCall with the new type object. + */ + ProcedureCall procedureInstance(ProcedureInstance<? extends ProcedureDef> pi); } Modified: trunk/x10.compiler/src/polyglot/ast/SourceCollection_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/SourceCollection_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/SourceCollection_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -8,7 +8,6 @@ package polyglot.ast; -import java.util.Iterator; import java.util.List; import polyglot.util.*; @@ -20,9 +19,9 @@ */ public class SourceCollection_c extends Node_c implements SourceCollection { - protected List sources; + protected List<SourceFile> sources; - public SourceCollection_c(Position pos, List sources) { + public SourceCollection_c(Position pos, List<SourceFile> sources) { super(pos); assert(sources != null); this.sources = TypedList.copyAndCheck(sources, SourceFile.class, true); @@ -45,7 +44,7 @@ } /** Reconstruct the collection. */ - protected SourceCollection_c reconstruct(List sources) { + protected SourceCollection_c reconstruct(List<SourceFile> sources) { if (! CollectionUtil.allEqual(sources, this.sources)) { SourceCollection_c n = (SourceCollection_c) copy(); n.sources = TypedList.copyAndCheck(sources, SourceFile.class, true); @@ -57,14 +56,13 @@ /** Visit the children of the block. */ public Node visitChildren(NodeVisitor v) { - List sources = visitList(this.sources, v); + List<SourceFile> sources = visitList(this.sources, v); return reconstruct(sources); } /** Write the source files to an output file. */ public void prettyPrint(CodeWriter w, PrettyPrinter tr) { - for (Iterator i = sources.iterator(); i.hasNext(); ) { - SourceFile s = (SourceFile) i.next(); + for (SourceFile s : sources) { print(s, w, tr); w.newline(0); } Modified: trunk/x10.compiler/src/polyglot/ast/SourceFile_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/SourceFile_c.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/SourceFile_c.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -172,8 +172,7 @@ Set<Name> names = new HashSet<Name>(); boolean hasPublic = false; - for (Iterator i = decls.iterator(); i.hasNext();) { - TopLevelDecl d = (TopLevelDecl) i.next(); + for (TopLevelDecl d : decls) { Name s = d.name().id(); if (names.contains(s)) { Modified: trunk/x10.compiler/src/polyglot/ast/Special.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/Special.java 2010-09-20 00:52:58 UTC (rev 16570) +++ trunk/x10.compiler/src/polyglot/ast/Special.java 2010-09-20 03:29:13 UTC (rev 16571) @@ -19,6 +19,7 @@ { /... [truncated message content] |
From: <mt...@us...> - 2010-09-20 06:35:23
|
Revision: 16574 http://x10.svn.sourceforge.net/x10/?rev=16574&view=rev Author: mtake Date: 2010-09-20 06:35:16 +0000 (Mon, 20 Sep 2010) Log Message: ----------- Fix for XTENLANG-1832 Modified Paths: -------------- trunk/x10.compiler/src/x10/emitter/Emitter.java trunk/x10.runtime/src-java/x10/rtt/Types.java Modified: trunk/x10.compiler/src/x10/emitter/Emitter.java =================================================================== --- trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-20 03:47:34 UTC (rev 16573) +++ trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-20 06:35:16 UTC (rev 16574) @@ -2017,18 +2017,22 @@ public void generateRTTInstance(X10ClassDef def) { - String unsignedClassName = null; + boolean isUnsignedType = isUnsignedClassType(def.asType()); + String unsignedClassName = null; - if (isUnsignedClassType(def.asType())) { + if (isUnsignedType) { unsignedClassName = def.asType().name().toString(); - w.write("public static final x10.rtt."+unsignedClassName+"Type"); - } else { + } + +// if (isUnsignedType) { +// w.write("public static final x10.rtt."+unsignedClassName+"Type"); +// } else { w.write("public static final x10.rtt.RuntimeType"); - } +// } w.write("<"); printType(def.asType(), X10PrettyPrinterVisitor.BOX_PRIMITIVES | X10PrettyPrinterVisitor.NO_QUALIFIER); w.write(">"); - if (isUnsignedClassType(def.asType())) { + if (isUnsignedType) { w.write(" _RTT = new x10.rtt."+unsignedClassName+"Type"); } else { w.write(" _RTT = new x10.rtt.RuntimeType"); @@ -2084,19 +2088,12 @@ w.write("};"); w.newline(); - if (isUnsignedClassType(def.asType())) { - w.write("static {"); - w.write("x10.rtt.Types."+unsignedClassName.toUpperCase()+" = _RTT;"); - w.write("}"); - w.newline(); - } - if (!def.flags().isInterface()) { - if (isUnsignedClassType(def.asType())) { - w.write("public x10.rtt."+unsignedClassName+"Type<"+unsignedClassName+"> getRTT() {"); - } else { +// if (isUnsignedType) { +// w.write("public x10.rtt."+unsignedClassName+"Type<"+unsignedClassName+"> getRTT() {"); +// } else { w.write("public x10.rtt.RuntimeType<?> getRTT() {"); - } +// } w.write("return _RTT;"); w.write("}"); w.newline(); Modified: trunk/x10.runtime/src-java/x10/rtt/Types.java =================================================================== --- trunk/x10.runtime/src-java/x10/rtt/Types.java 2010-09-20 03:47:34 UTC (rev 16573) +++ trunk/x10.runtime/src-java/x10/rtt/Types.java 2010-09-20 06:35:16 UTC (rev 16574) @@ -161,10 +161,28 @@ }; public static Type<Object> ANY = new RuntimeType<Object>(Object.class); - public static Type<?> UBYTE; // instance created and set in UByte static initializer - public static Type<?> USHORT; // instance created and set in UShort static initializer - public static Type<?> UINT; // instance created and set in UInt static initializer - public static Type<?> ULONG; // instance created and set in ULong static initializer + public static Type<?> UBYTE; + public static Type<?> USHORT; + public static Type<?> UINT; + public static Type<?> ULONG; + static { + try { + Class<?> c; + java.lang.reflect.Field f; + c = Class.forName("x10.lang.UByte"); + f = c.getDeclaredField("_RTT"); + UBYTE = (RuntimeType<?>) f.get(null); + c = Class.forName("x10.lang.UShort"); + f = c.getDeclaredField("_RTT"); + USHORT = (RuntimeType<?>) f.get(null); + c = Class.forName("x10.lang.UInt"); + f = c.getDeclaredField("_RTT"); + UINT = (RuntimeType<?>) f.get(null); + c = Class.forName("x10.lang.ULong"); + f = c.getDeclaredField("_RTT"); + ULONG = (RuntimeType<?>) f.get(null); + } catch (Exception e) {} + } public static Type<?> getNativeRepRTT(Object o) { if (o instanceof Boolean) return BOOLEAN; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spa...@us...> - 2010-09-20 20:31:56
|
Revision: 16582 http://x10.svn.sourceforge.net/x10/?rev=16582&view=rev Author: sparksparkspark Date: 2010-09-20 20:31:49 +0000 (Mon, 20 Sep 2010) Log Message: ----------- Some early work to resuscitate the CUDA backend. Got rid of some antiquated CUDA code from the core c++ runtime Moved CUDAUtilities to x10.util and added array manufacturing functions Added a general header for CUDA kernels with .cuh extension (standard for cuda headers) Tweaked CUDAKernelTest.x10 to use the new object model for its kernel Added some functionality to allow RemoteArray to be used as a basic Array substitute, if you are in the right place. Added some @Native("cuda",...) to Array Modified Paths: -------------- trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java trunk/x10.compiler/src/x10cuda/types/X10CUDAContext_c.java trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 trunk/x10.runtime/src-cpp/Makefile trunk/x10.runtime/src-cpp/x10aux/config.h trunk/x10.runtime/src-cpp/x10aux/network.cc trunk/x10.runtime/src-cpp/x10rt.h trunk/x10.runtime/src-x10/x10/array/Array.x10 trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 Added Paths: ----------- trunk/x10.runtime/src-cpp/x10aux/kernel.cuh trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 Removed Paths: ------------- trunk/x10.runtime/src-cpp/x10aux/cuda/ trunk/x10.runtime/src-x10/x10/compiler/CUDAUtilities.x10 Modified: trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java 2010-09-20 20:31:49 UTC (rev 16582) @@ -1450,6 +1450,14 @@ return arrayType_; } + protected ClassType remoteArrayType_ = null; + + public Type RemoteArray() { + if (remoteArrayType_ == null) + remoteArrayType_ = load("x10.array.RemoteArray"); + return remoteArrayType_; + } + protected ClassType distArrayType_ = null; public Type DistArray() { @@ -1633,6 +1641,20 @@ return ta.get(0).typeEquals(p, createContext()); } + public boolean isRemoteArray(Type t) { + return hasSameClassDef(t, RemoteArray()); + } + + public boolean isRemoteArrayOf(Type t, Type p) { + if (!isRemoteArray(t)) return false; + List<Type> ta = ((X10ClassType)X10TypeMixin.baseType(t)).typeArguments(); + assert (ta.size() == 1); + Type array_type = ta.get(0); + List<Type> ta2 = ((X10ClassType)X10TypeMixin.baseType(array_type)).typeArguments(); + assert (ta2.size() == 1); + return ta2.get(0).typeEquals(p, createContext()); + } + public boolean hasSameClassDef(Type t1, Type t2) { Type b1 = X10TypeMixin.baseType(t1); Type b2 = X10TypeMixin.baseType(t2); Modified: trunk/x10.compiler/src/x10cuda/types/X10CUDAContext_c.java =================================================================== --- trunk/x10.compiler/src/x10cuda/types/X10CUDAContext_c.java 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.compiler/src/x10cuda/types/X10CUDAContext_c.java 2010-09-20 20:31:49 UTC (rev 16582) @@ -87,7 +87,7 @@ j.compiler().outputFiles().add(wrappingClass()+".cu"); ((X10CPPCompilerOptions)j.extensionInfo().getOptions()).compilationUnits().add(wrappingClass()+".cu"); cudaStream.write("#include <x10aux/config.h>"); cudaStream.newline(); - cudaStream.write("#include <cfloat>"); cudaStream.newline(); + cudaStream.write("#include <x10aux/kernel.cuh>"); cudaStream.newline(); cudaStream.forceNewline(); cudaStream.write("extern __shared__ char __shm[];"); cudaStream.newline(); cudaStream.write("extern __constant__ char __cmem[64*1024];"); cudaStream.newline(); Modified: trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java =================================================================== --- trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java 2010-09-20 20:31:49 UTC (rev 16582) @@ -218,33 +218,42 @@ private String env = "__env"; - private Type railCargo(Type typ) { - if (!xts().isRail(typ) && !xts().isValRail(typ)) { - //System.out.println("type: "+typ+" is not a rail"); - return null; + private Type arrayCargo(Type typ) { + if (xts().isArray(typ)) { + typ = typ.toClass(); + X10ClassType ctyp = (X10ClassType) typ; + assert ctyp.typeArguments().size() == 1; + return ctyp.typeArguments().get(0); } - typ = typ.toClass(); - X10ClassType ctyp = (X10ClassType) typ; - assert ctyp.typeArguments().size() == 1; - return ctyp.typeArguments().get(0); + if (xts().isRemoteArray(typ)) { + typ = typ.toClass(); + X10ClassType ctyp = (X10ClassType) typ; + assert ctyp.typeArguments().size() == 1; + Type type2 = ctyp.typeArguments().get(0); + X10ClassType ctyp2 = (X10ClassType) typ; + assert ctyp2.typeArguments().size() == 1; + return ctyp2.typeArguments().get(0); + } + return null; + } - private boolean isFloatRail(Type typ) { - Type cargo = railCargo(typ); + private boolean isFloatArray(Type typ) { + Type cargo = arrayCargo(typ); return cargo != null && cargo.isFloat(); } - private boolean isIntRail(Type typ) { - Type cargo = railCargo(typ); + private boolean isIntArray(Type typ) { + Type cargo = arrayCargo(typ); return cargo != null && cargo.isInt(); } String prependCUDAType(Type t, String rest) { String type = Emitter.translateType(t, true); - if (isIntRail(t)) { + if (isIntArray(t)) { type = "x10_int *"; - } else if (isFloatRail(t)) { + } else if (isFloatArray(t)) { type = "x10_float *"; } else { type = type + " "; @@ -723,14 +732,14 @@ String name = var.name().toString(); inc.write("__env."+name+" = "); - if (isIntRail(t)) { + if (isIntArray(t)) { if (xts().isRail(t)) { inc.write("(x10_int*)(size_t)x10aux::get_remote_ref_maybe_null("+name+".operator->())"); } else { inc.write("(x10_int*)(size_t)x10aux::remote_alloc(__gpu, sizeof(x10_int)*"+name+"->FMGL(length));"); inc.newline(); inc.write("x10aux::cuda_put(__gpu, (x10_ulong) __env."+name+", &(*"+name+")[0], sizeof(x10_int)*"+name+"->FMGL(length))"); } - } else if (isFloatRail(t)) { + } else if (isFloatArray(t)) { if (xts().isRail(t)) { inc.write("(x10_float*)(size_t)x10aux::get_remote_ref_maybe_null("+name+".operator->())"); } else { Modified: trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 =================================================================== --- trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 2010-09-20 20:31:49 UTC (rev 16582) @@ -10,34 +10,33 @@ */ import x10.io.Console; +import x10.util.CUDAUtilities; import x10.compiler.CUDA; public class CUDAKernelTest { - static def doWork (init:Rail[Float], recv:Rail[Float], p:Place, len:Int) { - val remote = Rail.makeRemote(p,len,(Int)=>0.0 as Float); // allocate + static def doWork (init:Array[Float]{rail}, recv:Array[Float]{rail}, p:Place, len:Int) { - //finish init.copyTo(0, remote, 0, len); // dma there - val init_ = ValRail.make[Float](init); - finish async (p) @CUDA { - for ((block):Point in 0..7) { - for ((thread):Point in 0..63) async { + val remote = CUDAUtilities.makeRemoteArray[Float](p,len,(Int)=>0.0 as Float); // allocate + + finish async at (p) @CUDA { + for ([block] in 0..7) { + for ([thread] in 0..63) async { val tid = block*64 + thread; val tids = 8*64; for (var i:Int=tid ; i<len ; i+=tids) { - //remote(i) = Math.sqrt(remote(i)); - remote(i) = Math.sqrt(init_(i)); + remote(i) = Math.sqrt(init(i)); } } } } - finish recv.copyFrom(0, remote, 0, len); // dma back + finish Array.asyncCopy(remote, 0, recv, 0, len); // dma back // validate var success:Boolean = true; - for ((i) in 0..remote.length-1) { + for ([i] in remote.region) { if (Math.abs(1 - (recv(i)*recv(i))/(i as Float)) > 1E-6f) { Console.ERR.println("recv("+i+"): "+recv(i)+" * "+recv(i)+" = "+(recv(i)*recv(i))); success = false; @@ -51,8 +50,8 @@ for (host in Place.places) at (host) { - val init = Rail.make[Float](len,(i:Int)=>i as Float); - val recv = Rail.make[Float](len,(i:Int)=>0.0 as Float); + val init = new Array[Float](len,(i:Int)=>i as Float); + val recv = new Array[Float](len,(i:Int)=>0.0 as Float); var done_work:Boolean = false; Modified: trunk/x10.runtime/src-cpp/Makefile =================================================================== --- trunk/x10.runtime/src-cpp/Makefile 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.runtime/src-cpp/Makefile 2010-09-20 20:31:49 UTC (rev 16582) @@ -207,6 +207,7 @@ @find x10 -name \*.h | tar cf - $(INC_FLAG) | (cd $(INSTDIR)/include && tar xf -) @find x10 -name \*.struct_h | tar cf - $(INC_FLAG) | (cd $(INSTDIR)/include && tar xf -) @find x10aux -name \*.h | tar cf - $(INC_FLAG) | (cd $(INSTDIR)/include && tar xf -) + @find x10aux -name \*.cuh | tar cf - $(INC_FLAG) | (cd $(INSTDIR)/include && tar xf -) @cp -p x10rt.h $(INSTDIR)/include @cp -p $(XRX_ARCHIVE) $(INSTDIR)/lib @cp -p $(XRX_MANIFEST) $(INSTDIR)/lib Modified: trunk/x10.runtime/src-cpp/x10aux/config.h =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/config.h 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.runtime/src-cpp/x10aux/config.h 2010-09-20 20:31:49 UTC (rev 16582) @@ -39,26 +39,7 @@ * X10_TRACE_ALL - all of the above */ -#ifdef __CUDA_ARCH__ - #ifndef X10_USE_CUDA_HOST - #define X10_USE_CUDA_HOST - #endif - #ifndef X10_USE_CUDA_DEVICE - #define X10_USE_CUDA_DEVICE - #endif - #ifndef NO_IOSTREAM - #define NO_IOSTREAM // this apparently will be fixed in a future release of cuda - #endif - #define GPUSAFE __host__ __device__ - #ifndef NO_CHECKS - #define NO_CHECKS // can't abort() assert() or throw exception on the gpu - #endif - #ifndef NDEBUG - #define NDEBUG // as above - #endif -#else - #define GPUSAFE -#endif +#define GPUSAFE #ifdef NO_CHECKS #ifndef NO_BOUNDS_CHECKS Added: trunk/x10.runtime/src-cpp/x10aux/kernel.cuh =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/kernel.cuh (rev 0) +++ trunk/x10.runtime/src-cpp/x10aux/kernel.cuh 2010-09-20 20:31:49 UTC (rev 16582) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +// [DC] This file is included at the top of each .cu file. These files contain +// CUDA kernels. They are compiled by nvcc only. This file should not be +// included in normal c++ or header files. + +#ifndef X10AUX_KERNEL_CUH +#define X10AUX_KERNEL_CUH + +#ifndef NO_IOSTREAM + #define NO_IOSTREAM // this apparently will be fixed in a future release of cuda +#endif +#ifndef NO_CHECKS + #define NO_CHECKS // can't abort() assert() or throw exception on the gpu +#endif +#ifndef NDEBUG + #define NDEBUG // as above +#endif + +#include <cfloat> + +namespace x10aux { + template<class T> __device__ T *nullCheck (T *v) { return v; } +} + +#endif + +// vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10aux/network.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/network.cc 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.runtime/src-cpp/x10aux/network.cc 2010-09-20 20:31:49 UTC (rev 16582) @@ -16,8 +16,6 @@ #include <x10aux/RTT.h> #include <x10aux/basic_functions.h> -#include <x10aux/cuda/cuda_utils.h> - #include <x10aux/serialization.h> #include <x10aux/deserialization_dispatcher.h> Modified: trunk/x10.runtime/src-cpp/x10rt.h =================================================================== --- trunk/x10.runtime/src-cpp/x10rt.h 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.runtime/src-cpp/x10rt.h 2010-09-20 20:31:49 UTC (rev 16582) @@ -42,9 +42,5 @@ #include <x10aux/place_local.h> -#include <x10aux/cuda/cuda_utils.h> -#include <x10aux/cuda/bridge_buffer.h> -#include <x10aux/cuda/ring_buffer.h> - #endif // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-x10/x10/array/Array.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-20 20:31:49 UTC (rev 16582) @@ -302,6 +302,7 @@ * @see #apply(Point) * @see #set(T, Int) */ + @Native("cuda", "(#0)[#1]") public safe @Header @Inline def apply(i0:int){rank==1}:T { if (cachedRail) { if (checkBounds() && !((i0 as UInt) < (size as UInt))) { @@ -402,6 +403,7 @@ * @see #apply(Int) * @see #set(T, Point) */ + @Native("cuda", "(#0)[#2] = #1") public safe @Header @Inline def set(v:T, i0:int){rank==1}:T { if (cachedRail) { if (checkBounds() && !((i0 as UInt) < (size as UInt))) { Modified: trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 2010-09-20 20:31:49 UTC (rev 16582) @@ -12,6 +12,7 @@ package x10.array; import x10.compiler.Global; +import x10.compiler.Native; import x10.util.IndexedMemoryChunk; /** @@ -25,25 +26,73 @@ * If the Region is actually needed, it can be retreived by using the array GlobalRef * to return to the referenced array's home location and access its region. */ -public class RemoteArray[T] { - val array:GlobalRef[Array[T]]; - val rawData:IndexedMemoryChunk[T]; - val rawLength:int; +public class RemoteArray[T](home:Place, region:Region, size:Int) {} { + val array:GlobalRef[Array[T]{self.region==this.region, self.size==this.size}]{self.home==this.home}; + val rawData:IndexedMemoryChunk[T]; + val rawLength:int; - public property home:Place = array.home; + public property rank:Int = region.rank; - public def this(a:Array[T]) { - array = GlobalRef[Array[T]](a); - rawData = a.raw(); - rawLength = a.rawLength; - } + public def this(a:Array[T]) : RemoteArray[T]{self.home==here, self.region==a.region, self.size==this.size} { + property(here, a.region, a.size); + // cast needed as type of 'this' does not include {a.region==this.region, a.size==this.size} even though this is established by property statement + val arr = a as Array[T]{self.region==this.region, self.size == this.size}; + // cast needed as type of 'this' does not include {here==this.home} even though this is established by property statement + array = GlobalRef[Array[T]{self.region==this.region, self.size==this.size}](arr) as GlobalRef[Array[T]{self.region==this.region, self.size==this.size}]{self.home==this.home}; + rawData = a.raw(); + rawLength = a.rawLength; + } - public safe def equals(other:Any) { - if (!(other instanceof RemoteArray[T])) return false; - val oRA = other as RemoteArray[T]; - return oRA.array.equals(array); - } + public safe def equals(other:Any) { + if (!(other instanceof RemoteArray[T])) return false; + val oRA = other as RemoteArray[T]; + return oRA.array.equals(array); + } - public safe def hashCode() = array.hashCode(); + @Native("cuda", "(#0)[#2] = #1") + public safe def set(v:T, i:Int) {here==home, rank==1} = array().set(v,i); + + public safe def set(v:T, p:Point{self.rank==this.rank}) {here==home} = array().set(v,p); + + @Native("cuda", "(#0)[#1]") + public safe def apply(i:Int) {here==home, rank==1} = array()(i); + + public safe def apply(p:Point{self.rank==this.rank}) {here==home} = array()(p); + + public safe def hashCode() = array.hashCode(); } +/* This version is preferable, as it does not duplicate state from the global ref, but it does not work: +x10/array/RemoteArray.x10:72: This or super cannot be used (implicitly or explicitly) in a property initializer. +Expr: new x10.lang.GlobalRef[x10.array.Array[T]{self.region==x10.array.RemoteArray#this.region, self.size==x10.array.RemoteArray#this.size}](...) + +public class RemoteArray[T](region:Region, size:Int, array:GlobalRef[Array[T]{self.region==this.region, self.size==this.size}]) { + val rawData:IndexedMemoryChunk[T]; + val rawLength:int; + + public property rank:Int = region.rank; + + public def this(a:Array[T]) : RemoteArray[T]{self.region==a.region, self.size==this.size, self.array.home == here} { + property(a.region, a.size, GlobalRef[Array[T]{self.region==this.region, self.size==this.size}](a as Array[T]{self.region==this.region, self.size == this.size})); + rawData = a.raw(); + rawLength = a.rawLength; + } + + public safe def equals(other:Any) { + if (!(other instanceof RemoteArray[T])) return false; + val oRA = other as RemoteArray[T]; + return oRA.array.equals(array); + } + + public safe def set(v:T, i:Int) {here==array.home, rank==1} = array().set(v,i); + + public safe def set(v:T, p:Point{self.rank==this.rank}) {here==array.home} = array().set(v,p); + + public safe def apply(i:Int) {here==array.home, rank==1} = array()(i); + + public safe def apply(p:Point{self.rank==this.rank}) {here==array.home} = array()(p); + + public safe def hashCode() = array.hashCode(); +} +*/ + Deleted: trunk/x10.runtime/src-x10/x10/compiler/CUDAUtilities.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/compiler/CUDAUtilities.x10 2010-09-20 19:48:31 UTC (rev 16581) +++ trunk/x10.runtime/src-x10/x10/compiler/CUDAUtilities.x10 2010-09-20 20:31:49 UTC (rev 16582) @@ -1,43 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -package x10.compiler; - -/** A collection of independent functions useful in/around CUDA kernels. - * @author Dave Cunningham - */ -public class CUDAUtilities { - - /** Automatically choose enough blocks to saturate the GPU. This takes - * account features of the GPU and kernel in question. If running on the CPU - * it returns a fixed number of blocks. Intended to be used with autoThreads(). - * <p> - * <code> - * async (gpu) { - * val threads = CUDAUtilities.autoThreads(), blocks = CUDAUtilities.autoBlocks(); - * for ((block) in 0..blocks-1) { - * ... - * for ((thread) in 0..threads-1) async { ... } - * } - * } - * </code> - * @see autoThreads - */ - public static def autoBlocks() : UInt = 8; - - /** Automatically choose enough threads to saturate the GPU. - * @see autoBlocks - */ - public static def autoThreads() : UInt = 1; -} - -// vim: shiftwidth=4:tabstop=4:expandtab - Added: trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 (rev 0) +++ trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 2010-09-20 20:31:49 UTC (rev 16582) @@ -0,0 +1,62 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +package x10.util; + +/** A collection of independent functions useful in/around CUDA kernels. + * @author Dave Cunningham + */ +public class CUDAUtilities { + + /** Automatically choose enough blocks to saturate the GPU. This takes + * account features of the GPU and kernel in question. If running on the CPU + * it returns a fixed number of blocks. Intended to be used with autoThreads(). + * <p> + * <code> + * async at (gpu) { + * val threads = CUDAUtilities.autoThreads(), blocks = CUDAUtilities.autoBlocks(); + * for ((block) in 0..blocks-1) { + * ... + * for ((thread) in 0..threads-1) async { ... } + * } + * } + * </code> + * @see autoThreads + */ + public static def autoBlocks() : UInt = 8; + + /** Automatically choose enough threads to saturate the GPU. + * @see autoBlocks + */ + public static def autoThreads() : UInt = 1; + + + public static def makeRemoteArray[T] (place:Place, numElements:Int, init: Array[T]{rail}) + : RemoteArray[T]{self.rank==1, self.home==place} + { + return at (place) new RemoteArray[T](new Array[T](numElements, (p:Int)=>init(p))); + } + + public static def makeRemoteArray[T] (place:Place, numElements:Int, init: T) + : RemoteArray[T]{self.rank==1, self.home==place} + { + return at (place) new RemoteArray[T](new Array[T](numElements, init)); + } + + public static def makeRemoteArray[T] (place:Place, numElements:Int, init: (Int)=>T) + : RemoteArray[T]{self.rank==1, self.home==place} + { + return at (place) new RemoteArray[T](new Array[T](numElements, (p:Int)=>init(p))); + } +} + +// vim: shiftwidth=4:tabstop=4:expandtab + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vj...@us...> - 2010-09-21 09:39:40
|
Revision: 16590 http://x10.svn.sourceforge.net/x10/?rev=16590&view=rev Author: vj0 Date: 2010-09-21 09:39:33 +0000 (Tue, 21 Sep 2010) Log Message: ----------- Partial support conjunction of boolean terms as nested terms in a constraint. (Full support will be enabled in a Shostak-style canonicalizing constraint-solver.) (Support in X10Binary, and in XConstraint.lookup -- which now correctly interns formulas.) Move static type-checking methods from XField_c to Checker. Add support for expanding bodies of user-defined property methods when adding clauses to types. Modified Paths: -------------- trunk/x10.compiler/src/x10/ast/X10Binary_c.java trunk/x10.compiler/src/x10/ast/X10Call_c.java trunk/x10.compiler/src/x10/ast/X10Disamb_c.java trunk/x10.compiler/src/x10/ast/X10Field_c.java trunk/x10.compiler/src/x10/types/X10TypeMixin.java trunk/x10.compiler/src/x10/types/XTypeTranslator.java trunk/x10.compiler/src/x10/types/checker/Checker.java trunk/x10.constraints/src/x10/constraint/XConstraint.java Modified: trunk/x10.compiler/src/x10/ast/X10Binary_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Binary_c.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.compiler/src/x10/ast/X10Binary_c.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -51,12 +51,16 @@ import polyglot.util.Pair; import polyglot.util.Position; import polyglot.visit.ContextVisitor; +import x10.constraint.XFailure; +import x10.constraint.XTerm; +import x10.constraint.XTerms; import x10.errors.Errors; import x10.types.X10Context; import x10.types.X10MethodInstance; import x10.types.X10TypeMixin; import x10.types.X10TypeSystem; import x10.types.X10TypeSystem_c; +import x10.types.checker.Checker; import x10.types.checker.Converter; import x10.types.checker.PlaceChecker; import x10.visit.ExprFlattener; @@ -316,22 +320,7 @@ Type lbase = X10TypeMixin.baseType(left.type()); Type rbase = X10TypeMixin.baseType(right.type()); - - /* if (op == EQ || op == NE) { - if (xts.isExactlyFunctionType(lbase)) { - Errors.issue(tc.job(), - new SemanticException("The " + op + - " operator cannot be applied to the function " + left, - position())); - } - if (xts.isExactlyFunctionType(rbase)) { - Errors.issue(tc.job(), - new SemanticException("The " + op + - " operator cannot be applied to the function " + right, - position())); - } - } -*/ + if (op == EQ || op == NE || op == LT || op == GT || op == LE || op == GE) { Object lv = left.isConstant() ? left.constantValue() : null; Object rv = right.isConstant() ? right.constantValue() : null; @@ -424,8 +413,28 @@ if (!xts.hasUnknown(l) && !xts.hasUnknown(r)) { if (op == COND_OR || op == COND_AND) { + Type result = xts.Boolean(); + if (op == COND_OR) + return type(result); + // Support conjunction of boolean terms. + // Once we shift to Shostak we will have more comprehensive + // support for all operators. if (l.isBoolean() && r.isBoolean()) { - return type(xts.Boolean()); + XTerm xt = X10TypeMixin.selfBinding(l); + if (xt != null) { + XTerm yt = X10TypeMixin.selfBinding(r); + if (yt != null) { + + try { + result = X10TypeMixin.addSelfBinding(result, + XTerms.makeAnd(xt, yt)); + } catch (XFailure z) { + X10TypeMixin.setInconsistent(result); + } + } + } + + return type(result); } } @@ -462,7 +471,7 @@ args = p.snd(); } catch (SemanticException e) { } } - Type rt = X10Field_c.rightType(mi.rightType(), mi.x10Def(), call.target(), tc.context()); + Type rt = Checker.rightType(mi.rightType(), mi.x10Def(), call.target(), tc.context()); call = (X10Call_c) call.methodInstance(mi).type(rt); call = (X10Call_c) call.arguments(args); return call; Modified: trunk/x10.compiler/src/x10/ast/X10Call_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Call_c.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.compiler/src/x10/ast/X10Call_c.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -428,7 +428,7 @@ protected X10Call typeCheckNullTargetForMethod(ContextVisitor tc, List<Type> typeArgs, List<Type> argTypes, X10MethodInstance mi, List<Expr> args) throws SemanticException { Receiver r = computeReceiver(tc, mi); X10Call_c call = (X10Call_c) this.targetImplicit(true).target(r).arguments(args); - Type rt = X10Field_c.rightType(mi.rightType(), mi.x10Def(), r, (X10Context) tc.context()); + Type rt = Checker.rightType(mi.rightType(), mi.x10Def(), r, (X10Context) tc.context()); call = (X10Call_c)call.methodInstance(mi).type(rt); return call; } @@ -679,7 +679,7 @@ } } - Type rt = X10Field_c.rightType(mi.rightType(), mi.x10Def(), target, c); + Type rt = Checker.rightType(mi.rightType(), mi.x10Def(), target, c); X10Call_c methodCall = (X10Call_c) this.methodInstance(mi).type(rt); methodCall = (X10Call_c) methodCall.arguments(args); if (this.target() == null) Modified: trunk/x10.compiler/src/x10/ast/X10Disamb_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Disamb_c.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.compiler/src/x10/ast/X10Disamb_c.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -53,6 +53,7 @@ import x10.types.X10NamedType; import x10.types.X10TypeMixin; import x10.types.X10TypeSystem; +import x10.types.checker.Checker; public class X10Disamb_c extends Disamb_c { @@ -107,7 +108,7 @@ if (xfi.isProperty()) { Field f = nf.Field(pos, makeMissingPropertyTarget(xfi, t), this.name); f = f.fieldInstance(xfi); - Type ftype = X10Field_c.rightType(xfi.rightType(), xfi.x10Def(), f.target(), c); + Type ftype = Checker.rightType(xfi.rightType(), xfi.x10Def(), f.target(), c); f = (Field) f.type(ftype); return f; } @@ -134,7 +135,7 @@ if (X10Flags.toX10Flags(mi.flags()).isProperty()) { Call call = nf.Call(pos, makeMissingPropertyTarget(mi, t), this.name); call = call.methodInstance(mi); - Type ftype = X10Field_c.rightType(mi.rightType(), mi.x10Def(), call.target(), c); + Type ftype = Checker.rightType(mi.rightType(), mi.x10Def(), call.target(), c); call = (Call) call.type(ftype); return call; } @@ -179,7 +180,7 @@ if (X10Flags.toX10Flags(mi.flags()).isProperty()) { Call call = nf.Call(pos, makeMissingMethodTarget(mi), this.name); call = call.methodInstance(mi); - Type ftype = X10Field_c.rightType(mi.rightType(), mi.x10Def(), call.target(), c); + Type ftype = Checker.rightType(mi.rightType(), mi.x10Def(), call.target(), c); call = (Call) call.type(ftype); return call; } @@ -284,7 +285,7 @@ if (X10Flags.toX10Flags(mi.flags()).isProperty()) { Call call = nf.Call(pos, e, this.name); call = call.methodInstance(mi); - Type ftype = X10Field_c.rightType(mi.rightType(), mi.x10Def(), call.target(), c); + Type ftype = Checker.rightType(mi.rightType(), mi.x10Def(), call.target(), c); call = (Call) call.type(ftype); return call; } Modified: trunk/x10.compiler/src/x10/ast/X10Field_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Field_c.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.compiler/src/x10/ast/X10Field_c.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -35,11 +35,9 @@ import polyglot.types.StructType; import polyglot.types.Type; import polyglot.util.ErrorInfo; -import polyglot.util.InternalCompilerError; import polyglot.util.Position; import polyglot.visit.ContextVisitor; -import x10.constraint.XFailure; import x10.constraint.XVar; import x10.constraint.XTerm; import x10.constraint.XTerms; @@ -51,15 +49,14 @@ import x10.types.X10Context; import x10.types.X10FieldInstance; import x10.types.X10Flags; -import x10.types.X10MemberDef; import x10.types.X10MethodInstance; import x10.types.X10TypeSystem_c; import x10.types.X10TypeMixin; import x10.types.X10TypeSystem; +import x10.types.checker.Checker; import x10.types.checker.PlaceChecker; import x10.types.constraints.CConstraint; -import x10.types.constraints.CConstraint; import x10.types.matcher.Subst; import x10.visit.X10TypeChecker; import x10.errors.Errors; @@ -225,7 +222,7 @@ if (fi != null) { // Found! X10Field_c result = this; - Type t = c.inDepType()? rightType(fi.rightType(), fi.x10Def(), target, c) + Type t = c.inDepType()? Checker.rightType(fi.rightType(), fi.x10Def(), target, c) : fi.rightType(); // fieldRightType(fi.rightType(), fi.x10Def(), target, c); result = (X10Field_c) result.fieldInstance(fi).type(t); return result; @@ -253,9 +250,10 @@ if (X10Flags.toX10Flags(mi.flags()).isProperty()) { Call call = nf.Call(pos, target, this.name); call = call.methodInstance(mi); - Type nt = c.inDepType() ? - rightType(mi.rightType(), mi.x10Def(), target, c) - :fieldRightType(mi.rightType(), mi.x10Def(), target, c); + Type nt = c.inDepType() ? + Checker.rightType(mi.rightType(), mi.x10Def(), target, c) + : + Checker.expandCall(mi.rightType(), call, c); call = (Call) call.type(nt); return call; @@ -272,8 +270,8 @@ // throw new NoMemberException(NoMemberException.FIELD, "interface property access will be translated to property method call"); // } - Type type = c.inDepType()? rightType(fi.rightType(), fi.x10Def(), target, c) : - fieldRightType(fi.rightType(), fi.x10Def(), target, c); + Type type = c.inDepType()? Checker.rightType(fi.rightType(), fi.x10Def(), target, c) : + Checker.fieldRightType(fi.rightType(), fi.x10Def(), target, c); Type retType = type; @@ -300,68 +298,8 @@ return result; } - public static Type rightType(Type t, X10MemberDef fi, Receiver target, Context c) { - CConstraint x = X10TypeMixin.xclause(t); - if (x != null && fi.thisVar() != null) { - if (target instanceof Expr) { - XVar receiver = null; - - X10TypeSystem ts = (X10TypeSystem) t.typeSystem(); - XTerm r = ts.xtypeTranslator().trans(new CConstraint(), target, (X10Context) c); - if (r instanceof XVar) { - receiver = (XVar) r; - } - - if (receiver == null) - receiver = XTerms.makeEQV(); - try { - t = Subst.subst(t, (new XVar[] { receiver }), (new XVar[] { fi.thisVar() }), new Type[] { }, new ParameterType[] { }); - } catch (SemanticException e) { - throw new InternalCompilerError("Unexpected error while computing field type", e); - } - } - } - return t; - } - - public static Type fieldRightType(Type t, X10MemberDef fi, Receiver target, Context c) throws SemanticException { - CConstraint x = X10TypeMixin.xclause(t); - if (x != null && fi.thisVar() != null) { - x = x.copy(); - // Need to add the target's constraints in here because the target may not - // be a variable. hence the type information wont be in the context. - if (target instanceof Expr) { // ) { - CConstraint xc = X10TypeMixin.xclause(target.type()); - if (xc != null && ! xc.valid()) { - xc = xc.copy(); - try { - XVar receiver = X10TypeMixin.selfVarBinding(target.type()); - //assert receiver != null; - XVar root = null; - if (receiver == null) { - receiver = root = XTerms.makeUQV(); - - } - xc = xc.substitute(receiver, xc.self()); - if (! X10TypeMixin.contextKnowsType(target)) - x.addIn(xc); - x=x.substitute(receiver, fi.thisVar()); - if (root != null) { - x = x.project(root); - } - t = X10TypeMixin.addConstraint(X10TypeMixin.baseType(t), x); - } catch (XFailure z) { - // should not happen - } - } - } - } - //System.err.println("X10Field_c: fieldRightType returns " + t); - return t; - } - /** - * Check thst if this field is a clocked field, it is being accessed from within a clocked method. + * Check that if this field is a clocked field, it is being accessed from within a clocked method. * @param result * @param tc * @throws SemanticException Modified: trunk/x10.compiler/src/x10/types/X10TypeMixin.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -179,6 +179,11 @@ return c1; } } + /** + * Returns a copy of t's constraint, if it has one, null otherwise. + * @param t + * @return + */ public static CConstraint xclause(Type t) { if (t instanceof AnnotatedType) { AnnotatedType at = (AnnotatedType) t; @@ -475,6 +480,22 @@ if (c == null) return true; return c.consistent(); } + public static void setInconsistent(Type t) { + if (t instanceof AnnotatedType) { + AnnotatedType at = (AnnotatedType) t; + setInconsistent(at.baseType()); + } + if (t instanceof MacroType) { + MacroType mt = (MacroType) t; + setInconsistent(mt.definedType()); + } + if (t instanceof ConstrainedType) { + ConstrainedType ct = (ConstrainedType) t; + CConstraint c = Types.get(ct.constraint()); + c.setInconsistent(); + return; + } + } public static XVar selfVar(Type thisType) { CConstraint c = xclause(thisType); // Should this be realX(thisType) ??? - Bowen Modified: trunk/x10.compiler/src/x10/types/XTypeTranslator.java =================================================================== --- trunk/x10.compiler/src/x10/types/XTypeTranslator.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.compiler/src/x10/types/XTypeTranslator.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -539,31 +539,27 @@ addTypeToEnv(body, xmi.returnType()); return body; } - else { - if (t.arguments().size() == 0) { - XName field = XTerms.makeName(xmi.def(), Types.get(xmi.def().container()) + "#" + xmi.name() + "()"); - XTerm v; - if (r instanceof XVar) { - v = XTerms.makeField((XVar) r, field); - } - else { - v = XTerms.makeAtom(field, r); - } - addTypeToEnv(v, xmi.returnType()); - return v; + + if (t.arguments().size() == 0) { + XName field = XTerms.makeName(xmi.def(), Types.get(xmi.def().container()) + "#" + xmi.name() + "()"); + XTerm v; + if (r instanceof XVar) { + v = XTerms.makeField((XVar) r, field); } else { - - List<XTerm> terms = new ArrayList<XTerm>(); - terms.add(r); - for (Expr e : t.arguments()) { - terms.add(trans(c, e, xc)); - } - XTerm v = XTerms.makeAtom(XTerms.makeName(xmi, xmi.name().toString()), terms); - addTypeToEnv(v, xmi.returnType()); - return v; + v = XTerms.makeAtom(field, r); } + addTypeToEnv(v, xmi.returnType()); + return v; } + List<XTerm> terms = new ArrayList<XTerm>(); + terms.add(r); + for (Expr e : t.arguments()) { + terms.add(trans(c, e, xc)); + } + XTerm v = XTerms.makeAtom(XTerms.makeName(xmi, xmi.name().toString()), terms); + addTypeToEnv(v, xmi.returnType()); + return v; } Type type = t.type(); return X10TypeMixin.selfVarBinding(type); // maybe null. Modified: trunk/x10.compiler/src/x10/types/checker/Checker.java =================================================================== --- trunk/x10.compiler/src/x10/types/checker/Checker.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.compiler/src/x10/types/checker/Checker.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -11,6 +11,8 @@ package x10.types.checker; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import polyglot.ast.Assign; @@ -21,6 +23,9 @@ import polyglot.ast.Node; import polyglot.ast.NodeFactory; import polyglot.ast.Assign.Operator; +import polyglot.ast.Receiver; +import polyglot.types.Context; +import polyglot.types.Flags; import polyglot.types.Name; import polyglot.types.ProcedureDef; import polyglot.types.SemanticException; @@ -32,6 +37,12 @@ import polyglot.visit.ContextVisitor; import x10.ast.X10Binary_c; import x10.ast.X10New_c; +import x10.constraint.XFailure; +import x10.constraint.XName; +import x10.constraint.XNameWrapper; +import x10.constraint.XTerm; +import x10.constraint.XTerms; +import x10.constraint.XVar; import x10.errors.Errors; import x10.errors.Errors.CannotAssign; import x10.types.ConstrainedType; @@ -40,9 +51,15 @@ import x10.types.X10ClassDef; import x10.types.X10ClassType; import x10.types.X10Context; +import x10.types.X10Flags; +import x10.types.X10MemberDef; import x10.types.X10MethodInstance; import x10.types.X10ProcedureInstance; import x10.types.X10TypeMixin; +import x10.types.X10TypeSystem; +import x10.types.XTypeTranslator; +import x10.types.constraints.CConstraint; +import x10.types.matcher.Subst; import x10.visit.X10TypeChecker; import static polyglot.ast.Assign.*; @@ -196,4 +213,139 @@ checkVariancesOfType(pos, at, requiredVariance, desc, vars, tc); } } + + public static Type rightType(Type t, X10MemberDef fi, Receiver target, Context c) { + CConstraint x = X10TypeMixin.xclause(t); + if (x==null || fi.thisVar()==null || (! (target instanceof Expr))) + return t; + XVar receiver = null; + + X10TypeSystem ts = (X10TypeSystem) t.typeSystem(); + XTerm r = ts.xtypeTranslator().trans(new CConstraint(), target, (X10Context) c); + if (r instanceof XVar) { + receiver = (XVar) r; + } + + if (receiver == null) + receiver = XTerms.makeEQV(); + try { + t = Subst.subst(t, (new XVar[] { receiver }), (new XVar[] { fi.thisVar() }), new Type[] { }, new ParameterType[] { }); + } catch (SemanticException e) { + throw new InternalCompilerError("Unexpected error while computing field type", e); + } + + return t; + } + + public static Type expandCall(Type type, Call t, Context c) throws SemanticException { + X10Context xc = (X10Context) c; + X10MethodInstance xmi = (X10MethodInstance) t.methodInstance(); + XTypeTranslator xt = ((X10TypeSystem) type.typeSystem()).xtypeTranslator(); + Flags f = xmi.flags(); + XTerm body = null; + if (X10Flags.toX10Flags(f).isProperty()) { + CConstraint cs = new CConstraint(); + XTerm r = xt.trans( cs,t.target(), xc); + if (r == null) + return null; + // FIXME: should just return the atom, and add atom==body to the real clause of the class + // FIXME: fold in class's real clause constraints on parameters into real clause of type parameters + body = xmi.body(); + if (body != null) { + if (xmi.x10Def().thisVar() != null && t.target() instanceof Expr) { + //XName This = XTerms.makeName(new Object(), Types.get(xmi.def().container()) + "#this"); + //body = body.subst(r, XTerms.makeLocal(This)); + body = body.subst(r, xmi.x10Def().thisVar()); + } + for (int i = 0; i < t.arguments().size(); i++) { + //XVar x = (XVar) X10TypeMixin.selfVarBinding(xmi.formalTypes().get(i)); + //XVar x = (XVar) xmi.formalTypes().get(i); + XVar x = (XVar) XTerms.makeLocal(new XNameWrapper(xmi.formalNames().get(i).def())); + XTerm y = xt.trans(cs, t.arguments().get(i), xc); + if (y == null) + assert y != null : "XTypeTranslator: translation of arg " + i + " of " + t + " yields null (pos=" + + t.position() + ")"; + body = body.subst(y, x); + } + } else + + if (t.arguments().size() == 0) { + XName field = XTerms.makeName(xmi.def(), Types.get(xmi.def().container()) + "#" + xmi.name() + "()"); + if (r instanceof XVar) { + body = XTerms.makeField((XVar) r, field); + } + else { + body = XTerms.makeAtom(field, r); + } + } else { + List<XTerm> terms = new ArrayList<XTerm>(); + terms.add(r); + for (Expr e : t.arguments()) { + terms.add(xt.trans(cs, e, xc)); + } + body = XTerms.makeAtom(XTerms.makeName(xmi, xmi.name().toString()), terms); + } + } + CConstraint x = X10TypeMixin.xclause(type); + X10MemberDef fi = (X10MemberDef) t.methodInstance().def(); + Receiver target = t.target(); + if (x == null || fi.thisVar() == null || !(target instanceof Expr)) + return type; + + x = x.copy(); + try { + XVar receiver = X10TypeMixin.selfVarBinding(target.type()); + XVar root = null; + if (receiver == null) { + receiver = root = XTerms.makeUQV(); + } + // Need to add the target's constraints in here because the target may not + // be a variable. hence the type information wont be in the context. + CConstraint ttc = X10TypeMixin.xclause(target.type()); + ttc = ttc == null ? new CConstraint() : ttc.copy(); + ttc = ttc.substitute(receiver, ttc.self()); + if (! X10TypeMixin.contextKnowsType(target)) + x.addIn(ttc); + if (body != null) + x.addSelfBinding(body); + x=x.substitute(receiver, fi.thisVar()); + if (root != null) { + x = x.project(root); + } + type = X10TypeMixin.addConstraint(X10TypeMixin.baseType(type), x); + } catch (XFailure z) { + X10TypeMixin.setInconsistent(type); + } + return type; + } + public static Type fieldRightType(Type type, X10MemberDef fi, Receiver target, Context c) throws SemanticException { + CConstraint x = X10TypeMixin.xclause(type); + if (x == null || fi.thisVar() == null || !(target instanceof Expr)) + return type; + // Need to add the target's constraints in here because the target may not + // be a variable. hence the type information wont be in the context. + CConstraint xc = X10TypeMixin.xclause(target.type()); + if (xc == null || xc.valid()) + return type; + xc = xc.copy(); + x = x.copy(); + try { + XVar receiver = X10TypeMixin.selfVarBinding(target.type()); + XVar root = null; + if (receiver == null) { + receiver = root = XTerms.makeUQV(); + } + xc = xc.substitute(receiver, xc.self()); + if (! X10TypeMixin.contextKnowsType(target)) + x.addIn(xc); + x=x.substitute(receiver, fi.thisVar()); + if (root != null) { + x = x.project(root); + } + type = X10TypeMixin.addConstraint(X10TypeMixin.baseType(type), x); + } catch (XFailure z) { + X10TypeMixin.setInconsistent(type); + } + return type; + } } Modified: trunk/x10.constraints/src/x10/constraint/XConstraint.java =================================================================== --- trunk/x10.constraints/src/x10/constraint/XConstraint.java 2010-09-21 09:37:35 UTC (rev 16589) +++ trunk/x10.constraints/src/x10/constraint/XConstraint.java 2010-09-21 09:39:33 UTC (rev 16590) @@ -821,6 +821,8 @@ int index = resultC.lookupReturnValue(); return (index == vars.length) ? result : null; } + if (term instanceof XFormula) + return result; return null; } @@ -917,6 +919,7 @@ } } + @SuppressWarnings({ "unchecked"}) protected void applySubstitution(XTerm y, XVar x) throws XFailure { if (roots == null) { // nothing to substitute This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-21 20:11:42
|
Revision: 16607 http://x10.svn.sourceforge.net/x10/?rev=16607&view=rev Author: yzibin Date: 2010-09-21 20:11:34 +0000 (Tue, 21 Sep 2010) Log Message: ----------- fixed polyglot bug in FwdReferenceChecker. Improved initialization checks: - handled closures, - transient fields, - inlined field initializers correctly (errors in a field init is reported only once, and not for every ctor) - better position for "Field '...' was not definitely assigned." and "Field '...' was not definitely assigned in this constructor." fixed some test cases (changing () to [], removed incomplete, future, added nonblocking) Modified Paths: -------------- trunk/x10.compiler/src/polyglot/visit/FwdReferenceChecker.java trunk/x10.compiler/src/x10/ast/X10Binary_c.java trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java trunk/x10.compiler/src/x10/types/X10TypeMixin.java trunk/x10.compiler/src/x10/types/X10TypeSystem.java trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java trunk/x10.compiler/src/x10/util/RunTestSuite.java trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 trunk/x10.tests/examples/Constructs/DepType/MethodArgDepTypes2.x10 trunk/x10.tests/examples/Constructs/Distribution/BlockDistWithPlaceSet.x10 trunk/x10.tests/examples/Constructs/Future/Future1.x10 trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 trunk/x10.tests/examples/Constructs/Modifiers/SafeClass.x10 trunk/x10.tests/examples/Constructs/Place/AtThisIntoAtHere.x10 trunk/x10.tests/examples/Constructs/Place/ClosureBang.x10 trunk/x10.tests/examples/x10lib/harness/x10Test.x10 trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish1.x10 trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish2.x10 trunk/x10.tests/tests/ScalableFinish/SimpleFinish1.x10 trunk/x10.tests/tests/ScalableFinish/SimpleFinish2.x10 trunk/x10.tests/tests/ScalableFinish/SimpleFinish3.x10 trunk/x10.tests/tests/ScalableFinish/SimpleFinish4.x10 trunk/x10.tests/tests/ScalableFinish/SimpleFinish5.x10 Modified: trunk/x10.compiler/src/polyglot/visit/FwdReferenceChecker.java =================================================================== --- trunk/x10.compiler/src/polyglot/visit/FwdReferenceChecker.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/polyglot/visit/FwdReferenceChecker.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -34,8 +34,9 @@ if (n instanceof FieldDecl) { FieldDecl fd = (FieldDecl)n; if (fd.flags().flags().isStatic()) { + FwdReferenceChecker frc = (FwdReferenceChecker)this.copy(); + frc.declaredFields = new HashSet<FieldDef>(declaredFields); declaredFields.add(fd.fieldDef()); - FwdReferenceChecker frc = (FwdReferenceChecker)this.copy(); frc.inInitialization = true; return frc; } Modified: trunk/x10.compiler/src/x10/ast/X10Binary_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Binary_c.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/ast/X10Binary_c.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -29,7 +29,6 @@ import polyglot.ast.LocalDecl; import polyglot.ast.Node; import polyglot.ast.NodeFactory; -import polyglot.ast.Precedence; import polyglot.ast.Prefix; import polyglot.ast.Receiver; import polyglot.ast.Stmt; @@ -64,7 +63,6 @@ import x10.types.checker.Converter; import x10.types.checker.PlaceChecker; import x10.visit.ExprFlattener; -import x10.visit.X10TypeChecker; import x10.visit.ExprFlattener.Flattener; /** @@ -99,19 +97,6 @@ X10TypeSystem xts = (X10TypeSystem) lt.typeSystem(); if (lt == null || rt == null) return false; - /* In X10 2.0, nothing can be of Value type. - * if (operator() == Binary.EQ || operator() == Binary.NE) { - X10Context context = (X10Context) xts.emptyContext(); - if (xts.isValueType(lt, context) && xts.isReferenceOrInterfaceType(rt, context)) - return true; - if (xts.isReferenceOrInterfaceType(lt, context) && xts.isValueType(rt, context)) - return true; - if (xts.isValueType(lt, context) && rt.isNull()) - return true; - if (xts.isValueType(rt, context) && lt.isNull()) - return true; - } - */ return false; } @@ -131,9 +116,9 @@ // [IP] An optimization: an value and null can never be equal if (op == EQ) { - if (xts.isStructType(lt) && xts.isReferenceOrInterfaceType(rt, context)) + if (xts.isStructType(lt) && xts.isObjectOrInterfaceType(rt, context)) return Boolean.FALSE; - if (xts.isReferenceOrInterfaceType(lt, context) && xts.isStructType(rt)) + if (xts.isObjectOrInterfaceType(lt, context) && xts.isStructType(rt)) return Boolean.FALSE; if ( xts.isStructType(lt) && rt.isNull()) return Boolean.FALSE; @@ -141,9 +126,9 @@ return Boolean.FALSE; } if (op == NE) { - if (xts.isStructType(lt) && xts.isReferenceOrInterfaceType(rt, context)) + if (xts.isStructType(lt) && xts.isObjectOrInterfaceType(rt, context)) return Boolean.TRUE; - if (xts.isReferenceOrInterfaceType(lt, context) && xts.isStructType(rt)) + if (xts.isObjectOrInterfaceType(lt, context) && xts.isStructType(rt)) return Boolean.TRUE; if (xts.isStructType(lt) && rt.isNull()) return Boolean.TRUE; Modified: trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -418,12 +418,22 @@ X10FieldDecl_c n = (X10FieldDecl_c) this.type(nf.CanonicalTypeNode(type().position(), type)); // Add an initializer to uninitialized var field unless field is annotated @Uninitialized. - if (!n.flags().flags().isFinal() && n.init() == null && !X10TypeMixin.isUninitializedField(((X10FieldDef) n.fieldDef()),ts)) { + final X10FieldDef fieldDef = (X10FieldDef) n.fieldDef(); + final boolean needsInit = !n.flags().flags().isFinal() && n.init() == null && !X10TypeMixin.isUninitializedField(fieldDef, ts); + final boolean isTransient = X10TypeMixin.isTransientField(fieldDef, ts); + if (needsInit || isTransient) { // creating an init. Expr e = X10TypeMixin.getZeroVal(type,position().markCompilerGenerated(),tc); - if (e != null) { - n = (X10FieldDecl_c) n.init(e); - } + if (needsInit) { + if (e != null) { + n = (X10FieldDecl_c) n.init(e); + } + } + if (isTransient) { + // Transient fields must have a default value + if (e==null) + Errors.issue(tc.job(), new SemanticException("The @Transient field '"+n.name()+"' must have a type with a default value.",position())); + } } if (n.init != null) { @@ -444,7 +454,6 @@ public Type childExpectedType(Expr child, AscriptionVisitor av) { if (child == init) { - TypeSystem ts = av.typeSystem(); return type.type(); } Modified: trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -25,7 +25,6 @@ import polyglot.types.ClassType; import polyglot.types.ConstructorInstance; import polyglot.types.Context; -import polyglot.types.Def; import polyglot.types.DerefTransform; import polyglot.types.LazyRef; import polyglot.types.LazyRef_c; @@ -36,7 +35,6 @@ import polyglot.types.NoMemberException; import polyglot.types.NullType; import polyglot.types.ObjectType; -import polyglot.types.PrimitiveType; import polyglot.types.ProcedureDef; import polyglot.types.ProcedureInstance; import polyglot.types.ProcedureInstance_c; @@ -52,27 +50,21 @@ import polyglot.util.CollectionUtil; import polyglot.util.InternalCompilerError; import polyglot.util.TransformingList; -import x10.ast.X10Special; import x10.constraint.XEQV; import x10.constraint.XFailure; import x10.constraint.XLit; import x10.constraint.XName; import x10.constraint.XNameWrapper; import x10.constraint.XVar; -import x10.constraint.XTerm; import x10.constraint.XTerms; -import x10.constraint.XVar; import x10.errors.Errors; import x10.types.ParameterType.Variance; import x10.types.X10TypeSystem_c.Bound; import x10.types.X10TypeSystem_c.Kind; import x10.types.checker.PlaceChecker; import x10.types.constraints.CConstraint; -import x10.types.constraints.CConstraint; import x10.types.constraints.SubtypeConstraint; -import x10.types.constraints.SubtypeConstraint; import x10.types.constraints.TypeConstraint; -import x10.types.constraints.XConstrainedTerm; import x10.types.matcher.Matcher; import x10.types.matcher.Subst; @@ -379,7 +371,7 @@ if (X10Flags.toX10Flags(ct.flags()).isStruct()) return Kind.STRUCT; else - return Kind.REFERENCE; + return Kind.OBJECT; } if (t instanceof ParameterType) { Kind k = Kind.EITHER; @@ -393,8 +385,8 @@ ; else if (k == Kind.EITHER && k2 == Kind.STRUCT) k = Kind.STRUCT; - else if (k == Kind.EITHER && k2 == Kind.REFERENCE) - k = Kind.REFERENCE; + else if (k == Kind.EITHER && k2 == Kind.OBJECT) + k = Kind.OBJECT; else k = Kind.NEITHER; } @@ -1149,10 +1141,10 @@ if (baseType1 != fromType || baseType2 != toType) return isCastValid(baseType1, baseType2); - if (ts.isStructType(baseType1) && ts.isReferenceType(baseType2, (X10Context) context)) + if (ts.isStructType(baseType1) && ts.isObjectType(baseType2, (X10Context) context)) return false; - if (ts.isReferenceType(baseType1, (X10Context) context) && ts.isStructType(baseType2)) + if (ts.isObjectType(baseType1, (X10Context) context) && ts.isStructType(baseType2)) return false; if (ts.isParameterType(baseType1) || ts.isParameterType(baseType2)) Modified: trunk/x10.compiler/src/x10/types/X10TypeMixin.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -45,7 +45,6 @@ import polyglot.types.Types; import polyglot.types.UnknownType; import polyglot.types.QName; -import polyglot.types.MethodDef; import polyglot.util.InternalCompilerError; import polyglot.util.Position; import polyglot.visit.ContextVisitor; @@ -997,6 +996,9 @@ public static boolean isUninitializedField(X10FieldDef def,X10TypeSystem ts) { return isDefAnnotated(def,ts,"x10.compiler.Uninitialized"); } + public static boolean isTransientField(X10FieldDef def,X10TypeSystem ts) { + return isDefAnnotated(def,ts,"x10.compiler.Transient"); + } public static String getNonEscapingReadsFrom(X10ProcedureDef def,X10TypeSystem ts) { try { Type at = (Type) ts.systemResolver().find(QName.make("x10.compiler.NonEscaping")); @@ -1056,7 +1058,7 @@ e = nf.FloatLit(p, FloatLit.FLOAT, 0.0); } else if (ts.isDouble(t)) { e = nf.FloatLit(p, FloatLit.DOUBLE, 0.0); - } else if (ts.isReferenceType(t, context)) { + } else if (ts.isObjectOrInterfaceType(t, context)) { e = nf.NullLit(p); } // todo: we should handle user-defined structs, as well as generic type parameters with hasDefault. see hasZero Modified: trunk/x10.compiler/src/x10/types/X10TypeSystem.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeSystem.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/types/X10TypeSystem.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -282,7 +282,7 @@ boolean isStructType(Type me); - boolean isReferenceType(Type me, X10Context context); + boolean isObjectType(Type me, X10Context context); boolean isUByte(Type t); boolean isUShort(Type t); @@ -393,7 +393,7 @@ * @param context TODO*/ boolean consistent(Type t, X10Context context); - boolean isReferenceOrInterfaceType(Type t, X10Context context); + boolean isObjectOrInterfaceType(Type t, X10Context context); boolean isParameterType(Type toType); Modified: trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -30,7 +29,6 @@ import polyglot.frontend.Globals; import polyglot.frontend.Goal; import polyglot.frontend.Source; -import polyglot.main.Report; import polyglot.types.ClassDef; import polyglot.types.ClassType; import polyglot.types.CodeDef; @@ -776,7 +774,7 @@ } static enum Kind { - NEITHER, EITHER, REFERENCE, STRUCT, INTERFACE + NEITHER, EITHER, OBJECT, STRUCT, INTERFACE } public Kind kind(Type t, X10Context c) { @@ -788,34 +786,13 @@ return t instanceof ParameterType; } - public boolean isReferenceOrInterfaceType(Type t, X10Context c) { + public boolean isObjectOrInterfaceType(Type t, X10Context c) { Kind kind = kind(t, c); - return kind == Kind.REFERENCE || kind == Kind.INTERFACE; - // t = X10TypeMixin.baseType(t); - // if (t instanceof ClosureType) - // return false; - // return isReferenceType(t) || isInterfaceType(t); + return kind == Kind.OBJECT || kind == Kind.INTERFACE; } - public boolean isReferenceType(Type t, X10Context c) { - return kind(t, c) == Kind.REFERENCE; - // t = X10TypeMixin.baseType(t); - // if (t instanceof ClosureType) - // return false; - // if (t instanceof ClassType) { - // ClassType ct = (ClassType) t; - // if (ct.isAnonymous()) { - // if (ct.superClass() != null) - // return isReferenceType(ct.superClass()); - // else if (ct.interfaces().size() > 0) - // return isReferenceType(ct.interfaces().get(0)); - // else - // return false; - // } - // return !X10Flags.toX10Flags(ct.flags()).isValue(); - // } - // return false; - // return isX10BaseSubtype(t, Ref()); + public boolean isObjectType(Type t, X10Context c) { + return kind(t, c) == Kind.OBJECT; } Modified: trunk/x10.compiler/src/x10/util/RunTestSuite.java =================================================================== --- trunk/x10.compiler/src/x10/util/RunTestSuite.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/util/RunTestSuite.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -23,7 +23,7 @@ // todo: add support for various options, like testing with STATIC_CALLS/DYNAMIC_CALLS //_MustFailCompile means the compilation should fail. - // Inside those files we should have "ERR" markers that we use to test the position of the errors is correct. + // Inside those files we should have "//.*ERR" markers that we use to test the position of the errors is correct. //_MustFailTimeout means that when running the file it will have an infinite loop private static final String[] EXCLUDE_FILES_WITH_SUFFIX = { "_DYNAMIC_CALLS.x10","_MustFailCompile.x10", @@ -149,7 +149,7 @@ String line; while ((line=in.readLine())!=null) { lineNum++; - if (line.contains("ERR") && + if (line.contains("ERR") && line.contains("//") && !file.getName().contains("Console.x10")) { // Console defines "static ERR:Printer" foundErr = true; // try to find the matching error Modified: trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java =================================================================== --- trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -60,13 +60,9 @@ private static String flagsToString(int i) { return i==0? "none," : (isRead(i)?"read," : "")+(isWrite(i)?"write," : "")+(isSeqWrite(i)?"seqWrite," : ""); } - private class DataFlowItem extends DataFlow.Item { + private static class DataFlowItem extends DataFlow.Item { private final Map<FieldDef, Integer> initStatus = new HashMap<FieldDef, Integer>(); // immutable map of fields to 3flags - private DataFlowItem() { - for (FieldDef f : fields) - initStatus.put(f,0); - } public boolean equals(Object o) { if (o instanceof DataFlowItem) { return this.initStatus.equals(((DataFlowItem)o).initStatus); @@ -87,27 +83,24 @@ } } class FieldChecker extends DataFlow { - private final DataFlowItem INIT = new DataFlowItem(); - private final DataFlowItem CTOR_INIT = new DataFlowItem(); private ProcedureDecl currDecl; - public FieldChecker() { + private DataFlowItem init; + private DataFlowItem finalResult; + public FieldChecker(DataFlowItem init) { super(CheckEscapingThis.this.job, CheckEscapingThis.this.ts, CheckEscapingThis.this.nf, true /* forward analysis */, false /* perform dataflow when leaving CodeDecls, not when entering */); - - for (FieldDef field : superFields) { - CTOR_INIT.initStatus.put(field, build(false, true,true)); - } + this.init = init; } protected Item createInitialItem(FlowGraph graph, Term node, boolean entry) { - return isCtor() ? CTOR_INIT : INIT; + return init; } protected Item confluence(List<Item> items, List<EdgeKey> itemKeys, Term node, boolean entry, FlowGraph graph) { if (node instanceof ProcedureDecl) { List<Item> filtered = filterItemsNonException(items, itemKeys); if (filtered.isEmpty()) { - return INIT; + return init; } else if (filtered.size() == 1) { return (Item)filtered.get(0); @@ -166,7 +159,6 @@ } boolean isAssign = n instanceof FieldAssign; - // todo: closure call: check that all field access are legal if (isAssign || n instanceof Field) { final Receiver target = isAssign ? ((FieldAssign) n).target() : ((Field) n).target(); final FieldInstance fi = isAssign ? ((FieldAssign) n).fieldInstance() : ((Field) n).fieldInstance(); @@ -179,6 +171,36 @@ res.initStatus.put(field,valueAfter); } + } else if (n instanceof Closure) { + // the closure can write to whatever it wants and it won't affect the write-set (because it wasn't invoked yet) + // we only check that it can read what was written to, and call methods whose read-set was written to. + Closure closure = (Closure) n; + closure.body().visit( + new NodeVisitor() { + @Override public NodeVisitor enter(Node n) { + if (n instanceof Field) { + final Field f = (Field) n; + if (isThis(f.target()) && !isWrite( inItem.initStatus.get(f.fieldInstance().def()))) { + reportError("Cannot read from field '"+ f.name()+"' before it is definitely assigned.",n.position()); + wasError = true; + } + } + if (n instanceof X10Call) { + MethodInfo info = getInfo((X10Call) n); + if (info!=null) { + for (FieldDef def : info.read) { + if (!isWrite( inItem.initStatus.get(def))) { + reportError("The method call reads from field '"+ def.name()+"' before it is definitely assigned.",n.position()); + wasError = true; + } + } + } + } + return this; + } + } + ); + } else if (n instanceof ConstructorCall) { ConstructorCall ctorCall = (ConstructorCall) n; assert (ctorCall.kind()==ConstructorCall.SUPER) : "We do not analyze ctors with 'this()' calls, because they're always correct - everything must be initialized after the 'this()' call"; @@ -186,24 +208,15 @@ // Note that the super call should be the first statement, but I inline the field-inits before it. } else if (n instanceof X10Call) { - X10Call call = (X10Call) n; - Receiver receiver = call.target(); - if (isThis(receiver)) { - X10MethodDecl_c methodDecl = findMethod(call); - if (methodDecl!=null) { - final ProcedureDef procDef = methodDecl.procedureInstance(); - if (!isProperty(procDef)) { - res = new DataFlowItem(); - res.initStatus.putAll(inItem.initStatus); - MethodInfo info = allMethods.get(procDef); - assert info !=null : methodDecl; - for (FieldDef field : fields) { - boolean isRead = info.read.contains(field); - boolean isWrite = info.write.contains(field); - boolean isWriteSeq = info.seqWrite.contains(field); - res.initStatus.put(field, afterSeqBlock(res.initStatus.get(field),build(isRead,isWrite, isWriteSeq))); - } - } + MethodInfo info = getInfo((X10Call) n); + if (info!=null) { + res = new DataFlowItem(); + res.initStatus.putAll(inItem.initStatus); + for (FieldDef field : fields) { + boolean isRead = info.read.contains(field); + boolean isWrite = info.write.contains(field); + boolean isWriteSeq = info.seqWrite.contains(field); + res.initStatus.put(field, afterSeqBlock(res.initStatus.get(field),build(isRead,isWrite, isWriteSeq))); } } } else if (n instanceof Expr && ((Expr)n).type().isBoolean() && @@ -245,67 +258,84 @@ @Override protected void check(FlowGraph graph, Term n, boolean entry, Item inItem, Map<EdgeKey, Item> outItems) { DataFlowItem dfIn = (DataFlowItem)inItem; - if (dfIn == null) dfIn = INIT; + if (dfIn == null) dfIn = init; if (n == graph.root() && !entry) { - // finish method/ctor - ProcedureDecl decl = (ProcedureDecl)n; - assert decl!=null; - final ProcedureDef procDef = decl.procedureInstance(); - MethodInfo newInfo = new MethodInfo(); - for (Map.Entry<FieldDef, Integer> pair : dfIn.initStatus.entrySet()) { - int val = pair.getValue(); - final FieldDef f = pair.getKey(); - if (isRead(val)) newInfo.read.add(f); - if (isWrite(val)) newInfo.write.add(f); - if (isSeqWrite(val)) newInfo.seqWrite.add(f); + assert n==currDecl : n; + finalResult = dfIn; + } + } + public void checkResult() { + // finish method/ctor + ProcedureDecl decl = currDecl; + assert decl!=null; + final ProcedureDef procDef = decl.procedureInstance(); + MethodInfo newInfo = new MethodInfo(); + for (Map.Entry<FieldDef, Integer> pair : finalResult.initStatus.entrySet()) { + int val = pair.getValue(); + final FieldDef f = pair.getKey(); + if (isRead(val)) newInfo.read.add(f); + if (isWrite(val)) newInfo.write.add(f); + if (isSeqWrite(val)) newInfo.seqWrite.add(f); + } + + // everything must be assigned in a ctor (and nothing read) + if (isCtor()) { + int size = fields.size(); + if (!newInfo.read.isEmpty()) assert wasError; + assert newInfo.write.containsAll(newInfo.seqWrite); + if (newInfo.seqWrite.size()!=size) { + wasError = true; + // report the field that wasn't written to + for (FieldDef f : fields) + if (!newInfo.seqWrite.contains(f)) { + final Position pos = currDecl.position(); + if (pos.isCompilerGenerated()) // auto-generated ctor + reportError("Field '"+f.name()+"' was not definitely assigned.", f.position()); + else + reportError("Field '"+f.name()+"' was not definitely assigned in this constructor.", pos); + } } + } else { + MethodInfo oldInfo = allMethods.get(procDef); + assert oldInfo!=null : currDecl; + if (hasNonEscapingAnnot(procDef)) { + // the read-set should not change (we already reported an error if it did change) + newInfo.read.clear(); + newInfo.read.addAll(oldInfo.read); + } + if (noWrites(procDef)) { + newInfo.write.clear(); + newInfo.seqWrite.clear(); + } + // proof that the fix-point terminates: write set decreases while the read set increases + assert oldInfo.write.containsAll(newInfo.write); + assert oldInfo.seqWrite.containsAll(newInfo.seqWrite); + assert newInfo.read.containsAll(oldInfo.read); - // everything must be assigned in a ctor (and nothing read) - if (isCtor()) { - int size = fields.size(); - if (!newInfo.read.isEmpty()) assert wasError; - assert newInfo.write.containsAll(newInfo.seqWrite); - if (newInfo.seqWrite.size()!=size) { - wasError = true; - // report the field that wasn't written to - for (FieldDef f : fields) - if (!newInfo.seqWrite.contains(f)) { - reportError("Field '"+f.name()+"' was not definitely assigned.",f.position()); - } - } + + // fixed-point reached? + if (newInfo.read.equals(oldInfo.read) && + newInfo.write.equals(oldInfo.write) && + newInfo.seqWrite.equals(oldInfo.seqWrite)) { + // no change! } else { - MethodInfo oldInfo = allMethods.get(procDef); - assert oldInfo!=null : n; - if (hasNonEscapingAnnot(procDef)) { - // the read-set should not change (we already reported an error if it did change) - newInfo.read.clear(); - newInfo.read.addAll(oldInfo.read); - } - if (noWrites(procDef)) { - newInfo.write.clear(); - newInfo.seqWrite.clear(); - } - // proof that the fix-point terminates: write set decreases while the read set increases - assert oldInfo.write.containsAll(newInfo.write); - assert oldInfo.seqWrite.containsAll(newInfo.seqWrite); - assert newInfo.read.containsAll(oldInfo.read); - - - // fixed-point reached? - if (newInfo.read.equals(oldInfo.read) && - newInfo.write.equals(oldInfo.write) && - newInfo.seqWrite.equals(oldInfo.seqWrite)) { - // no change! - } else { - wasChange = true; - newInfo.canReadFrom = oldInfo.canReadFrom; - allMethods.put(procDef,newInfo); - } + wasChange = true; + newInfo.canReadFrom = oldInfo.canReadFrom; + allMethods.put(procDef,newInfo); } } - } } + private MethodInfo getInfo(X10Call call) { + final MethodInstance methodInstance = call.methodInstance(); + final X10ProcedureDef procDef = (X10ProcedureDef) methodInstance.def(); + if (isThis(call.target()) && !isProperty(procDef) && findMethod(call)!=null) { + final MethodInfo info = allMethods.get(procDef); + assert info!=null; + return info; + } + return null; + } private boolean hasNonEscapingAnnot(ProcedureDef def) { return X10TypeMixin.getNonEscapingReadsFrom((X10ProcedureDef) def, ts) != null; } @@ -320,6 +350,7 @@ return flags.isProperty(); } private boolean isPrivateOrFinal(ProcedureDef def) { + if (isXlassFinal) return true; final X10Flags flags = X10Flags.toX10Flags(((ProcedureDef_c)def).flags()); return flags.isPrivate() || flags.isFinal(); } @@ -331,9 +362,12 @@ this.job = job; } @Override public NodeVisitor enter(Node n) { - if (n instanceof X10ClassDecl_c) - new CheckEscapingThis((X10ClassDecl_c)n,job, + if (n instanceof X10ClassDecl_c) { + final X10ClassDecl_c classDecl_c = (X10ClassDecl_c) n; + if (!classDecl_c.flags().flags().isInterface()) // I have nothing to analyze in an interface + new CheckEscapingThis(classDecl_c,job, (X10TypeSystem)job.extensionInfo().typeSystem()); + } return this; } } @@ -350,6 +384,7 @@ private final X10NodeFactory nf; private final X10TypeSystem ts; private final X10ClassDecl_c xlass; + private final boolean isXlassFinal; private final Type xlassType; // the keys are either X10ConstructorDecl_c or X10MethodDecl_c private final HashMap<ProcedureDef,MethodInfo> allMethods = new LinkedHashMap<ProcedureDef, MethodInfo>(); // all ctors and methods recursively called from allMethods on receiver "this" @@ -359,6 +394,9 @@ // Therefore we can now treat both VAL and VAR identically. private final HashSet<FieldDef> fields = new HashSet<FieldDef>(); private final HashSet<FieldDef> superFields = new HashSet<FieldDef>(); // after the "super()" call, these fields are initialized + private final DataFlowItem INIT = new DataFlowItem(); + private final DataFlowItem CTOR_INIT = new DataFlowItem(); + private boolean wasChange = true, wasError = false; // for fixed point alg private HashSet<FieldDef> globalRef = new HashSet<FieldDef>();// There is one exception to the "this cannot escape" rule: val root = GlobalRef[...](this) @@ -376,7 +414,19 @@ this.ts = ts; nf = (X10NodeFactory)ts.extensionInfo().nodeFactory(); this.xlass = xlass; + isXlassFinal = xlass.flags().flags().isFinal(); this.xlassType = X10TypeMixin.baseType(xlass.classDef().asType()); + // calculate the set of all fields (including inherited fields) + calcFields(); + int notInited = build(false, false,false); + int inited = build(false, true,true); + for (FieldDef f : fields) { + INIT.initStatus.put(f,notInited); + CTOR_INIT.initStatus.put(f,notInited); + } + for (FieldDef field : superFields) { + CTOR_INIT.initStatus.put(field, inited); + } typeCheck(); } private void calcFields() { @@ -418,7 +468,7 @@ if (qName.equals(QName.make("x10.lang","GlobalRef"))) { // found the pattern! // must be private - if (!field.flags().flags().isPrivate()) + if (!isXlassFinal && !field.flags().flags().isPrivate()) reportError("In order to use the pattern GlobalRef[...](this) the field must be private.",field.position()); globalRef.add(field.fieldDef()); } @@ -441,9 +491,8 @@ // Find globalRefs calcGlobalRefs(nonStaticFields); - // calculate the set of all fields (including inherited fields) - calcFields(); + // inline the field-initializers in every ctor ArrayList<Stmt> fieldInits = new ArrayList<Stmt>(); final Position pos = Position.COMPILER_GENERATED; @@ -535,18 +584,27 @@ } } // run fix point alg: ctors do not need to be in the fixed point alg because nobody can call them directly - final FieldChecker fieldChecker = new FieldChecker(); + final FieldChecker fieldChecker = new FieldChecker(INIT); while (wasChange && !wasError) { wasChange =false; // do a DFS: starting from private/final methods, and then the ctors (this will reach a fixed-point fastest) - for (ProcedureDecl p : dfsMethods) + for (ProcedureDecl p : dfsMethods) { fieldChecker.dataflow(p); + fieldChecker.checkResult(); + } } // handle ctors and field initializers - //fieldChecker.dataflow(newInit); // todo: make a new method for field-init, and the ctors will call it at the begining - for (X10ConstructorDecl_c ctor : ctorsForDataFlow) { - X10ConstructorDecl_c newCtor = (X10ConstructorDecl_c) ctor.body( nf.Block(pos,newInit,ctor.body()) ); - fieldChecker.dataflow(newCtor); + // make a new special ctor for field-init, and the ctors will use its data-flow for their INIT + if (ctorsForDataFlow.size()>0) { + fieldChecker.init = CTOR_INIT; + X10ConstructorDecl_c fieldInitCtor = (X10ConstructorDecl_c) ctorsForDataFlow.get(0).body(newInit); + fieldChecker.dataflow(fieldInitCtor); + fieldChecker.init = fieldChecker.finalResult; + for (X10ConstructorDecl_c ctor : ctorsForDataFlow) { + // X10ConstructorDecl_c newCtor = (X10ConstructorDecl_c) ctor.body( nf.Block(pos,newInit,ctor.body()) ); //reports errors in the field-inits multiple times (if we have multiple ctors) + fieldChecker.dataflow(ctor); + fieldChecker.checkResult(); + } } } private FieldDef findField(String name) { Modified: trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-21 20:11:34 UTC (rev 16607) @@ -2491,7 +2491,7 @@ } else { - boolean is_location_access = xts.isReferenceOrInterfaceType(fi.container(), context) && fi.name().equals(xts.homeName()); + boolean is_location_access = xts.isObjectOrInterfaceType(fi.container(), context) && fi.name().equals(xts.homeName()); // WARNING: it's important to delegate to the appropriate visit() here! n.translate(w, tr); Modified: trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 =================================================================== --- trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -36,7 +36,7 @@ V:Float) { val blocks = 480; val threads = 128; - finish async (p) @CUDA @CUDADirectParams { + finish async at (p) @CUDA @CUDADirectParams { //val blocks = CUDAUtilities.autoBlocks(), // threads = CUDAUtilities.autoThreads(); for ((block) in 0..blocks-1) { Modified: trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Array/UserDefinedArray.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -31,7 +31,7 @@ // and a[1] is in D[1] but points to an object in D[0] val v1: E = at(D(1)) new E(1); val v2: E = at(D(0))new E(2); - val a = DistArray.make[E](D, ([i]: Point)=> (i==0) ? v1 : v2); + val a:DistArray[E](1) = DistArray.make[E](D, ([i]: Point(1))=> (i==0) ? v1 : v2); chk(a.dist(0) == D(0)); chk(at(a.dist(0))a(0) == v1); Modified: trunk/x10.tests/examples/Constructs/DepType/MethodArgDepTypes2.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/DepType/MethodArgDepTypes2.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/DepType/MethodArgDepTypes2.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -22,7 +22,7 @@ val R: Region{rank==a_dest.rank} = a_src.region&& a_dest.region; finish foreach (val p: Point{rank==a_dest.rank} in R) { //finish for( point p : R){ - a_dest(p)= (future(a_src.dist(p)) {a_src(p)}).force(); + a_dest(p)= Future.make(() => at(a_src.dist(p)) { return a_src(p);}).force(); } //for( point p : R) a_dest[p]=a_src[p]; //implicit syntax } Modified: trunk/x10.tests/examples/Constructs/Distribution/BlockDistWithPlaceSet.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Distribution/BlockDistWithPlaceSet.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Distribution/BlockDistWithPlaceSet.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -38,7 +38,7 @@ public static L = 5; public def run(): boolean = { - for (val (tries): Point in 1..COUNT) { + for (val [tries]: Point in 1..COUNT) { val lb1: int = ranInt(-L, L); val lb2: int = ranInt(-L, L); val ub1: int = ranInt(lb1, L); @@ -57,7 +57,7 @@ var pn: int = 0; //x10.io.Console.OUT.println("np = " + np + " lb1 = "+lb1+" ub1 = "+ub1+" lb2 = "+lb2+" ub2 = "+ub2+" totalPoints = "+totalPoints+" p = "+p+" q = "+q); - for (val (i,j): Point(2) in R) { + for (val [i,j]: Point(2) in R) { //x10.io.Console.OUT.println("placeNum = "+placeNums[pn]+" offsWithinPlace = "+offsWithinPlace+" i = "+i+" j = "+j+" DBlock[i,j] = "+DBlock[i,j].id); chk(DBlock(i, j) == P(placeNums(pn))); chk(P(placeNums(pn)).id == placeNums(pn)); @@ -96,7 +96,7 @@ do { np = 0; val THRESH: int = ranInt(10, 90); - for (val (i): Point(1) in P) { + for (val [i]: Point(1) in P) { val x: int = ranInt(0, 99); if (x >= THRESH) { placeSet.add(P(i)); Modified: trunk/x10.tests/examples/Constructs/Future/Future1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/Future1.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Future/Future1.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -16,7 +16,7 @@ */ public class Future1 extends x10Test { public def run(): boolean = { - val x = future 41 ; + val x = Future.make( () => 41 ); return x()+1 == 42; } Modified: trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -29,13 +29,13 @@ } public def foo(): Int = { - var r2: Future[Int] = future(here) { bar() }; + var r2: Future[Int] = Future.make( () => at (here) { return bar(); } ); return 42; } public def run(): Boolean = { atomic flag = false; - var r1: Future[Int] = future(here) { foo() }; + var r1: Future[Int] = Future.make( () => (here) { return foo(); } ); r1(); var b: Boolean; atomic b = flag; Modified: trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -16,7 +16,7 @@ */ public class FutureForced extends x10Test { public def run(): boolean = { - val x = future 41; + val x = Future.make( () => 41 ); val v = x(); return x.forced(); } Modified: trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -17,7 +17,7 @@ public class FutureTest2 extends x10Test { public def run(): boolean = { - val ret = future (here) { this.m() }; + val ret = Future.make( () => at (here) { return this.m(); } ); return ret(); } Modified: trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -68,7 +68,7 @@ // side effect in expression // (need atomic here if there is sharing. x10 should support atomic { expression } ) - var r1: int = (future {A(K) += 1}).force(); + var r1: int = Future.make( () => { return A(K) += 1;} ).force(); x10.io.Console.OUT.println("1"); atomic chk(A(K) == 1); chk(r1 == 1); @@ -77,7 +77,7 @@ var r2: int = -1; gotException = false; try { - r2 = (future {A(OUTOFRANGE) += 1}) .force(); + r2 = Future.make( () => { return A(OUTOFRANGE) += 1; } ) .force(); } catch (var e: ArrayIndexOutOfBoundsException) { gotException = true; } @@ -89,7 +89,7 @@ var r3: int = -1; gotException = false; try { - r3 = (future m1(A, K)) .force(); + r3 = Future.make( () => m1(A, K)) .force(); } catch (var e: Throwable) { gotException = true; } @@ -105,7 +105,7 @@ var r4: int = -1; gotException = false; try { - r4 = (future m2(A, K)) .force(); + r4 = Future.make( () => m2(A, K)) .force(); } catch (var e: Throwable) { gotException = true; } @@ -118,7 +118,7 @@ //Only force() throws the exception, //a plain future call just spawns the expression - val fr5 = future { m2(A, K) }; + val fr5 = Future.make( () => m2(A, K) ); x10.io.Console.OUT.println("5"); // must read old values of A here //atomic chk(A(K) == 3); Modified: trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -40,7 +40,7 @@ private def testUp_(val del: boolean): boolean = { atomic fut = null; async (here) { - val t1 = future (here) { 42 } ; + val t1 = Future.make( () => at (here) { return 42; } ); atomic fut = t1 as Box[Future[Int]]; if (del) Activity.sleep(500); @@ -56,7 +56,7 @@ * Create future in parent, force it in child. */ private def testDown_(): boolean = { - val fut_l = future (here) { 42 } ; + val fut_l = Future.make( () => 42 ); finish async (here) { var fortytwo: int = fut_l.force(); x10.io.Console.OUT.println("down done"); @@ -70,7 +70,7 @@ private def testSibling_(val del: boolean): boolean = { atomic fut = null; async (here) { - val t1= future (here) { 42 } ; + val t1= Future.make( () => 42 ); atomic fut = t1 as Box[Future[Int]]; if (del) Activity.sleep(500); Modified: trunk/x10.tests/examples/Constructs/Modifiers/SafeClass.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Modifiers/SafeClass.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Modifiers/SafeClass.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -19,7 +19,7 @@ */ public safe class SafeClass extends x10Test { - public def m(): void = { + public nonblocking def m(): void = { } public def run(): boolean = { Modified: trunk/x10.tests/examples/Constructs/Place/AtThisIntoAtHere.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Place/AtThisIntoAtHere.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Place/AtThisIntoAtHere.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -24,8 +24,8 @@ public class AtThisIntoAtHere extends x10Test { class Test { def n() { - private val x:GlobalRef[Test] = GlobalRef[Test](this); - private val y:GlobalRef[Test]{self.home==x.home} = GlobalRef[Test](this); + val x:GlobalRef[Test] = GlobalRef[Test](this); + val y:GlobalRef[Test]{self.home==x.home} = x; at (x) { // it is ok to invoke this.y() at the place of this.x. Modified: trunk/x10.tests/examples/Constructs/Place/ClosureBang.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Place/ClosureBang.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/Constructs/Place/ClosureBang.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -1,6 +1,6 @@ class ClosureBang { class C { - incomplete def n():Void; + def n():void { throw new RuntimeException(); } } def m(x:()=> GlobalRef[C]{self.home==here}) { at (here.next()) { Modified: trunk/x10.tests/examples/x10lib/harness/x10Test.x10 =================================================================== --- trunk/x10.tests/examples/x10lib/harness/x10Test.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/examples/x10lib/harness/x10Test.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -68,7 +68,7 @@ /** * Check if a given condition is true, and throw an error if not. */ - public static def chk(b: boolean): void = { + public static nonblocking def chk(b: boolean): void = { if (!b) throw new Error(); } @@ -76,7 +76,7 @@ * Check if a given condition is true, and throw an error with a given * message if not. */ - public static def chk(b: boolean, s: String): void = { + public static nonblocking def chk(b: boolean, s: String): void = { if (!b) throw new Error(s); } Modified: trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish1.x10 =================================================================== --- trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish1.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish1.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -7,7 +7,7 @@ var i:int = 0; for(i=0;i<1000;i++){ val p = Place.place(i % Place.MAX_PLACES); - async(p){ + async at (p){ @FinishAsync(1,1,true,1) finish{ for(var j:int = 0; j<50; j++){ Modified: trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish2.x10 =================================================================== --- trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish2.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/tests/ScalableFinish/ManyLocalFinish2.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -7,7 +7,7 @@ var i:int = 0; for(i=0;i<1000;i++){ val p = Place.place(i % Place.MAX_PLACES); - async(p){ + async at (p){ @FinishAsync(1,1,true,1) finish{ for(var j:int=0;j<50;j++){ Modified: trunk/x10.tests/tests/ScalableFinish/SimpleFinish1.x10 =================================================================== --- trunk/x10.tests/tests/ScalableFinish/SimpleFinish1.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/tests/ScalableFinish/SimpleFinish1.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -7,15 +7,15 @@ var i:int = 0; for(i=0;i<1000;i++){ val p1 = Place.place(i % Place.MAX_PLACES); - async(p1){ + async at (p1){ val p = here; @FinishAsync(1,1,false,2) finish{ - async(p.next().next()){ } - async(p.next()){ + async at (p.next().next()){ } + async at (p.next()){ async{} } - async(p.next()){ + async at (p.next()){ async{ async{} } Modified: trunk/x10.tests/tests/ScalableFinish/SimpleFinish2.x10 =================================================================== --- trunk/x10.tests/tests/ScalableFinish/SimpleFinish2.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/tests/ScalableFinish/SimpleFinish2.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -8,11 +8,11 @@ var i:int = 0; for(i=0;i<1000;i++){ val p1 = Place.place(i % Place.MAX_PLACES); - async(p1){ + async at (p1){ val p = here; @FinishAsync(1,1,false,2) finish{ - async(p.next()){} + async at (p.next()){} } } } Modified: trunk/x10.tests/tests/ScalableFinish/SimpleFinish3.x10 =================================================================== --- trunk/x10.tests/tests/ScalableFinish/SimpleFinish3.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/tests/ScalableFinish/SimpleFinish3.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -7,11 +7,11 @@ var i:int = 0; for(i=0;i<1000;i++){ val p1 = Place.place(i % Place.MAX_PLACES); - async(p1){ + async at (p1){ @FinishAsync(1,1,false,2) finish { for(var p:int = 0; p<Place.MAX_PLACES; p++){ - async(Place.places(p)){} + async at (Place.places(p)){} } } } Modified: trunk/x10.tests/tests/ScalableFinish/SimpleFinish4.x10 =================================================================== --- trunk/x10.tests/tests/ScalableFinish/SimpleFinish4.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/tests/ScalableFinish/SimpleFinish4.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -7,11 +7,11 @@ var i:int = 0; for(i=0;i<1000;i++){ val p1 = Place.place(i % Place.MAX_PLACES); - async(p1){ + async at (p1){ @FinishAsync(1,1,false,2) finish { for(var p:int = 0; p<Place.MAX_PLACES; p++){ - async(Place.places(p)){ + async at (Place.places(p)){ for(var pp:int = 0; pp<Place.MAX_PLACES; pp++){ val i = pp; async{} Modified: trunk/x10.tests/tests/ScalableFinish/SimpleFinish5.x10 =================================================================== --- trunk/x10.tests/tests/ScalableFinish/SimpleFinish5.x10 2010-09-21 19:39:45 UTC (rev 16606) +++ trunk/x10.tests/tests/ScalableFinish/SimpleFinish5.x10 2010-09-21 20:11:34 UTC (rev 16607) @@ -7,21 +7,21 @@ finish{ for(i=0;i<1000;i++){ val p1 = Place.place(i % Place.MAX_PLACES); - async(p1){ + async at (p1){ @FinishAsync(1,1,false,2) finish { for(var j:int = 0; j< 500; j++){ async{} } for(var p:int = 0; p<Place.MAX_PLACES; p++){ - async(Place.places(p)){ + async at (Place.places(p)){ for(var pp:int = 0; pp<50; pp++){ async{} } } } for(var p3:int = Place.MAX_PLACES-1; p3>=0;p3--){ - async(Place.places(p3)){} + async at (Place.places(p3)){} } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2010-09-22 06:13:30
|
Revision: 16617 http://x10.svn.sourceforge.net/x10/?rev=16617&view=rev Author: makinoy Date: 2010-09-22 06:13:21 +0000 (Wed, 22 Sep 2010) Log Message: ----------- WIP on a new generics implementation of Managed X10. Related: XTENLANG-533, 978, 979 Modified Paths: -------------- trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java trunk/x10.compiler/src/x10/emitter/Emitter.java trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java trunk/x10.compiler/src/x10c/visit/InlineHelper.java trunk/x10.compiler/src/x10c/visit/JavaCaster.java trunk/x10.runtime/src-java/x10/core/AnyRail.java trunk/x10.runtime/src-java/x10/core/GrowableRail.java trunk/x10.runtime/src-java/x10/core/Rail.java trunk/x10.runtime/src-java/x10/core/RailFactory.java trunk/x10.runtime/src-java/x10/core/ValRail.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_1.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_2.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_3.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_4.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_5.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_6.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_7.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_8.java trunk/x10.runtime/src-java/x10/core/fun/Fun_0_9.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_1.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_2.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_3.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_4.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_5.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_6.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_7.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_8.java trunk/x10.runtime/src-java/x10/core/fun/VoidFun_0_9.java trunk/x10.runtime/src-java/x10/rtt/BooleanType.java trunk/x10.runtime/src-java/x10/rtt/ByteType.java trunk/x10.runtime/src-java/x10/rtt/CharType.java trunk/x10.runtime/src-java/x10/rtt/DoubleType.java trunk/x10.runtime/src-java/x10/rtt/FloatType.java trunk/x10.runtime/src-java/x10/rtt/IntType.java trunk/x10.runtime/src-java/x10/rtt/LongType.java trunk/x10.runtime/src-java/x10/rtt/ShortType.java trunk/x10.runtime/src-x10/x10/lang/Indexable.x10 trunk/x10.runtime/src-x10/x10/lang/Iterable.x10 trunk/x10.runtime/src-x10/x10/lang/Iterator.x10 trunk/x10.runtime/src-x10/x10/lang/Settable.x10 Removed Paths: ------------- trunk/x10.runtime/src-java/x10/core/Indexable.java trunk/x10.runtime/src-java/x10/core/Iterable.java trunk/x10.runtime/src-java/x10/core/Iterator.java trunk/x10.runtime/src-java/x10/core/RailIterator.java trunk/x10.runtime/src-java/x10/core/Settable.java Modified: trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -679,19 +679,20 @@ } - Map<X10ClassDef,X10ClassType> map = new HashMap<X10ClassDef, X10ClassType>(); - for (X10ClassType ct : supers) { - X10ClassType t = map.get(ct.x10Def()); - if (t != null) { - if (!t.typeEquals(ct, tc.context())) { - String kind = ct.flags().isInterface() ? "interface" : "class"; - Errors.issue(tc.job(), - new Errors.CannotExtendTwoInstancesSameInterfaceLimitation(t, ct, - position())); - } - } - map.put(ct.x10Def(), ct); - } + // fix for XTENLANG-978 +// Map<X10ClassDef,X10ClassType> map = new HashMap<X10ClassDef, X10ClassType>(); +// for (X10ClassType ct : supers) { +// X10ClassType t = map.get(ct.x10Def()); +// if (t != null) { +// if (!t.typeEquals(ct, tc.context())) { +// String kind = ct.flags().isInterface() ? "interface" : "class"; +// Errors.issue(tc.job(), +// new Errors.CannotExtendTwoInstancesSameInterfaceLimitation(t, ct, +// position())); +// } +// } +// map.put(ct.x10Def(), ct); +// } n = (X10ClassDecl_c) n.adjustAbstractMethods(oldtc); Modified: trunk/x10.compiler/src/x10/emitter/Emitter.java =================================================================== --- trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -22,6 +22,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import polyglot.ast.Binary; @@ -53,6 +54,7 @@ import polyglot.types.QName; import polyglot.types.Ref; import polyglot.types.SemanticException; +import polyglot.types.StructType; import polyglot.types.Type; import polyglot.types.TypeSystem; import polyglot.types.Types; @@ -77,10 +79,15 @@ import x10.types.X10Def; import x10.types.X10Flags; import x10.types.X10MethodInstance; +import x10.types.X10ParsedClassType; import x10.types.X10ParsedClassType_c; +import x10.types.X10TypeEnv; +import x10.types.X10TypeEnv_c; import x10.types.X10TypeMixin; import x10.types.X10TypeSystem; +import x10.types.X10TypeSystem_c; import x10.types.checker.Converter; +import x10.types.matcher.X10TypeMatcher; import x10.visit.X10PrettyPrinterVisitor; import x10c.types.BackingArrayType; @@ -554,7 +561,7 @@ type.print(w); } } else if (type.isNull()) { - w.write("java.lang.Object"); + w.write(X10PrettyPrinterVisitor.JAVA_LANG_OBJECT); } else { type.print(w); } @@ -1038,15 +1045,30 @@ } if (n.typeParameters().size() > 0) w.write("> "); - - printType( - n.returnType().type(), - X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS - ); + + boolean isDispatch = false; + if (X10PrettyPrinterVisitor.isSelfDispatch && c.currentClass().flags().isInterface()) { + for (int i = 0; i < n.formals().size(); i++) { + Type type = n.formals().get(i).type().type(); + if (containsTypeParam(type)) { + isDispatch = true; + break; + } + } + } + + if (isDispatch) { + w.write(X10PrettyPrinterVisitor.JAVA_LANG_OBJECT); + } else { + printType( + n.returnType().type(), + X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS + ); + } w.allowBreak(2, 2, " ", 1); tr.print(n, n.name(), w); - if (X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType) { + if (!isDispatch && X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType) { w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); } w.write("("); @@ -1068,7 +1090,7 @@ w.write(" "); w.write(Emitter.mangleToJava(p.name().id())); } - + int formalNum = 1; for (int i = 0; i < n.formals().size(); i++) { Formal f = n.formals().get(i); if (!first) { @@ -1078,18 +1100,36 @@ first = false; tr.print(n, f.flags(), w); - printType( - f.type().type(), - X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS - | (boxPrimitives ? X10PrettyPrinterVisitor.BOX_PRIMITIVES - : 0)); - w.write(" "); + Type type = f.type().type(); + + if (X10PrettyPrinterVisitor.isSelfDispatch && c.currentClass().flags().isInterface() && containsTypeParam(type)) { + printType(type, 0); + w.write(" "); + Name name = f.name().id(); + if (name.toString().equals("")) { + name = Name.makeFresh("a"); + } + tr.print(n, f.name().id(name), w); - Name name = f.name().id(); - if (name.toString().equals("")) { - name = Name.makeFresh("a"); + w.write(","); + w.write(X10PrettyPrinterVisitor.X10_RUNTIME_TYPE_CLASS); + w.write(" "); + Name name1 = Name.make("t" + formalNum++); + tr.print(n, f.name().id(name1), w); } - tr.print(n, f.name().id(name), w); + else { + printType( + type, + (n.flags().flags().isStatic() ? X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS : 0) | + (boxPrimitives ? X10PrettyPrinterVisitor.BOX_PRIMITIVES: 0) + ); + w.write(" "); + Name name = f.name().id(); + if (name.toString().equals("")) { + name = Name.makeFresh("a"); + } + tr.print(n, f.name().id(name), w); + } } w.end(); @@ -1138,7 +1178,24 @@ } } - public void generateBridgeMethods(X10ClassDef cd) { + public static boolean containsTypeParam(Type type) { + if (type instanceof ParameterType) { + return true; + } + else if (type instanceof X10ClassType) { + List<Type> tas = ((X10ClassType) type).typeArguments(); + if (tas != null) { + for (Type type1 : tas) { + if (containsTypeParam(type1)) { + return true; + } + } + } + } + return false; + } + + public void generateBridgeMethods(X10ClassDef cd) { if (cd.flags().isInterface()) { return; } @@ -1158,18 +1215,57 @@ getInheritedMethods(ct, inheriteds); for (MethodInstance mi : inheriteds) { if (isInstantiate(mi.def().returnType().get(), mi.returnType())) { - printInheritedMethodBridge(mi, mi.def()); + printInheritedMethodBridge(mi); break; } for (int i = 0; i < mi.formalTypes().size(); ++ i) { if (isPrimitive(mi.formalTypes().get(i)) && isInstantiate(mi.def().formalTypes().get(i).get(), mi.formalTypes().get(i))) { - printInheritedMethodBridge(mi, mi.def()); + printInheritedMethodBridge(mi); break; } } - + List<MethodInstance> implMethods = new ArrayList<MethodInstance>(); + List<Type> interfaces = ct.interfaces(); + getImplMethods(mi, implMethods, interfaces); + for (MethodInstance mi2 : implMethods) { + printBridgeMethod(mi, mi2.def()); + } } } + + private void getImplMethods(MethodInstance mi, List<MethodInstance> implMethods, List<Type> interfaces) { + for (Type type : interfaces) { + if (type instanceof X10ClassType) { + List<MethodInstance> imis = ((X10ClassType) type).methods(); + for (MethodInstance imi : imis) { + if (!(imi.name().equals(mi.name()) && imi.formalTypes().size() == mi.formalTypes().size())) continue; + if (isContainInstantiateSamePlace(implMethods, imi)) continue; + Type returnType = mi.returnType(); + if ( + returnType.typeEquals(imi.returnType() , tr.context()) + && X10TypeMixin.baseType(imi.def().returnType().get()) instanceof ParameterType + && !(X10TypeMixin.baseType(returnType) instanceof ParameterType) + ) { + implMethods.add(imi); + break; + } + List<Ref<? extends Type>> types = imi.def().formalTypes(); + for (int i = 0;i < types.size(); ++i) { + if ( + mi.formalTypes().get(i).typeEquals(imi.formalTypes().get(i), tr.context()) + && isPrimitive(mi.formalTypes().get(i)) + && types.get(i).get() instanceof ParameterType + && !(mi.formalTypes().get(i) instanceof ParameterType) + ) { + implMethods.add(imi); + break; + } + } + } + getImplMethods(mi, implMethods, ((X10ClassType) type).interfaces()); + } + } + } private List<MethodInstance> getInstantiatedMethods(X10ClassType ct, MethodInstance mi) { List<MethodInstance> methods = new ArrayList<MethodInstance>(); @@ -1379,11 +1475,12 @@ } } - private void printInheritedMethodBridge(MethodInstance impl, MethodDef def) { + private void printInheritedMethodBridge(MethodInstance mi) { + MethodDef def = mi.def(); w.write("// bridge for " + def); w.newline(); - Flags flags = X10Flags.toX10Flags(impl.flags()); + Flags flags = X10Flags.toX10Flags(mi.flags()); w.begin(0); w.write(flags.clearAbstract() @@ -1392,18 +1489,18 @@ .translate() ); - printType(impl.returnType(), X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS); + printType(mi.returnType(), X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS); w.allowBreak(2, 2, " ", 1); - w.write(mangleToJava(impl.name())); + w.write(mangleToJava(mi.name())); - if (X10TypeMixin.baseType(impl.returnType()) instanceof ParameterType) { + if (X10TypeMixin.baseType(mi.returnType()) instanceof ParameterType) { w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); } w.write("("); for (int i = 0; i < def.formalTypes().size(); i++) { - Type f = impl.formalTypes().get(i); + Type f = mi.formalTypes().get(i); if (i != 0) { w.write(","); w.allowBreak(0, " "); @@ -1418,10 +1515,10 @@ w.end(); w.write(")"); - if (!impl.throwTypes().isEmpty()) { + if (!mi.throwTypes().isEmpty()) { w.allowBreak(6); w.write("throws "); - for (Iterator<Type> i = impl.throwTypes().iterator(); i.hasNext();) { + for (Iterator<Type> i = mi.throwTypes().iterator(); i.hasNext();) { Type t = i.next(); printType(t, X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS); if (i.hasNext()) { @@ -1432,20 +1529,20 @@ } w.write("{"); - if (!impl.returnType().isVoid()) { + if (!mi.returnType().isVoid()) { w.write("return "); } w.write("super."); - w.write(mangleToJava(impl.name())); + w.write(mangleToJava(mi.name())); if (X10TypeMixin.baseType(def.returnType().get()) instanceof ParameterType) { w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); } w.write("("); - for (int i = 0; i < impl.formalTypes().size(); i++) { - Type f = impl.formalTypes().get(i); + for (int i = 0; i < mi.formalTypes().size(); i++) { + Type f = mi.formalTypes().get(i); if (i != 0) { w.write(","); w.allowBreak(0, " "); @@ -1796,7 +1893,7 @@ } } - public boolean isNoArgumentType(Expr e) { + private boolean isNoArgumentType(Expr e) { while (e instanceof ParExpr_c) { e = ((ParExpr_c) e).expr(); if (e == null) { @@ -2182,4 +2279,301 @@ } throw new InternalCompilerError(""); // TODO } + + public void generateDispatchMethods(X10ClassDef cd) { + if (cd.flags().isInterface()) { + return; + } + + X10ClassType ct = (X10ClassType) cd.asType(); + + List<MethodInstance> methods = ct.methods(); + Map<MethodInstance, List<MethodInstance>> dispatcherToMyMethods = new HashMap<MethodInstance,List<MethodInstance>>(); + for (MethodInstance myMethod : methods) { + List<MethodInstance> implementeds = myMethod.implemented(tr.context()); + List<MethodInstance> targets = new ArrayList<MethodInstance>(); + for (MethodInstance implemented : implementeds) { + if (implemented.def().equals(myMethod.def())) continue; + + // only interface + StructType st = implemented.def().container().get(); + if (st instanceof X10ClassType) { + if (!((X10ClassType) st).flags().isInterface()) { + continue; + } + } + + boolean isContainsTypeParams = false; + List<Ref<? extends Type>> formalTypes = implemented.def().formalTypes(); + for (Ref<? extends Type> ref : formalTypes) { + Type type = ref.get(); + if (containsTypeParam(type)) { + isContainsTypeParams = true; + break; + } +// if (type instanceof ParameterType) { +// isContainsTypeParams = true; +// break; +// } + } + if (!isContainsTypeParams) continue; + + // only implements by itself not super class's + List<Type> allInterfaces = new ArrayList<Type>(); + getAllInterfaces(ct.interfaces(), allInterfaces); + boolean isContainInterfaces = false; + for (Type type : allInterfaces) { + if (type.typeEquals(implemented.container(), tr.context())) { + isContainInterfaces = true; + break; + } + } + if (!isContainInterfaces) continue; + + if (!isContainSameSignature(targets, implemented)) { + targets.add(implemented); + } + } + + for (MethodInstance target : targets) { + boolean isContainsSameSignature = false; + Set<Entry<MethodInstance, List<MethodInstance>>> entrySet = dispatcherToMyMethods.entrySet(); + for (Entry<MethodInstance, List<MethodInstance>> entry : entrySet) { + + MethodDef md = entry.getKey().def(); + MethodDef td = target.def(); + if (md.name().equals(td.name()) && md.formalTypes().size() == td.formalTypes().size()) { + List<Ref<? extends Type>> formalTypes = md.formalTypes(); + isContainsSameSignature = true; + for (int i = 0; i < formalTypes.size(); ++i) { + Type ft = formalTypes.get(i).get(); + Type tt = td.formalTypes().get(i).get(); + if ((ft instanceof ParameterType && td.formalTypes().get(i).get() instanceof ParameterType)) {} + else if (ft instanceof X10ClassType && tt instanceof X10ClassType && ((X10ClassType) ft).name().toString().equals(((X10ClassType) tt).name().toString())) {} + else { + isContainsSameSignature = false; + break; + } + } + if (isContainsSameSignature) { + entry.getValue().add(myMethod); + } + } + } + if (isContainsSameSignature) break; + + ArrayList<MethodInstance> mis = new ArrayList<MethodInstance>(); + mis.add(myMethod); + dispatcherToMyMethods.put(target, mis); + } + } + + Set<Entry<MethodInstance, List<MethodInstance>>> entrySet = dispatcherToMyMethods.entrySet(); + for (Entry<MethodInstance, List<MethodInstance>> entry : entrySet) { + printDispatchMethod(entry.getKey(), entry.getValue()); + } + +// List<MethodInstance> inheriteds = new ArrayList<MethodInstance>(); +// getInheritedMethods(ct, inheriteds); // not implement +// for (MethodInstance mi : inheriteds) { +// StructType st = mi.def().container().get(); +// System.out.println(mi); +// if (st instanceof X10ParsedClassType) { +// if (((X10ParsedClassType) st).flags().isInterface()) { +// ArrayList<MethodInstance> mis = new ArrayList<MethodInstance>(); +// mis.add(mi); +// printDispatchMethod(mi, mis); +// } +// } +// } + } + + private void getAllInterfaces(List<Type> interfaces, List<Type> allInterfaces) { + allInterfaces.addAll(interfaces); + for (Type type : interfaces) { + if (type instanceof X10ClassType) { + List<Type> interfaces1 = ((X10ClassType) type).interfaces(); + getAllInterfaces(interfaces1, allInterfaces); + } + } + } + + private boolean isContainSameSignature(List<MethodInstance> targets, MethodInstance mi1) { + boolean isContain = false; + for (MethodInstance mi2 : targets) { + if (mi2.name().equals(mi1.name())) { + List<Type> formalTypes1 = mi1.formalTypes(); + List<Type> formalTypes2 = mi2.formalTypes(); + if (formalTypes1.size() == formalTypes2.size()) { + for (int i = 0; i < formalTypes1.size(); ++i) { + Type type1 = formalTypes1.get(i); + Type type2 = formalTypes2.get(i); + if (type1.typeEquals(type2, tr.context()) || (type1 instanceof ParameterType && type2 instanceof ParameterType)) { + isContain = true; + break; + } + } + } + } + } + return isContain; + } + + private void printDispatchMethod(MethodInstance dispatch, List<MethodInstance> mis) { + MethodDef def = dispatch.def(); + w.write("// dispatcher for " + def); + w.newline(); + + Flags flags = X10Flags.toX10Flags(dispatch.flags()); + + w.begin(0); + w.write(flags.clearAbstract() + .clear(X10Flags.SAFE) + .clear(X10Flags.NATIVE) + .translate() + ); + + // e.g int m() overrides or implements T m() + boolean instantiateReturnType = X10TypeMixin.baseType(def.returnType().get()) instanceof ParameterType; +// if (instantiateReturnType) { +// printType(dispatch.returnType(), X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS | X10PrettyPrinterVisitor.BOX_PRIMITIVES); +// } +// else { +// if (containsTypeParam(def.returnType().get())) { +// +// } +// printType(dispatch.returnType(), X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS); +// } + w.write(X10PrettyPrinterVisitor.JAVA_LANG_OBJECT); + + w.allowBreak(2, 2, " ", 1); + w.write(mangleToJava(dispatch.name())); + + +// if (instantiateReturnType) { +// w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); +// } + + w.write("("); + Name[] names = new Name[def.formalTypes().size()]; + for (int i = 0; i < def.formalTypes().size(); i++) { + Type f = dispatch.formalTypes().get(i); + if (i != 0) { + w.write(","); + w.allowBreak(0, " "); + } + Type type = def.formalTypes().get(i).get(); + if (containsTypeParam(type)) { +// if (X10TypeMixin.baseType(type) instanceof ParameterType) { + if (type instanceof ParameterType) { + w.write(X10PrettyPrinterVisitor.JAVA_LANG_OBJECT); + } else { + printType(type, 0); + } + + w.write(" "); + + Name name = Name.make("a" + (i + 1)); + w.write(name.toString()); + + w.write(","); + w.write(X10PrettyPrinterVisitor.X10_RUNTIME_TYPE_CLASS); + w.write(" "); + Name name1 = Name.make("t" + (i + 1)); + w.write(name1.toString()); + + names[i] = name1; + } else { + printType(f, X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS); + + w.write(" "); + + Name name = Name.make("a" + (i + 1)); + w.write(name.toString()); + } + } + + w.end(); + w.write(")"); + + if (!dispatch.throwTypes().isEmpty()) { + w.allowBreak(6); + w.write("throws "); + for (Iterator<Type> i = dispatch.throwTypes().iterator(); i.hasNext();) { + Type t = i.next(); + printType(t, X10PrettyPrinterVisitor.PRINT_TYPE_PARAMS); + if (i.hasNext()) { + w.write(","); + w.allowBreak(4, " "); + } + } + } + + w.write("{"); + + for (MethodInstance mi : mis) { + if (mis.size() != 1) { + for (int i = 0; i < names.length; i++) { + Name name = names[i]; + if (name == null) continue; + w.write("if ("); + w.write(name.toString()); + w.write(".equals("); + new RuntimeTypeExpander(this, mi.formalTypes().get(i)).expand(); + w.write(")"); + w.write(") {"); + } + } + + if (!mi.returnType().isVoid()) { + w.write("return "); + } + + w.write(mangleToJava(mi.name())); + + if (X10TypeMixin.baseType(dispatch.returnType()) instanceof ParameterType) { + w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); + } + + w.write("("); + for (int i = 0; i < mi.formalTypes().size(); i++) { + Type f = mi.formalTypes().get(i); + if (i != 0) { + w.write(","); + w.allowBreak(0, " "); + } + if (def.formalTypes().get(i).get() instanceof ParameterType) { + // FIXME check + if (f.isBoolean() || f.isNumeric()) { + w.write("("); + printType(f, 0); + w.write(")"); + } + + w.write("("); + printType(f, X10PrettyPrinterVisitor.BOX_PRIMITIVES); + w.write(")"); + } + + Name name = Name.make("a" + (i + 1)); + w.write(name.toString()); + } + w.write(")"); + w.write(";"); + if (mi.returnType().isVoid()) { + w.write("return null;"); + } + if (mis.size() != 1) { + w.write("}"); + } + } + + if (mis.size() != 1) { + // TODO + w.write("throw new java.lang.RuntimeException();"); + } + + w.write("}"); + w.newline(); + } } Modified: trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -85,10 +85,12 @@ import polyglot.types.Flags; import polyglot.types.LocalDef; import polyglot.types.LocalInstance; +import polyglot.types.MethodDef; import polyglot.types.MethodInstance; import polyglot.types.MethodInstance_c; import polyglot.types.Name; import polyglot.types.QName; +import polyglot.types.Ref; import polyglot.types.SemanticException; import polyglot.types.Type; import polyglot.types.TypeSystem; @@ -164,6 +166,7 @@ import x10.emitter.Template; import x10.emitter.TryCatchExpander; import x10.emitter.TypeExpander; +import x10.types.ClosureType_c; import x10.types.FunctionType; import x10.types.ParameterType; import x10.types.ParameterType.Variance; @@ -212,8 +215,10 @@ final public Emitter er; public final Type imcType; + public static final String JAVA_LANG_OBJECT = "java.lang.Object"; + public static final boolean isSelfDispatch = true; - private static final String X10_RTT_TYPES = "x10.rtt.Types"; + private static final String X10_RTT_TYPES = "x10.rtt.Types"; private static int nextId_; /* to provide a unique name for local variables introduce in the templates */ @@ -411,7 +416,7 @@ throw new InternalCompilerError("Statement expression uses non-final variable " +li+ "(at " +li.position()+ ") from the outer scope", n.position()); } } - w.write("(new java.lang.Object() { "); + w.write("(new " + JAVA_LANG_OBJECT + "() { "); er.printType(n.type(), PRINT_TYPE_PARAMS); w.write(" eval() {"); w.newline(4); w.begin(0); @@ -489,7 +494,7 @@ // new Object() { T eval(R target, T right) { return (target.f = target.f.add(right)); } }.eval(x, e) Binary.Operator op = n.operator().binaryOperator(); Name methodName = X10Binary_c.binaryMethodName(op); - w.write("new java.lang.Object() {"); + w.write("new " + JAVA_LANG_OBJECT + "() {"); w.allowBreak(0, " "); w.write("final "); er.printType(n.type(), PRINT_TYPE_PARAMS); @@ -818,6 +823,7 @@ sups.add(0, supClassType); } + // FIXME if (sups.size() > 0) { w.write(" extends "); for (int i = 0; i < sups.size(); ++i) { @@ -864,6 +870,7 @@ interfaces.add(tr.nodeFactory().CanonicalTypeNode(n.position(), ts.Any())); } */ + List<Type> alreadyPrintedTypes = new ArrayList<Type>(); if (!interfaces.isEmpty()) { w.allowBreak(2); if (flags.isInterface()) { @@ -876,10 +883,13 @@ w.begin(0); for (Iterator<TypeNode> i = interfaces.iterator(); i.hasNext(); ) { TypeNode tn = (TypeNode) i.next(); - er.printType(tn.type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES | NO_VARIANCE); - if (i.hasNext()) { - w.write(","); - w.allowBreak(0); + if (!isSelfDispatch || (isSelfDispatch && !alreadyPrinted(alreadyPrintedTypes, tn))) { + if (alreadyPrintedTypes.size() != 0) { + w.write(","); + w.allowBreak(0); + } + alreadyPrintedTypes.add(tn.type()); + er.printType(tn.type(), (isSelfDispatch ? 0 : PRINT_TYPE_PARAMS) | BOX_PRIMITIVES | NO_VARIANCE); } } w.end(); @@ -904,6 +914,9 @@ // Generate dispatcher methods. // er.generateDispatchers(def); + if (isSelfDispatch) { + er.generateDispatchMethods(def); + } er.generateBridgeMethods(def); if (n.typeParameters().size() > 0) { @@ -946,6 +959,45 @@ // } } + private boolean alreadyPrinted(List<Type> alreadyPrintedTypes, TypeNode tn) { + boolean alreadyPrinted = false; + Type type = tn.type(); + if (type instanceof FunctionType) { + if (((FunctionType) type).returnType().isVoid()) { + for (Type apt : alreadyPrintedTypes) { + if (apt instanceof FunctionType && ((FunctionType) apt).returnType().isVoid()) { + if (((FunctionType) apt).typeArguments().size() == ((FunctionType) type).typeArguments().size()) { + alreadyPrinted = true; + break; + } + } + } + } else { + for (Type apt : alreadyPrintedTypes) { + if (apt instanceof FunctionType && !((FunctionType) apt).returnType().isVoid()) { + if (((FunctionType) apt).typeArguments().size() == ((FunctionType) type).typeArguments().size()) { + alreadyPrinted = true; + break; + } + } + } + } + } + else if (type instanceof X10ClassType) { + X10ClassType ct = (X10ClassType) type; + if (ct.typeArguments().size() > 0) { + for (Type apt : alreadyPrintedTypes) { + if (apt instanceof X10ClassType && !(apt instanceof FunctionType)) { + if (((X10ClassType) apt).name().toString().equals(((X10ClassType) type).name().toString())) { + alreadyPrinted = true; + break; + } + } + } + } + } + return alreadyPrinted; + } @@ -1061,7 +1113,7 @@ else if (t instanceof ParameterType) { // SYNOPSIS: (#0) #1 #0=param type #1=primitive or object #2=runtime type String regex = - "(new java.lang.Object() {" + + "(new " + JAVA_LANG_OBJECT + "() {" + "final #0 cast(final Object self) {" + "x10.rtt.Type rtt = #2;" + "#0 dep = (#0) x10.rtt.Types.conversion(rtt,self);" + @@ -1076,7 +1128,7 @@ assert !(t.isBoolean() || t.isNumeric() || t.isChar()); // SYNOPSIS: (#0) #1 #0=type #1=object #2=runtime type String regex = - "(new java.lang.Object() {" + + "(new " + JAVA_LANG_OBJECT + "() {" + "final #0 cast(final #0 self) {" + "if (self==null) return null;" + "x10.rtt.Type rtt = #2;" + @@ -1450,18 +1502,32 @@ X10MethodInstance mi = c.closureInstance(); - c.printSubExpr(target, w, tr); - w.write("."); - w.write("apply"); Expr expr = target; if (target instanceof ParExpr) { expr = ((ParExpr) target).expr(); } - if ( - (!(expr instanceof Closure_c) && !mi.returnType().isVoid()) - || (expr instanceof Closure_c && X10TypeMixin.baseType(mi.returnType()) instanceof ParameterType)) { - w.write(RETURN_PARAMETER_TYPE_SUFFIX); + boolean newClosure = expr instanceof Closure_c; + + if (isSelfDispatch && !newClosure && !c.type().isVoid()) { + w.write("("); + w.write("("); + er.printType(c.type(), BOX_PRIMITIVES); + w.write(")"); } + + c.printSubExpr(target, w, tr); + w.write("."); + w.write("apply"); + if (isSelfDispatch && (!newClosure && !mi.returnType().isVoid() && mi.formalTypes().size() == 0)) { + w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); + } + else if ( + !isSelfDispatch + && (!(expr instanceof Closure_c) && !mi.returnType().isVoid()) + || (expr instanceof Closure_c && X10TypeMixin.baseType(mi.returnType()) instanceof ParameterType)) { + w.write(RETURN_PARAMETER_TYPE_SUFFIX); + } + w.write("("); w.begin(0); @@ -1475,16 +1541,24 @@ } List<Expr> l = c.arguments(); - for (Iterator<Expr> i = l.iterator(); i.hasNext(); ) { - Expr e = (Expr) i.next(); + for (int i = 0; i < l.size(); i++) { + Expr e = l.get(i); c.print(e, w, tr); - if (i.hasNext()) { + if (isSelfDispatch && !newClosure) { + w.write(","); + new RuntimeTypeExpander(er, mi.formalTypes().get(i)).expand(); + } + if (i != l.size() - 1) { w.write(","); w.allowBreak(0, " "); } } w.end(); w.write(")"); + + if (isSelfDispatch && !newClosure && !c.type().isVoid()) { + w.write(")"); + } } public void visit(Try_c c) { @@ -1759,7 +1833,7 @@ ex2 }; er.dumpRegex("rail-make", components, tr2, - "(new java.lang.Object() {" + + "(new " + JAVA_LANG_OBJECT + "() {" + "final #0<#1> apply(int length) {" + "#6" + "for (int #5$ = 0; #5$ < length; #5$++) {" + @@ -1855,6 +1929,8 @@ if (xts.isParameterType(t)) { miContainer = new CastExpander(w, er, new TypeExpander(er, mi.container(), false, false, false), miContainer); + } else if (isSelfDispatch && mi.typeParameters().size() > 0) { + miContainer = new CastExpander(w, er, new TypeExpander(er, mi.container(), true, false, false), miContainer); } miContainer = new CastExpander(w, er, miContainer); } @@ -1893,10 +1969,37 @@ } Type returnType = X10TypeMixin.baseType(mi.def().returnType().get()); - if (returnType instanceof ParameterType || (isInstantiateReturn)) { - w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); + if (returnType instanceof ParameterType || isInstantiateReturn) { + if (isSelfDispatch) { + Type tt = X10TypeMixin.baseType(target.type()); + + if (tt instanceof X10ClassType && ((X10ClassType) tt).flags().isInterface()) { + boolean isDispatch = false; + List<Ref<? extends Type>> formalTypes = mi.def().formalTypes(); + for (Ref<? extends Type> ref : formalTypes) { + Type ft = ref.get(); + if (Emitter.containsTypeParam(ft)) { + isDispatch = true; + break; + } + } + // FIXME + if (!isDispatch) { + w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); + } + } + else if (target instanceof ParExpr && ((ParExpr) target).expr() instanceof Closure_c) { + if (mi.formalTypes().size() == 0) { + w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); + } + } + else { + w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); + } + } else { + w.write(X10PrettyPrinterVisitor.RETURN_PARAMETER_TYPE_SUFFIX); + } } - w.write("("); w.begin(0); @@ -1910,8 +2013,10 @@ } List<Expr> exprs = c.arguments(); + MethodDef def = c.methodInstance().def(); for (int i = 0; i < exprs.size(); ++i) { Expr e = exprs.get(i); + Type defType = def.formalTypes().get(i).get(); if (runAsync && e instanceof Closure_c) { c.print(((Closure_c)e).methodContainer(mi), w, tr); } @@ -1921,7 +2026,7 @@ else { if (e.type().isBoolean() || e.type().isNumeric() || e.type().isChar()) { // e.g) m((Integer) a) for m(T a) - if (X10TypeMixin.baseType(c.methodInstance().def().formalTypes().get(i).get()) instanceof ParameterType) { + if (X10TypeMixin.baseType(defType) instanceof ParameterType) { w.write("("); er.printType(e.type(), BOX_PRIMITIVES); w.write(")"); @@ -1975,6 +2080,15 @@ } } + // if I is an interface and val i:I , t = type of the type of the formal of method instance + // i.m(a) => i.m(a,t) + if (isSelfDispatch && X10TypeMixin.baseType(t) instanceof X10ClassType ) { + X10ClassType ct = (X10ClassType) X10TypeMixin.baseType(t); + if ((ct.flags().isInterface() || (xts.isFunctionType(ct) && ct.isAnonymous())) && er.containsTypeParam(defType)){ + w.write(","); + new RuntimeTypeExpander(er, c.methodInstance().formalTypes().get(i)).expand(); + } + } if (i != exprs.size() - 1) { w.write(","); w.allowBreak(0, " "); @@ -1994,16 +2108,10 @@ Translator tr2 = ((X10Translator) tr).inInnerClass(true); tr2 = tr2.context(n.enterScope(tr2.context())); - List<Expander> formals = new ArrayList<Expander>(); List<Expander> typeArgs = new ArrayList<Expander>(); for (final Formal f : n.formals()) { TypeExpander ft = new TypeExpander(er, f.type().type(), PRINT_TYPE_PARAMS | BOX_PRIMITIVES); typeArgs.add(ft); // must box formals - formals.add(new Expander(er) { - public void expand(Translator tr) { - er.printFormal(tr, n, f, false); - } - }); } boolean runAsync = false; @@ -2032,30 +2140,39 @@ w.write("() {"); - if (containsPrimitive(n) || !n.returnType().type().isVoid() && !(X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType)) { + List<Formal> formals = n.formals(); + // bridge + boolean bridge = containsPrimitive(n) || !n.returnType().type().isVoid() && !(X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType); + if (bridge) { w.write("public final "); ret.expand(tr2); w.write(" apply"); - if (!n.returnType().type().isVoid()) { + if (!n.returnType().type().isVoid() && (!isSelfDispatch || (isSelfDispatch && n.formals().size() == 0))) { w.write(RETURN_PARAMETER_TYPE_SUFFIX); } w.write("("); - List<Formal> formals2 = n.formals(); - for (int i = 0; i < formals2.size(); ++i) { + for (int i = 0; i < formals.size(); ++i) { if (i != 0) w.write(","); - er.printFormal(tr2, n, formals2.get(i), true); + er.printFormal(tr2, n, formals.get(i), true); + + if (isSelfDispatch) { + w.write(", "); + w.write(X10_RUNTIME_TYPE_CLASS); + w.write(" "); + w.write("t" + (i + 1)); + } } w.write(") { "); if (!n.returnType().type().isVoid()) { w.write("return "); } w.write("apply"); - if (X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType) { + if (X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType && (!isSelfDispatch || (isSelfDispatch && n.formals().size() == 0))) { w.write(RETURN_PARAMETER_TYPE_SUFFIX); } w.write("("); String delim = ""; - for (Formal f: formals2) { + for (Formal f: formals) { w.write(delim); delim = ","; if (f.type().type().isBoolean() || f.type().type().isNumeric() || f.type().type().isChar()) { @@ -2073,11 +2190,21 @@ w.write("public final "); new TypeExpander(er, n.returnType().type(), true, false, false).expand(tr2); w.write(" apply"); - if (X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType) { + if (X10TypeMixin.baseType(n.returnType().type()) instanceof ParameterType && (!isSelfDispatch || (isSelfDispatch && n.formals().size() == 0))) { w.write(RETURN_PARAMETER_TYPE_SUFFIX); } w.write("("); - new Join(er, ", ", formals).expand(tr2); + for (int i = 0; i < formals.size(); i++) { + if (i != 0) w.write(", "); + er.printFormal(tr2, n, formals.get(i), false); + if (isSelfDispatch && !bridge) { + w.write(", "); + w.write(X10_RUNTIME_TYPE_CLASS); + w.write(" "); + w.write("t" + (i + 1)); + } + } + w.write(") { "); List<Stmt> statements = n.body().statements(); @@ -2423,7 +2550,7 @@ }, tr, regex); } else { // SYNOPSIS: for (#0 #2: #1 in #3) #4 #5=unboxed type - String regex = "for (x10.core.Iterator #2__ = (#3).iterator(); #2__.hasNext(); ) { #0 #1 #2 = (#5) #2__.next$G(); #4 }"; + String regex = "for (x10.lang.Iterator #2__ = (#3).iterator(); #2__.hasNext(); ) { #0 #1 #2 = (#5) #2__.next$G(); #4 }"; er.dumpRegex("forloop", new Object[] { form.flags(), form.type(), @@ -2667,7 +2794,7 @@ return; } - w.write("new java.lang.Object() {"); + w.write("new " + JAVA_LANG_OBJECT + "() {"); w.allowBreak(0, " "); w.write("final "); er.printType(n.type(), PRINT_TYPE_PARAMS); @@ -2804,7 +2931,7 @@ // TODO: handle type args // TODO: handle setter method - w.write("new java.lang.Object() {"); + w.write("new " + JAVA_LANG_OBJECT + "() {"); w.allowBreak(0, " "); w.write("final "); er.printType(t, PRINT_TYPE_PARAMS); Modified: trunk/x10.compiler/src/x10c/visit/InlineHelper.java =================================================================== --- trunk/x10.compiler/src/x10c/visit/InlineHelper.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.compiler/src/x10c/visit/InlineHelper.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -219,7 +219,13 @@ excTypes.add(tn.typeRef()); } - Expr call = xnf.Call(pos, xnf.Local(pos, xnf.Id(pos, cd.name())).type(cd.asType()), mdcl.name(), args).methodInstance(mdcl.methodDef().asInstance()).type(mdcl.returnType().type()); + Expr call; + if (mdcl.flags().flags().isStatic()) { + call = xnf.Call(pos, xnf.CanonicalTypeNode(pos, cd.asType()), mdcl.name(), args).methodInstance(mdcl.methodDef().asInstance()).type(mdcl.returnType().type()); + } else { + call = xnf.Call(pos, xnf.Local(pos, xnf.Id(pos, cd.name())).type(cd.asType()), mdcl.name(), args).methodInstance(mdcl.methodDef().asInstance()).type(mdcl.returnType().type()); + } + Block body; if (mdcl.returnType().type().isVoid()) { body = xnf.Block(pos, xnf.Eval(pos, call)); Modified: trunk/x10.compiler/src/x10c/visit/JavaCaster.java =================================================================== --- trunk/x10.compiler/src/x10c/visit/JavaCaster.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.compiler/src/x10c/visit/JavaCaster.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -25,9 +25,12 @@ import polyglot.ast.Node; import polyglot.ast.NodeFactory; import polyglot.ast.NullLit; +import polyglot.ast.Receiver; import polyglot.ast.Stmt; +import polyglot.ast.TypeNode; import polyglot.frontend.Job; import polyglot.types.QName; +import polyglot.types.Ref; import polyglot.types.SemanticException; import polyglot.types.Type; import polyglot.types.TypeSystem; @@ -38,12 +41,14 @@ import x10.ast.X10Call; import x10.ast.X10NodeFactory; import x10.ast.X10Return_c; +import x10.emitter.Emitter; import x10.types.ParameterType; import x10.types.X10ClassType; import x10.types.X10ParsedClassType_c; import x10.types.X10TypeMixin; import x10.types.X10TypeSystem; import x10.types.constraints.SubtypeConstraint; +import x10.visit.X10PrettyPrinterVisitor; // add cast node for java code generator public class JavaCaster extends ContextVisitor { @@ -73,9 +78,44 @@ protected Node leaveCall(Node parent, Node old, Node n, NodeVisitor v) throws SemanticException { n = typeConstraintsCast(parent, old, n); n = railAccessCast(parent, n); + if (X10PrettyPrinterVisitor.isSelfDispatch) { + n = typeParamCast(parent, n); + } return n; } + private Node typeParamCast(Node parent, Node n) throws SemanticException { + if (n instanceof X10Call && !(parent instanceof Eval)) { + X10Call call = (X10Call) n; + Receiver target = call.target(); + if (!(target instanceof TypeNode) && !xts.isRail(call.target().type())) { + Type bt = X10TypeMixin.baseType(target.type()); + if (bt instanceof X10ClassType) { + if (((X10ClassType) bt).typeArguments().size() > 0) { + boolean isDispatch = false; + if (((X10ClassType) bt).flags().isInterface()) { + List<Ref<? extends Type>> formalTypes = call.methodInstance().def().formalTypes(); + for (Ref<? extends Type> ref : formalTypes) { + Type type = ref.get(); + if (Emitter.containsTypeParam(type)) { + isDispatch = true; + break; + } + } + } + if (isDispatch) { + return cast(call, call.type()); + } + else if (Emitter.containsTypeParam(call.methodInstance().def().returnType().get())) { + return cast(call, call.type()); + } + } + } + } + } + return n; + } + private Node railAccessCast(Node parent, Node n) throws SemanticException { if (n instanceof X10Call) { X10Call call = (X10Call) n; Modified: trunk/x10.runtime/src-java/x10/core/AnyRail.java =================================================================== --- trunk/x10.runtime/src-java/x10/core/AnyRail.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.runtime/src-java/x10/core/AnyRail.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -11,7 +11,7 @@ package x10.core; -public interface AnyRail<T> extends Indexable<Integer,T>, Iterable<T> { +public interface AnyRail<T> extends x10.lang.Indexable<Integer,T>, x10.lang.Iterable<T> { // Methods to get the backing array. May be called by generated code. public Object getBackingArray(); Modified: trunk/x10.runtime/src-java/x10/core/GrowableRail.java =================================================================== --- trunk/x10.runtime/src-java/x10/core/GrowableRail.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.runtime/src-java/x10/core/GrowableRail.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -14,12 +14,12 @@ import x10.rtt.ParameterizedType; import x10.rtt.RuntimeType; +import x10.rtt.RuntimeType.Variance; import x10.rtt.Type; import x10.rtt.Types; import x10.rtt.UnresolvedType; -import x10.rtt.RuntimeType.Variance; -public final class GrowableRail<T> extends Ref implements Indexable<Integer,T>, Iterable<T>, Settable<Integer, T> { +public final class GrowableRail<T> extends Ref implements x10.lang.Indexable<Integer,T>, x10.lang.Iterable<T>, x10.lang.Settable<Integer, T> { private Type<T> elementType; private Object array; private int length; @@ -46,7 +46,7 @@ this.length = 0; } - public T set$G(T v, Integer i) { + public T set(T v, Type t1, Integer i, Type t2) { return set$G(v, (int)i); } @@ -104,11 +104,11 @@ return RailFactory.makeValRailFromJavaArray(elementType, tmp); } - public Iterator<T> iterator() { + public x10.lang.Iterator<T> iterator() { return new RailIterator(); } - protected class RailIterator implements Iterator<T> { + protected class RailIterator implements x10.lang.Iterator<T> { int i = 0; public boolean hasNext() { @@ -141,8 +141,8 @@ array = tmp; } - public T apply$G(Integer i) { - return apply$G((int)i); + public T apply(Object i, Type t) { + return apply$G((int)(Integer)i); } public T apply$G(int i) { /* @@ -180,9 +180,9 @@ GrowableRail.class, new Variance[] {Variance.INVARIANT}, new Type<?>[] { - new ParameterizedType(Indexable._RTT, Types.INT, new UnresolvedType(0)), - new ParameterizedType(Iterable._RTT, new UnresolvedType(0)), - new ParameterizedType(Settable._RTT, Types.INT, new UnresolvedType(0)) + new ParameterizedType(x10.lang.Indexable._RTT, Types.INT, new UnresolvedType(0)), + new ParameterizedType(x10.lang.Iterable._RTT, new UnresolvedType(0)), + new ParameterizedType(x10.lang.Settable._RTT, Types.INT, new UnresolvedType(0)) } ) { @Override Deleted: trunk/x10.runtime/src-java/x10/core/Indexable.java =================================================================== --- trunk/x10.runtime/src-java/x10/core/Indexable.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.runtime/src-java/x10/core/Indexable.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -1,36 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -package x10.core; - -import x10.core.fun.Fun_0_1; -import x10.rtt.ParameterizedType; -import x10.rtt.RuntimeType; -import x10.rtt.Type; -import x10.rtt.UnresolvedType; -import x10.rtt.RuntimeType.Variance; - -public interface Indexable<D,R> extends Fun_0_1<D,R> { - - public static final RuntimeType<Indexable<?,?>> _RTT = new RuntimeType<Indexable<?,?>>( - Indexable.class, - new Variance[] {Variance.CONTRAVARIANT, Variance.COVARIANT}, - new Type<?>[] { - new ParameterizedType(Fun_0_1._RTT, new UnresolvedType(0), new UnresolvedType(1)) - } - ) { - @Override - public String typeName() { - return "x10.lang.Indexable"; - } - }; - -} Deleted: trunk/x10.runtime/src-java/x10/core/Iterable.java =================================================================== --- trunk/x10.runtime/src-java/x10/core/Iterable.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.runtime/src-java/x10/core/Iterable.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -1,30 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -package x10.core; - -import x10.rtt.RuntimeType; -import x10.rtt.RuntimeType.Variance; - -public interface Iterable<T> { - Iterator<T> iterator(); - - public static final RuntimeType<Iterable<?>> _RTT = new RuntimeType<Iterable<?>>( - Iterable.class, - new Variance[] {Variance.COVARIANT} - ) { - @Override - public String typeName() { - return "x10.lang.Iterable"; - } - }; - -} Deleted: trunk/x10.runtime/src-java/x10/core/Iterator.java =================================================================== --- trunk/x10.runtime/src-java/x10/core/Iterator.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.runtime/src-java/x10/core/Iterator.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -1,31 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -package x10.core; - -import x10.rtt.RuntimeType; -import x10.rtt.RuntimeType.Variance; - -/** Just like java.util.Iterator, but without remove(). */ -public interface Iterator<T> { - public boolean hasNext(); - public T next$G(); - - public static final RuntimeType<Iterator<?>> _RTT = new RuntimeType<Iterator<?>>( - Iterator.class, - new Variance[] {Variance.COVARIANT} - ) { - @Override - public String typeName() { - return "x10.lang.Iterator"; - } - }; -} Modified: trunk/x10.runtime/src-java/x10/core/Rail.java =================================================================== --- trunk/x10.runtime/src-java/x10/core/Rail.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.runtime/src-java/x10/core/Rail.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -21,7 +21,7 @@ import x10.rtt.UnresolvedType; import x10.rtt.RuntimeType.Variance; -public final class Rail<T> extends Ref implements AnyRail<T>, Settable<Integer,T> { +public final class Rail<T> extends Ref implements AnyRail<T>, x10.lang.Settable<Integer,T> { public final int length; public final Object value; @@ -49,11 +49,11 @@ System.arraycopy(src.value, src_off, value, dst_off, len); } - public Iterator<T> iterator() { + public x10.lang.Iterator<T> iterator() { return new RailIterator(); } - protected class RailIterator implements Iterator<T> { + protected class RailIterator implements x10.lang.Iterator<T> { int i = 0; public boolean hasNext() { @@ -126,8 +126,8 @@ return length; } - public T apply$G(Integer i) { - return apply$G((int)i); + public T apply(Object i, Type t) { + return apply$G((int)(Integer)i); } public T apply$G(int i) { @@ -158,7 +158,7 @@ return sb.toString(); } - public T set$G(T v, Integer i) { + public T set(T v, Type t1, Integer i, Type t2) { return set$G(v, (int)i); } @@ -172,7 +172,7 @@ public void reset(Fun_0_1<Integer,T> v) { for (int i=0; i<length; i++) { - set$G(v.apply$G(i), i); + set$G(v.apply(i, Types.INT), i); } } @@ -210,9 +210,9 @@ Rail.class, new Variance[] {Variance.INVARIANT}, new Type<?>[] { - new ParameterizedType(Indexable._RTT, Types.INT, new UnresolvedType(0)), - new ParameterizedType(Iterable._RTT, new UnresolvedType(0)), - new ParameterizedType(Settable._RTT, Types.INT, new UnresolvedType(0)) + new ParameterizedType(x10.lang.Indexable._RTT, Types.INT, new UnresolvedType(0)), + new ParameterizedType(x10.lang.Iterable._RTT, new UnresolvedType(0)), + new ParameterizedType(x10.lang.Settable._RTT, Types.INT, new UnresolvedType(0)) } ) { @Override Modified: trunk/x10.runtime/src-java/x10/core/RailFactory.java =================================================================== --- trunk/x10.runtime/src-java/x10/core/RailFactory.java 2010-09-22 04:24:05 UTC (rev 16616) +++ trunk/x10.runtime/src-java/x10/core/RailFactory.java 2010-09-22 06:13:21 UTC (rev 16617) @@ -120,47 +120,47 @@ if (value instanceof int[]) { int[] typed_value = (int[]) value; for (int i = 0; i < typed_value.length; i++) { - typed_value[i] = (Integer) init.apply$G(i); + typed_value[i] = (Integer) init.apply(i, Types.INT); } } else if (value instanceof long[]) { long[] typed_value = (long[]) value; for (int i = 0; i < typed_value.length; i++) { - typed_value[i] = (Long) init.apply$G(i); + typed_value[i] = (Long) init.apply(i, Types.INT); } } else if (value instanceof float[]) { float[] typed_value = (float[]) value; for (int i = 0; i < typed_value.length; i++) { - typed_value[i] = (Float) init.apply$G(i); + typed_value[i] = (Float) init.apply(i, Types.INT); } } else if (value instanceof double[]) { double[] typed_value = (double[]) value; for (int i = 0; i < typed_value.length; i++) { - typed_value[i] = (Double) init.apply$G(i); + typed_value[i] = (Double) init.apply(i, Types.INT); } } else if (value instanceof byte[]) { byte[] typed_value = (byte[]) value; for (int i = 0; i < typed_value.length; i++) { - typed_value[i] = (Byte) i... [truncated message content] |
From: <mt...@us...> - 2010-09-22 08:09:57
|
Revision: 16619 http://x10.svn.sourceforge.net/x10/?rev=16619&view=rev Author: mtake Date: 2010-09-22 08:09:51 +0000 (Wed, 22 Sep 2010) Log Message: ----------- Implement custom serialization Modified Paths: -------------- trunk/x10.compiler/src/x10/emitter/Emitter.java trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java Added Paths: ----------- trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 Modified: trunk/x10.compiler/src/x10/emitter/Emitter.java =================================================================== --- trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-22 06:56:17 UTC (rev 16618) +++ trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-22 08:09:51 UTC (rev 16619) @@ -2212,6 +2212,24 @@ } } + public void generateCustomSerializer(X10ClassDef def) { + String fieldName = "__serialized__"; + w.write("// custom serializer"); + w.newline(); + w.write("private Object " + fieldName + ";"); + w.newline(); + w.write("private Object writeReplace() { " + fieldName + " = serialize(); return this; }"); + w.newline(); + w.write("private Object readResolve() { return new "); + printType(def.asType(), X10PrettyPrinterVisitor.BOX_PRIMITIVES | X10PrettyPrinterVisitor.NO_QUALIFIER); + w.write("(" + fieldName + "); }"); + w.newline(); + w.write("private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException { oos.writeObject(" + fieldName + "); }"); + w.newline(); + w.write("private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException { " + fieldName + " = ois.readObject(); }"); + w.newline(); + } + private void printParents(X10ClassDef def, Type type) { if (type instanceof ConstrainedType_c) { type = ((ConstrainedType_c) type).baseType().get(); Modified: trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-22 06:56:17 UTC (rev 16618) +++ trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-22 08:09:51 UTC (rev 16619) @@ -719,6 +719,15 @@ } + private boolean hasCustomSerializer(X10ClassDecl_c n) { + boolean hasCustomSerializer = false; + for (TypeNode tn: n.interfaces()) { + if ("x10.io.CustomSerialization".equals(tn.type().toString())) { + hasCustomSerializer = true; + } + } + return hasCustomSerializer; + } public void visit(X10ClassDecl_c n) { String className = n.classDef().name().toString(); @@ -911,6 +920,10 @@ // XTENLANG-1102 er.generateRTTInstance(def); + if (hasCustomSerializer(n)) { + er.generateCustomSerializer(def); + } + // Generate dispatcher methods. // er.generateDispatchers(def); Added: trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 (rev 0) +++ trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 2010-09-22 08:09:51 UTC (rev 16619) @@ -0,0 +1,16 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +package x10.io; + +public interface CustomSerialization { + def serialize(): Any; +} Property changes on: trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vj...@us...> - 2010-09-22 11:17:17
|
Revision: 16623 http://x10.svn.sourceforge.net/x10/?rev=16623&view=rev Author: vj0 Date: 2010-09-22 11:17:08 +0000 (Wed, 22 Sep 2010) Log Message: ----------- Support anonymous clocks for 2.1. Added translation to explicit named clock construct in Desugarer. Check that a clocked async can only occur inside a lexically enclosing clocked finish. Do not use the anonymous clocked statements if you want to name the clock, e.g. you want anactivity clocked on multiple clocks, or you want to pass the clock into a method. Introduce resume statement (like the next statement)-- resumes on all the clocks the activity is registered on. Modified Paths: -------------- trunk/x10.compiler/src/x10/ast/Async.java trunk/x10.compiler/src/x10/ast/Async_c.java trunk/x10.compiler/src/x10/ast/Finish.java trunk/x10.compiler/src/x10/ast/Finish_c.java trunk/x10.compiler/src/x10/ast/Next_c.java trunk/x10.compiler/src/x10/ast/X10NodeFactory.java trunk/x10.compiler/src/x10/ast/X10NodeFactory_c.java trunk/x10.compiler/src/x10/parser/X10KWLexer.gi trunk/x10.compiler/src/x10/parser/X10KWLexer.java trunk/x10.compiler/src/x10/parser/X10KWLexerprs.java trunk/x10.compiler/src/x10/parser/X10KWLexersym.java trunk/x10.compiler/src/x10/parser/X10Lexer.java trunk/x10.compiler/src/x10/parser/X10Parser.java trunk/x10.compiler/src/x10/parser/X10Parserprs.java trunk/x10.compiler/src/x10/parser/X10Parsersym.java trunk/x10.compiler/src/x10/parser/x10.g trunk/x10.compiler/src/x10/types/X10Context.java trunk/x10.compiler/src/x10/types/X10Context_c.java trunk/x10.compiler/src/x10/visit/Desugarer.java trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 Added Paths: ----------- trunk/x10.compiler/src/x10/ast/Resume.java trunk/x10.compiler/src/x10/ast/Resume_c.java Modified: trunk/x10.compiler/src/x10/ast/Async.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Async.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/ast/Async.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -27,4 +27,6 @@ /** Get the body of the Async. */ Stmt body(); + + boolean clocked(); } Modified: trunk/x10.compiler/src/x10/ast/Async_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Async_c.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/ast/Async_c.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -89,6 +89,7 @@ this.clocks = new ArrayList<Expr>(); } + public boolean clocked() { return clocked;} public Async_c(Position p) { super(p); } @@ -191,6 +192,9 @@ if (c.inSequentialCode()) Errors.issue(tc.job(), new SemanticException("async may not be invoked in sequential code.", position())); + if (clocked() && ! c.inClockedFinishScope()) + Errors.issue(tc.job(), + new SemanticException("clocked async must be invoked inside a statically enclosing clocked finish.", position())); for (Expr e : clocks()) { Type t = e.type(); Modified: trunk/x10.compiler/src/x10/ast/Finish.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Finish.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/ast/Finish.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -20,5 +20,6 @@ */ public interface Finish extends CompoundStmt { Stmt body(); + boolean clocked(); } Modified: trunk/x10.compiler/src/x10/ast/Finish_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Finish_c.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/ast/Finish_c.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -45,7 +45,9 @@ this.clocked = clocked; } - + public boolean clocked() { + return clocked; + } /* (non-Javadoc) * @see x10.ast.Finish#body() */ @@ -66,7 +68,7 @@ /** Write the statement to an output file. */ public void prettyPrint(CodeWriter w, PrettyPrinter tr) { - w.write("finish "); + w.write((clocked ? "clocked " : "") + "finish "); printSubStmt(body, w, tr); } Modified: trunk/x10.compiler/src/x10/ast/Next_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Next_c.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/ast/Next_c.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -25,21 +25,15 @@ public class Next_c extends Stmt_c implements Next { - public Next_c(Position p) { super(p); } - - - public Term firstChild() { - // TODO: return null; } public <S> List<S> acceptCFG(CFGBuilder v, List<S> succs) { - // TODO: return succs; } public Node typeCheck(ContextVisitor tc) throws SemanticException { Added: trunk/x10.compiler/src/x10/ast/Resume.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Resume.java (rev 0) +++ trunk/x10.compiler/src/x10/ast/Resume.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -0,0 +1,22 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +package x10.ast; + +import polyglot.ast.Stmt; + +/** The node constructed for the X10 construct resume; + * @author vj + */ +public interface Resume extends Stmt +{ + +} Property changes on: trunk/x10.compiler/src/x10/ast/Resume.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/x10.compiler/src/x10/ast/Resume_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Resume_c.java (rev 0) +++ trunk/x10.compiler/src/x10/ast/Resume_c.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -0,0 +1,45 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +package x10.ast; + +import java.util.List; + +import polyglot.ast.Node; +import polyglot.ast.Term; +import polyglot.ast.Stmt_c; +import polyglot.types.SemanticException; +import polyglot.types.TypeSystem; +import polyglot.util.Position; +import polyglot.visit.CFGBuilder; +import polyglot.visit.ContextVisitor; +import x10.types.X10Context; + +public class Resume_c extends Stmt_c implements Resume { + + public Resume_c(Position p) { + super(p); + } + + public Term firstChild() { + return null; + } + + public <S> List<S> acceptCFG(CFGBuilder v, List<S> succs) { + return succs; + } + public Node typeCheck(ContextVisitor tc) throws SemanticException { + X10Context c = (X10Context) tc.context(); + if (c.inNonBlockingCode()) + throw new SemanticException("The resume statement cannot be used in nonblocking code.", position()); + return super.typeCheck(tc); + } +} Property changes on: trunk/x10.compiler/src/x10/ast/Resume_c.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/x10.compiler/src/x10/ast/X10NodeFactory.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10NodeFactory.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/ast/X10NodeFactory.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -107,6 +107,7 @@ When When(Position pos, Expr expr, Stmt statement); Next Next(Position pos); + Resume Resume(Position pos); X10ClassDecl X10ClassDecl(Position pos, FlagsNode flags, Id name, List<TypeParamNode> typeParameters, Modified: trunk/x10.compiler/src/x10/ast/X10NodeFactory_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10NodeFactory_c.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/ast/X10NodeFactory_c.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -300,6 +300,11 @@ n = (Next) n.ext(extFactory().extStmt()); return (Next) n.del(delFactory().delStmt()); } + public Resume Resume(Position pos) { + Resume n = new Resume_c(pos); + n = (Resume) n.ext(extFactory().extStmt()); + return (Resume) n.del(delFactory().delStmt()); + } public Offer Offer(Position pos, Expr e) { Offer n = new Offer_c(pos,e); Modified: trunk/x10.compiler/src/x10/parser/X10KWLexer.gi =================================================================== --- trunk/x10.compiler/src/x10/parser/X10KWLexer.gi 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/parser/X10KWLexer.gi 2010-09-22 11:17:08 UTC (rev 16623) @@ -122,6 +122,7 @@ property protected public + resume return safe self @@ -385,6 +386,11 @@ $setResult($_public); $EndAction ./ + | r e s u m e + /.$BeginAction + $setResult($_resume); + $EndAction + ./ | r e t u r n /.$BeginAction $setResult($_return); Modified: trunk/x10.compiler/src/x10/parser/X10KWLexer.java =================================================================== --- trunk/x10.compiler/src/x10/parser/X10KWLexer.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/parser/X10KWLexer.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -17,7 +17,7 @@ public class X10KWLexer extends X10KWLexerprs { private char[] inputChars; - private final int keywordKind[] = new int[67 + 1]; + private final int keywordKind[] = new int[68 + 1]; public int[] getKeywordKinds() { return keywordKind; } @@ -427,138 +427,145 @@ // - // Rule 49: KeyWord ::= r e t u r n + // Rule 49: KeyWord ::= r e s u m e // - keywordKind[49] = (X10Parsersym.TK_return); + keywordKind[49] = (X10Parsersym.TK_resume); // - // Rule 50: KeyWord ::= s a f e + // Rule 50: KeyWord ::= r e t u r n // - keywordKind[50] = (X10Parsersym.TK_safe); + keywordKind[50] = (X10Parsersym.TK_return); // - // Rule 51: KeyWord ::= s e l f + // Rule 51: KeyWord ::= s a f e // - keywordKind[51] = (X10Parsersym.TK_self); + keywordKind[51] = (X10Parsersym.TK_safe); // - // Rule 52: KeyWord ::= s e q u e n t i a l + // Rule 52: KeyWord ::= s e l f // - keywordKind[52] = (X10Parsersym.TK_sequential); + keywordKind[52] = (X10Parsersym.TK_self); // - // Rule 53: KeyWord ::= s t a t i c + // Rule 53: KeyWord ::= s e q u e n t i a l // - keywordKind[53] = (X10Parsersym.TK_static); + keywordKind[53] = (X10Parsersym.TK_sequential); // - // Rule 54: KeyWord ::= s t r u c t + // Rule 54: KeyWord ::= s t a t i c // - keywordKind[54] = (X10Parsersym.TK_struct); + keywordKind[54] = (X10Parsersym.TK_static); // - // Rule 55: KeyWord ::= s u p e r + // Rule 55: KeyWord ::= s t r u c t // - keywordKind[55] = (X10Parsersym.TK_super); + keywordKind[55] = (X10Parsersym.TK_struct); // - // Rule 56: KeyWord ::= s w i t c h + // Rule 56: KeyWord ::= s u p e r // - keywordKind[56] = (X10Parsersym.TK_switch); + keywordKind[56] = (X10Parsersym.TK_super); // - // Rule 57: KeyWord ::= t h i s + // Rule 57: KeyWord ::= s w i t c h // - keywordKind[57] = (X10Parsersym.TK_this); + keywordKind[57] = (X10Parsersym.TK_switch); // - // Rule 58: KeyWord ::= t h r o w + // Rule 58: KeyWord ::= t h i s // - keywordKind[58] = (X10Parsersym.TK_throw); + keywordKind[58] = (X10Parsersym.TK_this); // - // Rule 59: KeyWord ::= t h r o w s + // Rule 59: KeyWord ::= t h r o w // - keywordKind[59] = (X10Parsersym.TK_throws); + keywordKind[59] = (X10Parsersym.TK_throw); // - // Rule 60: KeyWord ::= t r a n s i e n t + // Rule 60: KeyWord ::= t h r o w s // - keywordKind[60] = (X10Parsersym.TK_transient); + keywordKind[60] = (X10Parsersym.TK_throws); // - // Rule 61: KeyWord ::= t r u e + // Rule 61: KeyWord ::= t r a n s i e n t // - keywordKind[61] = (X10Parsersym.TK_true); + keywordKind[61] = (X10Parsersym.TK_transient); // - // Rule 62: KeyWord ::= t r y + // Rule 62: KeyWord ::= t r u e // - keywordKind[62] = (X10Parsersym.TK_try); + keywordKind[62] = (X10Parsersym.TK_true); // - // Rule 63: KeyWord ::= t y p e + // Rule 63: KeyWord ::= t r y // - keywordKind[63] = (X10Parsersym.TK_type); + keywordKind[63] = (X10Parsersym.TK_try); // - // Rule 64: KeyWord ::= v a l + // Rule 64: KeyWord ::= t y p e // - keywordKind[64] = (X10Parsersym.TK_val); + keywordKind[64] = (X10Parsersym.TK_type); // - // Rule 65: KeyWord ::= v a r + // Rule 65: KeyWord ::= v a l // - keywordKind[65] = (X10Parsersym.TK_var); + keywordKind[65] = (X10Parsersym.TK_val); // - // Rule 66: KeyWord ::= w h e n + // Rule 66: KeyWord ::= v a r // - keywordKind[66] = (X10Parsersym.TK_when); + keywordKind[66] = (X10Parsersym.TK_var); // - // Rule 67: KeyWord ::= w h i l e + // Rule 67: KeyWord ::= w h e n // - keywordKind[67] = (X10Parsersym.TK_while); + keywordKind[67] = (X10Parsersym.TK_when); + // + // Rule 68: KeyWord ::= w h i l e + // + + keywordKind[68] = (X10Parsersym.TK_while); + + for (int i = 0; i < keywordKind.length; i++) { if (keywordKind[i] == 0) Modified: trunk/x10.compiler/src/x10/parser/X10KWLexerprs.java =================================================================== --- trunk/x10.compiler/src/x10/parser/X10KWLexerprs.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/parser/X10KWLexerprs.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -24,19 +24,19 @@ public final static int MAX_NAME_LENGTH = 0; public final int getMaxNameLength() { return MAX_NAME_LENGTH; } - public final static int NUM_STATES = 221; + public final static int NUM_STATES = 224; public final int getNumStates() { return NUM_STATES; } public final static int NT_OFFSET = 27; public final int getNtOffset() { return NT_OFFSET; } - public final static int LA_STATE_OFFSET = 359; + public final static int LA_STATE_OFFSET = 364; public final int getLaStateOffset() { return LA_STATE_OFFSET; } public final static int MAX_LA = 1; public final int getMaxLa() { return MAX_LA; } - public final static int NUM_RULES = 67; + public final static int NUM_RULES = 68; public final int getNumRules() { return NUM_RULES; } public final static int NUM_NONTERMINALS = 2; @@ -48,7 +48,7 @@ public final static int SEGMENT_SIZE = 8192; public final int getSegmentSize() { return SEGMENT_SIZE; } - public final static int START_STATE = 68; + public final static int START_STATE = 69; public final int getStartState() { return START_STATE; } public final static int IDENTIFIER_SYMBOL = 0; @@ -60,10 +60,10 @@ public final static int EOLT_SYMBOL = 28; public final int getEoltSymbol() { return EOLT_SYMBOL; } - public final static int ACCEPT_ACTION = 291; + public final static int ACCEPT_ACTION = 295; public final int getAcceptAction() { return ACCEPT_ACTION; } - public final static int ERROR_ACTION = 292; + public final static int ERROR_ACTION = 296; public final int getErrorAction() { return ERROR_ACTION; } public final static boolean BACKTRACK = false; @@ -107,9 +107,9 @@ 5,5,7,8,3,7,2,4,7,6, 5,5,7,6,3,7,6,4,4,2, 10,6,2,10,9,6,3,4,11,4, - 5,6,8,7,7,8,9,6,6,4, - 4,10,6,6,5,6,4,5,6,9, - 4,3,4,3,3,4,5 + 5,6,8,7,7,8,9,6,6,6, + 4,4,10,6,6,5,6,4,5,6, + 9,4,3,4,3,3,4,5 }; }; public final static byte baseCheck[] = BaseCheck.baseCheck; @@ -125,30 +125,30 @@ 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,70, - 112,7,126,42,24,133,44,62,29,53, - 135,69,58,72,80,28,18,35,82,88, - 70,54,89,130,138,96,97,140,63,141, - 77,142,143,146,148,153,85,159,102,149, - 158,164,145,165,167,170,171,172,168,175, - 106,105,177,181,114,111,183,186,187,188, - 195,190,193,198,199,204,200,207,202,208, - 210,213,215,118,216,217,218,223,220,227, - 228,231,232,235,117,243,229,234,245,122, - 247,250,252,254,256,259,260,261,262,267, - 265,248,272,271,276,279,282,280,273,285, - 287,292,284,294,296,298,301,303,305,306, - 310,311,312,299,316,314,319,324,326,327, - 328,331,332,45,322,335,338,339,340,341, - 343,342,349,350,348,358,356,359,361,364, - 363,369,370,373,375,379,382,13,385,381, - 386,371,388,390,391,392,394,398,395,401, - 402,404,405,410,414,416,406,418,423,424, - 427,428,431,434,436,432,438,441,440,446, - 439,448,449,451,450,454,455,456,458,468, - 459,466,461,473,474,464,481,477,483,484, - 486,488,489,491,492,493,495,496,498,500, - 292,292 + 1,1,1,1,1,1,1,1,1,1, + 71,8,129,18,41,24,134,46,30,28, + 43,140,62,56,53,73,61,143,32,79, + 82,111,67,81,137,144,91,92,75,96, + 145,93,148,149,151,152,12,97,153,104, + 156,157,162,165,167,166,169,177,168,172, + 178,105,112,180,182,118,121,183,187,189, + 190,192,195,196,199,198,201,205,207,208, + 210,211,213,214,220,122,215,217,226,228, + 231,218,221,232,234,240,100,243,239,245, + 246,130,248,250,254,256,261,252,257,264, + 265,268,267,269,272,273,277,280,283,274, + 36,285,286,287,288,294,292,298,299,300, + 302,304,306,310,311,305,314,316,319,317, + 323,325,326,327,330,333,123,331,335,338, + 340,339,341,346,347,343,353,350,351,358, + 361,362,363,364,368,369,371,373,374,378, + 381,384,385,386,388,389,392,393,394,395, + 399,397,400,402,408,407,410,411,420,412, + 414,422,423,428,430,431,434,437,439,435, + 441,443,442,449,444,451,453,452,455,456, + 459,461,462,463,460,472,467,473,480,470, + 482,485,488,489,475,491,494,496,497,498, + 501,502,503,504,296,296 }; }; public final static char baseAction[] = BaseAction.baseAction; @@ -158,59 +158,60 @@ public interface TermCheck { public final static byte termCheck[] = {0, - 0,1,2,3,4,5,0,7,8,9, - 10,11,0,13,14,15,16,0,18,13, - 20,4,22,0,1,2,3,0,0,1, - 3,3,20,6,0,12,2,10,10,16, - 12,0,8,0,0,4,3,4,4,15, - 16,7,0,0,13,12,3,0,17,7, - 3,0,0,11,2,12,9,10,0,0, - 17,0,11,21,6,14,0,6,10,0, - 1,0,1,14,0,9,10,0,0,10, - 9,4,4,6,23,0,0,9,3,4, - 16,0,6,2,0,0,2,23,3,8, - 0,0,8,0,1,10,0,0,8,2, - 24,0,6,10,3,0,10,17,3,0, - 9,14,0,1,0,1,25,0,9,0, - 0,0,0,1,0,0,5,0,0,0, - 11,14,0,6,10,15,11,0,0,7, - 2,4,14,0,0,2,0,0,4,0, - 0,0,2,7,0,6,0,1,11,8, - 0,7,0,3,0,0,0,0,1,0, - 8,6,0,7,0,1,7,0,0,0, - 2,0,10,0,1,8,0,0,2,0, - 1,12,0,12,0,0,0,0,11,0, - 6,4,0,1,12,6,0,0,0,2, - 0,0,1,0,0,19,2,22,10,9, - 0,15,0,1,0,1,0,0,15,0, - 1,0,1,0,8,0,3,2,0,0, - 0,0,1,5,0,5,0,8,21,3, - 0,0,0,9,3,0,1,7,0,0, - 2,0,1,0,0,0,0,8,16,5, - 4,0,9,0,1,0,5,0,0,4, - 0,1,0,1,0,0,9,3,3,0, - 0,0,3,0,4,0,3,6,0,4, - 22,0,4,0,1,0,0,0,3,3, - 0,0,1,12,0,8,6,0,0,0, - 0,0,0,9,2,0,8,0,0,0, - 9,4,13,5,5,0,19,0,0,19, - 0,4,0,0,9,2,8,5,0,0, - 0,1,0,13,0,7,7,5,0,5, - 0,0,4,2,0,0,2,0,8,0, - 0,0,2,0,0,10,7,0,11,6, - 0,0,5,0,0,0,6,13,7,0, - 6,0,21,0,1,0,7,0,13,2, - 5,18,0,0,1,3,0,0,2,2, - 0,0,2,0,1,0,1,0,0,0, - 0,10,5,3,5,0,1,0,0,0, - 0,13,2,0,0,0,8,0,0,5, - 0,12,7,0,17,0,9,0,1,4, - 7,18,0,0,1,17,0,5,2,19, - 0,1,0,0,2,0,3,0,0,1, - 0,0,0,2,0,0,9,0,6,0, - 10,7,0,18,0,8,11,0,0,0, - 0,0,0,0,0,0,0,0,0,20, - 0,0,0,0,0,0,0 + 0,1,2,3,4,5,6,0,8,9, + 10,0,12,13,14,15,16,0,18,8, + 3,21,22,0,1,2,3,0,1,0, + 3,0,25,2,11,0,5,10,11,16, + 0,12,0,14,4,0,15,16,3,4, + 8,16,0,13,12,0,11,17,3,7, + 0,0,20,3,9,10,0,7,7,3, + 10,10,0,1,0,23,0,11,0,1, + 0,0,10,17,4,4,12,9,7,9, + 0,0,0,3,4,0,0,2,7,0, + 5,9,10,0,0,2,7,3,5,10, + 0,0,16,2,10,24,5,0,1,23, + 0,0,0,2,14,5,4,10,0,0, + 8,0,3,0,1,14,0,17,9,0, + 1,13,0,0,0,9,4,0,0,1, + 0,0,0,6,2,0,0,14,7,15, + 4,0,12,2,0,0,0,0,0,14, + 4,0,5,8,10,7,0,0,2,0, + 1,0,0,12,3,8,0,5,0,0, + 1,0,1,7,0,0,8,0,0,2, + 0,1,8,5,0,10,0,0,2,0, + 0,1,0,0,0,11,0,0,11,0, + 0,12,2,11,11,0,7,0,1,4, + 0,0,15,0,1,19,22,7,0,0, + 9,2,0,1,0,0,1,0,10,0, + 1,0,5,0,1,0,0,6,3,15, + 0,5,2,0,0,1,0,0,0,6, + 3,0,0,0,3,9,0,1,5,0, + 8,2,0,1,0,0,0,0,20,4, + 6,0,6,0,1,4,9,0,0,0, + 1,0,1,0,0,0,3,9,3,0, + 0,7,3,0,4,0,0,20,0,4, + 4,3,0,1,0,0,0,3,3,0, + 0,5,0,1,0,22,7,0,0,0, + 0,11,0,9,5,0,0,2,6,0, + 0,13,0,4,4,9,19,0,6,19, + 0,0,0,0,2,5,9,0,0,6, + 0,1,0,0,13,8,8,0,6,6, + 0,4,2,0,0,0,2,0,0,1, + 5,0,0,0,0,2,0,10,0,0, + 8,0,6,12,21,7,0,0,7,0, + 0,0,13,0,20,8,7,6,8,0, + 1,0,0,2,18,3,13,0,1,0, + 0,2,2,0,0,2,0,1,0,1, + 0,0,0,0,10,3,6,6,0,1, + 0,0,0,2,0,0,13,5,0,0, + 0,0,0,1,6,11,0,17,8,0, + 9,0,0,18,0,4,17,8,6,0, + 1,0,1,0,0,19,2,0,0,2, + 0,3,18,0,1,0,0,0,2,9, + 0,0,0,0,7,10,0,5,8,0, + 0,0,0,12,0,0,0,0,0,0, + 0,0,0,0,21,0,0,0,0,0, + 0 }; }; public final static byte termCheck[] = TermCheck.termCheck; @@ -218,58 +219,59 @@ public interface TermAction { public final static char termAction[] = {0, - 292,83,73,87,75,85,292,78,74,79, - 77,82,292,80,76,86,71,292,84,88, - 81,122,72,292,96,95,97,292,292,106, - 121,107,254,120,292,94,124,119,105,93, - 104,292,125,292,292,91,101,100,240,126, - 123,241,292,292,92,99,131,292,90,108, - 115,292,292,322,141,130,114,113,292,292, - 354,292,103,109,112,102,292,117,111,292, - 118,292,128,129,292,144,143,292,292,309, - 127,357,132,356,116,292,292,133,137,136, - 329,33,139,152,292,292,167,150,166,153, - 2,292,168,5,172,165,292,292,174,186, - 138,292,197,171,201,292,196,173,89,292, - 200,187,292,98,292,110,291,292,134,292, - 292,292,292,146,292,292,145,292,292,292, - 140,135,292,148,157,142,147,292,292,149, - 151,155,154,292,292,156,292,292,158,292, - 292,292,161,159,292,160,292,169,163,162, - 292,164,292,170,292,292,292,292,355,292, - 175,176,292,358,292,353,177,292,292,292, - 179,292,178,292,180,349,292,292,182,292, - 342,181,292,183,292,292,292,292,343,292, - 185,190,292,191,184,332,292,292,292,330, - 292,292,194,292,292,189,195,188,320,193, - 292,192,292,321,25,199,292,292,198,292, - 203,292,310,15,202,292,204,205,292,292, - 292,292,302,206,292,208,292,207,211,209, - 292,292,292,210,212,292,214,213,292,292, - 215,292,359,292,292,292,292,216,217,218, - 347,292,220,292,221,292,219,292,292,222, - 292,224,292,225,292,292,223,226,227,292, - 292,292,228,292,229,292,233,230,292,232, - 231,292,234,292,235,292,292,292,236,237, - 292,292,313,242,292,238,239,292,292,292, - 292,292,292,243,300,292,304,292,292,292, - 245,247,303,246,296,292,244,292,58,301, - 292,248,292,292,249,346,351,345,292,292, - 292,328,292,348,292,250,341,340,292,251, - 41,292,252,253,292,292,255,292,334,292, - 292,292,324,292,292,256,258,292,257,319, - 22,292,260,292,292,292,261,316,312,292, - 263,292,259,292,265,292,264,292,298,295, - 299,262,292,292,267,266,292,292,268,269, - 292,292,270,292,337,292,336,292,292,292, - 292,271,272,273,274,292,275,292,292,292, - 292,318,308,292,292,292,311,292,292,277, - 292,276,278,292,315,292,279,292,280,335, - 284,305,292,292,283,338,292,282,293,281, - 292,306,292,292,352,292,285,292,292,327, - 292,292,292,288,292,292,286,292,344,292, - 287,289,292,339,292,323,326,292,292,292, - 292,292,292,292,292,292,292,292,292,331 + 296,84,74,88,76,75,86,296,79,80, + 78,296,83,81,77,87,72,296,85,151, + 90,82,73,296,97,96,98,296,107,296, + 108,296,295,125,95,296,126,106,105,94, + 296,104,296,103,92,296,127,124,102,101, + 109,220,296,93,326,296,100,91,116,118, + 296,296,110,122,115,114,296,121,113,132, + 120,112,296,119,296,117,296,131,296,129, + 296,296,313,359,133,362,141,128,361,134, + 296,296,296,138,137,296,296,142,140,296, + 143,146,145,33,296,154,200,168,155,199, + 296,296,333,169,167,139,170,5,174,152, + 2,296,296,189,130,176,244,173,296,296, + 245,296,204,296,99,190,296,175,203,296, + 111,89,296,296,296,135,123,296,296,148, + 296,296,296,147,153,296,296,136,150,144, + 157,296,149,158,296,296,296,296,296,156, + 160,296,164,161,159,162,296,296,163,296, + 171,296,296,165,172,166,296,177,296,296, + 360,296,358,178,296,296,363,296,296,181, + 296,182,179,354,296,180,296,296,184,296, + 296,347,296,296,296,183,296,296,185,296, + 296,348,334,186,187,296,188,296,194,193, + 296,296,195,296,197,192,191,336,296,296, + 196,198,296,325,296,25,202,296,324,296, + 206,296,205,296,314,15,296,209,207,201, + 296,210,208,296,296,306,296,296,296,211, + 212,296,296,296,215,213,296,217,219,296, + 216,218,296,364,296,296,296,296,214,352, + 221,296,222,296,224,225,223,296,296,296, + 228,296,229,296,296,296,230,227,231,296, + 296,234,232,296,233,296,296,226,296,236, + 238,237,296,239,296,296,296,240,241,296, + 296,242,296,317,296,235,243,296,296,296, + 296,246,296,247,308,296,296,304,250,296, + 296,307,296,251,252,249,248,296,300,305, + 59,296,296,296,351,356,253,296,296,350, + 296,345,296,296,353,254,346,296,344,255, + 296,256,257,296,296,41,259,296,296,332, + 338,296,296,296,296,328,296,260,296,296, + 262,22,264,261,258,323,296,296,265,296, + 296,296,320,296,263,316,267,303,268,296, + 269,296,296,299,266,270,302,296,271,296, + 296,272,273,296,296,274,296,341,296,340, + 296,296,296,296,275,277,276,278,296,279, + 296,296,296,312,296,296,322,315,296,296, + 296,296,296,284,281,280,296,319,282,296, + 283,296,296,309,296,339,342,288,286,296, + 287,296,310,296,296,285,297,296,296,357, + 296,289,343,296,331,296,296,296,292,290, + 296,296,296,296,349,291,296,327,293,296, + 296,296,296,330,296,296,296,296,296,296, + 296,296,296,296,335 }; }; public final static char termAction[] = TermAction.termAction; Modified: trunk/x10.compiler/src/x10/parser/X10KWLexersym.java =================================================================== --- trunk/x10.compiler/src/x10/parser/X10KWLexersym.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/parser/X10KWLexersym.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -15,25 +15,25 @@ public final static int Char_a = 3, Char_b = 15, - Char_c = 5, + Char_c = 6, Char_d = 18, Char_e = 1, - Char_f = 11, - Char_g = 20, + Char_f = 12, + Char_g = 21, Char_h = 13, Char_i = 9, Char_j = 26, Char_k = 19, - Char_l = 6, - Char_m = 21, - Char_n = 7, + Char_l = 7, + Char_m = 20, + Char_n = 8, Char_o = 10, Char_p = 14, Char_q = 24, Char_r = 4, - Char_s = 8, + Char_s = 5, Char_t = 2, - Char_u = 12, + Char_u = 11, Char_v = 22, Char_w = 16, Char_x = 23, @@ -47,14 +47,14 @@ "t", "a", "r", + "s", "c", "l", "n", - "s", "i", "o", + "u", "f", - "u", "h", "p", "b", @@ -62,8 +62,8 @@ "y", "d", "k", + "m", "g", - "m", "v", "x", "q", Modified: trunk/x10.compiler/src/x10/parser/X10Lexer.java =================================================================== --- trunk/x10.compiler/src/x10/parser/X10Lexer.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/parser/X10Lexer.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -128,7 +128,7 @@ * simply report a lexical error. Otherwise, we produce a bad token. */ public void reportLexicalError(int startLoc, int endLoc) { - IPrsStream prs_stream = lexStream.getIPrsStream(); + IPrsStream prs_stream = lexStream.getPrsStream(); if (prs_stream == null) lexStream.reportLexicalError(startLoc, endLoc); else { Modified: trunk/x10.compiler/src/x10/parser/X10Parser.java =================================================================== --- trunk/x10.compiler/src/x10/parser/X10Parser.java 2010-09-22 11:13:29 UTC (rev 16622) +++ trunk/x10.compiler/src/x10/parser/X10Parser.java 2010-09-22 11:17:08 UTC (rev 16623) @@ -13,7 +13,7 @@ import lpg.runtime.*; -//#line 32 "x10/parser/x10.g" +//#line 32 "C:/eclipsews/head1/x10.compiler/src/x10/parser/x10.g" import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; @@ -176,24 +176,24 @@ { prsStream.remapTerminalSymbols(orderedTerminalSymbols(), prsTable.getEoftSymbol()); } - catch (NullExportedSymbolsException e) { + catch(NullExportedSymbolsException e) { } - catch (NullTerminalSymbolsException e) { + catch(NullTerminalSymbolsException e) { } - catch (UnimplementedTerminalsException e) + catch(UnimplementedTerminalsException e) { if (unimplementedSymbolsWarning) { - java.util.ArrayList<Integer> unimplemented_symbols = e.getSymbols(); + java.util.ArrayList unimplemented_symbols = e.getSymbols(); System.out.println("The Lexer will not scan the following token(s):"); for (int i = 0; i < unimplemented_symbols.size(); i++) { - Integer id = unimplemented_symbols.get(i); + Integer id = (Integer) unimplemented_symbols.get(i); System.out.println(" " + X10Parsersym.orderedTerminalSymbols[id.intValue()]); } System.out.println(); } } - catch (UndefinedEofSymbolException e) + catch(UndefinedEofSymbolException e) { throw new Error(new UndefinedEofSymbolException ("The Lexer does not implement the Eof symbol " + @@ -281,7 +281,7 @@ // - //#line 314 "x10/parser/x10.g" + //#line 315 "C:/eclipsews/head1/x10.compiler/src/x10/parser/x10.g" private ErrorQueue eq; private X10TypeSystem ts; private X10NodeFactory nf; @@ -1152,7 +1152,6 @@ } - @SuppressWarnings("unchecked") // Casting Object to various generic types public void ruleAction(int ruleNumber) { switch (ruleNumber) @@ -1162,10 +1161,10 @@ // Rule 1: TypeName ::= TypeName . ErrorId // case 1: { - //#line 8 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 6 "x10/parser/MissingId.gi" + //#line 8 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 6 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName TypeName = (ParsedName) getRhsSym(1); - //#line 8 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 8 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new ParsedName(nf, ts, pos(getLeftSpan(), getRightSpan()), @@ -1178,10 +1177,10 @@ // Rule 2: PackageName ::= PackageName . ErrorId // case 2: { - //#line 18 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 16 "x10/parser/MissingId.gi" + //#line 18 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 16 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName PackageName = (ParsedName) getRhsSym(1); - //#line 18 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 18 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new ParsedName(nf, ts, pos(getLeftSpan(), getRightSpan()), @@ -1194,10 +1193,10 @@ // Rule 3: ExpressionName ::= AmbiguousName . ErrorId // case 3: { - //#line 28 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 26 "x10/parser/MissingId.gi" + //#line 28 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 26 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName AmbiguousName = (ParsedName) getRhsSym(1); - //#line 28 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 28 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new ParsedName(nf, ts, pos(getLeftSpan(), getRightSpan()), @@ -1210,10 +1209,10 @@ // Rule 4: MethodName ::= AmbiguousName . ErrorId // case 4: { - //#line 38 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 36 "x10/parser/MissingId.gi" + //#line 38 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 36 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName AmbiguousName = (ParsedName) getRhsSym(1); - //#line 38 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 38 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new ParsedName(nf, ts, pos(getLeftSpan(), getRightSpan()), @@ -1226,10 +1225,10 @@ // Rule 5: PackageOrTypeName ::= PackageOrTypeName . ErrorId // case 5: { - //#line 48 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 46 "x10/parser/MissingId.gi" + //#line 48 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 46 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName PackageOrTypeName = (ParsedName) getRhsSym(1); - //#line 48 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 48 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new ParsedName(nf, ts, pos(getLeftSpan(), getRightSpan()), @@ -1242,10 +1241,10 @@ // Rule 6: AmbiguousName ::= AmbiguousName . ErrorId // case 6: { - //#line 58 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 56 "x10/parser/MissingId.gi" + //#line 58 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 56 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName AmbiguousName = (ParsedName) getRhsSym(1); - //#line 58 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 58 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new ParsedName(nf, ts, pos(getLeftSpan(), getRightSpan()), @@ -1258,10 +1257,10 @@ // Rule 7: FieldAccess ::= Primary . ErrorId // case 7: { - //#line 68 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 66 "x10/parser/MissingId.gi" + //#line 68 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 66 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" Expr Primary = (Expr) getRhsSym(1); - //#line 68 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 68 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(nf.Field(pos(), Primary, nf.Id(pos(getRightSpan()), "*"))); break; @@ -1271,9 +1270,9 @@ // Rule 8: FieldAccess ::= super . ErrorId // case 8: { - //#line 74 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 74 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 74 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 74 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(nf.Field(pos(getRightSpan()), nf.Super(pos(getLeftSpan())), nf.Id(pos(getRightSpan()), "*"))); break; @@ -1283,12 +1282,12 @@ // Rule 9: FieldAccess ::= ClassName . super$sup . ErrorId // case 9: { - //#line 80 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 78 "x10/parser/MissingId.gi" + //#line 80 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 78 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName ClassName = (ParsedName) getRhsSym(1); - //#line 78 "x10/parser/MissingId.gi" + //#line 78 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" IToken sup = (IToken) getRhsIToken(3); - //#line 80 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 80 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(nf.Field(pos(getRightSpan()), nf.Super(pos(getRhsFirstTokenIndex(3)), ClassName.toType()), nf.Id(pos(getRightSpan()), "*"))); break; @@ -1298,12 +1297,12 @@ // Rule 10: MethodInvocation ::= MethodPrimaryPrefix ( ArgumentListopt ) // case 10: { - //#line 87 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 85 "x10/parser/MissingId.gi" + //#line 87 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 85 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" Object MethodPrimaryPrefix = (Object) getRhsSym(1); - //#line 85 "x10/parser/MissingId.gi" + //#line 85 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" List<Expr> ArgumentListopt = (List<Expr>) getRhsSym(3); - //#line 87 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 87 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" Expr Primary = (Expr) ((Object[]) MethodPrimaryPrefix)[0]; polyglot.lex.Identifier identifier = (polyglot.lex.Identifier) ((Object[]) MethodPrimaryPrefix)[1]; setResult(nf.Call(pos(), Primary, nf.Id(pos(), identifier.getIdentifier()), ArgumentListopt)); @@ -1314,12 +1313,12 @@ // Rule 11: MethodInvocation ::= MethodSuperPrefix ( ArgumentListopt ) // case 11: { - //#line 94 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 92 "x10/parser/MissingId.gi" + //#line 94 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 92 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" polyglot.lex.Identifier MethodSuperPrefix = (polyglot.lex.Identifier) getRhsSym(1); - //#line 92 "x10/parser/MissingId.gi" + //#line 92 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" List<Expr> ArgumentListopt = (List<Expr>) getRhsSym(3); - //#line 94 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 94 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" polyglot.lex.Identifier identifier = MethodSuperPrefix; setResult(nf.Call(pos(), nf.Super(pos(getLeftSpan())), nf.Id(pos(), identifier.getIdentifier()), ArgumentListopt)); break; @@ -1329,12 +1328,12 @@ // Rule 12: MethodInvocation ::= MethodClassNameSuperPrefix ( ArgumentListopt ) // case 12: { - //#line 100 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 98 "x10/parser/MissingId.gi" + //#line 100 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 98 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" Object MethodClassNameSuperPrefix = (Object) getRhsSym(1); - //#line 98 "x10/parser/MissingId.gi" + //#line 98 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" List<Expr> ArgumentListopt = (List<Expr>) getRhsSym(3); - //#line 100 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 100 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" ParsedName ClassName = (ParsedName) ((Object[]) MethodClassNameSuperPrefix)[0]; JPGPosition super_pos = (JPGPosition) ((Object[]) MethodClassNameSuperPrefix)[1]; polyglot.lex.Identifier identifier = (polyglot.lex.Identifier) ((Object[]) MethodClassNameSuperPrefix)[2]; @@ -1346,12 +1345,12 @@ // Rule 13: MethodPrimaryPrefix ::= Primary . ErrorId$ErrorId // case 13: { - //#line 109 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 107 "x10/parser/MissingId.gi" + //#line 109 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 107 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" Expr Primary = (Expr) getRhsSym(1); - //#line 107 "x10/parser/MissingId.gi" + //#line 107 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" IToken ErrorId = (IToken) getRhsIToken(3); - //#line 109 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 109 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" Object[] a = new Object[2]; a[0] = Primary; a[1] = id(getRhsFirstTokenIndex(3)); @@ -1363,10 +1362,10 @@ // Rule 14: MethodSuperPrefix ::= super . ErrorId$ErrorId // case 14: { - //#line 117 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 115 "x10/parser/MissingId.gi" + //#line 117 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 115 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" IToken ErrorId = (IToken) getRhsIToken(3); - //#line 117 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 117 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(id(getRhsFirstTokenIndex(3))); break; } @@ -1375,14 +1374,14 @@ // Rule 15: MethodClassNameSuperPrefix ::= ClassName . super$sup . ErrorId$ErrorId // case 15: { - //#line 122 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 120 "x10/parser/MissingId.gi" + //#line 122 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 120 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" ParsedName ClassName = (ParsedName) getRhsSym(1); - //#line 120 "x10/parser/MissingId.gi" + //#line 120 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" IToken sup = (IToken) getRhsIToken(3); - //#line 120 "x10/parser/MissingId.gi" + //#line 120 "C:/eclipsews/head1/x10.compiler/src/x10/parser/MissingId.gi" IToken ErrorId = (IToken) getRhsIToken(5); - //#line 122 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 122 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" Object[] a = new Object[3]; a[0] = ClassName; a[1] = pos(getRhsFirstTokenIndex(3)); @@ -1395,9 +1394,9 @@ // Rule 16: Modifiersopt ::= $Empty // case 16: { - //#line 1189 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1190 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1189 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1190 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new LinkedList<Modifier>()); break; } @@ -1406,12 +1405,12 @@ // Rule 17: Modifiersopt ::= Modifiersopt Modifier // case 17: { - //#line 1194 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1192 "x10/parser/x10.g" + //#line 1195 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1193 "C:/eclipsews/head1/x10.compiler/src/x10/parser/x10.g" List<Modifier> Modifiersopt = (List<Modifier>) getRhsSym(1); - //#line 1192 "x10/parser/x10.g" + //#line 1193 "C:/eclipsews/head1/x10.compiler/src/x10/parser/x10.g" Modifier Modifier = (Modifier) getRhsSym(2); - //#line 1194 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1195 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" Modifiersopt.add(Modifier); break; } @@ -1420,9 +1419,9 @@ // Rule 18: Modifier ::= abstract // case 18: { - //#line 1200 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1201 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1200 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1201 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.ABSTRACT)); break; } @@ -1431,10 +1430,10 @@ // Rule 19: Modifier ::= Annotation // case 19: { - //#line 1205 "lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1203 "x10/parser/x10.g" + //#line 1206 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1204 "C:/eclipsews/head1/x10.compiler/src/x10/parser/x10.g" AnnotationNode Annotation = (AnnotationNode) getRhsSym(1); - //#line 1205 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1206 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new AnnotationModifier(Annotation)); break; } @@ -1443,9 +1442,9 @@ // Rule 20: Modifier ::= atomic // case 20: { - //#line 1210 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1211 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1210 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1211 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.ATOMIC)); break; } @@ -1454,9 +1453,9 @@ // Rule 21: Modifier ::= extern // case 21: { - //#line 1215 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1216 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1215 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1216 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.EXTERN)); break; } @@ -1465,9 +1464,9 @@ // Rule 22: Modifier ::= final // case 22: { - //#line 1220 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1221 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1220 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1221 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.FINAL)); break; } @@ -1476,9 +1475,9 @@ // Rule 23: Modifier ::= global // case 23: { - //#line 1225 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1226 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1225 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1226 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.GLOBAL)); break; } @@ -1487,9 +1486,9 @@ // Rule 24: Modifier ::= incomplete // case 24: { - //#line 1230 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1231 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1230 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1231 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.INCOMPLETE)); break; } @@ -1498,9 +1497,9 @@ // Rule 25: Modifier ::= native // case 25: { - //#line 1235 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1236 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1235 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1236 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.NATIVE)); break; } @@ -1509,9 +1508,9 @@ // Rule 26: Modifier ::= nonblocking // case 26: { - //#line 1240 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1241 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1240 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1241 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.NON_BLOCKING)); break; } @@ -1520,9 +1519,9 @@ // Rule 27: Modifier ::= private // case 27: { - //#line 1245 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1246 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1245 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1246 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.PRIVATE)); break; } @@ -1531,9 +1530,9 @@ // Rule 28: Modifier ::= protected // case 28: { - //#line 1250 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1251 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1250 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1251 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.PROTECTED)); break; } @@ -1542,9 +1541,9 @@ // Rule 29: Modifier ::= public // case 29: { - //#line 1255 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1256 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1255 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1256 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.PUBLIC)); break; } @@ -1553,9 +1552,9 @@ // Rule 30: Modifier ::= safe // case 30: { - //#line 1260 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1261 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1260 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1261 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.SAFE)); break; } @@ -1564,9 +1563,9 @@ // Rule 31: Modifier ::= sequential // case 31: { - //#line 1265 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1266 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1265 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1266 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.SEQUENTIAL)); break; } @@ -1575,9 +1574,9 @@ // Rule 32: Modifier ::= static // case 32: { - //#line 1270 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1271 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" - //#line 1270 "lpg.generator/templates/java/btParserTemplateF.gi" + //#line 1271 "C:/eclipsews/head1/lpg.generator/templates/java/btParserTemplateF.gi" setResult(new FlagModifier(pos(), FlagModifier.STATIC)); break; } @@ -1586,9 +1585,9 @@ // Rule 33: Modifier ::= transient // case 33: { - //#line 1275 "lpg.generator/templates/j... [truncated message content] |
From: <spa...@us...> - 2010-09-22 21:46:02
|
Revision: 16640 http://x10.svn.sourceforge.net/x10/?rev=16640&view=rev Author: sparksparkspark Date: 2010-09-22 21:45:55 +0000 (Wed, 22 Sep 2010) Log Message: ----------- Some more work on CUDA Includes an Array constructor for copying an array Modified Paths: -------------- trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc trunk/x10.runtime/src-x10/x10/array/Array.x10 Modified: trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java =================================================================== --- trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java 2010-09-22 20:22:56 UTC (rev 16639) +++ trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java 2010-09-22 21:45:55 UTC (rev 16640) @@ -658,24 +658,24 @@ } - protected void generateClosureDeserializationIdDef(StreamWrapper inc, String cnamet, List<Type> freeTypeParams, String hostClassName, Block block) { - if (blockIsKernel(block)) { + protected void generateClosureDeserializationIdDef(ClassifiedStream defn_s, String cnamet, List<Type> freeTypeParams, String hostClassName, Block block) { + if (blockIsKernel(block)) { X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); boolean in_template_closure = freeTypeParams.size()>0; if (in_template_closure) - emitter.printTemplateSignature(freeTypeParams, inc); - inc.write("const x10aux::serialization_id_t "+cnamet+"::"+SharedVarsMethods.SERIALIZATION_ID_FIELD+" = "); - inc.newline(4); + emitter.printTemplateSignature(freeTypeParams, defn_s); + defn_s.write("const x10aux::serialization_id_t "+cnamet+"::"+SharedVarsMethods.SERIALIZATION_ID_FIELD+" = "); + defn_s.newline(4); String template = in_template_closure ? "template " : ""; - inc.write("x10aux::DeserializationDispatcher::addDeserializer("+ + defn_s.write("x10aux::DeserializationDispatcher::addDeserializer("+ cnamet+"::"+template+SharedVarsMethods.DESERIALIZE_METHOD+ chevrons("x10::lang::Reference")+", true, "+ cnamet+"::"+template+SharedVarsMethods.DESERIALIZE_CUDA_METHOD+", "+ "\""+hostClassName+".cubin\", \""+cnamet+"\");"); - inc.newline(); inc.forceNewline(); + defn_s.newline(); defn_s.forceNewline(); } else { - super.generateClosureDeserializationIdDef(inc.currentStream(), cnamet, freeTypeParams, hostClassName, block); + super.generateClosureDeserializationIdDef(defn_s, cnamet, freeTypeParams, hostClassName, block); } } Modified: trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 =================================================================== --- trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 2010-09-22 20:22:56 UTC (rev 16639) +++ trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 2010-09-22 21:45:55 UTC (rev 16640) @@ -21,18 +21,18 @@ import x10.util.OptionsParser; import x10.util.Option; +import x10.util.CUDAUtilities; import x10.compiler.Unroll; import x10.compiler.CUDA; -import x10.compiler.CUDAUtilities; import x10.compiler.Native; public class KMeansCUDA { - public static def printClusters (clusters:Rail[Float], dims:Int) { + public static def printClusters (clusters:Array[Float]{rank==1}, dims:Int) { for (var d:Int=0 ; d<dims ; ++d) { - for (var k:Int=0 ; k<clusters.length/dims ; ++k) { + for (var k:Int=0 ; k<clusters.size/dims ; ++k) { if (k>0) Console.OUT.print(" "); Console.OUT.printf("%.2f",clusters(k*dims+d)); } @@ -40,7 +40,7 @@ } } - private static def round_up (x:UInt, n:UInt) = (x-1) - ((x-1)%n) + n; + private static def round_up (x:Int, n:Int) = (x-1) - ((x-1)%n) + n; public static def main (args : Array[String](1)) { try { @@ -54,9 +54,9 @@ Option("s","slices","factor by which to oversubscribe computational resources"), Option("n","num","quantity of points")]); // The casts can go on resolution of XTENLANG-1413 - val fname = opts("-p", "points.dat"), num_clusters=opts("-c",8) as UInt, - num_slices=opts("-s",4) as UInt, num_global_points=opts("-n", 100000) as UInt, - iterations=opts("-i",500) as UInt; + val fname = opts("-p", "points.dat"), num_clusters=opts("-c",8), + num_slices=opts("-s",4), num_global_points=opts("-n", 100000), + iterations=opts("-i",500); val verbose = opts("-v"), quiet = opts("-q"); val MEM_ALIGN = 32; // FOR CUDA @@ -68,10 +68,10 @@ val file = new File(fname), fr = file.openRead(); val init_points = (Int) => Float.fromIntBits(Marshal.INT.read(fr).reverseBytes()); val num_file_points = (file.size() / 4 / 4) as Int; - val file_points = ValRail.make(num_file_points*4, init_points); + val file_points = new Array[Float](num_file_points*4, init_points); //val team = Team.WORLD; - val team = Team(Rail.make[Place](num_slices * Place.MAX_PLACES, (i:Int) => Place.places(i/num_slices))); + val team = Team(new Array[Place](num_slices * Place.MAX_PLACES, (i:Int) => Place.places(i/num_slices))); finish { @@ -95,35 +95,37 @@ }; // these are pretty big so allocate up front - val host_points = Rail.make((num_local_points_stride*4) as Int, init); - val gpu_points = Rail.makeRemote(gpu, (num_local_points_stride*4) as Int, host_points); - val host_nearest = Rail.make[Int](num_local_points as Int, (Int)=>0 as Int); - val gpu_nearest = Rail.makeRemote[Int](gpu, num_local_points as Int, (Int)=>0 as Int); + val host_points = new Array[Float]((num_local_points_stride*4), init); + val gpu_points = CUDAUtilities.makeRemoteArray(gpu, num_local_points_stride*4, host_points); + val host_nearest = new Array[Int](num_local_points, 0); + val gpu_nearest = CUDAUtilities.makeRemoteArray[Int](gpu, num_local_points, 0); - val host_clusters = Rail.make[Float](num_clusters*4, file_points); - val host_cluster_counts = Rail.make[Int](num_clusters, (Int)=>0); + val host_clusters = new Array[Float](num_clusters*4, (i:Int)=>file_points(i)); + val host_cluster_counts = new Array[Int](num_clusters, 0); val start_time = System.currentTimeMillis(); - main_loop: for (var iter:UInt=0 ; iter<iterations ; iter++) { + val clusters_copy = new Array[Float](num_clusters*4); - val clusters_copy = host_clusters as ValRail[Float]; + main_loop: for (var iter:Int=0 ; iter<iterations ; iter++) { + Array.copy(host_clusters, 0, clusters_copy, 0, num_clusters*4); + var k_start_time : Long = System.currentTimeMillis(); // classify kernel finish async at (gpu) @CUDA { val blocks = CUDAUtilities.autoBlocks(), threads = CUDAUtilities.autoThreads(); for ([block] in 0..blocks-1) { - val clustercache = Rail.make[Float](num_clusters*4, clusters_copy); + val clustercache = new Array[Float](clusters_copy); for ([thread] in 0..threads-1) async { val tid = block * threads + thread; val tids = blocks * threads; - for (var p:UInt=tid ; p<num_local_points ; p+=tids) { + for (var p:Int=tid ; p<num_local_points ; p+=tids) { var closest:Int = -1; var closest_dist:Float = Float.MAX_VALUE; @Unroll(20) for ([k] in 0..num_clusters-1) { - // Pythagoras (in d dimensions) + // Pythagoras (in 4 dimensions) var dist : Float = 0; for ([d] in 0..3) { val tmp = gpu_points(p+d*num_local_points_stride) @@ -145,38 +147,38 @@ // bring gpu results onto host k_start_time = System.currentTimeMillis(); - finish host_nearest.copyFrom(0, gpu_nearest, 0, num_local_points as Int); + finish Array.asyncCopy(gpu_nearest, 0, host_nearest, 0, num_local_points); Console.OUT.println("dma: "+(System.currentTimeMillis() - k_start_time)); // compute new clusters - host_clusters.reset(0); - host_cluster_counts.reset(0); + host_clusters.fill(0); + host_cluster_counts.fill(0); k_start_time = System.currentTimeMillis(); - for (var p:UInt=0 ; p<num_local_points ; p++) { + for (var p:Int=0 ; p<num_local_points ; p++) { val closest = host_nearest(p); - for (var d:UInt=0 ; d<4u ; ++d) + for (var d:Int=0 ; d<4 ; ++d) host_clusters(closest*4+d) += host_points(p+d*num_local_points_stride); host_cluster_counts(closest)++; } Console.OUT.println("reaverage: "+(System.currentTimeMillis() - k_start_time)); - team.allreduce(role, host_clusters, 0, host_clusters, 0, host_clusters.length, Team.ADD); - team.allreduce(role, host_cluster_counts, 0, host_cluster_counts, 0, host_cluster_counts.length, Team.ADD); + team.allreduce(role, host_clusters, 0, host_clusters, 0, host_clusters.size, Team.ADD); + team.allreduce(role, host_cluster_counts, 0, host_cluster_counts, 0, host_cluster_counts.size, Team.ADD); - for (var k:UInt=0 ; k<num_clusters ; ++k) { - for (var d:UInt=0 ; d<4u ; ++d) host_clusters(k*4u+d) /= host_cluster_counts(k); + for (var k:Int=0 ; k<num_clusters ; ++k) { + for (var d:Int=0 ; d<4 ; ++d) host_clusters(k*4+d) /= host_cluster_counts(k); } - if (offset==0u && verbose) { + if (offset==0 && verbose) { Console.OUT.println("Iteration: "+iter); - printClusters(host_clusters,4u); + printClusters(host_clusters,4); } /* // TEST FOR CONVERGENCE - for (var j:UInt=0 ; j<num_clusters*4 ; ++j) { + for (var j:Int=0 ; j<num_clusters*4 ; ++j) { if (true||Math.abs(clusters_copy(j)-host_clusters(j))>0.0001) continue main_loop; } @@ -185,7 +187,7 @@ } // main_loop - if (offset==0u) { + if (offset==0) { val stop_time = System.currentTimeMillis(); if (!quiet) Console.OUT.print(num_global_points+" "+num_clusters+" 4 "); Console.OUT.println((stop_time-start_time)/1E3); Modified: trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc 2010-09-22 20:22:56 UTC (rev 16639) +++ trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc 2010-09-22 21:45:55 UTC (rev 16640) @@ -183,7 +183,7 @@ } void DeserializationDispatcher::registerHandlers_ () { - for (size_t i=0 ; i<next_id ; ++i) { // FIXME: 0-based?! + for (size_t i=0 ; i<next_id ; ++i) { Data &d = data_v[i]; if (d.has_mt) { msg_type id; Modified: trunk/x10.runtime/src-x10/x10/array/Array.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-22 20:22:56 UTC (rev 16639) +++ trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-22 21:45:55 UTC (rev 16640) @@ -283,7 +283,24 @@ } + /** + * Construct a copy of the given Array. + * + * @param init The array to copy. + */ + public def this(init:Array[T]):Array[T]{self.region==init.region, self.size==init.size} { + property(init.region, init.size); + layout = RectLayout(region); + val n = layout.size(); + val r = IndexedMemoryChunk.allocate[T](n); + init.raw.asyncCopyTo(0, here, r, 0, n, false); + raw = r; + rawLength = n; + cachedRail = rail; + } + + /** * Return an iterator over the points in the region of this array. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-22 23:12:31
|
Revision: 16641 http://x10.svn.sourceforge.net/x10/?rev=16641&view=rev Author: yzibin Date: 2010-09-22 23:12:23 +0000 (Wed, 22 Sep 2010) Log Message: ----------- Fixed the test suite, fixed the "safe class" modifier, allow safe modifier on ctors. Modified Paths: -------------- trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java trunk/x10.compiler/src/polyglot/types/TypeSystem_c.java trunk/x10.compiler/src/polyglot/visit/InitChecker.java trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java trunk/x10.compiler/src/x10/ast/X10Local_c.java trunk/x10.compiler/src/x10/ast/X10MethodDecl_c.java trunk/x10.compiler/src/x10/parser/X10Parser.java trunk/x10.compiler/src/x10/parser/x10.g trunk/x10.compiler/src/x10/types/X10ParsedClassType_c.java trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java trunk/x10.compiler/src/x10/util/RunTestSuite.java trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 trunk/x10.dist/samples/CUDA/CUDATopology.x10 trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 trunk/x10.tests/examples/Constructs/Clock/ClockTest18.x10 trunk/x10.tests/examples/Constructs/Closures/ClosureEnclosingScope6.x10 trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 trunk/x10.tests/examples/Constructs/DepType/ReferenceConsistencyCheck.x10 trunk/x10.tests/examples/Constructs/Future/Future1.x10 trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 trunk/x10.tests/examples/Constructs/Init/InitFieldWithInstanceClass.x10 trunk/x10.tests/examples/Constructs/PlaceCast/PlaceCast2.x10 trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 trunk/x10.tests/examples/Issues/XTENLANG_1565.x10 trunk/x10.tests/examples/Issues/XTENLANG_637.x10 trunk/x10.tests/examples/Misc/Stencil1D.x10 trunk/x10.tests/examples/Samples/CUDABlackScholesTest.x10 trunk/x10.tests/examples/Samples/CUDAKernelTestTest.x10 trunk/x10.tests/examples/Samples/CUDATopologyTest.x10 trunk/x10.tests/examples/Samples/KMeansCUDATest.x10 trunk/x10.tests/tests/Constructs/Rooted/RootedCall.x10 Removed Paths: ------------- trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithCall.x10 trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithInstanceClass.x10 Modified: trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/polyglot/ast/MethodDecl_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -15,6 +15,7 @@ import polyglot.util.*; import polyglot.visit.*; import x10.errors.Errors; +import x10.types.X10Flags; /** * A method declaration. @@ -180,7 +181,28 @@ if (ct.flags().isInterface()) { flags = flags.Public().Abstract(); } - + + // If the class is safe, mark all the methods safe. (what about ctors? this code should also be in ctors) + // The method inherits the flags of the enclosing containers (only for safe. The other modifiers will be removed: pinned, nonblocking, sequential) + boolean shouldAddSafe = false; + if (!X10Flags.toX10Flags(flags).isSafe()) { + ClassDef container = ct; + while (container!=null) { + if (X10Flags.toX10Flags(container.flags()).isSafe()) + shouldAddSafe = true; + Ref<? extends ClassDef> ref = container.outer(); + if (ref==null) break; + container = ref.get(); + } + } + MethodDecl_c n = this; + if (shouldAddSafe) { + // we need to change both the def and the decl + flags = X10Flags.toX10Flags(flags).Safe(); // these flags are for the def + n = (MethodDecl_c) n.flags(n.flags().flags(flags)); // changing the decl + } + + MethodDef mi = createMethodDef(ts, ct, flags); ct.addMethod(mi); @@ -189,7 +211,7 @@ final TypeBuilder tbx = tb; final MethodDef mix = mi; - MethodDecl_c n = (MethodDecl_c) this.visitSignature(new NodeVisitor() { + n = (MethodDecl_c) n.visitSignature(new NodeVisitor() { public Node override(Node n) { return MethodDecl_c.this.visitChild(n, tbx.pushCode(mix)); } Modified: trunk/x10.compiler/src/polyglot/types/TypeSystem_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/types/TypeSystem_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/polyglot/types/TypeSystem_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -2275,14 +2275,6 @@ return f; } - public Flags flagsForName(String name) { - Flags f = (Flags) flagsForName.get(name); - if (f == null) { - throw new InternalCompilerError("No flag named \"" + name + "\"."); - } - return f; - } - protected String getCreatorStack(int limit) { StackTraceElement[] trace = creator.getStackTrace(); // The first 3 elements will be the factory methods and the constructor Modified: trunk/x10.compiler/src/polyglot/visit/InitChecker.java =================================================================== --- trunk/x10.compiler/src/polyglot/visit/InitChecker.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/polyglot/visit/InitChecker.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -1048,7 +1048,7 @@ checkLocal(graph, (Local)n, dfIn, dfOut); } else if (n instanceof Field) { - checkField(graph, (Field)n, dfIn, dfOut); + // checkField(graph, (Field)n, dfIn, dfOut); - field access is checked by CheckEscapingThis } else if (n instanceof LocalAssign) { checkLocalAssign(graph, (LocalAssign)n, dfIn, dfOut); Modified: trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/ast/X10ClassDecl_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -238,29 +238,6 @@ super.setInterfaces(ts, thisType); } - - public Node disambiguate(ContextVisitor ar) throws SemanticException { - ClassDecl n = (ClassDecl) super.disambiguate(ar); - - // If the class is safe, mark all the methods safe. - X10Flags xf = X10Flags.toX10Flags(n.flags().flags()); - if (xf.isSafe()) { - ClassBody b = n.body(); - List<ClassMember> m = b.members(); - List<ClassMember> newM = new ArrayList<ClassMember>(m.size()); - for (ClassMember mem : m) { - if (mem instanceof MethodDecl) { - MethodDecl decl = (MethodDecl) mem; - X10Flags mxf = X10Flags.toX10Flags(decl.flags().flags()).Safe(); - mem = decl.flags(decl.flags().flags(mxf)); - } - newM.add(mem); - } - n = n.body(b.members(newM)); - } - - return n; - } @Override public Context enterScope(Context c) { return c.pushBlock(); Modified: trunk/x10.compiler/src/x10/ast/X10Local_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Local_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/ast/X10Local_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -68,14 +68,15 @@ } // if the local is defined in an outer class, then it must be final - if (!context.isLocal(li.name())) { - // this local is defined in an outer class - if (!li.flags().isFinal() && !X10Flags.toX10Flags(li.flags()).isShared()) { - Errors.issue(tc.job(), new SemanticException("Local variable \"" + li.name() + - "\" is accessed from an inner class or a closure, and must be declared final or shared.", - this.position())); - } - } + // shared was removed from the language: you can access var in a closure (backends need to be fixed) +// if (!context.isLocal(li.name())) { +// // this local is defined in an outer class +// if (!li.flags().isFinal() && !X10Flags.toX10Flags(li.flags()).isShared()) { +// Errors.issue(tc.job(), new SemanticException("Local variable \"" + li.name() + +// "\" is accessed from an inner class or a closure, and must be declared final or shared.", +// this.position())); +// } +// } X10Local_c result = (X10Local_c) localInstance(li).type(li.type()); Modified: trunk/x10.compiler/src/x10/ast/X10MethodDecl_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10MethodDecl_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/ast/X10MethodDecl_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -242,7 +242,7 @@ // property implies public, final if (xf.isProperty()) { - if (xf.isAbstract()) + if (xf.isAbstract()) //todo: Yoav thinks we should not have abstract property methods (all property methods, even in interfaces, should have a body so they can be expanded) xf = X10Flags.toX10Flags(xf.Public()); else xf = X10Flags.toX10Flags(xf.Public().Final()); Modified: trunk/x10.compiler/src/x10/parser/X10Parser.java =================================================================== --- trunk/x10.compiler/src/x10/parser/X10Parser.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/parser/X10Parser.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -566,6 +566,7 @@ constructorModifiers[PRIVATE] = true; constructorModifiers[PROTECTED] = true; constructorModifiers[PUBLIC] = true; + constructorModifiers[SAFE] = true; } public boolean isConstructorModifier(int flag) { return constructorModifiers[flag]; Modified: trunk/x10.compiler/src/x10/parser/x10.g =================================================================== --- trunk/x10.compiler/src/x10/parser/x10.g 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/parser/x10.g 2010-09-22 23:12:23 UTC (rev 16641) @@ -596,6 +596,7 @@ constructorModifiers[PRIVATE] = true; constructorModifiers[PROTECTED] = true; constructorModifiers[PUBLIC] = true; + constructorModifiers[SAFE] = true; } public boolean isConstructorModifier(int flag) { return constructorModifiers[flag]; Modified: trunk/x10.compiler/src/x10/types/X10ParsedClassType_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10ParsedClassType_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/types/X10ParsedClassType_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -270,13 +270,6 @@ return subst.reinstantiate(super.memberClasses()); } - /** - * A parsed class is safe iff it explicitly has a flag saying so. - */ - public boolean isSafe() { - return X10Flags.toX10Flags(flags()).isSafe(); - } - public static class X10FieldAsTypeTransform implements Transformation<X10FieldDef, FieldInstance> { public FieldInstance transform(X10FieldDef def) { return def.asInstance(); Modified: trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/types/X10TypeEnv_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -1906,8 +1906,7 @@ throw new SemanticException(mi.flags() + " " + mi.signature() + " in " + mi.container() + " cannot override " + mj.flags() + " " + mj.signature() + " in " + mj.container() + - "; attempting to assign weaker " + - "behavioral annotations", + "; attempting to assign weaker behavioral annotations", mi.position()); } } Modified: trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/types/X10TypeSystem_c.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -1914,7 +1914,7 @@ /** All flags allowed for a constructor. */ @Override public Flags legalConstructorFlags() { - return legalAccessFlags().Synchronized().Native(); // allow native (but + return X10Flags.toX10Flags(legalAccessFlags().Synchronized().Native()).Safe(); // allow native (but // not extern) } Modified: trunk/x10.compiler/src/x10/util/RunTestSuite.java =================================================================== --- trunk/x10.compiler/src/x10/util/RunTestSuite.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/util/RunTestSuite.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -105,8 +105,14 @@ private static void compileFiles(List<File> files, List<String> args) throws IOException { // replace \ with / ArrayList<String> fileNames = new ArrayList<String>(files.size()); - for (File f : files) + for (File f : files) { + final BufferedReader in = new BufferedReader(new FileReader(f)); + String firstLine = in.readLine(); + in.close(); + if (firstLine.contains("IGNORE_FILE")) + continue; fileNames.add(f.getAbsolutePath().replace('\\','/')); + } // adding the directories of the files to -sourcepath (in case they refer to other files that are not compiled, e.g., if we decide to compile the files one by one) HashSet<String> directories = new HashSet<String>(); for (String f : fileNames) { @@ -169,10 +175,12 @@ System.err.println("File "+file+" has an ERR marker on line "+lineNum+", but the compiler didn't report an error on that line!"); } } + in.close(); if (!foundErr && file.getName().endsWith("_MustFailCompile.x10")) { System.err.println("File "+file+" ends in _MustFailCompile.x10 but it doesn't contain any 'ERR' markers!"); } } + // 2. report all the remaining errors that didn't have a matching ERR marker // first report warnings int warningCount = 0; Modified: trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java =================================================================== --- trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.compiler/src/x10/visit/CheckEscapingThis.java 2010-09-22 23:12:23 UTC (rev 16641) @@ -241,10 +241,13 @@ if (canReadFrom!=null) { for (FieldDef f : fields) { boolean readBefore = isRead(inItem.initStatus.get(f)); - if (!readBefore && isRead(res.initStatus.get(f))) { + final int fRes = res.initStatus.get(f); + if (!readBefore && isRead(fRes)) { if (!canReadFrom.contains(f)) { // wasn't read before, and we read it now (either because of Field access, or X10Call) reportError("Cannot read from field '"+f.name()+"' before it is definitely assigned.",n.position()); + // I want to report more errors with this field, so I remove the read status + res.initStatus.put(f,build(false, isWrite(fRes),isSeqWrite(fRes))); wasError = true; } } Modified: trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 =================================================================== --- trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.dist/samples/CUDA/CUDABlackScholes.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * @@ -39,8 +40,8 @@ finish async at (p) @CUDA @CUDADirectParams { //val blocks = CUDAUtilities.autoBlocks(), // threads = CUDAUtilities.autoThreads(); - for ((block) in 0..blocks-1) { - for ((thread) in 0..threads-1) async { + for ([block] in 0..blocks-1) { + for ([thread] in 0..threads-1) async { val tid = block * threads + thread; val tids = blocks * threads; for (var opt:Int=tid; opt < opt_N; opt+=tids) { Modified: trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 =================================================================== --- trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.dist/samples/CUDA/CUDAKernelTest.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * Modified: trunk/x10.dist/samples/CUDA/CUDATopology.x10 =================================================================== --- trunk/x10.dist/samples/CUDA/CUDATopology.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.dist/samples/CUDA/CUDATopology.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * Modified: trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 =================================================================== --- trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.dist/samples/CUDA/KMeansCUDA.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * Modified: trunk/x10.tests/examples/Constructs/Clock/ClockTest18.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Clock/ClockTest18.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Clock/ClockTest18.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -51,7 +51,8 @@ } }; - var fooArray: Rail[foo] = Rail.make([f0,f1]); + val valRail:ValRail[foo] = [f0,f1]; + var fooArray: Rail[ClockTest18.foo] = Rail.make(valRail); x10.io.Console.OUT.println("#A0 before resume"); c0.resume(); x10.io.Console.OUT.println("#A0 before spawning A3"); Modified: trunk/x10.tests/examples/Constructs/Closures/ClosureEnclosingScope6.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Closures/ClosureEnclosingScope6.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Closures/ClosureEnclosingScope6.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -23,9 +23,9 @@ val a = 1; - class C { + final class C { def a() = 2; - class D { + final class D { def a() = 4; val sum = (()=>( ClosureEnclosingScope6.this.a // DYNAMIC_CHECK Modified: trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,10 +1,623 @@ -// check that "this" doesn't escape from any ctor -class Test(p:Test) { - var tt:Test; +// test object initialization + +import x10.compiler.*; + +//public class EscapingThisTest { + +class TransientTest { // The @Transient field '...' must have a type with a default value. + @Transient val x1 = 2; // ERR (because the type is infered to be Int{self==2} + @Transient val x2:Int = 2; + @Transient var y:Int; + @Transient var y2:Int{self==3} = 3; // ERR + @Transient var y3:Int{self!=0}; // ERR + @Transient var y4:Int{self==0}; + def this() { + y3 = 4; + } +} + + +final class ClosureTest57 { + val z = 1; + val c1 = () => z+1; + var x:Int{self!=0} = 1; + val c2 = () => { + x=3; + return x+1; + }; + var y:Int{self!=0}; // ERR: Field 'y' was not definitely assigned. + val c3 = () => { + y=3; + return y+1; // ERR: Cannot read from field 'y' before it is definitely assigned. (even though "y" was assigned before, I do not do flow-analysis within the closures) + }; + + val c4 = () => w; // ERR: Cannot read from field 'w' before it is definitely assigned. + val w = 42; + + def a() = q+2; + val q = 4; + + final class C { + def a() = q*3; + val q = 4; + final class D { + def a() = q+4; + val sum = (()=>(ClosureTest57.this.a() + +C.this.a() + +D.this.a() // ERR: The method call reads from field 'q' before it is definitely assigned. + +a() // ERR: The method call reads from field 'q' before it is definitely assigned. + ))(); + val z = q+2; // ERR: Cannot read from field 'q' before it is definitely assigned. + val q = 5; + } + } +} + +class MultipleCtorsAndFieldInits { + + var b:Int{self!=0}; + var i:Int{self!=0}; + var z:Int{self!=0} = (3*b*(b=1)) as Int{self!=0}; // ERR: Cannot read from field 'b' before it is definitely assigned. + var j:Boolean{self!=false}; + var k:Any{self!=null}; + + + def this(a:Int) { + this(); + } + def this(a:Boolean) { // ERR: Field 'k' was not definitely assigned in this conprivate structor. + i=4; + j = true; + } + def this() { // ERR: Field 'j' was not definitely assigned in this conprivate structor. + finish { + async { + i = 2; + val r1 = i; + } + val r2 = i; // ERR + } + val r3 = i; + k= new Object(); + } + def this(k:MultipleCtorsAndFieldInits) { // ERR: Field 'k' was not definitely assigned in this conprivate structor. + finish {k.i = 2; j=true; + async i=3; + } + } +} + +class UsingSuperFields { + static class Super { + val s1=1; + val s2:Int; + def this() { + s2 = 2; + } + } + static class Sub extends Super { + val a = s1+s2; + val b:Int; + def this() { + super(); + b = s1*s2; + } + } +} + + + + +class DynamicDispatchingInCtorTest { + abstract class Super { + val x:Int; + var size:Int; + def this() { + this.x = 3*4; + size = calcSize(); + } + @NonEscaping("x") abstract def calcSize():Int; + } + class Sub1 extends Super { + @NonEscaping("x") def calcSize():Int = x*2; + } + class Sub2 extends Super { + @NonEscaping("x") def calcSize():Int = x+2; + } +} + +class TestAsync { + var i:Int{self!=0}; + def this() { + finish { + async { + i = 2; + val r1 = i; + } + val r2 = i; // ERR: Cannot read from field 'i' before it is definitely assigned. + } + val r3 = i; + } +} + + +class PropertyTest(p:Int) { + static val i = 3; + def this() { + property(1); + val w = p(); + val q = p; + } +} + +abstract class SuperClassTest { + val a=1; + val b=2; + val c:Int; + val d:Int; + var x:Int{self!=0}; + var y:Int{self!=0}; + var z:Int{self!=0}; + + def this(i:Int) { this(); x = y; } + def this() { // ERR: Field 'x' was not definitely assigned in this conprivate structor. (because assignments in non final/private @NonEscaping methods do not count, cause they might be overriden) + super(); + q(); + f0(); // ERR: Cannot read from field 'c' before it is definitely assigned. + c = 2; + f0(); + setX(); + setY(); + setZ(); + f1(); + d=4; + } + + @NonEscaping("") def setX() { + x = 42; + } + @NonEscaping("") final def setZ() { + z = 42; + } + final def setY() { + y = 42; + } + + def g():Int = 1; + abstract @NonEscaping("a,b") def q():Int; + @NonEscaping("b,a") def ba():Int = a+b; + @NonEscaping("a,b,c") def f0():Int = a+b+c; + @NonEscaping("a,c") def f1():Int = a+c; + @NonEscaping("a,e") def e1():Int = 1; // ERR: Could not find field 'e' used in the annotation @NonEscaping. + @NonEscaping("a,c") def e2():Int = a+b+c; // ERR: reading from "b" +} +class Sub1Test extends SuperClassTest { + val w = 1; + var q:Int{self!=0} = 1; + def this(i:Int) { this(); x = y; } + def this() { + super(); + readD(); + g(); + f2(); // ERR: The call Sub1.this.f2() is illegal because you can only call private/final/@NonEscaping methods from a NonEscaping method (such as a conprivate structor, a field initializer, or a @NonEscaping method) + } + final def readD() { + val q = d; + } + @NonEscaping("a,b,c") def f0():Int = a+b+c+d; // ERR: Cannot read from field 'd' before it is definitely assigned. + @NonEscaping("a,b") def q():Int { + f0(); // ERR: Cannot read from field 'c' before it is definitely assigned. + readD(); // ERR: Cannot read from field 'd' before it is definitely assigned. + super.ba(); + val t = w; // ERR: Cannot read from field 'w' before it is definitely assigned. + return a+b; + } + @NonEscaping("g") def e3():Int = 1; // ERR: Could not find field 'g' used in the annotation @NonEscaping. + @NonEscaping("w") def g():Int = 1; + @NonEscaping("c,a") def f1():Int = 1; // ERR: You must annotate x10.lang.Int f1(...) with @NonEscaping("a,c") because it overrides a method annotated with that. + def f2():Int = 1; +} +class Sub2Test extends Sub1Test { + @NonEscaping("a,b") def q():Int { + val t = w; // ERR: Cannot read from field 'w' before it is definitely assigned. + return a+b; + } + + def g():Int = 1; // ERR (annotation @NonEscaping must be preserved) + @NonEscaping("a,c") def f0():Int = 1; // ERR: You must annotate x10.lang.Int f0(...) with @NonEscaping("a,b,c") because it overrides a method annotated with that. + def f2():Int = 1; + def f3():Int = 1; +} + + +class TypeNameTest { + val n = typeName(); +} +struct TypeNameTest2 { + val n = typeName(); +} + + + +class TestNonEscaping { + val x = foo(); + + @NonEscaping("") def f1() {} + + @NonEscaping("") final def f5() { + bar(); // ERR: The call TestNonEscaping.this.bar() is illegal because you can only call private/final/@NonEscaping methods from a NonEscaping method (such as a conprivate structor, a field initializer, or a @NonEscaping method) + } + def bar() {} + + + + @NonEscaping("") final def foo() { + this.foo2(); + return 3; + } + final def foo2() { + } +} + + + +interface BlaInterface { + def bla():Int{self!=0}; +} +class TestAnonymousClass { + static val anonymous1 = new Object() {}; + val anonymous2 = new TestAnonymousClass() {}; // ERR + def foo() { + val x = new Object() {}; + } + @NonEscaping("") final def foo2() { + val x = new Object() {}; // ERR + } + + val anonymous = new BlaInterface() { // ERR + public def bla():Int{self!=0} { + return k; + } + }; + val inner = new Inner(); // ERR + val w:Int{self!=0} = anonymous.bla(); + val k:Int{self!=0}; + def this() { + assert w!=0; + k = 3; + } + + class Inner implements BlaInterface { + public def bla():Int{self!=0} { + return k; + } + } +} + + +class C57 { + var m: Int{self!=0}, n:Int{self!=0}; + private final def ctorLike() { + n = m; + } + def this() { + ctorLike(); // ERR: Cannot read from field 'm' before it is definitely assigned. + m = 7; + } +} + + + + +class TestGlobalRefRestriction { + private var k:GlobalRef[TestGlobalRefRestriction] = GlobalRef[TestGlobalRefRestriction](this); + private val z = GlobalRef[TestGlobalRefRestriction](this); + val z2 = GlobalRef[TestGlobalRefRestriction](this); // ERR (must be private) + var f:GlobalRef[TestGlobalRefRestriction]; + val q1 = k; // ERR (can't use GlobalRef(this) ) + val w1 = GlobalRef[GlobalRef[TestGlobalRefRestriction]](this.k); // ERR (can't use "k" cause it is a GlobalRef(this) ) + var other:TestGlobalRefRestriction = null; + val q2 = other.k; + val w2 = GlobalRef[GlobalRef[TestGlobalRefRestriction]](other.k); + + def this() { + foo1(); + k = GlobalRef[TestGlobalRefRestriction](null); // ok, can assign to globalRef fields (but you can't read from them) + k = + f = k; // ERR + f = k; // ERR + k = f; + f = other.k; + k = other.k; + f = GlobalRef[TestGlobalRefRestriction](this); // ERR (this escaped) + } + private def foo1() { + val z = (k as GlobalRef[TestGlobalRefRestriction]{home==here}); // ERR (because it is called from a ctor) + z(); + } + private def foo2() { + val z = (k as GlobalRef[TestGlobalRefRestriction]{home==here}); + z(); + } + + class Inner { + private var k1:GlobalRef[Inner] = GlobalRef[Inner](this); + private val k2:GlobalRef[Inner] = GlobalRef[Inner](Inner.this); + val z1 = k1; // ERR + val z2 = k2; // ERR + var w:GlobalRef[TestGlobalRefRestriction] = GlobalRef[TestGlobalRefRestriction](TestGlobalRefRestriction.this); + val z3 = w; // ok, because the outer class is already cooked. + def this() { + k1 = GlobalRef[Inner](this); // ERR + w = GlobalRef[TestGlobalRefRestriction](TestGlobalRefRestriction.this); + } + } +} + + +class TestFieldInitializer { + var flag:Boolean = true; + var z:Int = flag ? 3 : z+1; // ERR: Cannot read from field 'z' before it is definitely assigned. + val j = flag ? 3 : foo(); // ERR: reads from j before it is assigned. + val k = foo(); + var i:Int{self!=0}; + final def foo() { + val z = j; + i = 1; + return 2; + } +} + +class Test2 { + val layout:Int{self!=0}; + def this() { + bla(); // ERR: bla() reads from layout before it is written to! + layout = 1; + } + private def bla() { + Console.OUT.println(layout); // previously printed 0 + } +} + +class Person { + var name:String{name!=null}; + def this(name:String{name != null}) { + setName(name); + } + public final def setName(name:String{name != null}) { + this.name = name; + } +} +class Example1 { + var flag:Boolean; + var i1:Int{self!=0}; + def this() { + setI(); + // i1 is definitely-assigned now + } + final def setI() { + if (flag) { + i1 = 2; + } else { + setI(); + } + } +} +class Example2 { + var flag:Boolean; + var i1:Int{self!=0}; + var i2:Int{self!=0}; + def this() { + finish m2(); + } + //Read=[i1] SeqWrite=[i2] Write=[i1,i2] + final def m1() { + val z1 = i1; + if (flag) { + async { i1 = 1; } + i2 = 2; + val z2 = i2; // doesn't need to be in Read set, because we assigned to it beforehand. + } else { + m2(); + i2 = 3; + } + } + //Read=[] SeqWrite=[i1] Write=[i1,i2] + private def m2() { + if (flag) { + finish async { i1 = 1; val z = i1; } + async { i2 = 2; } + } else { + i1 = 3; + m1(); + } + } +} +class Example3 { + var flag:Boolean; + var i1:Int{self!=0}; + var i2:Int{self!=0}; + var i3:Int{self!=0}; + + def this() { + m1(); + } + def this(i:Int) { + m2(); + } + //Read=[] SeqWrite=[i1,i2,i3] Write=[i1,i2,i3] + final def m1() { + i1 = 1; + m2(); + } + //Read=[] SeqWrite=[i1,i2,i3] Write=[i1,i2,i3] + private def m2() { + i2 = 2; + m3(); + } + //Read=[] SeqWrite=[i1,i2,i3] Write=[i1,i2,i3] + private def m3() { + i3 = 3; + if (flag) { + i1=1; i2=2; // stop the recursion. + } else { + m1(); + } + } +} + + +class LegalExample { + val f1:Int = 4*2; + val f2:Int; // must be initialized in every ctor + var v1:Int; // has a default value, does not have to be assigned + var v2:Int{self!=0}; // must be assigned because there is no default value + def this() { + this(4); + } + def this(i:Int{self!=0}) { + super(); + f2 = m1(); + setV2(i); + } + private def m1():Int = v1++; + public final def setV2(i:Int{self!=0}) { v2 = i; } +} +class IllegalExample { + var f2:Int{self!=0}; + var v2:Int{self!=0}; + def this() { // ERR field is not initialized in this() + f2 = 3; + if (3==4) setV2(); + } + def this(i:Int) { // ERR field is not initialized in this(Int) + setV2(); + } + final def setV2() { v2 = 3; } +} +class IllegalExample2[T] { + var t:T; // ERR (not initialized) +} + +class SuperTest22 { + def this() { + foo(); + } + final def foo() { + } +} +class SuperCallTest extends SuperTest22 { + def this() { + super(); + foo(); // ERR (cannot call super methods in a conprivate structor unless annotated with @NonEscaping) + } +} + +class TestFieldInitForwardRef { + val Y:Int = this.X; + static val X:Int = 2; + + class Inner { + var g:Int = this.f+2; // ERR + var h:Int = this.h*3; // ERR + var f:Int = q+2; + } + static class StaticInner { + var f:Int; + var g:Int = this.f+2; + var h:Int = this.h*3; // ERR + } + + var z1:Int = foo(null); + var z2:Int = this.foo(null); + var z3:TestFieldInitForwardRef = this; // ERR + var z4:Int = z3.foo(this); // ERR + var z5:Int = z3.foo(null); + var w1:Int = z3.a; + var w2:Int = this.a; // ERR + + var a:Int = q+2; // ERR + var b:Int = this.q+2; // ERR + var c:Int = a+b+this.q+2; // ERR + var w:Int = a*b+this.c; + var p:Int = a*b+this.c+q; // ERR + var q:Int = 1; + + var e:Inner = new Inner(); // ERR + var e2:StaticInner = new StaticInner(); + + private def foo(arg:TestFieldInitForwardRef):Int = 3; +} + + +struct UserDefinedStruct {} +class TestFieldsWithoutDefaults[T] { + // generic parameter test + var f2:T; // ERR + + // primitive private struct tests (when we'll add literals for Short,UShort,Byte,UByte, I should add more tests) + var i1:Int; + var i2:Int{self==0}; + var i3:Int{self!=1}; + var i4:Int{self!=0}; // ERR + var l1:Long; + var l2:Long{self==0l}; + var l3:Long{self!=0l}; // ERR + var ul1:ULong; + var ul2:ULong{self==0ul}; + var ul3:ULong{self!=0lu}; // ERR + var ui1:UInt; + var ui2:UInt{self==0u}; + var ui3:UInt{self!=0u}; // ERR + var ff1:Float; + var ff2:Float{self==0.0f}; + var ff3:Float{self!=0.0f}; // ERR + var d1:Double; + var d2:Double{self==0.0}; + var d3:Double{self!=0.0}; // ERR + @x10.compiler.Uninitialized var b0:Boolean; + var b1:Boolean; + var b2:Boolean{self==true}; // ERR + var b3:Boolean{self!=false}; // ERR + var b4:Boolean{self==false}; + var b5:Boolean{self}; // ERR + var b6:Boolean{!self}; + var ch1:Char; + var ch2:Char{self=='\0'}; + var ch3:Char{self!='\0'}; // ERR + // todo: do tests for Char, Byte, UByte, Short, UShort + + // references (with or without null) + var r0:Array[Int{self!=0}]; + var r1:Array[T]; + var r2:Any; + var r3:Array[T]{self!=null}; // ERR + var r4:Any{self!=null}; // ERR + + // closures can be null + var c1:() => Int = null; + var c2:() => void; + var c3:(t:T) => T; + + + // user-defined private struct examples + var s1:UserDefinedStruct; // ERR + +} + + + + + + + + +class EscapingCtorTest(p:EscapingCtorTest) { + var tt:EscapingCtorTest; val w:Int; val v1:Int = 1; var x1:Int; - static def foo(t:Test)=2; + static def foo(t:EscapingCtorTest)=2; static def bar(t:Inner)=2; def this() { this(null); @@ -12,8 +625,9 @@ def this(i:Int) { this(i,null); } - def this(q:Test!):Test{self.p==q} { - property(q); + def this(a:EscapingCtorTest) { + property(a); + val q:EscapingCtorTest = null; w = 2; val alias = q; val callToString = ""+q; @@ -25,9 +639,9 @@ q.z(q); val inner = q.new Inner(); } - def this(i:Int,q:Test!): - Test{self.p==self} { - property(this); // ERR + def this(i:Int,a:EscapingCtorTest) { + property(a); + val q:EscapingCtorTest = null; w = 4; val alias = this; // ERR val callToString = ""+this; // ERR @@ -37,15 +651,25 @@ this.tt = q; q.tt = this.tt; foo(this); // ERR - this.m(); // ERR q.z(this); // ERR val inner1 = new Inner(); // ERR val inner2 = this.new Inner(); // ERR + this.m(); + } - operator this+(that:Test):Test = null; - def m() {} - def g() {} - def z(q:Test) {} + operator this+(that:EscapingCtorTest):EscapingCtorTest = null; + final def m() { + g(); + } + private def g() { + z(null); + } + final def z(q:EscapingCtorTest) { + q.g(); + g(); + val inner1 = new Inner(); // ERR + val callOp1 = q+this; // ERR + } // inner class - this of the inner class cannot escape, but the outer can escape (because you access it's fields via methods, e.g., Outer.this.getHeader()) class Inner { @@ -57,13 +681,13 @@ x2 = v2; x2 = v1; // Outer "this" can escape - g(); - Test.this.g(); - z(Test.this); + g(); + EscapingCtorTest.this.g(); + z(EscapingCtorTest.this); // Inner "this" can NOT escape f(null); // ERR this.f(null); // ERR - val z:Inner! = null; + val z:Inner = null; z.f(z); z.f(this); // ERR bar(this); // ERR @@ -71,4 +695,67 @@ } def f(inner:Inner) {} } -} \ No newline at end of file +} + + +class Example4 { + var i1:Int{self!=0}; + var i2:Int{self!=0}; + var i3:Int{self!=0}; + + def this() { + m1(); + } + def this(i:Int) { + m2(); + } + final def m1() { + i1 = 1; + m2(); + } + private def m2() { + i2 = 2; + m3(); + } + private def m3() { + i3 = 3; + if (i3==4) { + i1=1; i2=2; // stop the recursion. + } else { + m1(); + } + } +} + + +struct Bla2Struct { + val x = 4; + def equals(i:Int)=false; +} + +struct Outer[U] { + static struct Test[U] { + def blabla()=2; + } + def bla() { + Console.OUT.println(Test[U]().blabla()); + return 42; + } +} + +interface InterfaceForStruct {} +struct BlaStruct(p:Int) implements InterfaceForStruct { + val i:Int = 4; + val jj:String = new String("as"); + val j:UInt = 4; + val h:Object = new Object(); + def this(p:Int) { property(p); } +} +struct Test3[U,B] { + val u:U; + val b:B; + def this(u:U,b:B) { + this.u = u; + this.b = b; + } +} Modified: trunk/x10.tests/examples/Constructs/DepType/ReferenceConsistencyCheck.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/DepType/ReferenceConsistencyCheck.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/DepType/ReferenceConsistencyCheck.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -13,7 +13,7 @@ public class ReferenceConsistencyCheck(R: Region{rank==2, zeroBased, rect}, D:Dist{region==this.R}, - A: DistArray[double]{dist==this.D}) extends x10Test { + A: DistArray[double]{dist==this.D, dist.rank==2}) extends x10Test { public def this(R: Region{rank==2&&zeroBased&&rect}, D: Dist{region==R}, Modified: trunk/x10.tests/examples/Constructs/Future/Future1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/Future1.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Future/Future1.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -11,6 +11,7 @@ import harness.x10Test; import x10.util.Future; + /** * Future test. */ Modified: trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Future/FutureForce.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -10,6 +10,7 @@ */ import harness.x10Test; +import x10.util.Future; /** * Checks force for grand-children. @@ -29,13 +30,13 @@ } public def foo(): Int = { - var r2: Future[Int] = Future.make( () => at (here) bar() ); + var r2: Future[Int] = Future.make( () => bar() ); return 42; } public def run(): Boolean = { atomic flag = false; - var r1: Future[Int] = Future.make( () => at (here) foo() ); + var r1: Future[Int] = Future.make( () => foo() ); r1(); var b: Boolean; atomic b = flag; Modified: trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Future/FutureForced.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -10,6 +10,7 @@ */ import harness.x10Test; +import x10.util.Future; /** Check that forced works correctly. * Future test. Modified: trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Future/FutureTest2.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -10,6 +10,7 @@ */ import harness.x10Test; +import x10.util.Future; import x10.util.Future; /** Modified: trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -10,6 +10,7 @@ */ import harness.x10Test; +import x10.util.Future; import x10.util.Future; /** @@ -33,7 +34,7 @@ * Spawns subactivities that cause delayed side-effects. */ def m1(val A: Array[int](1), val K: int): int = { - foreach (val (i): Point in A) { + foreach (val [i]: Point in A) { Activity.sleep(3000); atomic A(i) += 1; } @@ -47,7 +48,7 @@ * and exceptions. */ def m2(val A: Array[int](1), val K: int): int = { - foreach (val p(i): Point in A) { + foreach (val p[i]: Point in A) { Activity.sleep(3000); atomic A(i) += 1; atomic A(OUTOFRANGE) = -1; @@ -97,9 +98,9 @@ x10.io.Console.OUT.println("3"); chk(r3 == 1 && !gotException); // must read new values of A here - for (val (i): Point in A) x10.io.Console.OUT.println("A["+i+"] = "+A(i)); + for (val [i]: Point in A) x10.io.Console.OUT.println("A["+i+"] = "+A(i)); chk(A(K) == 2); - for (val (i): Point in A) atomic chk(imp(i != K, A(i) == 1)); + for (val [i]: Point in A) atomic chk(imp(i != K, A(i) == 1)); //future { e }.force() must throw //exceptions from subactivities of e @@ -113,9 +114,9 @@ x10.io.Console.OUT.println("4" + gotException + " r4 = " + r4); chk(r4 ==-1 && gotException); // must read new values of A here - for (val (i): Point in A) x10.io.Console.OUT.println("A["+i+"] = "+A(i)); + for (val [i]: Point in A) x10.io.Console.OUT.println("A["+i+"] = "+A(i)); atomic chk(A(K) == 3); - for (val (i): Point in A) atomic chk(imp(i != K, A(i) == 2)); + for (val [i]: Point in A) atomic chk(imp(i != K, A(i) == 2)); //Only force() throws the exception, //a plain future call just spawns the expression @@ -133,9 +134,9 @@ } chk(r5 ==-1 && gotException); // must read new values of A here - for (val (i): Point in A) x10.io.Console.OUT.println("A["+i+"] = "+A(i)); + for (val [i]: Point in A) x10.io.Console.OUT.println("A["+i+"] = "+A(i)); atomic chk(A(K) == 4); - for (val (i): Point in A) atomic chk(imp(i != K, A(i) == 3)); + for (val [i]: Point in A) atomic chk(imp(i != K, A(i) == 3)); return true; } @@ -143,7 +144,7 @@ /** * True iff x logically implies y */ - static def imp(x: boolean, y: boolean): boolean = { + static safe def imp(x: boolean, y: boolean): boolean = { return (!x||y); } Modified: trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Future/FutureTest5.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -11,6 +11,7 @@ import x10.util.Box; import harness.x10Test; +import x10.util.Future; /** * Checks if creation and force of Future in different activities work. @@ -39,8 +40,8 @@ */ private def testUp_(val del: boolean): boolean = { atomic fut = null; - async (here) { - val t1 = Future.make( () => 42); + async { + val t1 = Future.make( () => 42 ); atomic fut = t1 as Box[Future[Int]]; if (del) Activity.sleep(500); @@ -57,7 +58,7 @@ */ private def testDown_(): boolean = { val fut_l = Future.make( () => 42 ); - finish async (here) { + finish async { var fortytwo: int = fut_l.force(); x10.io.Console.OUT.println("down done"); }; @@ -69,13 +70,13 @@ */ private def testSibling_(val del: boolean): boolean = { atomic fut = null; - async (here) { + async { val t1= Future.make( () => 42 ); atomic fut = t1 as Box[Future[Int]]; if (del) Activity.sleep(500); } - finish async (here) { + finish async { var t2: Future[Int]; when (fut != null) { t2 = fut(); } var fortytwo: int = t2.force(); Modified: trunk/x10.tests/examples/Constructs/Init/InitFieldWithInstanceClass.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Init/InitFieldWithInstanceClass.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Init/InitFieldWithInstanceClass.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -15,12 +15,16 @@ /** * Check that it is ok to initialize a field with an instance of an instance inner class + * Yoav: it's not ok under the new initialization rules. "this" cannot escape. + This is equivalent to the prohibited pattern: + static class A(outer:InitFieldWithInstanceClass) {} + val a = new A(this); // "this" cannot escape! +We can't allow either pattern. */ public class InitFieldWithInstanceClass extends x10Test { - class A { - } + static class A {} val a = new A(); public def run() =true; Deleted: trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithCall.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithCall.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithCall.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,33 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - - - -/** - * Check that it is ok to have an instance initializer invoke a private or final method. Same restrictions - * on escaping this apply to this method as if it were called from a constructor. - */ - -public class InstanceInitializerWithCall extends x10Test { - - final def m()=1; - { - m(); - } - - public def run() =true; - - public static def main(Array[String](1)) { - new InstanceInitializerWithCall().execute(); - } -} Deleted: trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithInstanceClass.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithInstanceClass.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Init/InstanceInitializerWithInstanceClass.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,35 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - - - -/** - * Check that it is ok to initialize a field with an instance of an instance inner class - */ - -public class InstanceInitializerWithInstanceClass extends x10Test { - - class A { - } - val a:A; - { - a= new A(); - } - - - public def run() =true; - - public static def main(Array[String](1)) { - new InstanceInitializerWithInstanceClass().execute(); - } -} Modified: trunk/x10.tests/examples/Constructs/PlaceCast/PlaceCast2.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/PlaceCast/PlaceCast2.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/PlaceCast/PlaceCast2.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -30,8 +30,8 @@ try { // FIX: d(p) currently causes the compiler to assert an error. val dp = d(p); - val x = disagree(p) as BoxedBoolean!dp; - at (this) atomic nplaces++; + val x = disagree(p) as BoxedBoolean; // used to be: BoxedBoolean!dp; + at (dp) atomic nplaces++; // used to be: this } catch (x: BadPlaceException) { x10.io.Console.OUT.println("Caught bad place exception for " + p); } catch (x: ClassCastException) { Modified: trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -16,8 +16,8 @@ class PolyFromRail1 extends TestRegion { public def run() { - var foo: Rail[double] = [5.0,4.0,3.0,2.0,1.0]; - val a = new Array[double](foo); + var foo: Rail[double] = Rail.make([5.0,4.0,3.0,2.0,1.0]); + val a:Array[double] = new Array[double](0..foo.length, ([i]:Point(1)) => foo(i)); prArray("from native rail", a); return status(); } Modified: trunk/x10.tests/examples/Issues/XTENLANG_1565.x10 =================================================================== --- trunk/x10.tests/examples/Issues/XTENLANG_1565.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Issues/XTENLANG_1565.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -42,7 +42,7 @@ k=8; // k:[1,1,2,2] f(k); - //f(n); // ERR + f(n); // ERR } else { // n:[0,0,0,0] i:[1,1,1,1] j:[0,0,0,0] k:[0,0,0,0] n=9; q = 999; @@ -50,9 +50,9 @@ // n:[1,1,1,1] } // k:[0,1,0,2] n:[0,1,1,1] i:[1,1,1,2] j:[0,0,0,1] q:[0,0,0,1] - //f(k); // ERR - //f(n); // ERR - //f(j); // ERR + f(k); // ERR + f(n); // ERR + f(j); // ERR f(m); f(i); k=11; // k:[1,2,1,3] @@ -60,13 +60,13 @@ } // k:[1,3,1,3] n:[1,1,1,1] i:[1,2,1,2] j:[0,1,0,1] q:[0,1,0,1] f(k); f(n); f(m); f(i); - //f(j); // ERR + f(j); // ERR f(q); j=12; // j:[1,2,1,2] f(j); } - def f(i:Int):Int=i+1; + final def f(i:Int):Int=i+1; public def run(): boolean { return true; Modified: trunk/x10.tests/examples/Issues/XTENLANG_637.x10 =================================================================== --- trunk/x10.tests/examples/Issues/XTENLANG_637.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Issues/XTENLANG_637.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -18,10 +18,10 @@ class XTENLANG_637 extends x10Test { public def run(): boolean { - val sub = new Sub(); - val csub = new Get[Sub](sub); - val csup1 : Get[Super] = csub; - val csup2 : Get[Super] = csub; + val sub = new Sub_637(); + val csub = new Get_637[Sub_637](sub); + val csup1 : Get_637[Super_637] = csub; + val csup2 : Get_637[Super_637] = csub; return true; } @@ -30,12 +30,12 @@ } } -class Get[+X] { +class Get_637[+X] { var x : X; def this(x:X) { this.x = x; } } -class Super { +class Super_637 { } -class Sub extends Super { +class Sub_637 extends Super_637 { } \ No newline at end of file Modified: trunk/x10.tests/examples/Misc/Stencil1D.x10 =================================================================== --- trunk/x10.tests/examples/Misc/Stencil1D.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Misc/Stencil1D.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -61,10 +61,6 @@ public static def main(args: Array[String](1)) { var n: int = args.size > 0 ? Int.parse(args(0)) : 100; var p: int = args.size > 1 ? Int.parse(args(1)) : 2; - // x10.io.Console.ERR.println("Starting: N=" + n + " P=" + p); - // var time: Long = -System.nanoTime(); val s = new Stencil1D(n, p); s.execute(); - // time += System.nanoTime(); - // x10.io.Console.ERR.println("N=" + n + " P=" + p + " Iters=" + s.iters + " time=" + time/(1000*1000) + " ms"); } } Modified: trunk/x10.tests/examples/Samples/CUDABlackScholesTest.x10 =================================================================== --- trunk/x10.tests/examples/Samples/CUDABlackScholesTest.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Samples/CUDABlackScholesTest.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * Modified: trunk/x10.tests/examples/Samples/CUDAKernelTestTest.x10 =================================================================== --- trunk/x10.tests/examples/Samples/CUDAKernelTestTest.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Samples/CUDAKernelTestTest.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * Modified: trunk/x10.tests/examples/Samples/CUDATopologyTest.x10 =================================================================== --- trunk/x10.tests/examples/Samples/CUDATopologyTest.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Samples/CUDATopologyTest.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * Modified: trunk/x10.tests/examples/Samples/KMeansCUDATest.x10 =================================================================== --- trunk/x10.tests/examples/Samples/KMeansCUDATest.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/examples/Samples/KMeansCUDATest.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -1,3 +1,4 @@ +// Yoav added: IGNORE_FILE /* * This file is part of the X10 project (http://x10-lang.org). * Modified: trunk/x10.tests/tests/Constructs/Rooted/RootedCall.x10 =================================================================== --- trunk/x10.tests/tests/Constructs/Rooted/RootedCall.x10 2010-09-22 21:45:55 UTC (rev 16640) +++ trunk/x10.tests/tests/Constructs/Rooted/RootedCall.x10 2010-09-22 23:12:23 UTC (rev 16641) @@ -24,7 +24,7 @@ } public def run(): boolean = { - var a:A! = new A(); + var a:A = new A(); a.m(); // ok return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-23 13:42:45
|
Revision: 16657 http://x10.svn.sourceforge.net/x10/?rev=16657&view=rev Author: yzibin Date: 2010-09-23 13:42:39 +0000 (Thu, 23 Sep 2010) Log Message: ----------- removed @Transient and using "transient" instead. Modified Paths: -------------- trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java trunk/x10.compiler/src/x10/types/X10TypeMixin.java trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 trunk/x10.tests/examples/Constructs/Generics/Generics_ERR_MustFailCompile.x10 Removed Paths: ------------- trunk/x10.runtime/src-x10/x10/compiler/Transient.x10 Modified: trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java 2010-09-23 13:37:08 UTC (rev 16656) +++ trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java 2010-09-23 13:42:39 UTC (rev 16657) @@ -407,7 +407,7 @@ if (X10TypeMixin.isX10Struct(fieldDef().container().get()) && !isMutable(ts, fieldDef().container().get()) && - ! X10Flags.toX10Flags(fieldDef().flags()).isFinal()) + ! f.isFinal()) { Errors.issue(tc.job(), new SemanticException("A struct may not have var fields.", position())); } @@ -419,8 +419,8 @@ // Add an initializer to uninitialized var field unless field is annotated @Uninitialized. final X10FieldDef fieldDef = (X10FieldDef) n.fieldDef(); - final boolean needsInit = !n.flags().flags().isFinal() && n.init() == null && !X10TypeMixin.isUninitializedField(fieldDef, ts); - final boolean isTransient = X10TypeMixin.isTransientField(fieldDef, ts); + final boolean needsInit = !f.isFinal() && n.init() == null && !X10TypeMixin.isUninitializedField(fieldDef, ts); + final boolean isTransient = f.isTransient(); if (needsInit || isTransient) { // creating an init. Expr e = X10TypeMixin.getZeroVal(type,position().markCompilerGenerated(),tc); @@ -432,7 +432,7 @@ if (isTransient) { // Transient fields must have a default value if (e==null) - Errors.issue(tc.job(), new SemanticException("The @Transient field '"+n.name()+"' must have a type with a default value.",position())); + Errors.issue(tc.job(), new SemanticException("The transient field '"+n.name()+"' must have a type with a default value.",position())); } } Modified: trunk/x10.compiler/src/x10/types/X10TypeMixin.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-23 13:37:08 UTC (rev 16656) +++ trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-23 13:42:39 UTC (rev 16657) @@ -996,9 +996,6 @@ public static boolean isUninitializedField(X10FieldDef def,X10TypeSystem ts) { return isDefAnnotated(def,ts,"x10.compiler.Uninitialized"); } - public static boolean isTransientField(X10FieldDef def,X10TypeSystem ts) { - return isDefAnnotated(def,ts,"x10.compiler.Transient"); - } public static String getNonEscapingReadsFrom(X10ProcedureDef def,X10TypeSystem ts) { try { Type at = (Type) ts.systemResolver().find(QName.make("x10.compiler.NonEscaping")); Deleted: trunk/x10.runtime/src-x10/x10/compiler/Transient.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/compiler/Transient.x10 2010-09-23 13:37:08 UTC (rev 16656) +++ trunk/x10.runtime/src-x10/x10/compiler/Transient.x10 2010-09-23 13:42:39 UTC (rev 16657) @@ -1,16 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -package x10.compiler; - -import x10.lang.annotations.StatementAnnotation; - -public interface Transient extends StatementAnnotation {} Modified: trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-23 13:37:08 UTC (rev 16656) +++ trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-23 13:42:39 UTC (rev 16657) @@ -4,13 +4,13 @@ //public class EscapingThisTest { -class TransientTest { // The @Transient field '...' must have a type with a default value. - @Transient val x1 = 2; // ERR (because the type is infered to be Int{self==2} - @Transient val x2:Int = 2; - @Transient var y:Int; - @Transient var y2:Int{self==3} = 3; // ERR - @Transient var y3:Int{self!=0}; // ERR - @Transient var y4:Int{self==0}; +class TransientTest { // The transient field '...' must have a type with a default value. + transient val x1 = 2; // ERR (because the type is infered to be Int{self==2} + transient val x2:Int = 2; + transient var y:Int; + transient var y2:Int{self==3} = 3; // ERR + transient var y3:Int{self!=0}; // ERR + transient var y4:Int{self==0}; def this() { y3 = 4; } Modified: trunk/x10.tests/examples/Constructs/Generics/Generics_ERR_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Generics/Generics_ERR_MustFailCompile.x10 2010-09-23 13:37:08 UTC (rev 16656) +++ trunk/x10.tests/examples/Constructs/Generics/Generics_ERR_MustFailCompile.x10 2010-09-23 13:42:39 UTC (rev 16657) @@ -58,9 +58,6 @@ Bla // ERR = null; - static def m4() throws - Bla // ERR - {} def m5[U]() {U<:Bla[T]} {} static def m6[U]() {U<: Bla} // ERR This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2010-09-23 14:25:19
|
Revision: 16658 http://x10.svn.sourceforge.net/x10/?rev=16658&view=rev Author: bherta Date: 2010-09-23 14:25:12 +0000 (Thu, 23 Sep 2010) Log Message: ----------- updates for debug.h from debugger team, and the bare minimal updates to LineNumberMap so that things still compile Modified Paths: -------------- trunk/x10.compiler/src/x10cpp/debug/LineNumberMap.java trunk/x10.runtime/src-cpp/x10aux/debug.h Modified: trunk/x10.compiler/src/x10cpp/debug/LineNumberMap.java =================================================================== --- trunk/x10.compiler/src/x10cpp/debug/LineNumberMap.java 2010-09-23 13:42:39 UTC (rev 16657) +++ trunk/x10.compiler/src/x10cpp/debug/LineNumberMap.java 2010-09-23 14:25:12 UTC (rev 16658) @@ -676,8 +676,8 @@ w.write(""+offsets[cppMethodInfo.x10class]+", "); // _x10class w.write(""+offsets[cppMethodInfo.x10method]+", "); // _x10method w.write(""+offsets[cppMethodInfo.x10rettype]+", "); // _x10returnType - w.write("(uint64_t) 0, "); // TODO - this needs to be re-designed, with the debugger team w.write(""+offsets[cppMethodInfo.cppclass]+", "); // _cppClass + w.write("(uint64_t) 0, "); // TODO - this needs to be re-designed, with the debugger team w.write(""+cppMethodInfo.x10args.length+", "); // _x10argCount w.write(""+cppMethodInfo.cpplineindex); // _lineIndex w.writeln(" },"); @@ -688,13 +688,13 @@ w.write(""+offsets[cppMethodInfo.x10class]+", "); // _x10class w.write(""+offsets[cppMethodInfo.x10method]+", "); // _x10method w.write(""+offsets[cppMethodInfo.x10rettype]+", "); // _x10returnType + w.write(""+offsets[cppMethodInfo.cppclass]+", "); // _cppClass w.write("(uint64_t) "); for (i = 0; i < cppMethodInfo.x10args.length; i++) { int a = cppMethodInfo.x10args[i]; w.write("\""+encodeIntAsChars(offsets[a])+"\" "); // _x10args } w.write("\"\", "); - w.write(""+offsets[cppMethodInfo.cppclass]+", "); // _cppClass w.write(""+cppMethodInfo.x10args.length+", "); // _x10argCount w.write(""+cppMethodInfo.cpplineindex); // _lineIndex w.writeln(" },"); @@ -725,6 +725,12 @@ } else { w.writeln("0,"); } + // TODO - replace these 4 with real values + w.writeln("0,"); + w.writeln("0,"); + w.writeln("0,"); + w.writeln("0,"); + w.writeln("_X10strings,"); if (!m.isEmpty()) { w.writeln("_X10sourceList,"); @@ -740,6 +746,13 @@ } else { w.write("NULL,"); } + + // TODO - replace these 4 with real values + w.writeln("NULL,"); + w.writeln("NULL,"); + w.writeln("NULL,"); + w.writeln("NULL,"); + w.end(); w.newline(); w.writeln("};"); } Modified: trunk/x10.runtime/src-cpp/x10aux/debug.h =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/debug.h 2010-09-23 13:42:39 UTC (rev 16657) +++ trunk/x10.runtime/src-cpp/x10aux/debug.h 2010-09-23 14:25:12 UTC (rev 16658) @@ -84,10 +84,10 @@ uint32_t _x10class; // Index of the X10 containing class name in _X10strings uint32_t _x10method; // Index of the X10 method name in _X10strings uint32_t _x10returnType; // Index of the X10 return type in _X10strings + uint32_t _cppClass; // Index of the C++ class name in _X10strings uint64_t _x10args; // A pointer to a string that contains binary encodings of the // argument indices. Each group of 4 bytes represents the index // of the corresponding argument in _X10strings - uint32_t _cppClass; // Index of the C++ class name in _X10strings uint16_t _x10argCount; // The number of X10 arguments uint16_t _lineIndex; // Index into _CPPtoX10xrefList of the first line of the method }; @@ -95,10 +95,12 @@ struct _X10LocalVarMap { uint32_t _x10name; // Index of the X10 variable name in _X10strings - uint32_t _x10type; // Index of the X10 type in _X10strings + uint32_t _x10type; // Classification of this type + uint32_t _x10typeIndex; // Index of the X10 type into appropriate _X10ClassMap, _X10ClosureMap (if applicable) uint32_t _cppName; // Index of the C++ variable name in _X10strings - uint32_t _startLineIndex; // Index into _CPPtoX10xrefList of the line where the variable is created - uint32_t _endLineIndex; // Index into _CPPtoX10xrefList of the last line where the variable is still in scope + uint32_t _x10index; // Index of X10 file name in _X10sourceList + uint32_t _x10startLine; // First line number of X10 line range + uint32_t _x10endLine; // Last line number of X10 line range }; // The _X10TypeMap and extenders of it are used in the member variable mappings @@ -108,26 +110,42 @@ // The details of the type follow.. }; -struct _X10TypeMember : public _X10TypeMap +struct _X10TypeMember { - uint32_t _x10MemberName; // Index of the X10 member name in _X10strings - uint32_t _x10MemberOffset; // Offset of the member within the X10 class + uint32_t _x10Type; // Classification of this type + uint32_t _x10typeIndex; // Index of the X10 type into appropriate _X10typeMap + uint32_t _x10memberName; // Index of the X10 member name in _X10strings + uint32_t _cppMemberName; // Index of the C++ member name in _X10strings + uint32_t _cppClass; // Index of the C++ containing struct/class name in _X10strings }; -struct _X10ClassMap : public _X10TypeMap +struct _X10ClassMap { + uint32_t _x10type; // Classification of this type uint32_t _x10name; // Index of the X10 class type name in _X10 strings - uint32_t _x10ClassSize; // number of bytes in the class - uint32_t _x10ClassMemberCount; // number of members in the class - _X10TypeMember* _x10members; // pointer to an array of individual member types + uint32_t _x10size; // number of bytes in the class + uint32_t _x10memberCount; // number of members in the class + const struct _X10TypeMember* _x10members; // pointer to an array of individual member types }; -struct _X10ClosureMap : public _X10ClassMap +struct _X10ClosureMap { - uint32_t _x10StartLine; // the start line of the closure definition in the X10 source - uint32_t _x10EndLine; // the end line of the closure definition in the X10 source + uint32_t _x10type; // Classification of this type + uint32_t _x10name; // Index of the X10 class type name in _X10 strings + uint32_t _x10size; // number of bytes in the closure class + uint32_t _x10memberCount; // number of members in the class + uint32_t _x10index; // Index of X10 file name in _X10sourceList + uint32_t _x10startLine; // the start line of the closure definition in the X10 source + uint32_t _x10endLine; // the end line of the closure definition in the X10 source + const struct _X10TypeMember* const _x10members; // pointer to an array of individual member types }; +struct _X10ArrayMap +{ + uint32_t _x10type; // Classification of this type + uint32_t _x10typeIndex; // Index of the X10 type into appropriate _X10typeMap (if applicable) +}; + struct _X10RefMap : public _X10TypeMap { uint32_t _x10ReferredType; // type number of the referred type @@ -138,14 +156,7 @@ uint32_t _x10Name; // Offset to the name of the typedef in _X10strings }; -struct _X10ArrayMap : public _X10TypeMap -{ - uint32_t _x10ElementCount; // Number of elements in the array - uint32_t _x10ElementType; // type number of the array elements -}; - - enum _MetaLanguage { X10_META_LANG = 0 // Metalanguage 0 is X10 }; @@ -165,18 +176,20 @@ unsigned x10toCPPlistSize; // the size in bytes of the X10->C++ cross reference unsigned cPPtoX10xrefListSize; // the size in bytes of the C++->X10 cross reference unsigned x10methodNameListSize; // the size in bytes of the X10 method name mapping list -// TODO - uncomment these two lines once the compiler starts generating them. -// unsigned x10localVarListSize; // the size in bytes of the X10 local variable name mapping list -// unsigned x10typeListSize; // the size in bytes of the X10 type mapping list + unsigned x10localVarListSize; // the size in bytes of the X10 local variable name mapping list + unsigned x10classMapListSize; // the size in bytes of the X10 class mapping list + unsigned x10closureMapListSize; // the size in bytes of the X10 async closure mapping list + unsigned x10arrayMapListSize; // the size in bytes of the X10 array mapping list - const char* x10strings; // The string table - const struct _X10sourceFile* x10sourceList; // The list of X10 source files - const struct _X10toCPPxref* x10toCPPlist; // The X10->C++ cross reference - const struct _CPPtoX10xref* cPPtoX10xrefList; // The C++->X10 cross reference - const struct _X10methodName* x10methodNameList; // The method name mapping list -// TODO - uncomment these two lines once the compiler starts generating them. -// const struct _X10LocalVarMap* x10localVarList; // The local variable name mapping list -// const struct _X10TypeMap* x10typeList; // The type mapping list + const char* x10strings; // The string table + const struct _X10sourceFile* x10sourceList; // The list of X10 source files + const struct _X10toCPPxref* x10toCPPlist; // The X10->C++ cross reference + const struct _CPPtoX10xref* cPPtoX10xrefList; // The C++->X10 cross reference + const struct _X10methodName* x10methodNameList; // The method name mapping list + const struct _X10LocalVarMap* x10localVarList; // The local variable name mapping list + const struct _X10ClassMap* x10classMapList; // The class mapping list + const struct _X10ClosureMap* x10closureMapList; // The async closure mapping list + const struct _X10ArrayMap* x10arrayMapList; // The array mapping list }; //extern void _X10_Entry_Hook(); // A hook at the start of every X10 method. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-23 14:41:19
|
Revision: 16660 http://x10.svn.sourceforge.net/x10/?rev=16660&view=rev Author: yzibin Date: 2010-09-23 14:41:12 +0000 (Thu, 23 Sep 2010) Log Message: ----------- I added @SuppressTransientError to suppress the transient errors on some fields in XRX. Modified Paths: -------------- trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java trunk/x10.compiler/src/x10/types/X10TypeMixin.java trunk/x10.runtime/src-x10/x10/array/Array.x10 trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 trunk/x10.runtime/src-x10/x10/util/Future.x10 Modified: trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java 2010-09-23 14:38:53 UTC (rev 16659) +++ trunk/x10.compiler/src/x10/ast/X10FieldDecl_c.java 2010-09-23 14:41:12 UTC (rev 16660) @@ -420,7 +420,7 @@ // Add an initializer to uninitialized var field unless field is annotated @Uninitialized. final X10FieldDef fieldDef = (X10FieldDef) n.fieldDef(); final boolean needsInit = !f.isFinal() && n.init() == null && !X10TypeMixin.isUninitializedField(fieldDef, ts); - final boolean isTransient = f.isTransient(); + final boolean isTransient = f.isTransient() && !X10TypeMixin.isSuppressTransientErrorField(fieldDef,ts); if (needsInit || isTransient) { // creating an init. Expr e = X10TypeMixin.getZeroVal(type,position().markCompilerGenerated(),tc); @@ -430,7 +430,7 @@ } } if (isTransient) { - // Transient fields must have a default value + // transient fields (not annotated with @SuppressTransientError) must have a default value if (e==null) Errors.issue(tc.job(), new SemanticException("The transient field '"+n.name()+"' must have a type with a default value.",position())); } Modified: trunk/x10.compiler/src/x10/types/X10TypeMixin.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-23 14:38:53 UTC (rev 16659) +++ trunk/x10.compiler/src/x10/types/X10TypeMixin.java 2010-09-23 14:41:12 UTC (rev 16660) @@ -996,6 +996,9 @@ public static boolean isUninitializedField(X10FieldDef def,X10TypeSystem ts) { return isDefAnnotated(def,ts,"x10.compiler.Uninitialized"); } + public static boolean isSuppressTransientErrorField(X10FieldDef def,X10TypeSystem ts) { + return isDefAnnotated(def,ts,"x10.compiler.SuppressTransientError"); + } public static String getNonEscapingReadsFrom(X10ProcedureDef def,X10TypeSystem ts) { try { Type at = (Type) ts.systemResolver().find(QName.make("x10.compiler.NonEscaping")); Modified: trunk/x10.runtime/src-x10/x10/array/Array.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-23 14:38:53 UTC (rev 16659) +++ trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-23 14:41:12 UTC (rev 16660) @@ -11,6 +11,7 @@ package x10.array; +import x10.compiler.SuppressTransientError; import x10.compiler.Header; import x10.compiler.Inline; import x10.compiler.Native; @@ -101,7 +102,7 @@ private val cachedRail:boolean(rail); - private transient val raw:IndexedMemoryChunk[T]; + @SuppressTransientError private transient val raw:IndexedMemoryChunk[T]; /* package */ val rawLength:int; // Made accessible to RemoteArray private val layout:RectLayout; Modified: trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 2010-09-23 14:38:53 UTC (rev 16659) +++ trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 2010-09-23 14:41:12 UTC (rev 16660) @@ -17,6 +17,7 @@ import x10.compiler.NativeString; import x10.compiler.Pinned; import x10.compiler.Global; +import x10.compiler.SuppressTransientError; import x10.util.HashMap; import x10.util.GrowableRail; @@ -1014,7 +1015,7 @@ private val root = GlobalRef[SimpleRootFinish](this); transient protected var counts:int; transient protected var exceptions:Stack[Throwable]; - transient protected val latch = new Latch(); + @SuppressTransientError transient protected val latch = new Latch(); public def this() { counts = 1; @@ -1415,8 +1416,8 @@ private transient val pool:Pool; // per place members - private transient val monitor = new Monitor(); - private transient val finishStates = new FinishStates(); + @SuppressTransientError private transient val monitor = new Monitor(); + @SuppressTransientError private transient val finishStates = new FinishStates(); // constructor @@ -1577,7 +1578,7 @@ static class RemoteControl { private val root = GlobalRef[RemoteControl](this); transient var e:Box[Throwable] = null; - transient val latch = new Latch(); + @SuppressTransientError transient val latch = new Latch(); @Global public safe def equals(a:Any) = (a instanceof RemoteControl) && this.root.equals((a as RemoteControl).root); @Global public safe def hashCode()=root.hashCode(); @@ -1620,7 +1621,7 @@ static class Remote[T] { transient var t:Box[T] = null; transient var e:Box[Throwable] = null; - transient val latch = new Latch(); + @SuppressTransientError transient val latch = new Latch(); private val root = GlobalRef[Remote](this); @Global public safe def equals(a:Any)= (a instanceof Remote[T]) && this.root.equals((a as Remote[T]).root); Modified: trunk/x10.runtime/src-x10/x10/util/Future.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/util/Future.x10 2010-09-23 14:38:53 UTC (rev 16659) +++ trunk/x10.runtime/src-x10/x10/util/Future.x10 2010-09-23 14:41:12 UTC (rev 16660) @@ -11,6 +11,7 @@ package x10.util; +import x10.compiler.SuppressTransientError; import x10.util.GrowableRail; import x10.compiler.Pinned; import x10.compiler.Global; @@ -28,7 +29,7 @@ /** * Latch for signaling and wait */ - transient private val latch = new Latch(); + @SuppressTransientError transient private val latch = new Latch(); /** * Set if the activity terminated with an exception. @@ -37,8 +38,8 @@ */ // This cant be Cell because I need to create it before I know the value // that will go in. - transient private val exception = new GrowableRail[Throwable](); - transient private val result = new GrowableRail[T](); + @SuppressTransientError transient private val exception = new GrowableRail[Throwable](); + @SuppressTransientError transient private val result = new GrowableRail[T](); transient private val eval:()=>T; public static def make[T](eval:()=> T) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-23 15:17:05
|
Revision: 16662 http://x10.svn.sourceforge.net/x10/?rev=16662&view=rev Author: yzibin Date: 2010-09-23 15:16:59 +0000 (Thu, 23 Sep 2010) Log Message: ----------- AssignProperty should be a static context. Modified Paths: -------------- trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java Added Paths: ----------- trunk/x10.runtime/src-x10/x10/compiler/SuppressTransientError.x10 Modified: trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java 2010-09-23 15:10:27 UTC (rev 16661) +++ trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java 2010-09-23 15:16:59 UTC (rev 16662) @@ -126,6 +126,14 @@ return sb.toString(); } + /** + * An explicit property call is a static context. We need to record + * this. + */ + public Context enterScope(Context c) { + return c.pushStatic(); + } + public Node typeCheck(ContextVisitor tc) { TypeSystem ts = tc.typeSystem(); Context ctx = tc.context(); Added: trunk/x10.runtime/src-x10/x10/compiler/SuppressTransientError.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/compiler/SuppressTransientError.x10 (rev 0) +++ trunk/x10.runtime/src-x10/x10/compiler/SuppressTransientError.x10 2010-09-23 15:16:59 UTC (rev 16662) @@ -0,0 +1,19 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +package x10.compiler; + +import x10.lang.annotations.FieldAnnotation; + +/** + * We use this annotation to tell the compiler not to give errors on transient fields without a default value. + */ +public interface SuppressTransientError extends FieldAnnotation { } Property changes on: trunk/x10.runtime/src-x10/x10/compiler/SuppressTransientError.x10 ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-23 19:11:28
|
Revision: 16664 http://x10.svn.sourceforge.net/x10/?rev=16664&view=rev Author: yzibin Date: 2010-09-23 19:11:21 +0000 (Thu, 23 Sep 2010) Log Message: ----------- Deleted AssignPropertyChecker because it's code was never executed anyway because a term is never contained in a set of peers: if (graph.exitPeers().contains(n)) if (graph.entryPeers().contains(n)) Modified Paths: -------------- trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java trunk/x10.compiler/src/polyglot/types/Context_c.java trunk/x10.compiler/src/polyglot/visit/InitChecker.java trunk/x10.compiler/src/x10/ExtensionInfo.java trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 Removed Paths: ------------- trunk/x10.compiler/src/x10/visit/AssignPropertyChecker.java Modified: trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java 2010-09-23 18:41:06 UTC (rev 16663) +++ trunk/x10.compiler/src/polyglot/ast/ConstructorCall_c.java 2010-09-23 19:11:21 UTC (rev 16664) @@ -91,8 +91,7 @@ } /** - * An explicit constructor call is a static context. We need to record - * this. + * ConstructorCall and AssignPropertyCall are a static context. */ public Context enterScope(Context c) { return c.pushStatic(); Modified: trunk/x10.compiler/src/polyglot/types/Context_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/types/Context_c.java 2010-09-23 18:41:06 UTC (rev 16663) +++ trunk/x10.compiler/src/polyglot/types/Context_c.java 2010-09-23 19:11:21 UTC (rev 16664) @@ -384,7 +384,7 @@ */ public Context pushCode(CodeDef ci) { if (Report.should_report(TOPICS, 4)) - Report.report(4, "push code " + ci + " " + ci.position()); + Report.report(4, "push code " + ci.position()); Context_c v = push(); v.kind = CODE; v.code = ci; @@ -441,7 +441,7 @@ */ public void addVariable(VarInstance<?> vi) { if (Report.should_report(TOPICS, 3)) - Report.report(3, "Adding " + vi + " to context."); + Report.report(3, "Adding " + vi.name() + " to context."); addVariableToThisScope(vi); } @@ -450,7 +450,7 @@ */ public void addNamed(Named t) { if (Report.should_report(TOPICS, 3)) - Report.report(3, "Adding type " + t + " to context."); + Report.report(3, "Adding type " + t.name() + " to context."); addNamedToThisScope(t); } Modified: trunk/x10.compiler/src/polyglot/visit/InitChecker.java =================================================================== --- trunk/x10.compiler/src/polyglot/visit/InitChecker.java 2010-09-23 18:41:06 UTC (rev 16663) +++ trunk/x10.compiler/src/polyglot/visit/InitChecker.java 2010-09-23 19:11:21 UTC (rev 16664) @@ -1341,10 +1341,10 @@ DataFlowItem dfIn, DataFlowItem dfOut) { + if (!(currCBI.currCodeDecl instanceof ConstructorDecl)) return; // if we property(...) in some method for (FieldInstance p : a.properties()) { FieldDef fi = p.def(); assert (fi.flags().isFinal()); - assert (currCBI.currCodeDecl instanceof ConstructorDecl); // The property can be assigned to at most once. MinMaxInitCount initCount = dfOut.initStatus.get(fi); if (initCount == null) { Modified: trunk/x10.compiler/src/x10/ExtensionInfo.java =================================================================== --- trunk/x10.compiler/src/x10/ExtensionInfo.java 2010-09-23 18:41:06 UTC (rev 16663) +++ trunk/x10.compiler/src/x10/ExtensionInfo.java 2010-09-23 19:11:21 UTC (rev 16664) @@ -99,7 +99,6 @@ import x10.types.X10SourceClassResolver; import x10.types.X10TypeSystem; import x10.types.X10TypeSystem_c; -import x10.visit.AssignPropertyChecker; import x10.visit.CheckNativeAnnotationsVisitor; import x10.visit.Desugarer; import x10.visit.ExprFlattener; @@ -402,7 +401,6 @@ goals.add(InitializationsChecked(job)); goals.add(ConstructorCallsChecked(job)); goals.add(ForwardReferencesChecked(job)); - goals.add(PropertyAssignmentsChecked(job)); // goals.add(CheckNativeAnnotations(job)); goals.add(CheckASTForErrors(job)); // goals.add(TypeCheckBarrier()); @@ -811,11 +809,6 @@ return new ForgivingVisitorGoal("ForwardRefsChecked", job, new FwdReferenceChecker(job, ts, nf)).intern(this); } - public Goal PropertyAssignmentsChecked(Job job) { - TypeSystem ts = extInfo.typeSystem(); - NodeFactory nf = extInfo.nodeFactory(); - return new ForgivingVisitorGoal("PropertyAssignmentsChecked", job, new AssignPropertyChecker(job, ts, nf)).intern(this); - } public String nativeAnnotationLanguage() { return "java"; } Modified: trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java 2010-09-23 18:41:06 UTC (rev 16663) +++ trunk/x10.compiler/src/x10/ast/AssignPropertyCall_c.java 2010-09-23 19:11:21 UTC (rev 16664) @@ -127,8 +127,7 @@ } /** - * An explicit property call is a static context. We need to record - * this. + * ConstructorCall and AssignPropertyCall are a static context. */ public Context enterScope(Context c) { return c.pushStatic(); Deleted: trunk/x10.compiler/src/x10/visit/AssignPropertyChecker.java =================================================================== --- trunk/x10.compiler/src/x10/visit/AssignPropertyChecker.java 2010-09-23 18:41:06 UTC (rev 16663) +++ trunk/x10.compiler/src/x10/visit/AssignPropertyChecker.java 2010-09-23 19:11:21 UTC (rev 16664) @@ -1,255 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -package x10.visit; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import polyglot.ast.CodeNode; -import polyglot.ast.ConstructorCall; -import polyglot.ast.ConstructorDecl; -import polyglot.ast.MethodDecl; -import polyglot.ast.NodeFactory; -import polyglot.ast.Return; -import polyglot.ast.Term; -import polyglot.frontend.Job; -import polyglot.types.FieldInstance; -import polyglot.types.SemanticException; -import polyglot.types.TypeSystem; -import polyglot.visit.DataFlow; -import polyglot.visit.FlowGraph; -import polyglot.visit.DataFlow.Item; -import polyglot.visit.FlowGraph.EdgeKey; -import x10.ast.AssignPropertyCall; -import x10.types.X10ClassType; -import x10.types.X10ConstructorDef; -import x10.types.X10ConstructorInstance; -import x10.types.X10ParsedClassType; -import x10.types.X10TypeMixin; - -public class AssignPropertyChecker extends DataFlow { - ConstructorDecl cd; - - // InitChecker will check that all properties are assigned exactly once. - // TypeChecker will check that a property statement assigns to all defined properties. - // - // We just need to check that: - // 1. There is exactly one property() statement or this() constructor call on each normal control-flow path to the exit node. - // 2. The property statement implies the return type. - - public AssignPropertyChecker(Job job, TypeSystem ts, NodeFactory nf) { - super(job, ts, nf, false /* backward analysis */); - } - - protected FlowGraph initGraph(CodeNode code, Term root) { - if (code instanceof ConstructorDecl) { - ConstructorDecl d = (ConstructorDecl) code; - this.cd = d; - if (d.constructorDef() instanceof X10ConstructorDef) { - X10ConstructorDef xci = (X10ConstructorDef) d.constructorDef(); - if (xci.container().get() instanceof X10ClassType) { - X10ClassType xt = (X10ClassType) xci.container().get(); - if (! xt.definedProperties().isEmpty()) { - return super.initGraph(code, root); - } - } - } - } - - return null; - } - - public Item createInitialItem(FlowGraph graph, Term node, boolean entry) { - return createItem(DataFlowItem.ZERO, DataFlowItem.ZERO); - } - - public boolean needsProperty() { - X10ConstructorInstance xci = (X10ConstructorInstance) cd.constructorDef().asInstance(); - return X10TypeMixin.isConstrained(xci.container()) || X10TypeMixin.isConstrained(xci.returnType()); - } - - protected static class DataFlowItem extends Item { - /** set of properties on all non-exceptional paths from this node to an exit */ - public final int min, max; - - /** Create a data flow item with the given properties assigned. */ - protected DataFlowItem(int min, int max) { - this.min = min; - this.max = max; - } - - public final static int ZERO = 0; - public final static int ONE = 1; - public final static int MANY = 2; - public final static int DONT_CARE = 3; - - public String toString() { - return "propertyAssignCount=" + min + ".." + max; - } - public boolean equals(Object o) { - if (o instanceof DataFlowItem) { - DataFlowItem i = (DataFlowItem) o; - return this.min == i.min && this.max == i.max; - } - return false; - } - public int hashCode() { - return Integer.valueOf(min).hashCode() + Integer.valueOf(max << 2).hashCode(); - } - } - - public DataFlowItem increment(DataFlowItem in) { - int min, max; - if (in != null && (in.min == DataFlowItem.ONE || in.min == DataFlowItem.MANY)) - min = DataFlowItem.MANY; - else - min = DataFlowItem.ONE; - if (in != null && (in.max == DataFlowItem.ONE || in.max == DataFlowItem.MANY)) - max = DataFlowItem.MANY; - else - max = DataFlowItem.ONE; - return createItem(min, max); - } - - DataFlowItem[][] cache = new DataFlowItem[4][4]; - - protected DataFlowItem createItem(int min, int max) { - DataFlowItem i = cache[min][max]; - if (i == null) { - i = new DataFlowItem(min, max); - cache[min][max] = i; - } - return i; - } - - public Map<EdgeKey, Item> flow(Item in, FlowGraph graph, Term n, boolean entry, Set<EdgeKey> succEdgeKeys) { - // If every path from the exit node to the entry goes through a property - // assign, we're okay. So make the propAssign bit false at exit and true - // at every property assignment; the confluence operation is &&. - // We deal with exceptions specially, and assume that any exception - // edge to the exit node is OK. - - // Only flow from exit. - if (entry) - return itemToMap(in, succEdgeKeys); - - DataFlowItem inItem = (DataFlowItem) in; - - if (n instanceof Return) { - return itemToMap(createItem(DataFlowItem.ZERO, DataFlowItem.ZERO), succEdgeKeys); - } - - if (graph.exitPeers().contains(n)) { - // Exception edges are assumed to be safe - if (needsProperty()) { - Map<EdgeKey, Item> m = itemToMap(createItem(DataFlowItem.DONT_CARE, DataFlowItem.DONT_CARE), succEdgeKeys); - if (succEdgeKeys.contains(FlowGraph.EDGE_KEY_OTHER)) { - m.put(FlowGraph.EDGE_KEY_OTHER, createItem(DataFlowItem.ZERO, DataFlowItem.ZERO)); - } - if (succEdgeKeys.contains(FlowGraph.EDGE_KEY_TRUE)) { - m.put(FlowGraph.EDGE_KEY_TRUE, createItem(DataFlowItem.ZERO, DataFlowItem.ZERO)); - } - if (succEdgeKeys.contains(FlowGraph.EDGE_KEY_FALSE)) { - m.put(FlowGraph.EDGE_KEY_FALSE, createItem(DataFlowItem.ZERO, DataFlowItem.ZERO)); - } - - return m; - } - else { - return itemToMap(createItem(DataFlowItem.ZERO, DataFlowItem.ZERO), succEdgeKeys); - } - } - - if (n instanceof AssignPropertyCall) { - return itemToMap(increment(inItem), succEdgeKeys); - } - - if (n instanceof ConstructorCall) { - ConstructorCall cc = (ConstructorCall) n; - if (cc.kind() == ConstructorCall.THIS) { - return itemToMap(increment(inItem), succEdgeKeys); - } - } - - return itemToMap(in, succEdgeKeys); - } - -// protected Item confluence(List items, List itemKeys, Term node, boolean entry, FlowGraph graph) { -// List l1 = new ArrayList(3); -// List l2 = new ArrayList(3); -// Iterator i = items.iterator(); -// Iterator j = itemKeys.iterator(); -// while (i.hasNext() && j.hasNext()) { -// DataFlowItem dfi = (DataFlowItem) i.next(); -// FlowGraph.EdgeKey key = (FlowGraph.EdgeKey) j.next(); -// if (key instanceof FlowGraph.ExceptionEdgeKey) continue; -// l1.add(dfi); -// l2.add(key); -// } -// if (l1.size() == 0) { -// return new DataFlowItem(0, 0); -// } -// else if (l1.size() == 1) { -// return ((DataFlowItem) l1.get(0)); -// } -// return super.confluence(l1, l2, node, graph); -// } - - protected Item confluence(List<Item> items, Term node, boolean entry, FlowGraph graph) { - // intersect the items - int min = DataFlowItem.DONT_CARE; - int max = DataFlowItem.DONT_CARE; - for (Item item : items) { - DataFlowItem dfi = (DataFlowItem) item; - if (min == DataFlowItem.DONT_CARE || (dfi.min != DataFlowItem.DONT_CARE && dfi.min < min)) - min = dfi.min; - if (max == DataFlowItem.DONT_CARE || (dfi.max != DataFlowItem.DONT_CARE && dfi.max > max)) - max = dfi.max; - } - return createItem(min, max); - } - - public void check(FlowGraph graph, Term n, boolean entry, Item inItem, Map<EdgeKey, Item> outItems) { - if (entry) - return; - - // Check that all paths to exit have exactly one property() statement. - if (graph.entryPeers().contains(n)) { - if (outItems != null && !outItems.isEmpty()) { - // due to the flow equations, all DataFlowItems in the outItems map - // are the same, so just take the first one. - DataFlowItem outItem = (DataFlowItem)outItems.values().iterator().next(); - if (outItem != null) { - if (outItem.max == DataFlowItem.MANY) { - // This should be caught by InitChecker, but report it here just in case. - reportError("The constructor may have initialized properties more than once. There is a path with more than one property(...) statement or this(...) call.", - cd.position()); - return; - } - - if (!needsProperty() || outItem.min != DataFlowItem.ZERO) { - return; - } - - // fall through to report error - } - } - - reportError("The constructor incorrectly initializes properties. There is a path without a property(...) statement or this(...) call.", - cd.position()); - } - } -} Modified: trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-23 18:41:06 UTC (rev 16663) +++ trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-23 19:11:21 UTC (rev 16664) @@ -646,7 +646,12 @@ val alias = this; // ERR val callToString = ""+this; // ERR val callOp1 = q+this; // ERR - val callOp2 = this+q; // ERR + val callOp2 = this+q; + val callOp3 = q*this; + val callOp4 = this*q; // ERR + val callApply1 = this(null); + val callApply2 = this(this); // ERR + this(null); q.tt = this; // ERR this.tt = q; q.tt = this.tt; @@ -657,7 +662,10 @@ this.m(); } - operator this+(that:EscapingCtorTest):EscapingCtorTest = null; + final operator this+(that:EscapingCtorTest):EscapingCtorTest = null; + final operator (that:EscapingCtorTest)*this:EscapingCtorTest = null; + final def apply(that:EscapingCtorTest):EscapingCtorTest = null; + final def m() { g(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-23 20:02:30
|
Revision: 16666 http://x10.svn.sourceforge.net/x10/?rev=16666&view=rev Author: yzibin Date: 2010-09-23 20:02:21 +0000 (Thu, 23 Sep 2010) Log Message: ----------- removed from the *.x10 files the method modifiers: safe, pinned, sequential, nonblocking Modified Paths: -------------- trunk/x10.runtime/src-x10/x10/array/Array.x10 trunk/x10.runtime/src-x10/x10/array/BaseDist.x10 trunk/x10.runtime/src-x10/x10/array/Dist.x10 trunk/x10.runtime/src-x10/x10/array/DistArray.x10 trunk/x10.runtime/src-x10/x10/array/EmptyRegion.x10 trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 trunk/x10.runtime/src-x10/x10/array/MatBuilder.x10 trunk/x10.runtime/src-x10/x10/array/Point.x10 trunk/x10.runtime/src-x10/x10/array/PolyMat.x10 trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 trunk/x10.runtime/src-x10/x10/array/RectLayout.x10 trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 trunk/x10.runtime/src-x10/x10/array/Region.x10 trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 trunk/x10.runtime/src-x10/x10/array/Row.x10 trunk/x10.runtime/src-x10/x10/array/ValRow.x10 trunk/x10.runtime/src-x10/x10/array/VarRow.x10 trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 trunk/x10.runtime/src-x10/x10/lang/Any.x10 trunk/x10.runtime/src-x10/x10/lang/Boolean.x10 trunk/x10.runtime/src-x10/x10/lang/Byte.x10 trunk/x10.runtime/src-x10/x10/lang/Cell.x10 trunk/x10.runtime/src-x10/x10/lang/Char.x10 trunk/x10.runtime/src-x10/x10/lang/Clock.x10 trunk/x10.runtime/src-x10/x10/lang/Complex.x10 trunk/x10.runtime/src-x10/x10/lang/Double.x10 trunk/x10.runtime/src-x10/x10/lang/Float.x10 trunk/x10.runtime/src-x10/x10/lang/GlobalCell.x10 trunk/x10.runtime/src-x10/x10/lang/GlobalRef.x10 trunk/x10.runtime/src-x10/x10/lang/Int.x10 trunk/x10.runtime/src-x10/x10/lang/Long.x10 trunk/x10.runtime/src-x10/x10/lang/Math.x10 trunk/x10.runtime/src-x10/x10/lang/Object.x10 trunk/x10.runtime/src-x10/x10/lang/Place.x10 trunk/x10.runtime/src-x10/x10/lang/PlaceLocalHandle.x10 trunk/x10.runtime/src-x10/x10/lang/Rail.x10 trunk/x10.runtime/src-x10/x10/lang/Reducible.x10 trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 trunk/x10.runtime/src-x10/x10/lang/Short.x10 trunk/x10.runtime/src-x10/x10/lang/String.x10 trunk/x10.runtime/src-x10/x10/lang/Throwable.x10 trunk/x10.runtime/src-x10/x10/lang/UByte.x10 trunk/x10.runtime/src-x10/x10/lang/UInt.x10 trunk/x10.runtime/src-x10/x10/lang/ULong.x10 trunk/x10.runtime/src-x10/x10/lang/UShort.x10 trunk/x10.runtime/src-x10/x10/lang/ValRail.x10 trunk/x10.runtime/src-x10/x10/util/Box.x10 trunk/x10.runtime/src-x10/x10/util/HashMap.x10 trunk/x10.runtime/src-x10/x10/util/IndexedMemoryChunk.x10 trunk/x10.runtime/src-x10/x10/util/Map.x10 trunk/x10.runtime/src-x10/x10/util/Option.x10 trunk/x10.runtime/src-x10/x10/util/OptionsParser.x10 trunk/x10.runtime/src-x10/x10/util/Pair.x10 trunk/x10.runtime/src-x10/x10/util/StringBuilder.x10 trunk/x10.runtime/src-x10/x10/util/ValHashMap.x10 trunk/x10.runtime/src-x10/x10/util/ValMap.x10 trunk/x10.runtime/src-x10/x10/util/concurrent/atomic/AtomicBoolean.x10 trunk/x10.runtime/src-x10/x10/util/concurrent/atomic/AtomicInteger.x10 trunk/x10.runtime/src-x10/x10/util/concurrent/atomic/AtomicLong.x10 trunk/x10.runtime/src-x10/x10/util/concurrent/atomic/AtomicReference.x10 trunk/x10.runtime/src-x10/x10/util/concurrent/atomic/Fences.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF1.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF10.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF1Generic.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF2.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF2Generic.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF3.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF3Generic.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF3Generic_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF3_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF4_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF5_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF6.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF7.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF8.x10 trunk/x10.tests/examples/Constructs/CollectingFinish/CF9.x10 trunk/x10.tests/examples/Constructs/Future/FutureTest3.x10 trunk/x10.tests/examples/Constructs/Generics/GenericMethodEquals.x10 trunk/x10.tests/examples/Constructs/Inheritance/InheritedProperty2_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Inheritance/InheritedProperty3_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/PlaceCast/PlaceCheck1.x10 trunk/x10.tests/examples/Constructs/Structs/GenericStructTest.x10 trunk/x10.tests/examples/Constructs/Structs/StructImplicitCoercionToInterface.x10 trunk/x10.tests/examples/Issues/XTENLANG_1651.x10 trunk/x10.tests/examples/x10lib/harness/x10Test.x10 Removed Paths: ------------- trunk/x10.tests/examples/Constructs/Modifiers/ Modified: trunk/x10.runtime/src-x10/x10/array/Array.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/Array.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -321,7 +321,7 @@ * @see #set(T, Int) */ @Native("cuda", "(#0)[#1]") - public safe @Header @Inline def apply(i0:int){rank==1}:T { + public @Header @Inline def apply(i0:int){rank==1}:T { if (cachedRail) { if (checkBounds() && !((i0 as UInt) < (size as UInt))) { raiseBoundsError(i0); @@ -346,7 +346,7 @@ * @see #apply(Point) * @see #set(T, Int, Int) */ - public safe @Header @Inline def apply(i0:int, i1:int){rank==2}:T { + public @Header @Inline def apply(i0:int, i1:int){rank==2}:T { if (checkBounds() && !region.contains(i0, i1)) { raiseBoundsError(i0, i1); } @@ -365,7 +365,7 @@ * @see #apply(Point) * @see #set(T, Int, Int, Int) */ - public safe @Header @Inline def apply(i0:int, i1:int, i2:int){rank==3}:T { + public @Header @Inline def apply(i0:int, i1:int, i2:int){rank==3}:T { if (checkBounds() && !region.contains(i0, i1, i2)) { raiseBoundsError(i0, i1, i2); } @@ -385,7 +385,7 @@ * @see #apply(Point) * @see #set(T, Int, Int, Int, Int) */ - public safe @Header @Inline def apply(i0:int, i1:int, i2:int, i3:int){rank==4}:T { + public @Header @Inline def apply(i0:int, i1:int, i2:int, i3:int){rank==4}:T { if (checkBounds() && !region.contains(i0, i1, i2, i3)) { raiseBoundsError(i0, i1, i2, i3); } @@ -401,7 +401,7 @@ * @see #apply(Int) * @see #set(T, Point) */ - public safe @Header @Inline def apply(pt:Point{self.rank==this.rank}):T { + public @Header @Inline def apply(pt:Point{self.rank==this.rank}):T { if (checkBounds() && !region.contains(pt)) { raiseBoundsError(pt); } @@ -422,7 +422,7 @@ * @see #set(T, Point) */ @Native("cuda", "(#0)[#2] = #1") - public safe @Header @Inline def set(v:T, i0:int){rank==1}:T { + public @Header @Inline def set(v:T, i0:int){rank==1}:T { if (cachedRail) { if (checkBounds() && !((i0 as UInt) < (size as UInt))) { raiseBoundsError(i0); @@ -450,7 +450,7 @@ * @see #apply(Int, Int) * @see #set(T, Point) */ - public safe @Header @Inline def set(v:T, i0:int, i1:int){rank==2}:T { + public @Header @Inline def set(v:T, i0:int, i1:int){rank==2}:T { if (checkBounds() && !region.contains(i0, i1)) { raiseBoundsError(i0, i1); } @@ -472,7 +472,7 @@ * @see #apply(Int, Int, Int) * @see #set(T, Point) */ - public safe @Header @Inline def set(v:T, i0:int, i1:int, i2:int){rank==3}:T { + public @Header @Inline def set(v:T, i0:int, i1:int, i2:int){rank==3}:T { if (checkBounds() && !region.contains(i0, i1, i2)) { raiseBoundsError(i0, i1, i2); } @@ -495,7 +495,7 @@ * @see #apply(Int, Int, Int, Int) * @see #set(T, Point) */ - public safe @Header @Inline def set(v:T, i0:int, i1:int, i2:int, i3:int){rank==4}:T { + public @Header @Inline def set(v:T, i0:int, i1:int, i2:int, i3:int){rank==4}:T { if (checkBounds() && !region.contains(i0, i1, i2, i3)) { raiseBoundsError(i0, i1, i2, i3); } @@ -514,7 +514,7 @@ * @see #apply(Point) * @see #set(T, Int) */ - public safe @Header @Inline def set(v:T, p:Point{self.rank==this.rank}):T { + public @Header @Inline def set(v:T, p:Point{self.rank==this.rank}):T { if (checkBounds() && !region.contains(p)) { raiseBoundsError(p); } Modified: trunk/x10.runtime/src-x10/x10/array/BaseDist.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/BaseDist.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/BaseDist.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -313,7 +313,7 @@ return places.length==0? here : places(0); } - public safe def equals(thatObj:Any): boolean { + public def equals(thatObj:Any): boolean { if (!(thatObj instanceof Dist)) return false; val that:Dist = thatObj as Dist; for (p:Place in Place.places) @@ -370,7 +370,7 @@ // // - public safe def toString(): String { + public def toString(): String { var s: String = "Dist("; var first: boolean = true; for (p:Place in places) { Modified: trunk/x10.runtime/src-x10/x10/array/Dist.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Dist.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/Dist.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -448,7 +448,7 @@ * @param that the given distribution * @return true if that is equal to this distribution. */ - abstract public safe def equals(that:Any):boolean; + abstract public def equals(that:Any):boolean; // // other geometric ops Modified: trunk/x10.runtime/src-x10/x10/array/DistArray.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/DistArray.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/DistArray.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -131,14 +131,14 @@ @Native("java", "(!`NO_CHECKS`)") @Native("c++", "BOUNDS_CHECK_BOOL") - private safe native def checkBounds():boolean; + private native def checkBounds():boolean; @Native("java", "(!`NO_CHECKS`)") @Native("c++", "PLACE_CHECK_BOOL") - private safe native def checkPlace():boolean; + private native def checkPlace():boolean; - public final safe def apply(pt: Point(rank)): T { + public final def apply(pt: Point(rank)): T { if (checkBounds() && !region.contains(pt)) { raiseBoundsError(pt); } @@ -151,9 +151,9 @@ /** * @deprecated */ - public final safe def get(pt: Point(rank)): T = apply(pt); + public final def get(pt: Point(rank)): T = apply(pt); - final public safe def apply(i0: int){rank==1}: T { + final public def apply(i0: int){rank==1}: T { if (checkBounds() && !region.contains(i0)) { raiseBoundsError(i0); } @@ -163,7 +163,7 @@ return raw()(layout().offset(i0)); } - final public safe def apply(i0: int, i1: int){rank==2}: T { + final public def apply(i0: int, i1: int){rank==2}: T { if (checkBounds() && !region.contains(i0, i1)) { raiseBoundsError(i0, i1); } @@ -173,7 +173,7 @@ return raw()(layout().offset(i0,i1)); } - final public safe def apply(i0: int, i1: int, i2: int){rank==3}: T { + final public def apply(i0: int, i1: int, i2: int){rank==3}: T { if (checkBounds() && !region.contains(i0, i1, i2)) { raiseBoundsError(i0, i1, i2); } @@ -183,7 +183,7 @@ return raw()(layout().offset(i0,i1,i2)); } - final public safe def apply(i0: int, i1: int, i2: int, i3: int){rank==4}: T { + final public def apply(i0: int, i1: int, i2: int, i3: int){rank==4}: T { if (checkBounds() && !region.contains(i0, i1, i2, i3)) { raiseBoundsError(i0, i1, i2, i3); } @@ -195,7 +195,7 @@ // XXXX settable order - public final safe def set(v: T, pt: Point(rank)): T { + public final def set(v: T, pt: Point(rank)): T { if (checkBounds() && !region.contains(pt)) { raiseBoundsError(pt); } @@ -207,7 +207,7 @@ return v; } - final public safe def set(v: T, i0: int){rank==1}: T { + final public def set(v: T, i0: int){rank==1}: T { if (checkBounds() && !region.contains(i0)) { raiseBoundsError(i0); } @@ -218,7 +218,7 @@ return v; } - final public safe def set(v: T, i0: int, i1: int){rank==2}: T { + final public def set(v: T, i0: int, i1: int){rank==2}: T { if (checkBounds() && !region.contains(i0, i1)) { raiseBoundsError(i0, i1); } @@ -229,7 +229,7 @@ return v; } - final public safe def set(v: T, i0: int, i1: int, i2: int){rank==3}: T { + final public def set(v: T, i0: int, i1: int, i2: int){rank==3}: T { if (checkBounds() && !region.contains(i0, i1, i2)) { raiseBoundsError(i0, i1, i2); } @@ -240,7 +240,7 @@ return v; } - final public safe def set(v: T, i0: int, i1: int, i2: int, i3: int){rank==4}: T { + final public def set(v: T, i0: int, i1: int, i2: int, i3: int){rank==4}: T { if (checkBounds() && !region.contains(i0, i1, i2, i3)) { raiseBoundsError(i0, i1, i2, i3); } @@ -287,7 +287,7 @@ * restriction view */ - public safe def restriction(d: Dist(rank)) { + public def restriction(d: Dist(rank)) { return new DistArray[T](this, d) as DistArray[T](rank); } @@ -304,11 +304,11 @@ // views // - public safe def restriction(r: Region(rank)): DistArray[T](rank) { + public def restriction(r: Region(rank)): DistArray[T](rank) { return restriction(dist.restriction(r) as Dist(rank)); } - public safe def restriction(p: Place): DistArray[T](rank) { + public def restriction(p: Place): DistArray[T](rank) { return restriction(dist.restriction(p) as Dist(rank)); } @@ -389,11 +389,11 @@ // ops // - public safe operator this | (r: Region(rank)) = restriction(r); - public safe operator this | (p: Place) = restriction(p); + public operator this | (r: Region(rank)) = restriction(r); + public operator this | (p: Place) = restriction(p); - public safe def toString(): String { + public def toString(): String { return "Array(" + dist + ")"; } @@ -407,36 +407,36 @@ public def iterator(): Iterator[Point(rank)] = region.iterator() as Iterator[Point(rank)]; - private safe @NoInline @NoReturn def raiseBoundsError(i0:int) { + private @NoInline @NoReturn def raiseBoundsError(i0:int) { throw new ArrayIndexOutOfBoundsException("point (" + i0 + ") not contained in array"); } - private safe @NoInline @NoReturn def raiseBoundsError(i0:int, i1:int) { + private @NoInline @NoReturn def raiseBoundsError(i0:int, i1:int) { throw new ArrayIndexOutOfBoundsException("point (" + i0 + ", "+i1+") not contained in array"); } - private safe @NoInline @NoReturn def raiseBoundsError(i0:int, i1:int, i2:int) { + private @NoInline @NoReturn def raiseBoundsError(i0:int, i1:int, i2:int) { throw new ArrayIndexOutOfBoundsException("point (" + i0 + ", "+i1+", "+i2+") not contained in array"); } - private safe @NoInline @NoReturn def raiseBoundsError(i0:int, i1:int, i2:int, i3:int) { + private @NoInline @NoReturn def raiseBoundsError(i0:int, i1:int, i2:int, i3:int) { throw new ArrayIndexOutOfBoundsException("point (" + i0 + ", "+i1+", "+i2+", "+i3+") not contained in array"); } - private safe @NoInline @NoReturn def raiseBoundsError(pt:Point(rank)) { + private @NoInline @NoReturn def raiseBoundsError(pt:Point(rank)) { throw new ArrayIndexOutOfBoundsException("point " + pt + " not contained in array"); } - private safe @NoInline @NoReturn def raisePlaceError(i0:int) { + private @NoInline @NoReturn def raisePlaceError(i0:int) { throw new BadPlaceException("point (" + i0 + ") not defined at " + here); } - private safe @NoInline @NoReturn def raisePlaceError(i0:int, i1:int) { + private @NoInline @NoReturn def raisePlaceError(i0:int, i1:int) { throw new BadPlaceException("point (" + i0 + ", "+i1+") not defined at " + here); } - private safe @NoInline @NoReturn def raisePlaceError(i0:int, i1:int, i2:int) { + private @NoInline @NoReturn def raisePlaceError(i0:int, i1:int, i2:int) { throw new BadPlaceException("point (" + i0 + ", "+i1+", "+i2+") not defined at " + here); } - private safe @NoInline @NoReturn def raisePlaceError(i0:int, i1:int, i2:int, i3:int) { + private @NoInline @NoReturn def raisePlaceError(i0:int, i1:int, i2:int, i3:int) { throw new BadPlaceException("point (" + i0 + ", "+i1+", "+i2+", "+i3+") not defined at " + here); } - private safe @NoInline @NoReturn def raisePlaceError(pt:Point(rank)) { + private @NoInline @NoReturn def raisePlaceError(pt:Point(rank)) { throw new BadPlaceException("point " + pt + " not defined at " + here); } } Modified: trunk/x10.runtime/src-x10/x10/array/EmptyRegion.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/EmptyRegion.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/EmptyRegion.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -58,6 +58,6 @@ throw new UnsupportedOperationException("scanners not defined for empty region"); } - public safe def toString() = "empty(" + rank + ")"; + public def toString() = "empty(" + rank + ")"; } Modified: trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -54,7 +54,7 @@ protected def computeBoundingBox(): Region(rank) = this; public def contains(that: Region(rank)):Boolean = true; public def contains(p:Point):Boolean = true; - public safe def toString() = "full(" + rank + ")"; + public def toString() = "full(" + rank + ")"; public def scanners():Iterator[Region.Scanner] { Modified: trunk/x10.runtime/src-x10/x10/array/MatBuilder.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/MatBuilder.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/MatBuilder.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -30,41 +30,41 @@ need(rows, m, cols); } - public safe def add(row:Row) { + public def add(row:Row) { mat.add(row); } - public safe def add(a:(Int)=>int) { + public def add(a:(Int)=>int) { mat.add(new VarRow(cols, a)); } - public safe def apply(i:int, j:int) = mat(i)(j); + public def apply(i:int, j:int) = mat(i)(j); - public safe def set(v:int, i:int, j:int) { + public def set(v:int, i:int, j:int) { need(i+1); mat(i)(j) = v; } - public safe def setDiagonal(i:Int, j:Int, n:Int, v:(Int)=>int) { + public def setDiagonal(i:Int, j:Int, n:Int, v:(Int)=>int) { need(i+n); for (var k:int=0; k<n; k++) mat(i+k)(j+k) = v(k); } - public safe def setColumn(i:Int, j:Int, n:Int, v:(Int)=>int) { + public def setColumn(i:Int, j:Int, n:Int, v:(Int)=>int) { need(i+n); for (var k:int=0; k<n; k++) mat(i+k)(j) = v(k); } - public safe def setRow(i:Int, j:Int, n:Int, v:(Int)=>int) { + public def setRow(i:Int, j:Int, n:Int, v:(Int)=>int) { need(i+1); for (var k:int=0; k<n; k++) mat(i)(j+k) = v(k); } - private safe def need(n:int) = need(n, this.mat, this.cols); - private static safe def need(n:int, mat:ArrayList[Row], cols:int) { + private def need(n:int) = need(n, this.mat, this.cols); + private static def need(n:int, mat:ArrayList[Row], cols:int) { while (mat.size()<n) mat.add(new VarRow(cols)); } Modified: trunk/x10.runtime/src-x10/x10/array/Point.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Point.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/Point.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -26,23 +26,23 @@ /** * Returns the value of the ith coordinate. */ - public safe def apply(i: Int): Int = coords(i); + public def apply(i: Int): Int = coords(i); /** * Returns the coordinates as a <code>ValRail[Int]</code>. */ - public safe def coords(): ValRail[int] = coords; + public def coords(): ValRail[int] = coords; /** * Constructs a Point from a ValRail[int]. */ - public static safe def make(cs: ValRail[int]): Point(cs.length) = new Point(cs); + public static def make(cs: ValRail[int]): Point(cs.length) = new Point(cs); /** * Constructs a Point from a Rail[int] */ - public static safe def make(cs: Rail[int]): Point(cs.length) { + public static def make(cs: Rail[int]): Point(cs.length) { val a = ValRail.make[int](cs.length, (i:Int)=>cs(i)); return make(a); } @@ -50,97 +50,97 @@ /** * Returns a <code>Point p</code> of rank <code>rank</code> with <code>p(i)=init(i)</code>. */ - public static safe def make(rank:Int, init:(i:Int)=>int):Point(rank) { + public static def make(rank:Int, init:(i:Int)=>int):Point(rank) { val a = ValRail.make[int](rank, init); return make(a); } - public static safe def make(i0:int) = make([i0]); - public static safe def make(i0:int, i1:int) = make([i0,i1]); - public static safe def make(i0:int, i1:int, i2:int) = make([i0,i1,i2]); - public static safe def make(i0:int, i1:int, i2:int, i3:int) = make([i0,i1,i2,i3]); + public static def make(i0:int) = make([i0]); + public static def make(i0:int, i1:int) = make([i0,i1]); + public static def make(i0:int, i1:int, i2:int) = make([i0,i1,i2]); + public static def make(i0:int, i1:int, i2:int, i3:int) = make([i0,i1,i2,i3]); /** A <code>Rail</code> <code>r</code> of size <code>k</code> can be converted to a point <code>p</code> of the same rank with <code>p(i)=r(i)</code>. */ - public static safe operator (r: Rail[int]): Point(r.length) = make(r); + public static operator (r: Rail[int]): Point(r.length) = make(r); /** A <code>ValRail</code> <code>r</code> of size <code>k</code> can be converted to a point <code>p</code> of the same rank with <code>p(i)=r(i)</code>. */ - public static safe operator (r: ValRail[int]): Point(r.length) = make(r); + public static operator (r: ValRail[int]): Point(r.length) = make(r); /** The point <code>+p</code> is the same as <code>p</code>. */ - public safe operator + this: Point(rank) = this; + public operator + this: Point(rank) = this; /** The point <code>-p</code> is the same as <code>p</code> with each index negated. */ - public safe operator - this: Point(rank) + public operator - this: Point(rank) = Point.make(rank, (i:Int)=>-this.coords(i)); /** The ith coordinate of point <code>p+q</code> is <code>p(i)+q(i)</code>. */ - public safe operator this + (that: Point(rank)): Point(rank) + public operator this + (that: Point(rank)): Point(rank) = Point.make(rank, (i:Int)=> this.coords(i) + that.coords(i)); /** The ith coordinate of point <code>p-q</code> is <code>p(i)-q(i)</code>. */ - public safe operator this - (that: Point(rank)): Point(rank) + public operator this - (that: Point(rank)): Point(rank) = Point.make(rank, (i:Int)=> this.coords(i) - that.coords(i)); /** The ith coordinate of point <code>p*q</code> is <code>p(i)*q(i)</code>. */ - public safe operator this * (that: Point(rank)): Point(rank) + public operator this * (that: Point(rank)): Point(rank) = Point.make(rank, (i:Int)=> this.coords(i) * that.coords(i)); /** The ith coordinate of point <code>p/q</code> is <code>p(i)/q(i)</code>. */ - public safe operator this / (that: Point(rank)): Point(rank) + public operator this / (that: Point(rank)): Point(rank) = Point.make(rank, (i:Int)=> this.coords(i) / that.coords(i)); /** The ith coordinate of point <code>p+c</code> is <code>p(i)+c</code>. */ - public safe operator this + (c: int): Point(rank) + public operator this + (c: int): Point(rank) = Point.make(rank, (i:Int) => this.coords(i) + c); /** The ith coordinate of point <code>p-c</code> is <code>p(i)-c</code>. */ - public safe operator this - (c: int): Point(rank) + public operator this - (c: int): Point(rank) = Point.make(rank, (i:Int) => this.coords(i) - c); /** The ith coordinate of point <code>p*c</code> is <code>p(i)*c</code>. */ - public safe operator this * (c: int): Point(rank) + public operator this * (c: int): Point(rank) = Point.make(rank, (i:Int) => this.coords(i) * c); /** The ith coordinate of point <code>p/c</code> is <code>p(i)/c</code>. */ - public safe operator this / (c: int): Point(rank) + public operator this / (c: int): Point(rank) = Point.make(rank, (i:Int) => this.coords(i) / c); /** The ith coordinate of point <code>c+p</code> is <code>c+p(i)</code>. */ - public safe operator (c: int) + this: Point(rank) + public operator (c: int) + this: Point(rank) = Point.make(rank, (i:Int) => c + this.coords(i)); /** The ith coordinate of point <code>c-p</code> is <code>c-p(i)</code>. */ - public safe operator (c: int) - this: Point(rank) + public operator (c: int) - this: Point(rank) = Point.make(rank, (i:Int) => c - this.coords(i)); /** The ith coordinate of point <code>c*p</code> is <code>c*p(i)</code>. */ - public safe operator (c: int) * this: Point(rank) + public operator (c: int) * this: Point(rank) = Point.make(rank, (i:Int) => c * this.coords(i)); /** The ith coordinate of point <code>c/p</code> is <code>c/p(i)</code>. */ - public safe operator (c: int) / this: Point(rank) + public operator (c: int) / this: Point(rank) = Point.make(rank, (i:Int) => c / this.coords(i)); /** @@ -150,7 +150,7 @@ * fact that coordinates are biased to be small * positive numbers. */ - public safe def hashCode():int { + public def hashCode():int { var hc:int = coords(0); for (var i:int = 1; i<rank; i++) { hc = (hc * 17) ^ coords(i); @@ -161,7 +161,7 @@ /** Two points of the same rank are equal if and only if their * corresponding indices are equal. */ - public safe def equals(other:Any):boolean { + public def equals(other:Any):boolean { if (!(other instanceof Point)) return false; val otherPoint = other as Point; if (rank != otherPoint.rank) return false; @@ -173,7 +173,7 @@ /** For points a, b, <code> a < b</code> if <code>a</code> is lexicographically smaller than <code>b</code>. */ - public safe operator this < (that: Point(rank)): boolean { + public operator this < (that: Point(rank)): boolean { for (var i: int = 0; i<rank-1; i++) { val a = this.coords(i); val b = that.coords(i); @@ -185,7 +185,7 @@ /** For points <code>a, b</code>, <code> a > b</code> if <code>a</code> is lexicographically bigger than <code> b</code>. */ - public safe operator this > (that: Point(rank)): boolean { + public operator this > (that: Point(rank)): boolean { for (var i: int = 0; i<rank-1; i++) { val a = this.coords(i); val b = that.coords(i); @@ -197,7 +197,7 @@ /** For points <code>a, b</code>, <code> a ≤ b</code> if <code>a</code> is lexicographically less than <code> b</code> or the same as <code>b</code>. */ - public safe operator this <= (that: Point(rank)): boolean { + public operator this <= (that: Point(rank)): boolean { for (var i: int = 0; i<rank-1; i++) { val a = this.coords(i); val b = that.coords(i); @@ -209,7 +209,7 @@ /** For points <code>a, b</code>, <code> a ≥ b</code> if <code>a</code> is lexicographically greater than <code> b</code> or the same as <code>b</code>. */ - public safe operator this >= (that: Point(rank)): boolean { + public operator this >= (that: Point(rank)): boolean { for (var i: int = 0; i<rank-1; i++) { val a = this.coords(i); val b = that.coords(i); @@ -221,7 +221,7 @@ /** A point with coordinates <code>i1,..., ik</code> is printed as <code>(i1,.., ik)</code>. */ - public safe def toString() { + public def toString() { var s:String = "("; if (coords.length>0) s += coords(0); for (var i:int=1; i<coords.length; i++) Modified: trunk/x10.runtime/src-x10/x10/array/PolyMat.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/PolyMat.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/PolyMat.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -263,7 +263,7 @@ } - public safe def toString(): String { + public def toString(): String { var s: String = "("; var first: boolean = true; Modified: trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -368,7 +368,7 @@ mat.printInfo(out, /*this.getClass().getName()*/this.toString()); } - public safe def toString(): String { + public def toString(): String { return mat.toString(); } Modified: trunk/x10.runtime/src-x10/x10/array/RectLayout.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/RectLayout.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/RectLayout.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -140,7 +140,7 @@ return offset; } - public safe def toString() { + public def toString() { var s:String = "RectLayout["; s += "size=" + size; for (var i:int=0; i<min.length; i++) { Modified: trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -312,7 +312,7 @@ } - public safe def equals(thatObj:Any): boolean { + public def equals(thatObj:Any): boolean { if (this == thatObj) return true; if (!(thatObj instanceof Region)) return false; val that:Region = thatObj as Region; @@ -344,7 +344,7 @@ // // - public safe def toString(): String { + public def toString(): String { val thisMin = this.min(); val thisMax = this.max(); var s: String = "["; Modified: trunk/x10.runtime/src-x10/x10/array/Region.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Region.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/Region.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -378,7 +378,7 @@ // comparison // - public safe def equals(that:Any):boolean { + public def equals(that:Any):boolean { if (this == that) return true; // short-circuit if (!(that instanceof Region)) return false; val t1 = that as Region; Modified: trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -43,23 +43,23 @@ rawLength = a.rawLength; } - public safe def equals(other:Any) { + public def equals(other:Any) { if (!(other instanceof RemoteArray[T])) return false; val oRA = other as RemoteArray[T]; return oRA.array.equals(array); } @Native("cuda", "(#0)[#2] = #1") - public safe def set(v:T, i:Int) {here==home, rank==1} = array().set(v,i); + public def set(v:T, i:Int) {here==home, rank==1} = array().set(v,i); - public safe def set(v:T, p:Point{self.rank==this.rank}) {here==home} = array().set(v,p); + public def set(v:T, p:Point{self.rank==this.rank}) {here==home} = array().set(v,p); @Native("cuda", "(#0)[#1]") - public safe def apply(i:Int) {here==home, rank==1} = array()(i); + public def apply(i:Int) {here==home, rank==1} = array()(i); - public safe def apply(p:Point{self.rank==this.rank}) {here==home} = array()(p); + public def apply(p:Point{self.rank==this.rank}) {here==home} = array()(p); - public safe def hashCode() = array.hashCode(); + public def hashCode() = array.hashCode(); } /* This version is preferable, as it does not duplicate state from the global ref, but it does not work: @@ -78,21 +78,21 @@ rawLength = a.rawLength; } - public safe def equals(other:Any) { + public def equals(other:Any) { if (!(other instanceof RemoteArray[T])) return false; val oRA = other as RemoteArray[T]; return oRA.array.equals(array); } - public safe def set(v:T, i:Int) {here==array.home, rank==1} = array().set(v,i); + public def set(v:T, i:Int) {here==array.home, rank==1} = array().set(v,i); - public safe def set(v:T, p:Point{self.rank==this.rank}) {here==array.home} = array().set(v,p); + public def set(v:T, p:Point{self.rank==this.rank}) {here==array.home} = array().set(v,p); - public safe def apply(i:Int) {here==array.home, rank==1} = array()(i); + public def apply(i:Int) {here==array.home, rank==1} = array()(i); - public safe def apply(p:Point{self.rank==this.rank}) {here==array.home} = array()(p); + public def apply(p:Point{self.rank==this.rank}) {here==array.home} = array()(p); - public safe def hashCode() = array.hashCode(); + public def hashCode() = array.hashCode(); } */ Modified: trunk/x10.runtime/src-x10/x10/array/Row.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Row.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/Row.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -62,7 +62,7 @@ if (c!=0||first) ps.print((c>=0&&!first?"+":"") + c); } - public safe def toString(): String { + public def toString(): String { val os = new StringWriter(); val ps = new Printer(os); printEqn(ps, "", 0); Modified: trunk/x10.runtime/src-x10/x10/array/ValRow.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/ValRow.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/ValRow.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -29,9 +29,9 @@ row = ValRail.make[int](cols, init); } - public safe def apply(i:Int) = row(i); + public def apply(i:Int) = row(i); - public safe def set(v:int, i:Int):int { + public def set(v:int, i:Int):int { throw new IllegalOperationException("ValRow.set"); } } Modified: trunk/x10.runtime/src-x10/x10/array/VarRow.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/VarRow.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/array/VarRow.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -26,7 +26,7 @@ } def row() = row as Rail[int]; - public safe def apply(i:Int) = row()(i); + public def apply(i:Int) = row()(i); - public safe def set(v:int, i:Int) = (row()(i) = v); + public def set(v:int, i:Int) = (row()(i) = v); } Modified: trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/io/ByteWriter.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -36,7 +36,7 @@ @Global @Incomplete public def size() : Long { throw new UnsupportedOperationException(); } - @Global public safe def toString():String { + @Global public def toString():String { if (here == root.home) { val me = (root as GlobalRef[ByteWriter[T]]{self.home==here})(); return me.toString(); Modified: trunk/x10.runtime/src-x10/x10/lang/Any.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -42,7 +42,7 @@ */ @Native("java", "((java.lang.Object)(#0)).toString()") @Native("c++", "x10aux::to_string(#0)") - safe def toString():String; + def toString():String; /** * Return a string representation of the run-time type of this entity. @@ -53,7 +53,7 @@ @Native("java", "x10.rtt.Types.typeName(#0)") @Native("c++", "x10aux::type_name(#0)") @NonEscaping("") - safe def typeName():String; + def typeName():String; /** * Return true if this entity is equal to the given entity in an @@ -74,7 +74,7 @@ */ @Native("java", "((java.lang.Object)(#0)).equals(#1)") @Native("c++", "x10aux::equals(#0,#1)") - safe def equals(that:Any):Boolean; + def equals(that:Any):Boolean; /** * Return the implementation-defined hash code of this entity. @@ -92,7 +92,7 @@ */ @Native("java", "((Object)(#0)).hashCode()") @Native("c++", "x10aux::hash_code(#0)") - safe def hashCode():Int; + def hashCode():Int; } // vim:shiftwidth=4:tabstop=4:expandtab Modified: trunk/x10.runtime/src-x10/x10/lang/Boolean.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Boolean.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/lang/Boolean.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -32,7 +32,7 @@ */ @Native("java", "(!(#1))") @Native("c++", "(!(#1))") - public native static safe operator ! (x:Boolean): Boolean; + public native static operator ! (x:Boolean): Boolean; /** * A logical and operator (not short-circuiting). @@ -44,7 +44,7 @@ */ @Native("java", "((#1) & (#2))") @Native("c++", "((x10_boolean) (((#1) ? 1 : 0) & ((#2) ? 1 : 0)))") - public native static safe operator (x:Boolean) & (y:Boolean): Boolean; + public native static operator (x:Boolean) & (y:Boolean): Boolean; /** * A logical or operator (not short-circuiting). @@ -56,7 +56,7 @@ */ @Native("java", "((#1) | (#2))") @Native("c++", "((x10_boolean) (((#1) ? 1 : 0) | ((#2) ? 1 : 0)))") - public native static safe operator (x:Boolean) | (y:Boolean): Boolean; + public native static operator (x:Boolean) | (y:Boolean): Boolean; /** * A logical xor operator. @@ -67,7 +67,7 @@ */ @Native("java", "((#1) ^ (#2))") @Native("c++", "((x10_boolean) (((#1) ? 1 : 0) ^ ((#2) ? 1 : 0)))") - public native static safe operator (x:Boolean) ^ (y:Boolean): Boolean; + public native static operator (x:Boolean) ^ (y:Boolean): Boolean; /** @@ -91,7 +91,7 @@ */ @Native("java", "java.lang.Boolean.toString(#0)") @Native("c++", "x10aux::to_string(#0)") - public safe native def toString(): String; + public native def toString(): String; /** * @deprecated use {@link #parse(String)} instead @@ -121,7 +121,7 @@ //FIXME Java: use equalsequals()? @Native("java", "((((#2) instanceof boolean) && #1 == ((boolean)#2)) || (((#2) instanceof Boolean) && #1 == ((Boolean) #2).booleanValue()))") @Native("c++", "x10aux::equals(#0,#1)") - public safe native def equals(x:Any):Boolean; + public native def equals(x:Any):Boolean; /** * Returns true if this Boolean is equal to the given Boolean. @@ -130,16 +130,16 @@ */ @Native("java", "x10.rtt.Equality.equalsequals(#0, #1)") @Native("c++", "x10aux::equals(#0,#1)") - public safe native def equals(x:Boolean):Boolean; + public native def equals(x:Boolean):Boolean; // These operations are built-in. Declaring them will prevent the // short-circuiting behavior. // @Native("java", "((#0) && (#1))") // @Native("c++", "((x10_boolean) (((#1) ? 1 : 0) && ((#2) ? 1 : 0)))") -// public native static safe operator (x:Boolean) && (y:Boolean): Boolean; +// public native static operator (x:Boolean) && (y:Boolean): Boolean; // // @Native("java", "((#0) || (#1))") // @Native("c++", "((x10_boolean) (((#1) ? 1 : 0) || ((#2) ? 1 : 0)))") -// public native static safe operator (x:Boolean) || (y:Boolean): Boolean; +// public native static operator (x:Boolean) || (y:Boolean): Boolean; } Modified: trunk/x10.runtime/src-x10/x10/lang/Byte.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Byte.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/lang/Byte.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -36,7 +36,7 @@ */ @Native("java", "((#1) < (#2))") @Native("c++", "((#1) < (#2))") - public native static safe operator (x:Byte) < (y:Byte): Boolean; + public native static operator (x:Byte) < (y:Byte): Boolean; /** * A greater-than operator. @@ -48,7 +48,7 @@ */ @Native("java", "((#1) > (#2))") @Native("c++", "((#1) > (#2))") - public native static safe operator (x:Byte) > (y:Byte): Boolean; + public native static operator (x:Byte) > (y:Byte): Boolean; /** * A less-than-or-equal-to operator. @@ -60,7 +60,7 @@ */ @Native("java", "((#1) <= (#2))") @Native("c++", "((#1) <= (#2))") - public native static safe operator (x:Byte) <= (y:Byte): Boolean; + public native static operator (x:Byte) <= (y:Byte): Boolean; /** * A greater-than-or-equal-to operator. @@ -72,7 +72,7 @@ */ @Native("java", "((#1) >= (#2))") @Native("c++", "((#1) >= (#2))") - public native static safe operator (x:Byte) >= (y:Byte): Boolean; + public native static operator (x:Byte) >= (y:Byte): Boolean; /** @@ -85,7 +85,7 @@ */ @Native("java", "((byte) ((#1) + (#2)))") @Native("c++", "((x10_byte) ((#1) + (#2)))") - public native static safe operator (x:Byte) + (y:Byte): Byte; + public native static operator (x:Byte) + (y:Byte): Byte; /** * A binary minus operator. @@ -97,7 +97,7 @@ */ @Native("java", "((byte) ((#1) - (#2)))") @Native("c++", "((x10_byte) ((#1) - (#2)))") - public native static safe operator (x:Byte) - (y:Byte): Byte; + public native static operator (x:Byte) - (y:Byte): Byte; /** * A binary multiply operator. @@ -109,7 +109,7 @@ */ @Native("java", "((byte) ((#1) * (#2)))") @Native("c++", "((x10_byte) ((#1) * (#2)))") - public native static safe operator (x:Byte) * (y:Byte): Byte; + public native static operator (x:Byte) * (y:Byte): Byte; /** * A binary divide operator. @@ -120,7 +120,7 @@ */ @Native("java", "((byte) ((#1) / (#2)))") @Native("c++", "((x10_byte) ((#1) / (#2)))") - public native static safe operator (x:Byte) / (y:Byte): Byte; + public native static operator (x:Byte) / (y:Byte): Byte; /** * A binary remainder operator. @@ -131,7 +131,7 @@ */ @Native("java", "((byte) ((#1) % (#2)))") @Native("c++", "((x10_byte) ((#1) % (#2)))") - public native static safe operator (x:Byte) % (y:Byte): Byte; + public native static operator (x:Byte) % (y:Byte): Byte; /** * A unary plus operator. @@ -141,7 +141,7 @@ */ @Native("java", "((byte) +(#1))") @Native("c++", "((x10_byte) +(#1))") - public native static safe operator + (x:Byte): Byte; + public native static operator + (x:Byte): Byte; /** * A unary minus operator. @@ -152,7 +152,7 @@ */ @Native("java", "((byte) -(#1))") @Native("c++", "((x10_byte) -(#1))") - public native static safe operator - (x:Byte): Byte; + public native static operator - (x:Byte): Byte; /** @@ -164,7 +164,7 @@ */ @Native("java", "((byte) ((#1) & (#2)))") @Native("c++", "((x10_byte) ((#1) & (#2)))") - public native static safe operator (x:Byte) & (y:Byte): Byte; + public native static operator (x:Byte) & (y:Byte): Byte; /** * A bitwise or operator. @@ -175,7 +175,7 @@ */ @Native("java", "((byte) ((#1) | (#2)))") @Native("c++", "((x10_byte) ((#1) | (#2)))") - public native static safe operator (x:Byte) | (y:Byte): Byte; + public native static operator (x:Byte) | (y:Byte): Byte; /** * A bitwise xor operator. @@ -186,7 +186,7 @@ */ @Native("java", "((byte) ((#1) ^ (#2)))") @Native("c++", "((x10_byte) ((#1) ^ (#2)))") - public native static safe operator (x:Byte) ^ (y:Byte): Byte; + public native static operator (x:Byte) ^ (y:Byte): Byte; /** * A bitwise left shift operator. @@ -198,7 +198,7 @@ */ @Native("java", "((byte) ((#1) << (#2)))") @Native("c++", "((x10_byte) ((#1) << (#2)))") - public native static safe operator (x:Byte) << (count:Int): Byte; + public native static operator (x:Byte) << (count:Int): Byte; /** * A bitwise right shift operator. @@ -211,7 +211,7 @@ */ @Native("java", "((byte) ((#1) >> (#2)))") @Native("c++", "((x10_byte) ((#1) >> (#2)))") - public native static safe operator (x:Byte) >> (count:Int): Byte; + public native static operator (x:Byte) >> (count:Int): Byte; /** * A bitwise logical right shift operator (zero-fill). @@ -225,7 +225,7 @@ */ @Native("java", "((byte) ((#1) >>> (#2)))") @Native("c++", "((x10_byte) ((x10_uint) (#1) >> (#2)))") - public native static safe operator (x:Byte) >>> (count:Int): Byte; + public native static operator (x:Byte) >>> (count:Int): Byte; /** * A bitwise complement operator. @@ -235,7 +235,7 @@ */ @Native("java", "((byte) ~(#1))") @Native("c++", "((x10_byte) ~(#1))") - public native static safe operator ~ (x:Byte): Byte; + public native static operator ~ (x:Byte): Byte; /** @@ -245,7 +245,7 @@ */ @Native("java", "((byte)(short)(#1))") @Native("c++", "((x10_byte) (#1))") - public native static safe operator (x:Short) as Byte; + public native static operator (x:Short) as Byte; /** * Convert a given Int to a Byte. @@ -254,7 +254,7 @@ */ @Native("java", "((byte)(int)(#1))") @Native("c++", "((x10_byte) (#1))") - public native static safe operator (x:Int) as Byte; + public native static operator (x:Int) as Byte; /** * Convert a given Long to a Byte. @@ -263,7 +263,7 @@ */ @Native("java", "((byte)(long)(#1))") @Native("c++", "((x10_byte) (#1))") - public native static safe operator (x:Long) as Byte; + public native static operator (x:Long) as Byte; /** * Convert a given Float to a Byte. @@ -272,7 +272,7 @@ */ @Native("java", "x10.core.Floats.toByte(#1)") @Native("c++", "((x10_byte) (#1))") - public native static safe operator (x:Float) as Byte; + public native static operator (x:Float) as Byte; /** * Convert a given Double to a Byte. @@ -281,7 +281,7 @@ */ @Native("java", "x10.core.Floats.toByte(#1)") @Native("c++", "((x10_byte) (#1))") - public native static safe operator (x:Double) as Byte; + public native static operator (x:Double) as Byte; /** * Coerce a given UByte to a Byte. @@ -290,7 +290,7 @@ */ @Native("java", "((byte)(#1.byteVal))") @Native("c++", "((x10_byte) (#1))") - public native static safe operator (x:UByte): Byte; + public native static operator (x:UByte): Byte; /** @@ -314,7 +314,7 @@ */ @Native("java", "x10.core.Bytes.toString(#0, #1)") @Native("c++", "x10aux::byte_utils::toString(#0, #1)") - public safe native def toString(radix:Int): String; + public native def toString(radix:Int): String; /** * Returns a String representation of this Byte as a hexadecimal number. @@ -322,7 +322,7 @@ */ @Native("java", "x10.core.Bytes.toString(#0, 16)") @Native("c++", "x10aux::byte_utils::toHexString(#0)") - public safe native def toHexString(): String; + public native def toHexString(): String; /** * Returns a String representation of this Byte as an octal number. @@ -330,7 +330,7 @@ */ @Native("java", "x10.core.Bytes.toString(#0, 8)") @Native("c++", "x10aux::byte_utils::toOctalString(#0)") - public safe native def toOctalString(): String; + public native def toOctalString(): String; /** * Returns a String representation of this Byte as a binary number. @@ -338,7 +338,7 @@ */ @Native("java", "x10.core.Bytes.toString(#0, 2)") @Native("c++", "x10aux::byte_utils::toBinaryString(#0)") - public safe native def toBinaryString(): String; + public native def toBinaryString(): String; /** * Returns a String representation of this Byte as a decimal number. @@ -346,7 +346,7 @@ */ @Native("java", "java.lang.Byte.toString(#0)") @Native("c++", "x10aux::to_string(#0)") - public safe native def toString(): String; + public native def toString(): String; /** * @deprecated use {@link #parse(String,Int)} instead @@ -416,7 +416,7 @@ */ @Native("java", "x10.rtt.Equality.equalsequals(#0, #1)") @Native("c++", "x10aux::equals(#0,#1)") - public safe native def equals(x:Any):Boolean; + public native def equals(x:Any):Boolean; /** * Returns true if this Byte is equal to the given Byte. @@ -425,5 +425,5 @@ */ @Native("java", "x10.rtt.Equality.equalsequals(#0, #1)") @Native("c++", "x10aux::equals(#0,#1)") - public safe native def equals(x:Byte):Boolean; + public native def equals(x:Byte):Boolean; } Modified: trunk/x10.runtime/src-x10/x10/lang/Cell.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Cell.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/lang/Cell.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -39,7 +39,7 @@ * * @return the String object being constructed by the StringBuilder */ - public safe def toString() { + public def toString() { return "Cell(" + this.value.toString() + ")"; } Modified: trunk/x10.runtime/src-x10/x10/lang/Char.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Char.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/lang/Char.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -32,7 +32,7 @@ */ @Native("java", "((char) (#1))") @Native("c++", "((x10_char) (char) (#1))") - public native static safe operator (x:Byte) as Char; + public native static operator (x:Byte) as Char; /** * Convert a given Short to a Char with that ordinal value. @@ -41,7 +41,7 @@ */ @Native("java", "((char) (#1))") @Native("c++", "((x10_char) (int) (#1))") - public native static safe operator (x:Short) as Char; + public native static operator (x:Short) as Char; /** * Convert a given Int to a Char with that ordinal value. @@ -50,7 +50,7 @@ */ @Native("java", "((char) (#1))") @Native("c++", "((x10_char) (int) (#1))") - public native static safe operator (x:Int) as Char; + public native static operator (x:Int) as Char; /** * Convert a given Long to a Char with that ordinal value. @@ -59,7 +59,7 @@ */ @Native("java", "((char) (#1))") @Native("c++", "((x10_char) (int) (#1))") - public native static safe operator (x:Long) as Char; + public native static operator (x:Long) as Char; /** @@ -70,7 +70,7 @@ */ @Native("java", "((char) ((#1) + (#2)))") @Native("c++", "((x10_char) (int) ((#1) + (#2)))") - public native static safe operator (x:Char) + (y:Int): Char; + public native static operator (x:Char) + (y:Int): Char; /** * Translate a given Char's ordinal value forward by the specified distance. @@ -80,7 +80,7 @@ */ @Native("java", "((char) ((#1) + (#2)))") @Native("c++", "((x10_char) (int) ((#1) + (#2)))") - public native static safe operator (x:Int) + (y:Char): Char; + public native static operator (x:Int) + (y:Char): Char; /** * Translate a given Char's ordinal value backward by the specified distance. @@ -90,7 +90,7 @@ */ @Native("java", "((char) ((#1) - (#2)))") @Native("c++", "((x10_char) (int) ((#1) - (#2)))") - public native static safe operator (x:Char) - (y:Int): Char; + public native static operator (x:Char) - (y:Int): Char; /** * Compute the distance between two Chars. @@ -100,7 +100,7 @@ */ @Native("java", "((#1) - (#2))") @Native("c++", "((#1) - (#2))") - public native static safe operator (x:Char) - (y:Char): Int; + public native static operator (x:Char) - (y:Char): Int; // FIXME: Locale sensitivity @@ -113,7 +113,7 @@ */ @Native("java", "((#0) < (#1))") @Native("c++", "((#0) < (#1))") - public native safe operator this < (x:Char): Boolean; + public native operator this < (x:Char): Boolean; // FIXME: Locale sensitivity /** @@ -125,7 +125,7 @@ */ @Native("java", "((#0) > (#1))") @Native("c++", "((#0) > (#1))") - public native safe operator this > (x:Char): Boolean; + public native operator this > (x:Char): Boolean; // FIXME: Locale sensitivity /** @@ -137,7 +137,7 @@ */ @Native("java", "((#0) <= (#1))") @Native("c++", "((#0) <= (#1))") - public native safe operator this <= (x:Char): Boolean; + public native operator this <= (x:Char): Boolean; // FIXME: Locale sensitivity /** @@ -149,7 +149,7 @@ */ @Native("java", "((#0) >= (#1))") @Native("c++", "((#0) >= (#1))") - public native safe operator this >= (x:Char): Boolean; + public native operator this >= (x:Char): Boolean; /** @@ -158,7 +158,7 @@ */ @Native("java", "java.lang.Character.toString(#0)") @Native("c++", "x10aux::to_string(#0)") - public safe native def toString(): String; + public native def toString(): String; // Duplicate the methods from java.lang.Character, changing static methods to non-static. @@ -307,7 +307,7 @@ */ @Native("java", "x10.rtt.Equality.equalsequals(#0, #1)") @Native("c++", "x10aux::equals(#0,#1)") - public safe native def equals(x:Any):Boolean; + public native def equals(x:Any):Boolean; /** * Returns true if this Byte is equal to the given Byte. @@ -316,5 +316,5 @@ */ @Native("java", "x10.rtt.Equality.equalsequals(#0, #1)") @Native("c++", "x10aux::equals(#0,#1)") - public safe native def equals(x:Char):Boolean; + public native def equals(x:Char):Boolean; } Modified: trunk/x10.runtime/src-x10/x10/lang/Clock.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Clock.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/lang/Clock.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -26,12 +26,12 @@ public class Clock(name:String) { private val root = GlobalRef[Clock](this); - public safe def equals(a:Any) { + public def equals(a:Any) { if (a == null || ! (a instanceof Clock)) return false; return (a as Clock).root == this.root; } - public safe def hashCode() = root.hashCode(); + public def hashCode() = root.hashCode(); public static def make(): Clock = make(""); public static def make(name:String):Clock { Modified: trunk/x10.runtime/src-x10/x10/lang/Complex.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Complex.x10 2010-09-23 19:18:10 UTC (rev 16665) +++ trunk/x10.runtime/src-x10/x10/lang/Complex.x10 2010-09-23 20:02:21 UTC (rev 16666) @@ -48,45 +48,45 @@ /** * @return the sum of this complex number and the given complex number. */ - public safe operator this + (that:Complex):Complex { + public operator this + (that:Complex):Complex { return Complex(re + that.re, im + that.im); } /** * @return the sum of the given double and the given complex number. */ - public static safe operator (x:Double) + (y:Complex): Complex = y + x; + public static operator (x:Double) + (y:Complex): Complex = y + x; /** * @return the sum of this complex number and the given double. */ - public safe operator this + (that:Double):Complex { + public operator this + (that:Double):Complex { return Complex(re + that, im); } /** * @return the difference between this complex number and the given complex number. */ - public safe operator this - (that:Complex):Complex { + public operator this - (that:Complex):Complex { return Complex(re - that.re, im - that.im); } /** * @return the difference between the given double and this complex number. */ - public static safe operator (x:Double) - (y:Complex): Complex = Complex(x - y.re, -y.im); + public static operator (x:Double) - (y:Complex): Complex = Complex(x - y.re, -y.im); /** * @return the difference between this complex number and the given double. */ - public safe operator this - (that:Double):Complex { + public operator this - (that:Double):Complex { return Complex(re - that, im); } /** * @return the product of this complex number and the given complex number. */ - public safe operator this * (that:Complex):Complex { + public operator this * (that:Complex):Complex { return Complex(re * that.re - im * that.im, re * that.im + im * that.re); } @@ -94,12 +94,12 @@ /** * @return the product of the given double and this complex number. */ - public static safe operator (x:Double) * (y:Complex): Complex = y * x; + public static operator (x:Double) * (y:Complex): Complex = y * x; /** * @return the product of this complex number and the given double. */ - public safe operator this * (that:Double):Comple... [truncated message content] |
From: <spa...@us...> - 2010-09-24 22:24:38
|
Revision: 16696 http://x10.svn.sourceforge.net/x10/?rev=16696&view=rev Author: sparksparkspark Date: 2010-09-24 22:24:31 +0000 (Fri, 24 Sep 2010) Log Message: ----------- More work integrating remote refs to CUDA arrays with the new object model Still need to implement the link to the x10rt copy calls Simple kernels are now running, but can't check if they are working Also fixed a bug with apply() in GlobalRef, where ref<T> became ref<ref<T> > causing post compiler bugs Modified Paths: -------------- trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.h trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.struct_h trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.h trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.struct_h trunk/x10.runtime/src-cpp/x10aux/ref.h trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 trunk/x10.runtime/src-x10/x10/lang/GlobalRef.x10 trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 trunk/x10.runtime/x10rt/common/x10rt_cuda.cc trunk/x10.runtime/x10rt/common/x10rt_logical.cc Modified: trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java =================================================================== --- trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.compiler/src/x10cuda/visit/CUDACodeGenerator.java 2010-09-24 22:24:31 UTC (rev 16696) @@ -733,9 +733,9 @@ inc.write("__env."+name+" = "); //String addr = "&(*"+name+")[0]"; // old way for rails - String addr = "&"+name+"->FMGL(raw).data[0]"; + String addr = "&"+name+"->FMGL(raw).raw()[0]"; //String rr = "x10aux::get_remote_ref_maybe_null("+name+".operator->())"; // old object model - String rr = "&"+name+"->FMGL(rawData).data[0]"; + String rr = "&"+name+"->FMGL(rawData).raw()[0]"; if (isIntArray(t)) { if (xts().isRemoteArray(t)) { Modified: trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.h 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.h 2010-09-24 22:24:31 UTC (rev 16696) @@ -29,7 +29,7 @@ template<class T> class GlobalRef_methods { public: - static inline GlobalRef<T> _make(x10aux::ref<T> obj) { + static inline GlobalRef<T> _make(T obj) { return GlobalRef<T>(obj); } }; @@ -75,17 +75,17 @@ template<class T> void x10::lang::GlobalRef<T>::_serialize(x10::lang::GlobalRef<T> this_, x10aux::serialization_buffer& buf) { buf.write(this_->location); - buf.write((x10_long)(size_t)(this_->value.operator->())); + buf.write(this_->value); #if defined(X10_USE_BDWGC) || defined(X10_DEBUG_REFERENCE_LOGGER) if (this_->location == x10aux::here) { - if (!this_->value.isNull()) logGlobalReference(this_->value); + if (!this_->apply().isNull()) logGlobalReference(this_->apply()); } #endif } template<class T> void x10::lang::GlobalRef<T>::_deserialize_body(x10aux::deserialization_buffer& buf) { location = buf.read<x10aux::place>(); - value = (T*)(size_t)buf.read<x10_long>(); + value = buf.read<x10_ulong>(); } @@ -102,7 +102,7 @@ } template<class T> x10_int x10::lang::GlobalRef<T>::hashCode() { - return x10::lang::Object::identityHashCode(value); + return (x10_int)value; } template<class T> x10aux::ref<x10::lang::String> x10::lang::GlobalRef<T>::typeName() { Modified: trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.struct_h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.struct_h 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-cpp/x10/lang/GlobalRef.struct_h 2010-09-24 22:24:31 UTC (rev 16696) @@ -23,12 +23,14 @@ x10aux::itable_entry* _getITables() { return _itables; } x10aux::itable_entry* _getIBoxITables() { return _iboxitables; } - x10aux::ref<T> value; + x10_ulong value; x10aux::place location; - GlobalRef(x10aux::ref<T> obj = NULL) : value(obj), location(x10aux::here) { } + GlobalRef(T obj = NULL) : value((size_t)(obj.operator->())), location(x10aux::here) { } + GlobalRef(x10aux::place p, x10_ulong obj = 0) : value(obj), location(p) { } - inline x10aux::ref<T> apply() { return value; } + // we are assuming T is always of the form x10aux::ref<U> and use T::Type to get U + inline T apply() { return (typename T::Type*)(size_t)value; } GlobalRef<T>* operator->() { return this; } Modified: trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.h 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.h 2010-09-24 22:24:31 UTC (rev 16696) @@ -86,8 +86,8 @@ x10::util::IndexedMemoryChunk<T> dst, x10_int dstIndex, x10_int numElems, x10_boolean uncounted) { - void* srcAddr = (void*)(&data[srcIndex]); - void* dstAddr = (void*)(&dst->data[dstIndex]); + void* srcAddr = (void*)(&raw()[srcIndex]); + void* dstAddr = (void*)(&dst->raw()[dstIndex]); size_t numBytes = numElems * sizeof(T); IMC_copyToBody(srcAddr, dstAddr, numBytes, dstPlace, data == dst->data, uncounted); } @@ -96,8 +96,8 @@ template<class T> void x10::util::IndexedMemoryChunk<T>::copyFrom(x10_int dstIndex, x10::lang::Place srcPlace, x10::util::IndexedMemoryChunk<T> src, x10_int srcIndex, x10_int numElems, x10_boolean uncounted) { - void* srcAddr = (void*)(&src->data[srcIndex]); - void* dstAddr = (void*)(&data[dstIndex]); + void* srcAddr = (void*)(&src->raw()[srcIndex]); + void* dstAddr = (void*)(&raw()[dstIndex]); size_t numBytes = numElems * sizeof(T); IMC_copyFromBody(srcAddr, dstAddr, numBytes, srcPlace, data == src->data, uncounted); } @@ -106,11 +106,11 @@ template<class T> void x10::util::IndexedMemoryChunk<T>::_serialize(x10::util::IndexedMemoryChunk<T> this_, x10aux::serialization_buffer& buf) { - buf.write((x10_long)(size_t)(this_->data)); + buf.write((this_->data)); } template<class T> void x10::util::IndexedMemoryChunk<T>::_deserialize_body(x10aux::deserialization_buffer& buf) { - data = (T*)(size_t)buf.read<x10_long>(); + data = buf.read<x10_ulong>(); } @@ -122,7 +122,7 @@ } template<class T> x10aux::ref<x10::lang::String> x10::util::IndexedMemoryChunk<T>::toString() { - char* tmp = x10aux::alloc_printf("x10.util.IndexedMemoryChunk<%s>(%p)", x10aux::getRTT<T>()->name(), data); + char* tmp = x10aux::alloc_printf("x10.util.IndexedMemoryChunk<%s>(%llx)", x10aux::getRTT<T>()->name(), data); return x10::lang::String::Steal(tmp); } Modified: trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.struct_h =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.struct_h 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-cpp/x10/util/IndexedMemoryChunk.struct_h 2010-09-24 22:24:31 UTC (rev 16696) @@ -29,16 +29,18 @@ x10aux::itable_entry* _getITables() { return _itables; } x10aux::itable_entry* _getIBoxITables() { return _iboxitables; } - T* data; /* TODO: We would like this to be T* const data */ + x10_ulong data; /* TODO: We would like this to be const */ + T *raw (void) const { return (T*)(size_t)data; } - IndexedMemoryChunk(): data(NULL) {} - IndexedMemoryChunk(T* _data): data(_data) {} + IndexedMemoryChunk(): data(0) {} + IndexedMemoryChunk(T* _data): data((size_t)_data) {} + IndexedMemoryChunk(x10_ulong _data): data(_data) {} - inline T apply(x10_int index) { return data[index]; } - inline T apply(x10_long index) { return data[index]; } + inline T apply(x10_int index) { return raw()[index]; } + inline T apply(x10_long index) { return raw()[index]; } - inline void set(T val, x10_int index) { data[index] = val; } - inline void set(T val, x10_long index) { data[index] = val; } + inline void set(T val, x10_int index) { raw()[index] = val; } + inline void set(T val, x10_long index) { raw()[index] = val; } void copyTo(x10_int srcIndex, x10::lang::Place dstPlace, @@ -68,12 +70,12 @@ x10_boolean _struct_equals(x10aux::ref<x10::lang::Any>); x10_boolean _struct_equals(x10::util::IndexedMemoryChunk<T> that) { - return x10aux::struct_equals((size_t)data, (size_t)(that->data)); + return x10aux::struct_equals(data, that->data); } x10aux::ref<x10::lang::String> toString(); - x10_int hashCode() { return (x10_int)(data); } + x10_int hashCode() { return (x10_int)data; } x10_boolean at(x10aux::ref<x10::lang::Object> obj) { return true; } x10_boolean at(x10::lang::Place place) { return true; } Modified: trunk/x10.runtime/src-cpp/x10aux/ref.h =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/ref.h 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-cpp/x10aux/ref.h 2010-09-24 22:24:31 UTC (rev 16696) @@ -49,6 +49,7 @@ template<class T> class ref : public __ref { public: + typedef T Type; static const x10aux::RuntimeType* getRTT() { return T::getRTT(); } // Work around for an xlC ICE Modified: trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-x10/x10/array/RemoteArray.x10 2010-09-24 22:24:31 UTC (rev 16696) @@ -34,7 +34,8 @@ public property rank:Int = region.rank; - public def this(a:Array[T]) : RemoteArray[T]{self.home==here, self.region==a.region, self.size==this.size} { + public def this(a:Array[T]) + : RemoteArray[T]{self.home==here, self.region==a.region, self.size==this.size} { property(here, a.region, a.size); // cast needed as type of 'this' does not include {a.region==this.region, a.size==this.size} even though this is established by property statement val arr = a as Array[T]{self.region==this.region, self.size == this.size}; @@ -44,6 +45,16 @@ rawLength = a.rawLength; } + public def this (gpu:Place, reg:Region, raw:IndexedMemoryChunk[T], raw_len:Int) + : RemoteArray[T]{self.home==gpu, self.region==reg, self.size==reg.size()} { + property(gpu, reg, reg.size()); + rawData = raw; + rawLength = raw_len; + @Native("c++", "") { + array = (at (gpu) GlobalRef[Array[T]{self.region==this.region, self.size==this.size}](null)) as GlobalRef[Array[T]{self.region==this.region, self.size==this.size}]{self.home==this.home}; + } + } + public def equals(other:Any) { if (!(other instanceof RemoteArray[T])) return false; val oRA = other as RemoteArray[T]; Modified: trunk/x10.runtime/src-x10/x10/lang/GlobalRef.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/GlobalRef.x10 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-x10/x10/lang/GlobalRef.x10 2010-09-24 22:24:31 UTC (rev 16696) @@ -42,7 +42,7 @@ * created. Returns the object encapsulated in the value. */ @Native("java", "(#0).apply$G()") - @Native("c++", "((#1)((#0)->value))") + @Native("c++", "(#0)->apply()") public native def apply(){here == this.home}:T; /* Modified: trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/src-x10/x10/util/CUDAUtilities.x10 2010-09-24 22:24:31 UTC (rev 16696) @@ -11,7 +11,9 @@ package x10.util; -/** A collection of independent functions useful in/around CUDA kernels. +import x10.compiler.Native; + +/** A collection of functions useful in/around CUDA kernels. * @author Dave Cunningham */ public class CUDAUtilities { @@ -38,23 +40,50 @@ */ public static def autoThreads() : UInt = 1; + private static def makeCUDAArray[T] (gpu:Place, numElements:Int, init:IndexedMemoryChunk[T]) + : RemoteArray[T]{self.home==gpu, self.rank()==1} { + val reg = 0 .. numElements-1; + @Native("c++", + "x10_ulong addr = x10aux::remote_alloc(gpu.FMGL(id), ((size_t)numElements)*sizeof(FMGL(T)));"+ + "IndexedMemoryChunk<FMGL(T)> imc(addr);"+ + // TODO: initialise + "return x10::array::RemoteArray<FMGL(T)>::_make(gpu, reg, imc, numElements) ;" + ) { } + throw new UnsupportedOperationException(); + } public static def makeRemoteArray[T] (place:Place, numElements:Int, init: Array[T]{rail}) : RemoteArray[T]{self.rank==1, self.home==place} { - return at (place) new RemoteArray[T](new Array[T](numElements, (p:Int)=>init(p))); + if (place.isCUDA()) { + return makeCUDAArray(place, numElements, init.raw()); + } else { + return at (place) new RemoteArray(new Array[T](numElements, (p:Int)=>init(p))); + } } public static def makeRemoteArray[T] (place:Place, numElements:Int, init: T) : RemoteArray[T]{self.rank==1, self.home==place} { - return at (place) new RemoteArray[T](new Array[T](numElements, init)); + if (place.isCUDA()) { + val chunk = IndexedMemoryChunk.allocate[T](numElements); + for ([i] in 0..numElements-1) chunk(i) = init; + return makeCUDAArray(place, numElements, chunk); + } else { + return at (place) new RemoteArray(new Array[T](numElements, init)); + } } public static def makeRemoteArray[T] (place:Place, numElements:Int, init: (Int)=>T) : RemoteArray[T]{self.rank==1, self.home==place} { - return at (place) new RemoteArray[T](new Array[T](numElements, (p:Int)=>init(p))); + if (place.isCUDA()) { + val chunk = IndexedMemoryChunk.allocate[T](numElements); + for ([i] in 0..numElements-1) chunk(i) = init(i); + return makeCUDAArray(place, numElements, chunk); + } else { + return at (place) new RemoteArray(new Array[T](numElements, (p:Int)=>init(p))); + } } } Modified: trunk/x10.runtime/x10rt/common/x10rt_cuda.cc =================================================================== --- trunk/x10.runtime/x10rt/common/x10rt_cuda.cc 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/x10rt/common/x10rt_cuda.cc 2010-09-24 22:24:31 UTC (rev 16696) @@ -566,8 +566,12 @@ abort(); } - BaseOpKernel *op = new (safe_malloc<BaseOpKernel>()) BaseOpKernel(*p); + x10rt_msg_params p_ = *p; + p_.msg = safe_malloc<unsigned char>(p->len); + memcpy(p_.msg, p->msg, p->len); + BaseOpKernel *op = new (safe_malloc<BaseOpKernel>()) BaseOpKernel(p_); + x10rt_cuda_pre *pre = ctx->cbs[p->type].kernel_cbs.pre; DEBUG(2,"x10rt_cuda_send_msg: pre callback begins\n"); pre(p, &op->blocks, &op->threads, &op->shm, @@ -693,6 +697,7 @@ pthread_mutex_lock(&big_lock_of_doom); CU_SAFE(cuCtxPushCurrent(ctx->ctx)); DEBUG(2,"probe: post callback ends\n"); + safe_free(kop->p.msg); kop->~BaseOpKernel(); free(kop); } Modified: trunk/x10.runtime/x10rt/common/x10rt_logical.cc =================================================================== --- trunk/x10.runtime/x10rt/common/x10rt_logical.cc 2010-09-24 22:05:35 UTC (rev 16695) +++ trunk/x10.runtime/x10rt/common/x10rt_logical.cc 2010-09-24 22:24:31 UTC (rev 16696) @@ -630,6 +630,7 @@ case X10RT_LGL_CUDA: { x10rt_cuda_ctx *cctx = static_cast<x10rt_cuda_ctx*>(g.accel_ctxs[g.index[d]]); ch((x10rt_remote_ptr)(size_t) x10rt_cuda_device_alloc(cctx, sz),arg); + break; } case X10RT_LGL_SPE: { fprintf(stderr,"SPE remote_alloc still unsupported.\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vj...@us...> - 2010-09-25 00:15:34
|
Revision: 16697 http://x10.svn.sourceforge.net/x10/?rev=16697&view=rev Author: vj0 Date: 2010-09-25 00:15:27 +0000 (Sat, 25 Sep 2010) Log Message: ----------- Fix missing polyregion functionality so that all the tests below pass. Modified Paths: -------------- trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 trunk/x10.runtime/src-x10/x10/array/Region.x10 trunk/x10.tests/examples/Constructs/Array/PolyRestriction1.x10 trunk/x10.tests/examples/Constructs/Region/PolyContains1.x10 trunk/x10.tests/examples/Constructs/Region/PolyContains2.x10 trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 trunk/x10.tests/examples/Constructs/Region/PolyHalfspace1.x10 trunk/x10.tests/examples/Constructs/Region/PolyIntersection1.x10 trunk/x10.tests/examples/Constructs/Region/PolyProduct1.x10 trunk/x10.tests/examples/Constructs/Region/PolyUpperTriangular1.x10 Modified: trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.runtime/src-x10/x10/array/PolyRegion.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -48,8 +48,16 @@ return true; } - @Incomplete public def size():int { - throw new UnsupportedOperationException(); + var size:Int = -1; // uninitialized + public def size():int { + if (size < 0) { + var s:Int=0; + val it= iterator(); + for (p:Point in this) + s++; + size=s; + } + return size; } @Incomplete public def indexOf(Point):int { @@ -124,7 +132,10 @@ val pm = pmb.toSortedPolyMat(false); return PolyRegion.make(pm) as Region(rank); // XXXX why? - } /*else if (t instanceof UnionRegion) { + } else if (t instanceof RectRegion) { + return intersection((t as RectRegion).toPolyRegion()); + } + /*else if (t instanceof UnionRegion) { return (t as Region(rank)).intersection(this); Modified: trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.runtime/src-x10/x10/array/RectRegion.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -11,10 +11,10 @@ package x10.array; -import x10.compiler.TempNoInline; /** - * A RectRegion is a finite, rank-dimensional, dense rectangular region. + * A RectRegion is a finite dense rectangular region with a specified rank. + * This class implements a specialization of PolyRegion. */ public final class RectRegion extends Region{rect} { @@ -31,17 +31,20 @@ private val max2:int; private val max3:int; + private val myMin:(int)=>int; + private val myMax:(int)=>int; + private static def allZeros(x:ValRail[int]) { for (i in x) if (i != 0) return false; return true; } + /** + * Create a rectangular region containing all points p such that min <= p and p <= max. + */ def this(minArg:ValRail[int], maxArg:ValRail[int](minArg.length)):RectRegion{self.rank==minArg.length} { super(minArg.length, true, allZeros(minArg)); - if (minArg.length!=maxArg.length) - throw new IllegalOperationException("min and max must have same length"); - var s:int = 1; for (var i:int = 0; i<minArg.length; i++) { var rs:int = maxArg(i) - minArg(i) + 1; @@ -85,9 +88,31 @@ mins = null; maxs = null; } + myMin = (i:int) => { + switch(i) { + case 0: return min0; + case 1: return min1; + case 2: return min2; + case 3: return min3; + default: return mins(i); + } + }; + + myMax = (i:int) => { + switch(i) { + case 0: return max0; + case 1: return max1; + case 2: return max2; + case 3: return max3; + default: return maxs(i); + } + }; } - def this(min:int, max:int):RectRegion{self.rank==1} { + /** + * Create a 1-dim region min..max. + */ + def this(min:int, max:int):RectRegion(1){ this([min],[max]); } @@ -114,30 +139,10 @@ protected def computeBoundingBox(): Region(rank){self.rect}=this; - public @TempNoInline def min():(int)=>int { - return (i:int) => { - switch(i) { - case 0: return min0; - case 1: return min1; - case 2: return min2; - case 3: return min3; - default: return mins(i); - } - }; - } + + public def min():(int)=>int = myMin; + public def max():(int)=>int = myMax; - public @TempNoInline def max():(int)=>int { - return (i:int) => { - switch(i) { - case 0: return max0; - case 1: return max1; - case 2: return max2; - case 3: return max3; - default: return maxs(i); - } - }; - } - public def contains(that:Region(rank)): boolean { if (that instanceof RectRegion) { val thatMin = (that as RectRegion).min(); @@ -209,26 +214,41 @@ } + transient protected var polyRep:Region(rank)=null; + /** + * Return a PolyRegion with the same set of points as this region. This permits + * general algorithms for intersection, restriction etc to be applied to RectRegion's. + */ + public def toPolyRegion() { + if (polyRep==null) { + polyRep = Region.makeRectangularPoly(ValRail.make[int](rank, min()), ValRail.make[int](rank, max())); + } + return polyRep; + } + + @Override public def intersection(that: Region(rank)):Region(rank) { if (that.isEmpty()) { - return that; + return that; } else if (that instanceof FullRegion) { return this; } else if (that instanceof RectRegion) { val thatMin = (that as RectRegion).min(); val thatMax = (that as RectRegion).max(); - val newMin = ValRail.make[int](rank, (i:int)=>Math.max(min(i), thatMin(i))); - val newMax = ValRail.make[int](rank, (i:int)=>Math.min(max(i), thatMax(i))); - for ([i] in 0..newMin.length-1) { + val newMin = ValRail.make[int](rank, (i:int)=>Math.max(min(i), thatMin(i))); + val newMax = ValRail.make[int](rank, (i:int)=>Math.min(max(i), thatMax(i))); + for ([i] in 0..newMin.length-1) { if (newMax(i)<newMin(i)) return Region.makeEmpty(rank); } return new RectRegion(newMin, newMax); } else { - throw new UnsupportedOperationException("haven't implemented RectRegion intersection with "+that.typeName()); + // Use the general representation. + return (toPolyRegion() as Region(rank)).intersection(that); } } + @Override public def product(that:Region):Region /*self.rank==this.rank+that.rank*/{ if (that.isEmpty()) { return Region.makeEmpty(rank + that.rank); @@ -245,7 +265,7 @@ val newMax = ValRail.make[int](k, (i:int)=>i<rank?max(i):Int.MAX_VALUE); return new RectRegion(newMin,newMax); } else { - throw new UnsupportedOperationException("haven't implemented RectRegion product with "+that.typeName()); + return (toPolyRegion() as Region(rank)).product(that); } } @@ -340,11 +360,6 @@ return true; } - - // - // - // - public def toString(): String { val thisMin = this.min(); val thisMax = this.max(); @@ -357,10 +372,55 @@ return s; } + /** + * The Scanner class supports efficient scanning. Usage: + * + * for (s:Scanner in r.scanners()) { + * int min0 = s.min(0); + * int max0 = s.max(0); + * for (var i0:int=min0; i0<=max0; i0++) { + * s.set(0,i0); + * int min1 = s.min(1); + * int max1 = s.max(1); + * for (var i1:int=min1; i1<=max1; i1++) { + * ... + * } + * } + * } + * + */ - public def scanners():Iterator[Region.Scanner] { - throw new UnsupportedOperationException("TODO: scanners not defined for RectRegion"); + private class RectRegionScanner implements Region.Scanner { + var axis:Int=0; + def this(){} + public def set(axis:int, position: int) { + // ??? + } + public def min(axis:int):int = RectRegion.this.min()(axis); + public def max(axis:int):int = RectRegion.this.max()(axis); } + private class Scanners implements Iterator[Region.Scanner] { + var hasNext: boolean = true; + public def hasNext(): boolean { + return hasNext; + } + + public def next(): Region.Scanner { + if (hasNext) { + hasNext = false; + return new RectRegionScanner(); + } else + throw new x10.util.NoSuchElementException("in scanner"); + } + + public def remove(): void { + throw new UnsupportedOperationException("remove"); + } + } + + public def scanners()=new Scanners(); + + } Modified: trunk/x10.runtime/src-x10/x10/array/Region.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/Region.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.runtime/src-x10/x10/array/Region.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -68,12 +68,38 @@ val pm = pmb.toSortedPolyMat(false); return PolyRegion.make(pm) as Region(normal.rank); // XXXX Why is this cast here? } - // // rectangular factories // /** + * Returns a PolyRegion that represents the rectangular region with smallest point minArg and largest point + * maxArg. + * <p> Most users of the Region API should call makeRectangular which will return a + * RectRegion. Methods on RectRegion automatically construct a PolyRegion (by calling makeRectangularPoly) + * if they need to implement operations (such as intersection, product etc) that are difficult to define + * on a RectRegion's representation. + * @param minArg:ValRail[int] -- specifies the smallest point in the region + * @param maxArg:ValRail[int] -- specifies the largest point in the region (must have the same rank as minArg + * @return A Region of rank minarg.length + */ + + public static def makeRectangularPoly(minArg: ValRail[int], maxArg: ValRail[int](minArg.length)):Region(minArg.length){ + val rank = minArg.length; + val pmb = new PolyMatBuilder(rank); + for ([i] in 0..rank-1) { + // add -1*x(i) + minArg(i) <= 0, i.e. x(i) >= minArg(i) + val r = new PolyRow(Point.make(rank, (j:Int) => i==j ? -1 : 0), minArg(i)); + pmb.add(r); + // add 1*x(i) - maxArg(i) <= 0, i.e. x(i) <= maxArg(i) + val s = new PolyRow(Point.make(rank, (j:Int) => i==j ? 1 : 0), -maxArg(i)); + pmb.add(s); + } + val pm = pmb.toSortedPolyMat(false); + return PolyRegion.make(pm) as Region(minArg.length); + } + + /** * Construct a rectangular region whose bounds are specified as * rails of ints. */ @@ -115,6 +141,9 @@ * Construct a banded region of the given size, with the specified * number of diagonals above and below the main diagonal * (inclusive of the main diagonal). + * @param size -- number of elements in the banded region + * @param upper -- the number of diagonals in the band, above the main diagonal + * @param lower -- the number of diagonals in the band, below the main diagonal */ public static def makeBanded(size: int, upper: int, lower: int):Region(2) = @TempNoInline PolyRegion.makeBanded(size, upper, lower); @@ -277,28 +306,27 @@ /** * Returns the Cartesian product of two regions. The Cartesian - * product has rank this.rank+that.rank. For every point p in the - * Cartesian product, the first this.rank coordinates of p are a - * point in this region, while the last that.rank coordinates of p - * are a point in that.region. + * product has rank <code>this.rank+that.rank</code>. For every point <code>p</code> in the + * Cartesian product, the first <code>this.rank</code> coordinates of <code>p</code> are a + * point in this region, while the last <code>that.rank</code> coordinates of p + * are a point in that region. */ abstract public def product(that: Region): Region; /** * Returns the region shifted by a Point (vector). The Point has - * to have the same rank as the region. For every point p in the - * resulting region, each coordinate is that of the corresponding - * point q shifted by the same coordinate of the given point. + * to have the same rank as the region. A point p+v is in + * <code>translate(v)</code> iff <code>p</code> is in <code>this</code>. */ abstract public def translate(v: Point(rank)): Region(rank); /** * Returns the projection of a region onto the specified axis. The - * projection is a rank-1 region such that for every point (i) in - * the projection, there is some point p in this region such that - * p(axis)==i. + * projection is a rank-1 region such that for every point <code>[i]</code> in + * the projection, there is some point <code>p</code> in this region such that + * <code>p(axis)==i</code>. */ abstract public def projection(axis: int): Region(1); @@ -369,10 +397,8 @@ //public operator this - (that: Region(rank)): Region(rank) = difference(that); public operator this * (that: Region) = product(that); - public operator this + (v: Point(rank)) = translate(v); public operator (v: Point(rank)) + this = translate(v); - public operator this - (v: Point(rank)) = translate(-v); @@ -381,12 +407,12 @@ // public def equals(that:Any):boolean { - if (this == that) return true; // short-circuit - if (!(that instanceof Region)) return false; - val t1 = that as Region; - if (rank != t1.rank) return false; - val t2 = t1 as Region(rank); - return this.contains(t2) && t2.contains(this); + if (this == that) return true; // short-circuit + if (!(that instanceof Region)) return false; + val t1 = that as Region; + if (rank != t1.rank) return false; + val t2 = t1 as Region(rank); + return this.contains(t2) && t2.contains(this); } abstract public def contains(that: Region(rank)): boolean; @@ -402,8 +428,6 @@ public def contains(i0:int, i1:int, i2:int, i3:int){rank==4} = contains(@TempNoInline Point.make(i0,i1,i2,i3)); - - protected def this(r: int, t: boolean, z: boolean) :Region{self.rank==r, self.rect==t, self.zeroBased==z} { property(r, t, z); Modified: trunk/x10.tests/examples/Constructs/Array/PolyRestriction1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Array/PolyRestriction1.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Array/PolyRestriction1.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -34,7 +34,7 @@ } def expected() = - "--- PolyRestriction1: whole array\n"+ + "--- TestArray: whole array\n"+ "rank 2\n"+ "rect true\n"+ "zeroBased true\n"+ @@ -56,7 +56,7 @@ " 3 0 3 6 9 2 5 . . . . \n"+ " 4 0 4 8 2 6 0 . . . . \n"+ " 5 0 5 0 5 0 5 . . . . \n"+ - "--- PolyRestriction1: restricted array\n"+ + "--- TestArray: restricted array\n"+ "rank 2\n"+ "rect true\n"+ "zeroBased false\n"+ @@ -72,7 +72,7 @@ " 1 . . 2 3 4 . . . . . \n"+ " 2 . . 4 6 8 . . . . . \n"+ " 3 . . 6 9 2 . . . . . \n"+ - "--- PolyRestriction1: whole array modified\n"+ + "--- TestArray: whole array modified\n"+ "rank 2\n"+ "rect true\n"+ "zeroBased true\n"+ Modified: trunk/x10.tests/examples/Constructs/Region/PolyContains1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyContains1.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Region/PolyContains1.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -50,7 +50,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 5\n"+ "region: (x0-x1>=0 && x1>=0 && x0-x1<=0 && x0<=4)\n"+ " poly\n"+ " 0 0 . . . . . . . . . \n"+ @@ -72,7 +72,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 9\n"+ "region: (x0-x1>=0 && x1>=0 && x0-x1<=1 && x0<=4)\n"+ " poly\n"+ " 0 0 . . . . . . . . . \n"+ @@ -92,7 +92,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 9\n"+ "region: (x0>=0 && x0-x1>=-1 && x1<=4 && x0-x1<=0)\n"+ " poly\n"+ " 0 0 0 . . . . . . . . \n"+ Modified: trunk/x10.tests/examples/Constructs/Region/PolyContains2.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyContains2.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Region/PolyContains2.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -46,7 +46,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 10\n"+ "region: (x0>=0 && x1<=3 && x0-x1<=0)\n"+ " poly\n"+ " 0 0 0 0 0 . . . . . . \n"+ @@ -66,7 +66,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 10\n"+ "region: (x0-x1>=0 && x1>=0 && x0<=3)\n"+ " poly\n"+ " 0 0 . . . . . . . . . \n"+ Modified: trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Region/PolyFromRail1.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -17,7 +17,7 @@ class PolyFromRail1 extends TestRegion { public def run() { - var foo: Rail[double] = [5.0,4.0,3.0,2.0,1.0]; + val foo = Rail.make([5.0,4.0,3.0,2.0,1.0]); val a = new Array[double](foo); prArray("from native rail", a); return status(); Modified: trunk/x10.tests/examples/Constructs/Region/PolyHalfspace1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyHalfspace1.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Region/PolyHalfspace1.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -38,7 +38,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 8\n"+ "region: (x0+x1>=3 && x0-x1>=-1 && x0-x1<=1 && x0+x1<=7)\n"+ " poly\n"+ " 1 . . 2 . . . . . . . \n"+ Modified: trunk/x10.tests/examples/Constructs/Region/PolyIntersection1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyIntersection1.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Region/PolyIntersection1.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -39,7 +39,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 28\n"+ "region: (x0>=2 && x1<=7 && x0-x1<=1)\n"+ " poly\n"+ " 2 . 2 4 6 8 0 2 4 . . \n"+ @@ -81,7 +81,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 17\n"+ "region: (x0>=3 && x1>=3 && x1<=7 && x0-x1<=1 && x0<=6)\n"+ " poly\n"+ " 3 . . . 9 2 5 8 1 . . \n"+ Modified: trunk/x10.tests/examples/Constructs/Region/PolyProduct1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyProduct1.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Region/PolyProduct1.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -32,7 +32,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 12\n"+ "region: (x0>=1 && x1-x2>=0 && x2>=0 && x1<=2 && x0<=2)\n"+ " poly\n"+ " --- 1\n"+ Modified: trunk/x10.tests/examples/Constructs/Region/PolyUpperTriangular1.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Region/PolyUpperTriangular1.x10 2010-09-24 22:24:31 UTC (rev 16696) +++ trunk/x10.tests/examples/Constructs/Region/PolyUpperTriangular1.x10 2010-09-25 00:15:27 UTC (rev 16697) @@ -29,7 +29,7 @@ "zeroBased false\n"+ "rail false\n"+ "isConvex() true\n"+ - "size() size not supported\n"+ + "size() 15\n"+ "region: (x0>=0 && x1<=4 && x0-x1<=0)\n"+ " poly\n"+ " 0 0 0 0 0 0 . . . . . \n"+ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yz...@us...> - 2010-09-25 00:18:23
|
Revision: 16698 http://x10.svn.sourceforge.net/x10/?rev=16698&view=rev Author: yzibin Date: 2010-09-25 00:18:16 +0000 (Sat, 25 Sep 2010) Log Message: ----------- deleted asyncInitVal from Finish and Async, and moved it to X10Ext, and I add the VarDef for all kinds of Expr&Statements (for everything basically). Removed safe and the other 3 modifiers from the compiler. Modified Paths: -------------- trunk/x10.compiler/src/polyglot/visit/InitChecker.java trunk/x10.compiler/src/x10/ast/Async_c.java trunk/x10.compiler/src/x10/ast/AtStmt_c.java trunk/x10.compiler/src/x10/ast/Await_c.java trunk/x10.compiler/src/x10/ast/Finish_c.java trunk/x10.compiler/src/x10/ast/Next_c.java trunk/x10.compiler/src/x10/ast/PlacedClosure_c.java trunk/x10.compiler/src/x10/ast/Resume_c.java trunk/x10.compiler/src/x10/ast/When_c.java trunk/x10.compiler/src/x10/ast/X10Call_c.java trunk/x10.compiler/src/x10/ast/X10ClockedLoop_c.java trunk/x10.compiler/src/x10/extension/X10Ext_c.java trunk/x10.compiler/src/x10/types/X10Context.java trunk/x10.compiler/src/x10/types/X10Context_c.java trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 Modified: trunk/x10.compiler/src/polyglot/visit/InitChecker.java =================================================================== --- trunk/x10.compiler/src/polyglot/visit/InitChecker.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/polyglot/visit/InitChecker.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -16,6 +16,7 @@ import polyglot.types.*; import polyglot.util.InternalCompilerError; import polyglot.util.Position; +import polyglot.util.IdentityKey; import polyglot.visit.DataFlow.Item; import polyglot.visit.FlowGraph.EdgeKey; import x10.ast.AssignPropertyCall; @@ -24,6 +25,7 @@ import x10.ast.X10ClassDecl; import x10.ast.Async_c; import x10.ast.Finish_c; +import x10.extension.X10Ext_c; /** * Visitor which checks that all local variables must be defined before use, @@ -342,13 +344,6 @@ small.minAsync.count<=big.minAsync.count && small.maxAsync.count<=big.maxAsync.count; - // We also need to mark the variable as "initialized in async" to allow - // the backend to implement such initializations. - if (!small.equals(big) && v.flags().isFinal()) { - if (async.asyncInitVal ==null) async.asyncInitVal = new HashSet<VarDef>(); - async.asyncInitVal.add(v); - } - return new MinMaxInitCount(small.minSeq, small.maxSeq, big.minAsync, big.maxAsync); // [a',b', c, d] } // normal join: [min(a,a'), max(b,b'), min(c,c'), max(d,d')] @@ -731,6 +726,37 @@ */ public Map<EdgeKey, Item> flow(Item trueItem, Item falseItem, Item otherItem, FlowGraph graph, Term n, boolean entry, Set<EdgeKey> succEdgeKeys) { + + Map<EdgeKey, Item> res = flow_(trueItem,falseItem,otherItem,graph,n,entry, succEdgeKeys); + if (entry) return res; + + // We also need to mark the variable as "initialized in async" to allow + // the backend to implement such initializations. + final FlowGraph.Peer peer = graph.peer(n, Term.ENTRY); + final Item inItem = peer.inItem(); + if (inItem==null || inItem==BOTTOM) return res; + final DataFlowItem in = (DataFlowItem) inItem; + final X10Ext_c ext = (X10Ext_c) n.ext(); + for (Map.Entry<VarDef, MinMaxInitCount> e : in.initStatus.entrySet()) { + final MinMaxInitCount before = e.getValue(); + final VarDef v = e.getKey(); + for (Item outItem : res.values()) { + if (outItem==null || outItem==BOTTOM) continue; + final DataFlowItem out = (DataFlowItem) outItem; + final MinMaxInitCount after = out.initStatus.get(v); + if (after==null) continue; + final Flags flags = v.flags(); + if (!before.equals(after) && after.equals(MinMaxInitCount.ONE) && flags !=null && flags.isFinal()) { + if (ext.asyncInitVal ==null) ext.asyncInitVal = new HashSet<VarDef>(); + ext.asyncInitVal.add(v); + return res; + } + } + } + return res; + } + public Map<EdgeKey, Item> flow_(Item trueItem, Item falseItem, Item otherItem, + FlowGraph graph, Term n, boolean entry, Set<EdgeKey> succEdgeKeys) { Item inItem = safeConfluence(trueItem, FlowGraph.EDGE_KEY_TRUE, falseItem, FlowGraph.EDGE_KEY_FALSE, otherItem, FlowGraph.EDGE_KEY_OTHER, @@ -779,18 +805,12 @@ if (falseItem == null) falseItem = inDFItem; return itemsToMap(trueItem, falseItem, inDFItem, succEdgeKeys); } else if (n instanceof Finish_c) { - Finish_c finish = (Finish_c) n; Map<VarDef, MinMaxInitCount> m = new LinkedHashMap<VarDef, MinMaxInitCount>(); for (Map.Entry<VarDef, MinMaxInitCount> e : inDFItem.initStatus.entrySet()) { final MinMaxInitCount before = e.getValue(); final MinMaxInitCount after = before.finish(); final VarDef v = e.getKey(); m.put(v, after); - // for the backend - if (!before.equals(after) && v.flags().isFinal()) { - if (finish.asyncInitVal ==null) finish.asyncInitVal = new HashSet<VarDef>(); - finish.asyncInitVal.add(v); - } } return itemToMap(new DataFlowItem(m), succEdgeKeys); } Modified: trunk/x10.compiler/src/x10/ast/Async_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Async_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/Async_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -63,15 +63,6 @@ */ public class Async_c extends Stmt_c implements Async { - /* - For example: - val x:Int; - finish async { x = 42; } // "x" can either be boxed or be passed (to the async closure) by ref, because we need to assign to it. It cannot be passed by value. - async { val y = x; } // "x" can be passed by value or be be boxed. It cannot be passed by ref because the async outlives the var "x". - */ - public Set<VarDef> asyncInitVal = null; // used by the backend to know whether to pass a var to an async closure by ref or by value - - public Stmt body; protected List<Expr> clocks; protected boolean clocked; // should be equal to (clocks != null && clocks.size() > 0) @@ -189,9 +180,6 @@ X10NodeFactory nf = (X10NodeFactory) tc.nodeFactory(); X10Context c = (X10Context) tc.context(); - if (c.inSequentialCode()) - Errors.issue(tc.job(), - new SemanticException("async may not be invoked in sequential code.", position())); if (clocked() && ! c.inClockedFinishScope()) Errors.issue(tc.job(), new SemanticException("clocked async must be invoked inside a statically enclosing clocked finish.", position())); Modified: trunk/x10.compiler/src/x10/ast/AtStmt_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/AtStmt_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/AtStmt_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -197,18 +197,7 @@ return c; } - public Node typeCheck(ContextVisitor tc) { - X10TypeSystem ts = (X10TypeSystem) tc.typeSystem(); - X10NodeFactory nf = (X10NodeFactory) tc.nodeFactory(); - X10Context c = (X10Context) tc.context(); - if (c.inSequentialCode()) - Errors.issue(tc.job(), - new SemanticException("at may not be invoked in sequential code.", position())); - return this; - } - - public Type childExpectedType(Expr child, AscriptionVisitor av) { X10TypeSystem ts = (X10TypeSystem) av.typeSystem(); if (child == place) { Modified: trunk/x10.compiler/src/x10/ast/Await_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Await_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/Await_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -87,8 +87,6 @@ if (! ts.isSubtype(expr_.type(), ts.Boolean(), tc.context()) ) throw new SemanticException("The argument to await, " + expr_ +", must be of type boolean.", position()); X10Context c = (X10Context) tc.context(); - if (c.inNonBlockingCode()) - throw new SemanticException("The await statement cannot be used in nonblocking code.", position()); return super.typeCheck(tc); } Modified: trunk/x10.compiler/src/x10/ast/Finish_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Finish_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/Finish_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -33,14 +33,6 @@ * */ public class Finish_c extends Stmt_c implements Finish { - /* - asyncInitVal is used by the backend to handle async initialization. - For example: - val x:Int; - finish async { finish async { x = 42; } } - */ - public Set<VarDef> asyncInitVal = null; - protected Stmt body; protected boolean clocked; /** Modified: trunk/x10.compiler/src/x10/ast/Next_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Next_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/Next_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -36,10 +36,4 @@ public <S> List<S> acceptCFG(CFGBuilder v, List<S> succs) { return succs; } - public Node typeCheck(ContextVisitor tc) throws SemanticException { - X10Context c = (X10Context) tc.context(); - if (c.inNonBlockingCode()) - throw new SemanticException("The next statement cannot be used in nonblocking code.", position()); - return super.typeCheck(tc); - } } Modified: trunk/x10.compiler/src/x10/ast/PlacedClosure_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/PlacedClosure_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/PlacedClosure_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -120,16 +120,6 @@ return null; } - - public Node typeCheck(ContextVisitor tc) { - X10Context xc = (X10Context) tc.context(); - if (xc.inSequentialCode()) - Errors.issue(tc.job(), - new SemanticException("at may not be invoked in sequential code.", position())); - Node n = super.typeCheck(tc); - return n; - } - protected X10Context pushPlaceTerm(X10Context xc) { ClosureDef def = (ClosureDef) codeDef(); XConstrainedTerm pt = def.placeTerm(); Modified: trunk/x10.compiler/src/x10/ast/Resume_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Resume_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/Resume_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -36,10 +36,4 @@ public <S> List<S> acceptCFG(CFGBuilder v, List<S> succs) { return succs; } - public Node typeCheck(ContextVisitor tc) throws SemanticException { - X10Context c = (X10Context) tc.context(); - if (c.inNonBlockingCode()) - throw new SemanticException("The resume statement cannot be used in nonblocking code.", position()); - return super.typeCheck(tc); - } } Modified: trunk/x10.compiler/src/x10/ast/When_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/When_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/When_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -105,17 +105,6 @@ return reconstruct(e, s, es, ss); } - /** Type check the statement. */ - // TODO: cvp -> vj implement this - public Node typeCheck(ContextVisitor tc) throws SemanticException { - - X10Context c = (X10Context) tc.context(); - if (c.inNonBlockingCode()) - throw new SemanticException("The when statement cannot be used in nonblocking code.", position()); - return super.typeCheck(tc); - - } - public String toString() { return "when (" + expr + ")" + stmt + (exprs.size() > 0 ? "..." : ""); } Modified: trunk/x10.compiler/src/x10/ast/X10Call_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Call_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/X10Call_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -687,7 +687,6 @@ // Eliminate for orthogonal locality. // methodCall = (X10Call_c) PlaceChecker.makeReceiverLocalIfNecessary(methodCall, tc); //methodCall.checkConsistency(c); // [IP] Removed -- this is dead code at this point - methodCall.checkAnnotations(tc); X10TypeMixin.checkMissingParameters(methodCall); Checker.checkOfferType(position(), (X10MethodInstance) methodCall.methodInstance(), tc); return methodCall; @@ -713,31 +712,6 @@ return p; } - private void checkAnnotations(ContextVisitor tc) throws SemanticException { - X10Context c = (X10Context) tc.context(); - X10MethodInstance mi = (X10MethodInstance) methodInstance(); - try { - if (mi !=null) { - X10Flags flags = X10Flags.toX10Flags(mi.flags()); - if (c.inNonBlockingCode() - && ! (mi.isSafe() || flags.isNonBlocking() || flags.isExtern())) - throw new SemanticException(mi + ": Only nonblocking methods can be called from nonblocking code.", - position()); - if (c.inSequentialCode() - && ! (mi.isSafe() || flags.isSequential() || flags.isExtern())) - throw new SemanticException(mi + ": Only sequential methods can be called from sequential code.", - position()); - if (c.inLocalCode() - && ! (mi.isSafe() || flags.isPinned() || flags.isExtern())) - throw new SemanticException(mi + ": Only pinned methods can be called from pinned code.", - position()); - } - } - catch (SemanticException e) { - Warnings.issue(tc.job(), "WARNING (should be error, but method annotations in XRX are wrong): " + e.getMessage(), position()); - } - } - private Node superTypeCheck(ContextVisitor tc) throws SemanticException { return super.typeCheck(tc); } Modified: trunk/x10.compiler/src/x10/ast/X10ClockedLoop_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10ClockedLoop_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/ast/X10ClockedLoop_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -117,11 +117,6 @@ } } - X10Context c = (X10Context) tc.context(); - if (c.inSequentialCode()) { - throw new SemanticException("foreach/ateach may not be invoked in sequential code.", position()); - } - return super.typeCheck(tc); } } Modified: trunk/x10.compiler/src/x10/extension/X10Ext_c.java =================================================================== --- trunk/x10.compiler/src/x10/extension/X10Ext_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/extension/X10Ext_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -15,6 +15,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Set; import polyglot.ast.Node; import polyglot.ast.NodeFactory; @@ -22,12 +23,21 @@ import polyglot.types.ClassType; import polyglot.types.QName; import polyglot.types.Type; +import polyglot.types.VarDef; import polyglot.ast.Ext_c; import x10.ast.AnnotationNode; import x10.types.X10ClassType; import x10.types.X10TypeSystem; public class X10Ext_c extends Ext_c implements X10Ext { + /* + asyncInitVal is used by the backend to handle async initialization. + For example: + val x:Int; + finish async { finish async { x = 42; } } + */ + public Set<VarDef> asyncInitVal = null; + String comment; List<AnnotationNode> annotations; boolean subtreeValid = true; Modified: trunk/x10.compiler/src/x10/types/X10Context.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10Context.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/types/X10Context.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -156,15 +156,6 @@ */ X10Context pushAtomicBlock(); - void setSafeCode(); - void setNonBlockingCode(); - void setSequentialCode(); - void setLocalCode(); - boolean inSafeCode(); - boolean inLocalCode(); - boolean inSequentialCode(); - boolean inNonBlockingCode(); - Name getNewVarName(); void setVarWhoseTypeIsBeingElaborated(VarDef var); Modified: trunk/x10.compiler/src/x10/types/X10Context_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10Context_c.java 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.compiler/src/x10/types/X10Context_c.java 2010-09-25 00:18:16 UTC (rev 16698) @@ -348,20 +348,12 @@ } return false; } - public boolean inSafeCode() { return inSafeCode; } - public boolean inSequentialCode() { return inSequentialCode; } - public boolean inNonBlockingCode() { return inNonBlockingCode; } - public boolean inLocalCode() { return inLocalCode; } public boolean inLoopHeader() { return inLoopHeader; } public boolean inAnnotation() { return inAnnotation; } public boolean inAnonObjectScope() { return inAnonObjectScope;} public void restoreAnonObjectScope(boolean s) { inAnonObjectScope=s;} public void setInAssignment() { inAssignment = true;} - public void setSafeCode() { inSafeCode = true; } - public void setSequentialCode() { inSequentialCode = true; } - public void setNonBlockingCode() { inNonBlockingCode = true; } - public void setLocalCode() { inLocalCode = true; } public void setLoopHeader() { inLoopHeader = true; } public void setAnnotation() { inAnnotation = true; } public void setAnonObjectScope() { inAnonObjectScope = true;} @@ -635,9 +627,6 @@ public X10Context pushAtomicBlock() { assert (depType == null); X10Context c = (X10Context) super.pushBlock(); - c.setLocalCode(); - c.setNonBlockingCode(); - c.setSequentialCode(); return c; } Modified: trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-25 00:15:27 UTC (rev 16697) +++ trunk/x10.tests/examples/Constructs/Constructor/EscapingThisTest.x10 2010-09-25 00:18:16 UTC (rev 16698) @@ -16,7 +16,12 @@ } } +class XTENLANG_1643 { + var i:Int{self!=0}; + def this(j:Int{self!=0}) { i = j; } +} + final class ClosureTest57 { val z = 1; val c1 = () => z+1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ipe...@us...> - 2010-09-25 23:18:39
|
Revision: 16711 http://x10.svn.sourceforge.net/x10/?rev=16711&view=rev Author: ipeshansky Date: 2010-09-25 23:18:33 +0000 (Sat, 25 Sep 2010) Log Message: ----------- Fix warning; adjust formatting in X10PrettyPrinterVisitor. Fix setters to only create a copy if changing something. Fix ParsedClassType_c.toString(). Remove dead code from AmbDepTypeNode_c. Minor whitespace fixes. Modified Paths: -------------- trunk/x10.compiler/src/polyglot/types/ParsedClassType_c.java trunk/x10.compiler/src/x10/ast/AmbDepTypeNode_c.java trunk/x10.compiler/src/x10/ast/Closure_c.java trunk/x10.compiler/src/x10/types/ConstrainedType_c.java trunk/x10.compiler/src/x10/types/X10LocalInstance_c.java trunk/x10.compiler/src/x10/types/XTypeTranslator.java trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java trunk/x10.constraints/src/x10/constraint/XField.java Modified: trunk/x10.compiler/src/polyglot/types/ParsedClassType_c.java =================================================================== --- trunk/x10.compiler/src/polyglot/types/ParsedClassType_c.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.compiler/src/polyglot/types/ParsedClassType_c.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -166,6 +166,6 @@ } public String toString() { - return def.getCached().toString(); + return super.toString(); } } Modified: trunk/x10.compiler/src/x10/ast/AmbDepTypeNode_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/AmbDepTypeNode_c.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.compiler/src/x10/ast/AmbDepTypeNode_c.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -161,43 +161,9 @@ result = (CanonicalTypeNode) ((X10Del) result.del()).annotations(((X10Del) n.del()).annotations()); result = (CanonicalTypeNode) ((X10Del) result.del()).setComment(((X10Del) n.del()).comment()); - // [IP] This is wrong! - //LazyRef<Type> sym = (LazyRef<Type>) result.typeRef(); - //sym.update(fixInnerParams(sym.get())); - return result; } - // [IP] This is wrong! - // Fix inner classes by adding type arguments from their enclosing classes. - // That is, convert C[T].D into C[T].D[T]. - static Type fixInnerParams(Type t) { - Type b = X10TypeMixin.baseType(t); - if (b instanceof X10ClassType) { - X10ClassType ct = (X10ClassType) b; - List<Type> params = new ArrayList<Type>(); - - if (ct.isMember() && ! ct.flags().isStatic()) { - X10ClassType outer = (X10ClassType) ct.outer(); - while (outer != null) { - params.addAll(outer.typeArguments()); - if (outer.isMember()) - outer = (X10ClassType) outer.outer(); - else - outer = null; - } - } - - if (params.size() > 0) { - params.addAll(0, ct.typeArguments()); - ct = ct.typeArguments(params); - t = X10TypeMixin.baseType(ct); - } - } - - return t; - } - public Node exceptionCheck(ExceptionChecker ec) throws SemanticException { throw new InternalCompilerError(position(), "Cannot exception check ambiguous node " + this + "."); Modified: trunk/x10.compiler/src/x10/ast/Closure_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/Closure_c.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.compiler/src/x10/ast/Closure_c.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -415,7 +415,7 @@ if (hasType != null) { final TypeNode h = (TypeNode) n.visitChild(n.hasType, tc); Type hasType = PlaceChecker.ReplaceHereByPlaceTerm(h.type(), ( X10Context ) tc.context()); - n = n.hasType(h); + n = n.hasType(h); if (!xts.isSubtype(n.returnType().type(), hasType, tc.context())) { Errors.issue(tc.job(), new Errors.TypeIsNotASubtypeOfTypeBound(type, hasType, position())); } Modified: trunk/x10.compiler/src/x10/types/ConstrainedType_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/ConstrainedType_c.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.compiler/src/x10/types/ConstrainedType_c.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -131,6 +131,7 @@ } */ public ConstrainedType baseType(Ref<? extends Type> baseType) { + if (baseType == this.baseType) return this; ConstrainedType_c n = (ConstrainedType_c) copy(); n.baseType = baseType; return n; @@ -141,6 +142,7 @@ } public ConstrainedType constraint(Ref<CConstraint> constraint) { + if (constraint == this.constraint) return this; ConstrainedType_c n = (ConstrainedType_c) copy(); n.constraint = constraint; return n; Modified: trunk/x10.compiler/src/x10/types/X10LocalInstance_c.java =================================================================== --- trunk/x10.compiler/src/x10/types/X10LocalInstance_c.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.compiler/src/x10/types/X10LocalInstance_c.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -54,14 +54,15 @@ } public X10LocalInstance type(Type t) { + if (t == this.type) return this; X10LocalInstance_c n = (X10LocalInstance_c) super.type(t); - assert n != this; + if (n == this) n = (X10LocalInstance_c) this.copy(); // clear right type so it is recomputed from type n.rightType = null; return n; } - Type rightType; + private Type rightType; public Type rightType() { if (rightType != null) @@ -105,8 +106,8 @@ return n; } public String toString() { - String s = "local " + X10Flags.toX10Flags(flags()).prettyPrint() + name() + ": " + type(); - return s; + String s = "local " + X10Flags.toX10Flags(flags()).prettyPrint() + name() + ": " + type(); + return s; } public boolean isValid() { Modified: trunk/x10.compiler/src/x10/types/XTypeTranslator.java =================================================================== --- trunk/x10.compiler/src/x10/types/XTypeTranslator.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.compiler/src/x10/types/XTypeTranslator.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -346,13 +346,14 @@ public XTerm subst(XTerm y, XVar x, boolean propagate) { XTypeLit_c n = (XTypeLit_c) super.subst(y, x, propagate); - if (n == this) n = (XTypeLit_c) clone(); + Type newVal = n.type(); try { - n.val = Subst.subst(type(), y, x); - } - catch (SemanticException e) { + newVal = Subst.subst(type(), y, x); + } catch (SemanticException e) { } + if (newVal == n.type()) return n; - } + if (n == this) n = (XTypeLit_c) clone(); + n.val = newVal; return n; } } Modified: trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -906,6 +906,7 @@ w.unifiedBreak(0); w.end(); w.write("{"); + w.newline(4); w.begin(0); // Generate the run-time type. We have to wrap in a class since n might be an interface // and interfaces can't have static methods. @@ -939,6 +940,7 @@ for (TypeParamNode tp : n.typeParameters()) { w.write("private final "); w.write(X10_RUNTIME_TYPE_CLASS); +// w.write("<"); n.print(tp, w, tr); w.write(">"); // TODO w.write(" "); n.print(tp.name(), w, tr); w.write(";"); @@ -961,9 +963,8 @@ } n.print(n.body(), w, tr); - w.newline(); - + w.end(); w.newline(); w.write("}"); w.newline(0); @@ -2097,7 +2098,7 @@ // i.m(a) => i.m(a,t) if (isSelfDispatch && X10TypeMixin.baseType(t) instanceof X10ClassType ) { X10ClassType ct = (X10ClassType) X10TypeMixin.baseType(t); - if ((ct.flags().isInterface() || (xts.isFunctionType(ct) && ct.isAnonymous())) && er.containsTypeParam(defType)){ + if ((ct.flags().isInterface() || (xts.isFunctionType(ct) && ct.isAnonymous())) && Emitter.containsTypeParam(defType)){ w.write(","); new RuntimeTypeExpander(er, c.methodInstance().formalTypes().get(i)).expand(); } Modified: trunk/x10.constraints/src/x10/constraint/XField.java =================================================================== --- trunk/x10.constraints/src/x10/constraint/XField.java 2010-09-25 23:14:41 UTC (rev 16710) +++ trunk/x10.constraints/src/x10/constraint/XField.java 2010-09-25 23:18:33 UTC (rev 16711) @@ -33,13 +33,14 @@ @Override public XTerm subst(XTerm y, XVar x, boolean propagate) { XTerm r = super.subst(y, x, propagate); - if (! equals(r)) + if (! equals(r)) return r; XVar newReceiver = (XVar) receiver.subst(y, x); - XField result= clone(); - if (newReceiver != receiver) { - result.receiver = newReceiver; + if (newReceiver == receiver) { + return this; } + XField result = clone(); + result.receiver = newReceiver; return result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vj...@us...> - 2010-09-26 11:40:52
|
Revision: 16713 http://x10.svn.sourceforge.net/x10/?rev=16713&view=rev Author: vj0 Date: 2010-09-26 11:40:43 +0000 (Sun, 26 Sep 2010) Log Message: ----------- WIP -- ensure that an IllegalOperationException is thrown at runtime if a when/next/resume/async/finish/FutureMake/FutureForce/at is executed within an atomic or a when. TODO: Handle at expressions. Added tests. Modified Paths: -------------- trunk/x10.compiler/src/x10/visit/Desugarer.java trunk/x10.runtime/src-x10/x10/lang/Activity.x10 trunk/x10.runtime/src-x10/x10/lang/Clock.x10 trunk/x10.runtime/src-x10/x10/lang/Latch.x10 trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 trunk/x10.runtime/src-x10/x10/util/Future.x10 trunk/x10.tests/examples/Constructs/Atomic/WhenReturnAll.x10 Added Paths: ----------- trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhenMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhenMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhenMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhenMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhenMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhenMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoWhenInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/NoWhenInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/NoWhenInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/NoWhenInWhenMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/OKAtomicInAtomic.x10 trunk/x10.tests/examples/Constructs/Atomic/OKAtomicInAtomicMethod.x10 trunk/x10.tests/examples/Constructs/Atomic/OKAtomicInWhen.x10 trunk/x10.tests/examples/Constructs/Atomic/OKAtomicInWhenMethod.x10 Removed Paths: ------------- trunk/x10.tests/examples/Constructs/Atomic/AtomicContainingWhen_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Atomic/AtomicNonLocal_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Atomic/NoAwaitInAtomic_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Atomic/NoForEachInAtomic_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic_MustFailCompile.x10 trunk/x10.tests/examples/Constructs/Atomic/NoWhenInAtomic_MustFailCompile.x10 Modified: trunk/x10.compiler/src/x10/visit/Desugarer.java =================================================================== --- trunk/x10.compiler/src/x10/visit/Desugarer.java 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.compiler/src/x10/visit/Desugarer.java 2010-09-26 11:40:43 UTC (rev 16713) @@ -163,9 +163,15 @@ private static final Name HERE_INT = Name.make("hereInt"); private static final Name NEXT = Name.make("next"); private static final Name RESUME = Name.make("resume"); + private static final Name LOCK = Name.make("lock"); private static final Name AWAIT = Name.make("await"); private static final Name RELEASE = Name.make("release"); + private static final Name ENTER_ATOMIC = Name.make("enterAtomic"); + private static final Name ENSURE_NOT_IN_ATOMIC = Name.make("ensureNotInAtomic"); + private static final Name ENTER_ATOMIC_WHEN = Name.make("enterAtomicWhen"); + private static final Name EXIT_ATOMIC = Name.make("exitAtomic"); + private static final Name START_FINISH = Name.make("startFinish"); private static final Name PUSH_EXCEPTION = Name.make("pushException"); private static final Name STOP_FINISH = Name.make("stopFinish"); @@ -663,27 +669,27 @@ return xnf.Eval(pos, call(pos, RESUME, xts.Void())); } - // atomic S; -> try { Runtime.lock(); S } finally { Runtime.release(); } + // atomic S; -> try { Runtime.enterAtomic(); S } finally { Runtime.exitAtomic(); } private Stmt visitAtomic(Atomic a) throws SemanticException { Position pos = a.position(); - Block tryBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, LOCK, xts.Void())), a.body()); - Block finallyBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, RELEASE, xts.Void()))); + Block tryBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, ENTER_ATOMIC, xts.Void())), a.body()); + Block finallyBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, EXIT_ATOMIC, xts.Void()))); return xnf.Try(pos, tryBlock, Collections.<Catch>emptyList(), finallyBlock); } // await(E); -> - // try { Runtime.lock(); while (!E) Runtime.await(); } finally { Runtime.release(); } + // try { Runtime.enterAtomicWhen(); while (!E) Runtime.await(); } finally { Runtime.exitAtomic(); } private Stmt visitAwait(Await a) throws SemanticException { Position pos = a.position(); return xnf.Try(pos, xnf.Block(pos, - xnf.Eval(pos, call(pos, LOCK, xts.Void())), + xnf.Eval(pos, call(pos, ENTER_ATOMIC_WHEN, xts.Void())), xnf.While(pos, xnf.Unary(pos, a.expr(), Unary.NOT).type(xts.Boolean()), // TODO: handle constraints (should be done in the synthesizer) xnf.Eval(pos, call(pos, AWAIT, xts.Void())))), Collections.<Catch>emptyList(), xnf.Block(pos, - xnf.Eval(pos, call(pos, RELEASE, xts.Void())))); + xnf.Eval(pos, call(pos, EXIT_ATOMIC, xts.Void())))); } private Stmt wrap(Position pos, Stmt s) { @@ -691,9 +697,10 @@ } // when(E1) S1 or(E2) S2...; -> - // try { Runtime.lock(); + // Runtime.ensureNotInAtomic(); + // try { Runtime.enterAtomic(); // while (true) { if (E1) { S1; break; } if (E2) { S2; break; } ... Runtime.await(); } - // finally { Runtime.release(); } + // finally { Runtime.exitAtomic(); } private Stmt visitWhen(When w) throws SemanticException { Position pos = w.position(); Block body = xnf.Block(pos, xnf.If(pos, w.expr(), wrap(pos, w.stmt()))); @@ -701,10 +708,17 @@ body = body.append(xnf.If(pos, (Expr) w.exprs().get(i), wrap(pos, (Stmt) w.stmts().get(i)))); } body = body.append(xnf.Eval(pos, call(pos, AWAIT, xts.Void()))); - Block tryBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, LOCK, xts.Void())), - xnf.While(pos, xnf.BooleanLit(pos, true), body)); - Block finallyBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, RELEASE, xts.Void()))); - return xnf.Try(pos, tryBlock, Collections.<Catch>emptyList(), finallyBlock); + Block tryBlock = xnf.Block(pos, + xnf.Eval(pos, call(pos, ENTER_ATOMIC, xts.Void())), + xnf.While(pos, + xnf.BooleanLit(pos, true), + body)); + Block finallyBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, EXIT_ATOMIC, xts.Void()))); + return xnf.Block(pos, + xnf.Eval(pos, call(pos, ENSURE_NOT_IN_ATOMIC, xts.Void())), + xnf.Try(pos, + tryBlock, Collections.<Catch>emptyList(), + finallyBlock)); } private Expr call(Position pos, Name name, Type returnType) throws SemanticException { @@ -794,6 +808,7 @@ } } // finish S; -> + // Runtime.ensureNotInAtomic(); // try { Runtime.startFinish(); S; } // catch (t:Throwable) { Runtime.pushException(t); } // finally { Runtime.stopFinish(); } @@ -816,11 +831,15 @@ xnf.Id(pos, PUSH_EXCEPTION), Collections.<TypeNode>emptyList(), Collections.singletonList(local)).methodInstance(mi).type(xts.Void()); - Block tryBlock = xnf.Block(pos, xnf.Eval(pos,specializedFinish2(f)), f.body()); + Block tryBlock = xnf.Block(pos, + xnf.Eval(pos,specializedFinish2(f)), + f.body()); Catch catchBlock = xnf.Catch(pos, formal, xnf.Block(pos, xnf.Eval(pos, call))); Block finallyBlock = xnf.Block(pos, xnf.Eval(pos, call(pos, STOP_FINISH, xts.Void()))); - return xnf.Try(pos, tryBlock, Collections.singletonList(catchBlock), finallyBlock); + return xnf.Block(pos, + xnf.Eval(pos, call(pos, ENSURE_NOT_IN_ATOMIC, xts.Void())), + xnf.Try(pos, tryBlock, Collections.singletonList(catchBlock), finallyBlock)); } // x = finish (R) S; -> @@ -1001,7 +1020,7 @@ } // ateach (p in D) S; -> - // { val d = D.dist; for (p in d.places()) async (p) for (pt in d|here) async S; } + // { Runtime.ensureNotInAtomic(); val d = D.dist; for (p in d.places()) async (p) for (pt in d|here) async S; } private Stmt visitAtEach(AtEach a) throws SemanticException { Position pos = a.position(); Position bpos = a.body().position(); @@ -1044,7 +1063,10 @@ xnf.CanonicalTypeNode(pos, pType), xnf.Id(pos, pTmp)).localDef(pDef); Stmt body1 = async(bpos, inner, a.clocks(), xnf.Local(bpos, xnf.Id(bpos, pTmp)).localInstance(pDef.asInstance()).type(pType), null); - return xnf.Block(pos, local, xnf.ForLoop(pos, pFormal, places, body1)); + return xnf.Block(pos, + xnf.Eval(pos, call(pos, ENSURE_NOT_IN_ATOMIC, xts.Void())), + local, + xnf.ForLoop(pos, pFormal, places, body1)); } // desugar binary operators @@ -1082,7 +1104,7 @@ X10MethodInstance ami = call.methodInstance(); // List<Type> aTypes = new ArrayList<Type>(ami.formalTypes()); // aTypes.add(0, ami.returnType()); // rhs goes before index -// X10MethodInstance smi = xts.findMethod(ami.container(), +// MethodInstance smi = xts.findMethod(ami.container(), // xts.MethodMatcher(ami.container(), SET, aTypes, context)); a = ((SettableAssign_c) a).methodInstance(smi); a = ((SettableAssign_c) a).applyMethodInstance(ami); Modified: trunk/x10.runtime/src-x10/x10/lang/Activity.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Activity.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.runtime/src-x10/x10/lang/Activity.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -67,6 +67,8 @@ * Lazily created. */ var finishStack:Stack[Runtime.FinishState]; + + var atomicDepth:int = 0; /** * Create activity. @@ -86,6 +88,17 @@ clockPhases = Runtime.ClockPhases.make(clocks, phases); } + def pushAtomic() { + atomicDepth++; + } + def popAtomic() { + atomicDepth--; + } + def inAtomic():boolean=atomicDepth > 0; + def ensureNotInAtomic() { + if (atomicDepth > 0) + throw new IllegalOperationException(); + } /** * Create uncounted activity. */ Modified: trunk/x10.runtime/src-x10/x10/lang/Clock.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Clock.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.runtime/src-x10/x10/lang/Clock.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -83,6 +83,7 @@ return ph; } @Global def resumeUnsafe() { + Runtime.ensureNotInAtomic(); val ph = get(); if (ph < 0) return; at (root) { @@ -92,6 +93,7 @@ put(-ph); } @Global def nextUnsafe() { + Runtime.ensureNotInAtomic(); val ph = get(); val abs = Math.abs(ph); at (root) { Modified: trunk/x10.runtime/src-x10/x10/lang/Latch.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Latch.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.runtime/src-x10/x10/lang/Latch.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -25,6 +25,7 @@ public def await():void { // avoid locking if state == true + Runtime.ensureNotInAtomic(); if (!state) { lock(); while (!state) super.await(); Modified: trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.runtime/src-x10/x10/lang/Runtime.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1508,6 +1508,9 @@ * Run async */ public static def runAsync(place:Place, clocks:ValRail[Clock], body:()=>void):void { + // Do this before anything else + activity().ensureNotInAtomic(); + val state = currentState(); val phases = clockPhases().register(clocks); state.notifySubActivitySpawn(place); @@ -1520,6 +1523,9 @@ } public static def runAsync(place:Place, body:()=>void):void { + // Do this before anything else + activity().ensureNotInAtomic(); + val state = currentState(); state.notifySubActivitySpawn(place); val ok = safe(); @@ -1539,6 +1545,9 @@ } public static def runAsync(clocks:ValRail[Clock], body:()=>void):void { + // Do this before anything else + activity().ensureNotInAtomic(); + val state = currentState(); val phases = clockPhases().register(clocks); state.notifySubActivitySpawn(here); @@ -1546,12 +1555,18 @@ } public static def runAsync(body:()=>void):void { + // Do this before anything else + activity().ensureNotInAtomic(); + val state = currentState(); state.notifySubActivitySpawn(here); execute(new Activity(body, state, safe())); } public static def runUncountedAsync(place:Place, body:()=>void):void { + // Do this before anything else + activity().ensureNotInAtomic(); + val ok = safe(); if (place.id == hereInt()) { execute(new Activity(body, ok)); @@ -1569,6 +1584,9 @@ } public static def runUncountedAsync(body:()=>void):void { + // Do this before anything else + activity().ensureNotInAtomic(); + execute(new Activity(body, safe())); } @@ -1586,7 +1604,7 @@ } public static def runAt(place:Place, body:()=>void):void { - + Runtime.ensureNotInAtomic(); val box = (new RemoteControl()).root; async at(place) { try { @@ -1682,6 +1700,21 @@ public static def lock():void { runtime().monitor.lock(); } + + public static def enterAtomic() { + lock(); + activity().pushAtomic(); + } + public static def inAtomic():boolean = activity().inAtomic(); + public static def ensureNotInAtomic() { + val act = activity(); + if (act != null) // could be null in main thread? + act.ensureNotInAtomic(); + } + public static def exitAtomic() { + activity().popAtomic(); + release(); + } /** * Wait on current place lock @@ -1715,7 +1748,10 @@ /** * Next statement = next on all clocks in parallel. */ - public static def next():void = clockPhases().next(); + public static def next():void { + ensureNotInAtomic(); + clockPhases().next(); + } /** * Resume statement = resume on all clocks in parallel. Modified: trunk/x10.runtime/src-x10/x10/util/Future.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/util/Future.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.runtime/src-x10/x10/util/Future.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -43,6 +43,7 @@ transient private val eval:()=>T; public static def make[T](eval:()=> T) { + Runtime.ensureNotInAtomic(); val f = new Future[T](eval); async f.run(); return f; @@ -62,7 +63,10 @@ /** * Wait for the completion of this activity and return the computed value. */ - @Global public def force():T = at (root) root().forceLocal(); + @Global public def force():T { + Runtime.ensureNotInAtomic(); + return at (root) root().forceLocal(); + } @Pinned private def forceLocal():T { latch.await(); if (exception.length() > 0) { Deleted: trunk/x10.tests/examples/Constructs/Atomic/AtomicContainingWhen_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/AtomicContainingWhen_MustFailCompile.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.tests/examples/Constructs/Atomic/AtomicContainingWhen_MustFailCompile.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1,130 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - -/** - * - * @author kemal 11/2005 - * @author vj 12 2006 --- converted to fail at compile time. - */ -public class AtomicContainingWhen_MustFailCompile extends x10Test { - - val fooArray: Rail[foo] = Rail.make([ new f0() as foo, new f1() as foo, - new f2() as foo, new f3()as foo ]); - - public def run(): boolean = { - val x: X = new X(); - - val l: lockStruct = new lockStruct(); - - atomic Y.test(fooArray(x.one()), l); - atomic Y.test(fooArray(x.zero()), l); - atomic Y.test(fooArray(x.two()), l); - atomic Y.test(fooArray(3), l); - - return true; - } - - // just to confuse a compiler - public def modifyFoo(var x: X): void = { fooArray(x.two()+1) = new f2(); } - - public static def main(var args: Array[String](1)): void = { - new AtomicContainingWhen_MustFailCompile().execute(); - } - - /** - * A class to invoke a 'function pointer' inside of async - */ - static class Y { - static def test(val f: foo, val l: lockStruct): void = { - // Compiler analysis may not be possible here - f.apply(l); // it is hard to determine if f executes an async or when - } - } - - /** - * class containing miscellaneous synchronization constructs. - */ - static class lockStruct { - var lock0: boolean; - var lock1: boolean; - var futureInt: Future[int]; - var c: Clock; - def this(): lockStruct = { - futureInt = future 1; - lock0 = false; - lock1 = false; - c = Clock.make(); - } - } - - /** - * An interface to use like a simple 'function pointer' - */ - static interface foo { - public def apply(var l: lockStruct): void; - } - - static class f0 implements foo { - // it is hard to determine if this is invoked inside - // an atomic, at compile time. - public def apply(val l: lockStruct): void = { - x10.io.Console.OUT.println("in f0:#1"); - when (!l.lock0) l.lock0 = true; - x10.io.Console.OUT.println("in f0:#2"); - } - } - - static class f1 implements foo { - // it is hard to determine if this is invoked inside - // an atomic, at compile time. - public def apply(val l: lockStruct): void = { - x10.io.Console.OUT.println("in f1:#1"); - when (!l.lock1) l.lock1 = true; - x10.io.Console.OUT.println("in f1:#2"); - } - } - - static class f2 implements foo { - // it is hard to determine if this is invoked inside - // an atomic, at compile time. - public def apply(val l: lockStruct): void = { - x10.io.Console.OUT.println("in f2:#1"); - l.c.resume(); - x10.io.Console.OUT.println("in f2:#2"); - finish async { }; - x10.io.Console.OUT.println("in f2:#3"); - var x: int = (future { l.futureInt.force() }).force(); - x10.io.Console.OUT.println("in f2:#4"); - next; - x10.io.Console.OUT.println("in f2:#5"); - } - } - - static class f3 implements foo { - public def apply(val l: lockStruct): void = { - x10.io.Console.OUT.println("in f3"); - } - } - - /** - * Dummy class to make static memory disambiguation difficult - * for a typical compiler - */ - static class X { - public var z: Array[int](1) = new Array[Int](0..1, (i:Point(1))=> 1-i(0)); - def zero(): int = { return z(z(z(1))); } - def one(): int = { return z(z(z(0))); } - def two(): int = { return (zero()-1) * (zero()-1) + one(); } - def modify(): void = { z(0) += 1; } - } -} Deleted: trunk/x10.tests/examples/Constructs/Atomic/AtomicNonLocal_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/AtomicNonLocal_MustFailCompile.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.tests/examples/Constructs/Atomic/AtomicNonLocal_MustFailCompile.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1,49 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -/* - * - * (C) Copyright IBM Corporation 2006 - * - * This file is part of X10 Test. - * - */ -import harness.x10Test; - -/** - * Remote accesses in atomic must be checked by the compiler. - * - * Not yet caught by the compiler, error thrown at runtime. - * - * @author Kemal 4/2005, vj - */ -public class AtomicNonLocal_MustFailCompile extends x10Test { - - public def run(): boolean = { - val A = DistArray.make[int](Dist.makeUnique()); - chk(Place.MAX_PLACES >= 2); - chk(A.dist(0) == here); - chk(A.dist(1) != here); - - - finish async { A(0) += 1; } - A(0) += 1; - - finish async { A(1) += 1; } - atomic { at(A(1)) { A(1) += 1; }; } - return true; - } - - public static def main(Array[String](1)) { - new AtomicNonLocal_MustFailCompile().execute(); - } - -} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,36 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * An atomic cannot spawn an async. Check that a runtime exception is thrown. + * @vj + */ +public class NoAsyncInAtomic extends x10Test { + + var b: boolean; + + public def run(): boolean = { + try { + atomic + async + x10.io.Console.OUT.println("Cannot reach this point."); + return false; + } catch (IllegalOperationException) { + return true; + } + } + + public static def main(var args: Array[String](1)): void = { + new NoAsyncInAtomic().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomicMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomicMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomicMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * An async statement cannot occur in a method called from within an atomic. + * @vj + */ +public class NoAsyncInAtomicMethod extends x10Test { + + public def run(): boolean = { + try { + atomic + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + async + Console.OUT.println("This should not print."); + } + + public static def main(Array[String](1)){ + new NoAsyncInAtomicMethod().execute(); + } +} Deleted: trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic_MustFailCompile.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInAtomic_MustFailCompile.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1,34 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - -/** - * An await statement cannot occur in an atomic. - * @vj - */ -public class NoAsyncInAtomic_MustFailCompile extends x10Test { - - var b: boolean; - - public def run(): boolean = { - atomic { - async { - x10.io.Console.OUT.println("Cannot reach this point."); - } - } - return true; - } - - public static def main(var args: Array[String](1)): void = { - new NoAsyncInAtomic_MustFailCompile().execute(); - } -} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhen.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhen.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhen.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A conditional atomic cannot spawn an async. Check that a runtime exception is thrown. + * @vj + */ +public class NoAsyncInWhen extends x10Test { + + var b: boolean; + + public def run(): boolean = { + b=true; + try { + when (b==true) + async + x10.io.Console.OUT.println("Cannot reach this point."); + return false; + } catch (IllegalOperationException) { + return true; + } + } + + public static def main(Array[String](1)) { + new NoAsyncInWhen().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhenMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhenMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAsyncInWhenMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,38 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * An async statement cannot occur in a method called from within a when. + * @vj + */ +public class NoAsyncInWhenMethod extends x10Test { + + public def run(): boolean = { + try { + val b=true; + when (b==true) + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + async + Console.OUT.println("This should not print."); + } + + public static def main(Array[String](1)){ + new NoAsyncInWhenMethod().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * An await statement cannot occur in an atomic. + * @vj + */ +public class NoAtEachInAtomic extends x10Test { + + var b: boolean; + + public def run(): boolean = { + try { + atomic + ateach (1..10 -> here) + Console.OUT.println("Cannot reach this point."); + } catch (IllegalOperationException) { + return true; + } + + return false; + } + + public static def main(Array[String](1)) { + new NoAtEachInAtomic().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomicMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomicMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomicMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * An ateach statement cannot occur in a method called from within an atomic. + * @vj + */ +public class NoAtEachInAtomicMethod extends x10Test { + + public def run(): boolean = { + try { + atomic + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + ateach(1..10->here) + Console.OUT.println("This should not print."); + } + + public static def main(Array[String](1)){ + new NoAtEachInAtomicMethod().execute(); + } +} Deleted: trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic_MustFailCompile.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInAtomic_MustFailCompile.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1,34 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - -/** - * An await statement cannot occur in an atomic. - * @vj - */ -public class NoAtEachInAtomic_MustFailCompile extends x10Test { - - var b: boolean; - - public def run(): boolean = { - atomic { - ateach (val p: Point in [1..10]) { - x10.io.Console.OUT.println("Cannot reach this point."); - } - } - return true; - } - - public static def main(var args: Array[String](1)): void = { - new NoAtEachInAtomic_MustFailCompile().execute(); - } -} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhen.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhen.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhen.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,38 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * An ateach statement cannot occur in a when statement. + * @vj + */ +public class NoAtEachInWhen extends x10Test { + + var b: boolean; + + public def run(): boolean = { + b=true; + try { + when (b==true) + ateach (1..10 -> here) + Console.OUT.println("Cannot reach this point."); + } catch (IllegalOperationException) { + return true; + } + + return false; + } + + public static def main(Array[String](1)) { + new NoAtEachInWhen().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhenMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhenMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAtEachInWhenMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +/** + * An ateach statement cannot occur in a method called from within a when. + * @vj + */ +public class NoAtEachInWhenMethod extends x10Test { + + public def run(): boolean = { + try { + val b=true; + when (b==true) + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + ateach(1..10->here) + Console.OUT.println("This should not print."); + } + + public static def main(Array[String](1)){ + new NoAtEachInWhenMethod().execute(); + } +} Deleted: trunk/x10.tests/examples/Constructs/Atomic/NoAwaitInAtomic_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoAwaitInAtomic_MustFailCompile.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.tests/examples/Constructs/Atomic/NoAwaitInAtomic_MustFailCompile.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1,32 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - -/** - * An await statement cannot occur in an atomic. - * @vj - */ -public class NoAwaitInAtomic_MustFailCompile extends x10Test { - - var b: boolean; - - public def run(): boolean = { - atomic { - await b; // must be caught at compile time. - } - return true; - } - - public static def main(var args: Array[String](1)): void = { - new NoAwaitInAtomic_MustFailCompile().execute(); - } -} Deleted: trunk/x10.tests/examples/Constructs/Atomic/NoForEachInAtomic_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoForEachInAtomic_MustFailCompile.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.tests/examples/Constructs/Atomic/NoForEachInAtomic_MustFailCompile.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1,34 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - -/** - * An await statement cannot occur in an atomic. - * @vj - */ -public class NoForEachInAtomic_MustFailCompile extends x10Test { - - var b: boolean; - - public def run(): boolean = { - atomic { - foreach (val p: Point in [1..10]) { - x10.io.Console.OUT.println("Cannot reach this point."); - } - } - return true; - } - - public static def main(var args: Array[String](1)): void = { - new NoForEachInAtomic_MustFailCompile().execute(); - } -} Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomic.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomic.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomic.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,35 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future.force expression cannot occur in an atomic. + * @vj + */ +public class NoFutureForceInAtomic extends x10Test { + + public def run(): boolean = { + try { + val x = Future.make[int](()=>0); + atomic { + x.force(); + } + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoFutureForceInAtomic().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomicMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomicMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInAtomicMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,38 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future force expression cannot occur in a method called from within an atomic. + * @vj + */ +public class NoFutureForceInAtomicMethod extends x10Test { + + public def run(): boolean = { + try { + val f=Future.make[int](()=>0); + atomic + m(f); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m(f:Future[int]) { + return f.force(); + } + + public static def main(Array[String](1)){ + new NoFutureForceInAtomicMethod().execute(); + } +} + Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhen.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhen.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhen.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,36 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future.make expression cannot occur in a when. + * @vj + */ +public class NoFutureForceInWhen extends x10Test { + + public def run(): boolean = { + try { + val b=true; + val x = Future.make[int](()=>0); + when (b=true) { + x.force(); + } + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoFutureForceInWhen().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhenMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhenMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureForceInWhenMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,39 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future force expression cannot occur in a method called from within a when. + * @vj + */ +public class NoFutureForceInWhenMethod extends x10Test { + + public def run(): boolean = { + try { + val b=true; + val f=Future.make[int](()=>0); + when (b==true) + m(f); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m(f:Future[int]) { + return f.force(); + } + + public static def main(Array[String](1)){ + new NoFutureForceInWhenMethod().execute(); + } +} + Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomic.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomic.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomic.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,34 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future.make expression cannot occur in an atomic. + * @vj + */ +public class NoFutureMakeInAtomic extends x10Test { + + public def run(): boolean = { + try { + atomic { + val x = Future.make[int](()=>0); + } + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoFutureMakeInAtomic().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomicMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomicMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInAtomicMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future.make expression cannot occur in a method called from within an atomic. + * @vj + */ +public class NoFutureMakeInAtomicMethod extends x10Test { + + public def run(): boolean = { + try { + atomic + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + return Future.make[int](()=>0); + } + + public static def main(Array[String](1)){ + new NoFutureMakeInAtomicMethod().execute(); + } +} + Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhen.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhen.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhen.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,35 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future.make expression cannot occur in a when. + * @vj + */ +public class NoFutureMakeInWhen extends x10Test { + + public def run(): boolean = { + try { + val b=true; + when (b=true) { + val x = Future.make[int](()=>0); + } + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoFutureMakeInWhen().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhenMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhenMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoFutureMakeInWhenMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,38 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; +import x10.util.Future; +/** + * A Future.make expression cannot occur in a method called from within a when. + * @vj + */ +public class NoFutureMakeInWhenMethod extends x10Test { + + public def run(): boolean = { + try { + val b=true; + when (b==true) + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + return Future.make[int](()=>0); + } + + public static def main(Array[String](1)){ + new NoFutureMakeInWhenMethod().execute(); + } +} + Added: trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,34 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A next statement cannot occur in an atomic. + * @vj + */ +public class NoNextInAtomic extends x10Test { + + public def run(): boolean = { + val c = Clock.make(); + try { + atomic + next; + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoNextInAtomic().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomicMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomicMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomicMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A next statement cannot occur in a method called from within an atomic. + * @vj + */ +public class NoNextInAtomicMethod extends x10Test { + + public def run(): boolean = { + try { + val c = Clock.make(); + atomic + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + next; + } + + public static def main(Array[String](1)){ + new NoNextInAtomicMethod().execute(); + } +} Deleted: trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic_MustFailCompile.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic_MustFailCompile.x10 2010-09-26 01:40:50 UTC (rev 16712) +++ trunk/x10.tests/examples/Constructs/Atomic/NoNextInAtomic_MustFailCompile.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -1,36 +0,0 @@ -/* - * This file is part of the X10 project (http://x10-lang.org). - * - * This file is licensed to You under the Eclipse Public License (EPL); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.opensource.org/licenses/eclipse-1.0.php - * - * (C) Copyright IBM Corporation 2006-2010. - */ - -import harness.x10Test; - -/** - * A next statement cannot occur in an atomic. - * @vj - */ -public class NoNextInAtomic_MustFailCompile extends x10Test { - - var b: boolean; - - public def run(): boolean = { - async { - var c: Clock = Clock.make(); - atomic { - next; - } - - } - return true; - } - - public static def main(var args: Array[String](1)): void = { - new NoNextInAtomic_MustFailCompile().execute(); - } -} Added: trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhen.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhen.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhen.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,35 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A next statement cannot occur in a when statement. + * @vj + */ +public class NoNextInWhen extends x10Test { + + public def run(): boolean = { + val c = Clock.make(); + val b=true; + try { + when (b==true) + next; + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoNextInWhen().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhenMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhenMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoNextInWhenMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,38 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A next statement cannot occur in a method called from within a when. + * @vj + */ +public class NoNextInWhenMethod extends x10Test { + + public def run(): boolean = { + try { + val c = Clock.make(); + val b=true; + when (b==true) + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + next; + } + + public static def main(Array[String](1)){ + new NoNextInWhenMethod().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomic.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomic.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomic.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,34 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A resume statement cannot occur in an atomic. + * @vj + */ +public class NoResumeInAtomic extends x10Test { + + public def run(): boolean = { + val c = Clock.make(); + try { + atomic + resume; + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoResumeInAtomic().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomicMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomicMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoResumeInAtomicMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,37 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A resume statement cannot occur in a method called from within an atomic. + * @vj + */ +public class NoResumeInAtomicMethod extends x10Test { + + public def run(): boolean = { + try { + val c = Clock.make(); + atomic + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + resume; + } + + public static def main(Array[String](1)){ + new NoResumeInAtomicMethod().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhen.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhen.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhen.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,35 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A resume statement cannot occur in a when statement. + * @vj + */ +public class NoResumeInWhen extends x10Test { + + public def run(): boolean = { + val c = Clock.make(); + val b=true; + try { + when (b==true) + resume; + } catch (IllegalOperationException) { + return true; + } + return false; + } + + public static def main(Array[String](1)){ + new NoResumeInWhen().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhenMethod.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhenMethod.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoResumeInWhenMethod.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,38 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A resume statement cannot occur in a method called from within a when. + * @vj + */ +public class NoResumeInWhenMethod extends x10Test { + + public def run(): boolean = { + try { + val c = Clock.make(); + val b=true; + when (b==true) + m(); + } catch (IllegalOperationException) { + return true; + } + return false; + } + def m() { + resume; + } + + public static def main(Array[String](1)){ + new NoResumeInWhenMethod().execute(); + } +} Added: trunk/x10.tests/examples/Constructs/Atomic/NoWhenInAtomic.x10 =================================================================== --- trunk/x10.tests/examples/Constructs/Atomic/NoWhenInAtomic.x10 (rev 0) +++ trunk/x10.tests/examples/Constructs/Atomic/NoWhenInAtomic.x10 2010-09-26 11:40:43 UTC (rev 16713) @@ -0,0 +1,35 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +import harness.x10Test; + +/** + * A when statement cannot occur in an atomic. + * @vj + */ +public class NoWhenInAtomic extends x10Test { + + public def run(): boolean = { + try { + var lock1:boolean=false; + atomic + when (!lock1) + lock1 = true; + } catch (IllegalOperationException) {... [truncated message content] |