X10
  1. X10
  2. XTENLANG-2469

Implement new 'at' and 'athome' constructs.

    Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: X10 2.6
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Here is the revision of 'at', and the new related construct 'athome'.
      See the spec for more details.

      at(p)S copies all values in 'val' variables in S to place p, giving them the same
      names that they have in S. 'var' variables from outside are not accessible in
      S. (In particular, 'at' does not permit either delayed initialization, or
      assignment to vars.)

      'at' may take a list of bindings. If this list is provided, only values in
      the list will be copied to S, and they will be referred to by the names given
      in the list. Specific examples:

      at(p; x1 = x)S ---- copies the value of x, giving it the name x1. It will
      be a 'val' variable.

      at(p; val x1 = x)S ---- same as at(p; x1=x)S

      at(p; x) S ---- copies the value of x, reusing the name x for the copy.

      at(p; x,y,z) S ---- If S's free variables are the vals x,y,z, then this is
      the same as at(p)S.

      at(p; var y : Int = x) S ---- copies the value of x to an Int-valued var y.
      y's home is p, and it is a var and can be updated.

      at(p; f = this.f) S ---- see how easy it is to copy a field of 'this'
      without copying all of 'this'

      at(p; f = this.m()) S ---- Note that this.m() isn't kept locally; it is
      evaluated and transmitted.

      at(p; ) S ---- evaluate S at p, copying nothing.

      at(p; x, y1=y, val z1=z) S ---- you can copy many things.

      The at-expression at(...)E is just like at(...)S, but it evaluates to a copy
      of the result of E.

      athome(x) S evaluates S at the place where variable x was defined. x may be a
      local var, in which case x may be read or written. Or, x may be a val, in which
      case it may be initialized (if it isn't) or read (once it is initialized).

      athome(x,y,z) S — evaluates S at the place where x,y, and z are declared.
      It is a static error if X10 can't tell that all three of these are the same
      place. All three variables can be accessed and modified/initialized inside
      of S.

      athome(v,a,r,s ; stuffToCopy) S — athome has precisely the same copying
      behavior as 'at'.

      athome S is equivalent to athome(x1,...,xn) S, where x1-xn are the variables
      appearing on lhs of '=' in S but not in the scope of any interior 'at' or 'athome'.

      ------------------------------------------------------------------------------

      EXAMPLES:

      Here's the basic there-and-back-again idiom.

        val sum: Int, product: Int;
        at(mathProcessor; x, y) {
          val s = x + y;
          val p = x * y;
          athome(sum, product) {
             sum = s;
             product = p;
          }
        }
        println("Sum = " + sum + "; product = " + product);
      

      Here's a distributed summation.

      public class Summer {
        public static def sum(f:(Int)=>Int, low : Int, high:Int) : Int {
           var sum : Int = 0;
           finish for(p in Place.places()) {
             async{
               at(p; f, var i : Int = low + p.id(), high) {
                  var localSum : Int = 0;
                  while(i <= high) {
                     localSum += f(i);
                     i += Place.MAX_PLACES;
                  }
                  athome(sum; localSum) {
                     atomic{ sum += localSum; }
                  }//athome
               }//at
             }//async
           }//finish for
        }
      }
      

      ------------------------------------------------------------------------------

      Conversion

      Converting existing code to the new atorigin syntax:

      • if you accessed a "var" in an "at", or
      • if you used remote initialization for a "val"
        then you will get an error suggesting you should use "atorigin" (or initialize the "val")

        Issue Links

          Activity

          Hide
          Igor Peshansky added a comment -

          Parsing support committed in r21200.

          Show
          Igor Peshansky added a comment - Parsing support committed in r21200.
          Hide
          Bard Bloom added a comment -

          The full list of copying forms in the spec is:

          val x = E
          val x:T = E
          x : T = E
          val x <: T = E
          x <: T = E
          
          var x : T = E
          
          x = E
          
          x
          
          x.f = E
          
          x(E1...En) = F
          
          *
          

          Forms not specifically mentioned in the JIRA are:

          
          val x:T = E
          x : T = E
          val x <: T = E
          x <: T = E
          
          x.f = E
          
          x(E1...En) = F
          
          *
          
          Show
          Bard Bloom added a comment - The full list of copying forms in the spec is: val x = E val x:T = E x : T = E val x <: T = E x <: T = E var x : T = E x = E x x.f = E x(E1...En) = F * Forms not specifically mentioned in the JIRA are: val x:T = E x : T = E val x <: T = E x <: T = E x.f = E x(E1...En) = F *
          Hide
          Bard Bloom added a comment -

          Oh, and the '*' has to come last in the list, if it is present.

          Show
          Bard Bloom added a comment - Oh, and the '*' has to come last in the list, if it is present.
          Hide
          Igor Peshansky added a comment -

          Support for at (p; *) added in r21231. That revision also fixes a grammar bug that allowed an empty variable list for athome, as well as adds support for * as the athome variable list.

          Show
          Igor Peshansky added a comment - Support for at (p; *) added in r21231. That revision also fixes a grammar bug that allowed an empty variable list for athome , as well as adds support for * as the athome variable list.
          Hide
          Bard Bloom added a comment -

          The spec says this should parse (and work):

          package Activities_Activities_Activities;
          // file Activities line 263
           class EquivCode {
           static def S(pt:Point) {}
           static def example(D:Dist) {
          for (place in D.places()) async at (place; p, D, * ) {
              for (p in D|here) {
                  S(p);
              }
          }
          }}
          
          

          Also, this should parse - the list of copy specifiers can be arbitrary.
          (It won't go further than parsing because of undeclared identifiers)

          package Activities_Activities_Activities;
          // file Activities line 263
           class EquivCode {
           static def S(pt:Point) {}
           static def example(D:Dist) {
          for (place in D.places()) async at (place; p, var a:Int = b, val c = d, f , * ) {
              for (p in D|here) {
                  S(p);
              }
          }
          }}
          
          
          Show
          Bard Bloom added a comment - The spec says this should parse (and work): package Activities_Activities_Activities; // file Activities line 263 class EquivCode { static def S(pt:Point) {} static def example(D:Dist) { for (place in D.places()) async at (place; p, D, * ) { for (p in D|here) { S(p); } } }} Also, this should parse - the list of copy specifiers can be arbitrary. (It won't go further than parsing because of undeclared identifiers) package Activities_Activities_Activities; // file Activities line 263 class EquivCode { static def S(pt:Point) {} static def example(D:Dist) { for (place in D.places()) async at (place; p, var a:Int = b, val c = d, f , * ) { for (p in D|here) { S(p); } } }}
          Hide
          Vijay Saraswat added a comment -

          This is falling off the plate for 2.2. So we will push this out to 2.3, since it is new functionality.

          To prepare for it, lets remove from the language the ability for code inside an at statement to modify a local variable declared outside the at statement.To get the effect of this programmers will have to change their code to box the local variable. Once this jira is implemented, programmers will use athome(v) { v = ...;} to get this effect.

          Show
          Vijay Saraswat added a comment - This is falling off the plate for 2.2. So we will push this out to 2.3, since it is new functionality. To prepare for it, lets remove from the language the ability for code inside an at statement to modify a local variable declared outside the at statement.To get the effect of this programmers will have to change their code to box the local variable. Once this jira is implemented, programmers will use athome(v) { v = ...; } to get this effect.
          Hide
          David Grove added a comment -

          bulk defer of open issues to 2.2.2.

          Show
          David Grove added a comment - bulk defer of open issues to 2.2.2.
          Hide
          David Grove added a comment -

          bulk defer of issues to 2.2.3.

          Show
          David Grove added a comment - bulk defer of issues to 2.2.3.
          Hide
          David Grove added a comment -

          bulk defer of 2.3.0 open issues to 2.3.1.

          Show
          David Grove added a comment - bulk defer of 2.3.0 open issues to 2.3.1.
          Hide
          David Grove added a comment -

          bulk defer to 2.3.2

          Show
          David Grove added a comment - bulk defer to 2.3.2
          Hide
          David Grove added a comment -

          bulk defer to 2.4.1.

          Show
          David Grove added a comment - bulk defer to 2.4.1.
          Hide
          David Grove added a comment -

          bulk defer features from X10 2.5 to X10 2.6.

          Show
          David Grove added a comment - bulk defer features from X10 2.5 to X10 2.6.

            People

            • Assignee:
              Unassigned
              Reporter:
              Bard Bloom
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: