Skip to content

std.parallelism.task: Can't move value to task param #10418

Open
@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

nin-jin reported this on 2020-05-23T15:37:09Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20858

CC List

  • Ajieskola

Description

src\phobos\std\parallelism.d(444,29): Error: struct jin.go.Output!long.Output is not copyable because it is annotated with @disable

src\phobos\std\parallelism.d(832,16): Error: template instance std.parallelism.Task!(wrapper, void function(Output!long) @system, Output!long) error instantiating

Problem in this phobos code:

    private static void impl(void* myTask)
    {
        import std.algorithm.internal : addressOf;

        Task* myCastedTask = cast(typeof(this)*) myTask;
        static if (is(ReturnType == void))
        {
            fun(myCastedTask._args); // !!!
        }
        else static if (is(typeof(&(fun(myCastedTask._args)))))
        {
            myCastedTask.returnVal = addressOf(fun(myCastedTask._args));
        }
        else
        {
            myCastedTask.returnVal = fun(myCastedTask._args);
        }
    }

See workaround in VibeD to call function with move semantic: https://github.com/vibe-d/vibe-core/blob/master/source/vibe/core/taskpool.d#L210

mixin(callWithMove!ARGS("c", "args.expand")); // !!!

package string callWithMove(ARGS...)(string func, string args)
{
	import std.string;
	string ret = func ~ "(";
	foreach (i, T; ARGS) {
		if (i > 0) ret ~= ", ";
		ret ~= format("%s[%s]", args, i);
		static if (needsMove!T) ret ~= ".move";
	}
	return ret ~ ");";
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions