Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 122 - Fails to compile std.parallelism.reduce
Summary: Fails to compile std.parallelism.reduce
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: x86_64 Linux
: --- major
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2014-04-21 09:42 CEST by Russel Winder
Modified: 2014-06-14 17:25 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Russel Winder 2014-04-21 09:42:50 CEST
A small program that compiles and executed fine with DMD 2.065 and LDC master (794d5d, DMD v2.063.2 and LLVM 3.4), gives the following error using GDC 4.8.1

/usr/include/d/4.8/std/parallelism.d: In member function 'reduce':
/usr/include/d/4.8/std/parallelism.d:2630: error: cannot access frame of function 'main' from 'reduce'
Comment 1 Iain Buclaw 2014-05-18 17:32:43 CEST
Sorry for the delayed response. Would you have this 'small program' available as a test case?
Comment 2 Russel Winder 2014-05-18 18:11:23 CEST
It is the variant of my π by Quadrature example that David Simcha and I came up with whilst he was writing parallelism.d:

/*
 *  A D program to calculate π using quadrature as a parallel reduce of individual expression evaluations
 *  with no manual batching.
 *
 *  Copyright © 2011–2013  Russel Winder
 */

//  This version originally due to David Simcha, stemming from various emails on the various D email lists
//  and reified in the documentation for std.parallelism: http://dlang.org/phobos/std_parallelism.html,
//  http://cis.jhu.edu/~dsimcha/d/phobos/std_parallelism.html

import std.algorithm;
import std.datetime;
import std.parallelism;
import std.range;

import outputFunctions;

int main(immutable string[] args) {
  immutable n = 1000000000;
  immutable delta = 1.0 / n;
  StopWatch stopWatch;
  stopWatch.start();
  //  There is a problem using a lambda function here.  David Simcha reports it is a consequence of issue
  //  5710 http://d.puremagic.com/issues/show_bug.cgi?id=5710.  Live with this and use the string syntax
  //  for specifying a lambda function.
  //immutable pi = 4.0 * delta * taskPool.reduce !((a, b) { return a + b; }) (
  //immutable pi = 4.0 * delta * taskPool.reduce !((a, b) => a + b) (
  immutable pi = 4.0 * delta * taskPool.reduce!"a + b"(
      map!((int i) { immutable x = (i - 0.5) * delta; return 1.0 / (1.0 + x * x); })(iota(n)));
  stopWatch.stop();
  immutable elapseTime = stopWatch.peek().hnsecs * 100e-9;
  output(__FILE__, pi, n, elapseTime);
  return 0;
}
Comment 3 Russel Winder 2014-06-07 14:41:18 CEST
Problem still happens with gdc 4.9 :-(

gdc -I. -O3 -c -o pi_parallelReduce.o pi_parallelReduce.d
/usr/include/d/4.9/std/parallelism.d: In member function 'reduce':
/usr/include/d/4.9/std/parallelism.d:2630: error: cannot access frame of function 'main' from 'reduce'
scons: *** [pi_parallelReduce.o] Error 1
Comment 4 Iain Buclaw 2014-06-12 08:36:00 CEST
Two things have happened that have opened this up for fixing:

https://github.com/D-Programming-GDC/GDC/commit/eb915d6dd4b2bcd96463a5c73f74774ae5941404

https://github.com/D-Programming-GDC/GDC/commit/8b77c001db6cc78fd4b4c33ba7963aad4f62ed6f

This error being in the glue is now only historical for preventing an ICE in the backend that should no longer occur.  However as all things historical, it's rather deep rooted.
Comment 5 Iain Buclaw 2014-06-12 08:37:22 CEST
Oops, that first link should have been:

https://github.com/D-Programming-GDC/GDC/commit/16be749d160c19bd2cc2fbc70853a7409b3b96da
Comment 6 Iain Buclaw 2014-06-14 10:23:05 CEST
Technical notes (so I don't forget when I look at this):

AssignExp::toElem
- e1->op == TOKslice
- this->ismemset == true

There is no shortcut for calling BUILT_IN_MEMSET here, so the initialisation is handed down to IRState::doArraySet, which needlessly attempts to generate each individual initialiser.