Fix passing sync/single variables by ref/blank intent.

I fixed the bug where sync/single variables were not passed by reference
to generic blank/ref-intent formals. Instead, readFE/readFF were applied
so the formals were instantiated to those variables' base types.

The fix itself is trivial - see

  compiler/resolution/generics.cpp

However, it exposed a couple of implementation and conceptual bugs.


* Putting a single variable in a tuple results in an extra deallocation
of that single variable, e.g. at close-brace here:

  {
    var x$: single int = 1;
    writeln((x$, 1));
  }

This is new because _build_tuple now takes that single variable by
reference. I wonder if it's easy to fix by throwing some flag
"do not deallocate" on the single var?
It might be worth generating a compiler error for attempting
to stash a sync/single into a tuple.

My workaround is to add readFF() in the above. See

  spec/Task_Parallelism_and_Synchronization.tex


* To make write(x$) write the base variable, the most natural place
is to add

  //  modules/internal/ChapelSyncvar.chpl
  proc _syncvar.writeThis(x: Writer) { x.write(this.readFE()); }
  proc _singlevar.writeThis(x: Writer) { x.write(this.readFF()); }

However, the effect of this is that the sync var's lock is sought
*after* locking the channel that's being written to.

Indeed, the call write(x$) progresses as follows:

  channel.write(args ...?k):bool
  channel.write(args ...?k, out error:syserr):bool  <--- IO.chpl:1991
  _write_one_internal(_channel_internal:qio_channel_ptr_t, param kind:iokind, x\
:?t)
  Writer.write(args ...?k)
  Writer.writeIt(x:?t)
  _syncvar.writeThis(x: Writer)

The channel gets locked in channel.write/IO.chpl:1991.
The sync var readFE() only happens in writeThis, when the channel
is already locked.

Therefore this code is a deadlock, which it wasn't before:

  var x$: sync int;

  cobegin {
    { writeln(x$); }
    { sleep(1);
      writeln("about to assign x$");
      x$ = 1;  }
  }

The first writeln() is stuck on x$; the second writeln() is stuck
on the channel lock that the first one is holding.

My workaround is, again, to add readFE().

  test/multilocale/deitz/needMultiLocales/test_on_begin1.chpl
  test/parallel/single/waynew/class0.chpl
  test/parallel/single/waynew/class1.chpl


* min/max do not behave as expected when passed sync vars:

  proc min(x, y) return if x < y then x else y;

If the 'then' branch is taken and x's actual is a sync variable,
it gets read twice, which is not intuitive.
I added an additional definition of min/max to address this.

  modules/internal/ChapelBase.chpl

although there may be alternative solutions.

I'll take Tom's note one step further and ask: can't we just provide three overloads of StmtLevelSymbol, where the sync and single versions do readFE/readFF and the third returns x to avoid having these (confusing) calls?  That feels much cleaner to me than requiring a new call and overloading it for non-syncs/singles.  The other place they're used -- the min/max calls -- I'd suggest requiring the caller to do the read**()ing of the variable (and updating any tests that do this at present).  I think it's more natural to not support min/max on syncs than it is do so -- ideally blocking operations on syncs should happen in user code, not library code like this.