D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9598 - Cannot use moveFront on MapResult!(lambda, ByLine!(char, char))
Summary: Cannot use moveFront on MapResult!(lambda, ByLine!(char, char))
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All Windows
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-26 22:33 UTC by Chris Cain
Modified: 2018-10-16 18:24 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Chris Cain 2013-02-26 22:33:51 UTC
Using DMD 2.062 with no command line arguments other than the source file in question

I have the following (expected valid) code:

---

import std.stdio, std.file, std.algorithm, std.conv, std.range;

void main() {
	dirEntries("data", "*.out", SpanMode.shallow)
		.map!(e => File(e.name).byLine()
			.map!(line => text(line))() // compile error
		)()
		.array()
		.nWayUnion() // line 9
		.copy(stdout.lockingTextWriter);
}

---

Which produces errors. Error 1 is a compile-time failure producing the following message:

---
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range.d(6695): Error: static assert  "Cannot move front of a range with a postblit and an rvalue front."
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container.d(3797):        instantiated from here: moveFront!(MapResult!(__lambda4, ByLine!(char, char))[])
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(10526):        instantiated from here: BinaryHeap!(MapResult!(__lambda4, ByLine!(char, char))[], compFront)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(10562):        instantiated from here: NWayUnion!("a < b", MapResult!(__lambda4, ByLine!(char, char))[])
D:\[snip]\src\reducedCase.d(9):        instantiated from here: nWayUnion!("a < b", MapResult!(__lambda4, ByLine!(char, char))[])

---

If I change the code to this:

---

import std.stdio, std.file, std.algorithm, std.conv, std.range;

void main() {
	dirEntries("data", "*.out", SpanMode.shallow)
		.map!(e => File(e.name).byLine()
			.map!text() // Compiles, runtime error
		)()
		.array()
		.nWayUnion() // line 9
		.copy(stdout.lockingTextWriter);
}

---

Then the code compiles, but produces a runtime error (when files are in data directory and named *.out):

object.Error: Access Violation
----------------
0x00429674
0x004294FF
0x7730B459 in LdrRemoveLoadAsDataTable
0x7730B42B in LdrRemoveLoadAsDataTable
0x772C0133 in KiUserExceptionDispatcher
0x0018F6E8
0x0018F738
----------------


Specifically, these errors apply to MapResult!(lambda, ByLine!(char, char)). For instance, using a string[][] as an array and applying a .map!text() as above, there is no problem for either case.

---

import std.stdio, std.file, std.algorithm, std.conv, std.range;

void main() {
	[["abc", "cbd"], ["dce", "efg"]]
		.map!(e =>
			//e.map!text()               // OK
			e.map!(line => text(line))() // OK
		)()
		.array()
		.nWayUnion()
		.copy(stdout.lockingTextWriter);
}

---
Comment 1 Maxim Fomin 2013-02-27 04:49:11 UTC
Can confirm on linux. What's interesting is that executable crashes during garbage collection which I haven't met before.
Comment 2 bearophile_hugs 2013-02-27 05:02:04 UTC
(In reply to comment #0)

> Then the code compiles, but produces a runtime error (when files are in data
> directory and named *.out):
> 
> object.Error: Access Violation
> ----------------
> 0x00429674
> 0x004294FF
> 0x7730B459 in LdrRemoveLoadAsDataTable
> 0x7730B42B in LdrRemoveLoadAsDataTable
> 0x772C0133 in KiUserExceptionDispatcher
> 0x0018F6E8
> 0x0018F738
> ----------------

In such cases it's better to _also_ compile with -g, that shows an error in void* gc.gcx.GC.mallocNoSync(uint, uint, uint*).
Comment 3 Chris Cain 2013-02-27 05:13:20 UTC
(In reply to comment #2)
> In such cases it's better to _also_ compile with -g, that shows an error in
> void* gc.gcx.GC.mallocNoSync(uint, uint, uint*).

Good point, thanks for the information. Here's what it's giving me on my system (running Windows 7 64-bit):

object.Error: Access Violation
----------------
0x0042C7C4 in char[][] core.sys.windows.stacktrace.StackTrace.trace()
0x0042C64F in core.sys.windows.stacktrace.StackTrace core.sys.windows.stacktrace
.StackTrace.__ctor()
0x7730B459 in LdrRemoveLoadAsDataTable
0x7730B42B in LdrRemoveLoadAsDataTable
0x772C0133 in KiUserExceptionDispatcher
0x002B1ECB
----------------
Comment 4 safety0ff.bugz 2013-10-25 13:48:08 UTC
The access violation case seems to have been fixed sometime between 2.063.2 and current git version.