[Swift-devel] strange behavior evaluating function call as trace arg

Mihael Hategan hategan at mcs.anl.gov
Thu Feb 5 10:22:04 CST 2009


On Thu, 2009-02-05 at 16:06 +0000, Ben Clifford wrote:
> On Thu, 5 Feb 2009, Michael Wilde wrote:
> 
> > I dont understand this - can you clarify?
> > 
> > I understand an "lvalue" in swift to be one of:
> > - a var (eg var=value)
> > - an array element (eg a[i]=value)
> > - a struct element (eg s.a=value)
> 
> yes.
> 
> > But swift procedures do indeed return a list of values, right?
> 
> no.

Another way of viewing this would be the following:

Returns from swift procedures are not actually returns but arguments
passed by reference. This is there in order to support the automatic
parallelization scheme.

So assuming 

(int s) add(int x, int y) { s = x + y; }
int s;
s = add(1, 2);, this translates to (in C-like pointerish pseudocode):

add(int* s, int* x, int* y) {
  *s = *x + *y;
}
int *s = malloc(sizeof(int));
add(s, newInt(1), newInt(2));

where newInt(int) allocates an int pointer, puts some value into it and
returns the address. Pointers here are DSHandles (Swift's way of dealing
with data).




More information about the Swift-devel mailing list