Skip to content
This repository

Nested function passed by alias not emitted (std.file.dirEntries) #131

Closed
bioinfornatics opened this Issue · 6 comments

3 participants

jonathan MERCIER David Nadlinger Alex Rønne Petersen
jonathan MERCIER

This code fail at build

import std.file;

void main( ){
    auto dFiles = dirEntries( "./", "*.d", SpanMode.depth);
}
search.o: In function `_D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result6__ctorMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result':
search:(.text._D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result6__ctorMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result[_D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result6__ctorMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result]+0xdb): undefined reference to `_D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result1fMFS3std4file8DirEntryZb'
search.o: In function `_D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result8popFrontMFZv':
search:(.text._D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result8popFrontMFZv[_D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result8popFrontMFZv]+0xc8): undefined reference to `_D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result1fMFS3std4file8DirEntryZb'
collect2: erreur: ld a retourné 1 code d'état d'exécution
Error: linki

Note: edit some bug disappear after the update left this one

David Nadlinger
Owner

Seems like we are declaring _D3std4file10dirEntriesFAyaAyaE3std4file8SpanModebZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterMFS3std4file11DirIteratorZS3std4file10dirEntries62__T6filterS48_D3std4file10dirEntries1fMFS3std4file8DirEntryZbZ35__T6filterTS3std4file11DirIteratorZ6filterM6Result6Result1fMFS3std4file8DirEntryZb (which seems to be the nested function f in dirEntries), but never defining it.

David Nadlinger
Owner

DtoDeclareFunction(std.file.dirEntries.f) is first called from nested within DtoDefineFunc(std.file.dirEntries.filter!(f).filter!(DirIterator).filter.Result.this), and (gIR->dmodule is the main module, s->getModule() is std.file) the function never gets pushed back into the global function list. This might have worked for D1 because of https://github.com/ldc-developers/ldc/blob/master/gen/nested.cpp#L353. @AlexeyProkhin, does this ring any bell to you?

Alex Rønne Petersen
alexrp commented

FWIW, I can confirm this exact bug in my project as well.

David Nadlinger
Owner

A related test case which causes a segfault using latest LDC:

// algorithm.d

template filter(alias pred) {
    auto filter(Range)(Range rs) {
        return FilterResult!(pred, Range)(rs);
    }
}

struct FilterResult(alias pred, Range) {
    this(Range r) {}
}
// file.d
import algorithm;

struct DirIterator {}

auto dirEntries() {
    void f() {}
    return filter!f(DirIterator());
}
ldc2 file.d algorithm.d

Hopefully, fixing the root cause of this will also fix the dirEntries issue.

David Nadlinger
Owner

Getting closer (hopefully for real, this time):

// test.d
template filter(alias pred)
{
    auto filter(Range)(Range rs)
    {
        return FilterResult!(pred, Range)(rs);
    }
}

private struct FilterResult(alias pred, Range)
{
    Range _input;
    this(Range r)
    {
        auto a = pred(r.front);
    }
}

struct RefCounted(T)
{
    T payload;
    ~this() {}
}

struct DirIteratorImpl {}

struct DirIterator
{
    RefCounted!(DirIteratorImpl) impl;
    @property int front(){ return 0; }
}

auto dirEntries()
{
    bool f(int a) { return false; }
    return filter!f(DirIterator());
}
import file;

void main() {
    auto dFiles = dirEntries();
}
David Nadlinger klickverbot referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
David Nadlinger
Owner

Fixed, at last!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.