From: <vj...@us...> - 2010-04-08 23:32:18
|
Revision: 13762 http://x10.svn.sourceforge.net/x10/?rev=13762&view=rev Author: vj0 Date: 2010-04-08 23:32:11 +0000 (Thu, 08 Apr 2010) Log Message: ----------- Ensure that casts are generated for weak closure calls. Added -VERBOSE_CALLS compiler option. This prints out a warning for each weak call, together with the type the expression was cast to. Added -STRONG_CALLS compiler option. This causes the compiler to give an error when it encounters a weak call, instead of generating a cast. The default (no -VERBOSE_CALLS, no -STRONG_CALLS) is to print out a count of weak calls. Modified Paths: -------------- trunk/x10.compiler/src/x10/Configuration.java trunk/x10.compiler/src/x10/ExtensionInfo.java trunk/x10.compiler/src/x10/ast/X10Call_c.java trunk/x10.compiler/src/x10/types/checker/Converter.java trunk/x10.compiler/src/x10/types/checker/PlaceChecker.java trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 Modified: trunk/x10.compiler/src/x10/Configuration.java =================================================================== --- trunk/x10.compiler/src/x10/Configuration.java 2010-04-08 21:52:49 UTC (rev 13761) +++ trunk/x10.compiler/src/x10/Configuration.java 2010-04-08 23:32:11 UTC (rev 13762) @@ -79,6 +79,12 @@ public static boolean WORK_STEALING = false; private static final String WORK_STEALING_desc = "Code generation for work-stealing scheduling"; + + public static boolean VERBOSE_CALLS = false; + private static final String VERBOSE_CALLS_desc = "Print details of casts introduced for weak calls."; + + public static boolean STRONG_CALLS = false; + private static final String STRONG_CALLS_desc = "Treat weak calls as errors."; /** * Parses one argument from the command line. This allows the user Modified: trunk/x10.compiler/src/x10/ExtensionInfo.java =================================================================== --- trunk/x10.compiler/src/x10/ExtensionInfo.java 2010-04-08 21:52:49 UTC (rev 13761) +++ trunk/x10.compiler/src/x10/ExtensionInfo.java 2010-04-08 23:32:11 UTC (rev 13762) @@ -56,10 +56,12 @@ import polyglot.types.SemanticException; import polyglot.types.TopLevelResolver; import polyglot.types.TypeSystem; +import polyglot.util.ErrorInfo; import polyglot.util.ErrorQueue; import polyglot.util.InternalCompilerError; import polyglot.util.Position; import polyglot.visit.ContextVisitor; +import polyglot.visit.PostCompiled; import polyglot.visit.PruningVisitor; import polyglot.visit.TypeChecker; import x10.ast.X10NodeFactory_c; @@ -223,6 +225,14 @@ return errors; } + private static int weakCallsCount = 0; + public void incrWeakCallsCount() { + weakCallsCount++; + } + public int weakCallsCount() { + return weakCallsCount; + } + protected void initTypeSystem() { try { TopLevelResolver r = new X10SourceClassResolver(compiler, this, getOptions().constructFullClasspath(), @@ -356,11 +366,53 @@ // the barrier will handle prereqs on its own CodeGenerated(job).addPrereq(CodeGenBarrier()); - + return goals; } - public Goal CodeGenBarrier() { + Goal PrintWeakCallsCount; + @Override + protected Goal PostCompiled() { + if (PrintWeakCallsCount == null) { + PrintWeakCallsCount = new PrintWeakCallsCount((ExtensionInfo) extInfo); + Goal oldPost = super.PostCompiled(); + PrintWeakCallsCount.addPrereq(oldPost); + } + return PrintWeakCallsCount; + } + + static class PrintWeakCallsCount extends AllBarrierGoal { + ExtensionInfo ext; + public PrintWeakCallsCount(ExtensionInfo extInfo) { + super("PrintWeakCallsCount",extInfo.scheduler()); + this.ext = extInfo; + } + public Goal prereqForJob(Job job) { + if (scheduler.shouldCompile(job)) { + return scheduler.End(job); + } + else { + return new SourceGoal_c("WCCDummyEnd", job) { + public boolean runTask() { return true; } + }.intern(scheduler); + } + } + public boolean runTask() { + Compiler compiler = ext.compiler(); + + if (! Configuration.VERBOSE_CALLS) { + int count = ext.weakCallsCount; + if (count > 0) { + compiler.errorQueue().enqueue(ErrorInfo.WARNING, count + " weak calls."); + } + } + return true; + + } + + } + + public Goal CodeGenBarrier() { if (Globals.Options().compile_command_line_only) { return new BarrierGoal("CodeGenBarrier", commandLineJobs()) { @Override @@ -383,6 +435,7 @@ }; } } + public Goal Serialized(Job job) { Compiler compiler = job.extensionInfo().compiler(); Modified: trunk/x10.compiler/src/x10/ast/X10Call_c.java =================================================================== --- trunk/x10.compiler/src/x10/ast/X10Call_c.java 2010-04-08 21:52:49 UTC (rev 13761) +++ trunk/x10.compiler/src/x10/ast/X10Call_c.java 2010-04-08 23:32:11 UTC (rev 13762) @@ -110,7 +110,9 @@ n.arguments = new ArrayList<Expr>(args); return n; } - + public Call_c reconstruct(Receiver target, Id name, List<Expr> arguments) { + return super.reconstruct(target, name, arguments); + } @Override public Node visitChildren(NodeVisitor v) { @@ -502,20 +504,7 @@ } if (n instanceof X10Call_c) { - try { - PlaceChecker.checkLocalReceiver((Call) n, tc); - } catch (PlaceTypeErrorMethodShouldBeLocalOrGlobal z) { - // ok, compensate by generating a dynamic cast. - X10Call_c result = (X10Call_c) n; - Receiver r = result.target(); - if (r instanceof Expr) { - Expr target = (Expr) r; - Type type = PlaceChecker.AddIsHereClause(target.type(), tc.context()); - target = Converter.attemptCoercion(tc, target, type); - n = result.reconstruct(target, result.name(), result.arguments()); - } - - } + n = PlaceChecker.makeReceiverLocalIfNecessary((X10Call) n, tc); } @@ -614,7 +603,7 @@ ///////////////////////////////////////////////////////////////////// result.checkProtoMethod(); - PlaceChecker.checkLocalReceiver(result, tc); + result = (X10Call_c) PlaceChecker.makeReceiverLocalIfNecessary(result, tc); // the arguments here. result.checkConsistency(c); // result = result.adjustMI(tc); Modified: trunk/x10.compiler/src/x10/types/checker/Converter.java =================================================================== --- trunk/x10.compiler/src/x10/types/checker/Converter.java 2010-04-08 21:52:49 UTC (rev 13761) +++ trunk/x10.compiler/src/x10/types/checker/Converter.java 2010-04-08 23:32:11 UTC (rev 13762) @@ -26,6 +26,7 @@ import polyglot.ast.New; import polyglot.ast.Node; import polyglot.ast.TypeNode; +import polyglot.frontend.Globals; import polyglot.main.Report; import polyglot.types.ClassDef; import polyglot.types.Context; @@ -43,6 +44,8 @@ import polyglot.util.Pair; import polyglot.util.Position; import polyglot.visit.ContextVisitor; +import x10.Configuration; +import x10.ExtensionInfo; import x10.ast.SemanticError; import x10.ast.X10CanonicalTypeNode; import x10.ast.X10CanonicalTypeNode_c; @@ -117,7 +120,11 @@ // alright, now we actually synthesized a new depexpr. // lets splice it in. result = check(nf.X10Cast(e.position(), tn, e, ct),tc); - System.out.println("[" + e.position() + "] Synthesized " + tn + " for " + e + "."); + if (Configuration.VERBOSE_CALLS) + System.out.println("[" + e.position() + "] Synthesized " + tn + " for " + e + "."); + else { + ((ExtensionInfo) Globals.Extension()).incrWeakCallsCount(); + } } } return result; @@ -511,18 +518,19 @@ } // Added 03/28/10 to support new call conversion semantics. - if (cast.conversionType() == ConversionType.CALL_CONVERSION - && ts.isCastValid(fromType, toType, context)) { + if (! Configuration.STRONG_CALLS) + if (cast.conversionType() == ConversionType.CALL_CONVERSION + && ts.isCastValid(fromType, toType, context)) { X10Cast n = cast.conversionType(ConversionType.CHECKED); XVar sv = X10TypeMixin.selfVarBinding(fromType); if (sv != null) - try { - toType = X10TypeMixin.addSelfBinding((Type) toType.copy(), sv); - } catch (XFailure f) { - throw new SemanticError("Inconsistent type: " + toType + " {self==" + sv+"}", cast.position()); - } - return n.type(toType); - } + try { + toType = X10TypeMixin.addSelfBinding((Type) toType.copy(), sv); + } catch (XFailure f) { + throw new SemanticError("Inconsistent type: " + toType + " {self==" + sv+"}", cast.position()); + } + return n.type(toType); + } throw new Errors.CannotConvertExprToType(cast.expr(), cast.conversionType(), toType, cast.position()); } Modified: trunk/x10.compiler/src/x10/types/checker/PlaceChecker.java =================================================================== --- trunk/x10.compiler/src/x10/types/checker/PlaceChecker.java 2010-04-08 21:52:49 UTC (rev 13761) +++ trunk/x10.compiler/src/x10/types/checker/PlaceChecker.java 2010-04-08 23:32:11 UTC (rev 13762) @@ -20,6 +20,9 @@ import polyglot.types.Type; import polyglot.util.InternalCompilerError; import polyglot.visit.ContextVisitor; +import x10.Configuration; +import x10.ast.X10Call; +import x10.ast.X10Call_c; import x10.ast.X10CanonicalTypeNode_c; import x10.constraint.XEQV_c; import x10.constraint.XFailure; @@ -31,6 +34,7 @@ import x10.constraint.XTerm; import x10.constraint.XTerms; import x10.errors.Errors; +import x10.errors.Errors.PlaceTypeErrorMethodShouldBeLocalOrGlobal; import x10.types.ClosureType_c; import x10.types.X10ClassDef; import x10.types.X10Context; @@ -479,6 +483,25 @@ } */ + public static Call makeReceiverLocalIfNecessary(X10Call n, ContextVisitor tc) throws SemanticException { + try { + checkLocalReceiver(n, tc); + } catch (PlaceTypeErrorMethodShouldBeLocalOrGlobal z) { + // ok, compensate by generating a dynamic cast. + if (Configuration.STRONG_CALLS) + throw z; + X10Call_c result = (X10Call_c) n; + Receiver r = result.target(); + if (r instanceof Expr) { + Expr target = (Expr) r; + Type type = PlaceChecker.AddIsHereClause(target.type(), tc.context()); + target = Converter.attemptCoercion(tc, target, type); + n = (X10Call) result.reconstruct(target, result.name(), result.arguments()); + } + + } + return n; + } /** * Check that this method call is place safe (throwing an error if it isnt, i.e. * if the call is to a method that is not global, and the receiver Modified: trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 2010-04-08 21:52:49 UTC (rev 13761) +++ trunk/x10.runtime/src-x10/x10/array/FullRegion.x10 2010-04-08 23:32:11 UTC (rev 13762) @@ -19,7 +19,7 @@ * @author bdlucas */ -class FullRegion extends PolyRegion { +class FullRegion {rect} extends PolyRegion { def this(val rank: int): FullRegion{self.rank==rank} { super((new PolyMatBuilder(rank)).toSortedPolyMat(false), true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |