Skip to content

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Mar 28, 2018

Here's the reduced issue of std.algorithm.sorting that still remains:

ref front(T)(T[] a) {
    return a[0];
}

struct Merge(Rs...)
{
    Rs source;
    auto ref front()
    {
        foreach (i, _; Rs)
            return source[i].front;
    }

}

auto merge(Rs...)(Rs rs)
{
    return Merge!Rs(rs);
}

void main() @safe
{
    struct DummyType
    {
        int payload;
        ref inout(typeof(payload)) front() inout
        {
            return payload;
        }
    }
    DummyType d;
    d.merge([1.]);
}
test.d(8): Error: function type pure nothrow @nogc return @safe double() has return but does not return any indirections

(this can be solved with a static if, but it seems weird that the compiler can't infer it)

CC @carblue

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#6359"

@wilzbach wilzbach added the Review:Vision Vision Plan https://wiki.dlang.org/Vision/2018H1 label Mar 28, 2018
@wilzbach wilzbach force-pushed the searching-dip1000 branch 2 times, most recently from 99e628a to 82c8ba1 Compare March 28, 2018 05:49
@wilzbach
Copy link
Contributor Author

Argh .. as scope to parameters can break a lot of code, so I reverted this bit of the PR for now.
For reference, the problem with std.algorithm.searching is find as it gets needle asscope parameter

InputRange find(alias pred = "a == b", InputRange, Element)(InputRange haystack, scope Element needle)

but calls mismatch:

auto m = mismatch(partitions[2], needle);

which can't be scope because that would require tuple to be scope-annotated too and that breaks a lot of other things.

@carblue
Copy link
Contributor

carblue commented Mar 29, 2018

@wilzbach

With
dmd: Latest commit a1dffd1
druntime: Latest commit f6f537f
phobos: Latest commit 0750238

Your fix #6359 applied and preliminary slist.d fix #6295 applied,

https://github.com/dlang/phobos/blob/master/dip1000.mak with
aa[std.algorithm.searching]=-dip1000
I get these errors when running: make -f posix.mak std/algorithm/searching.test
...

T=`mktemp -d /tmp/.dmd-run-test.XXXXXX` &&                                                              \
  (                                                                                                     \
    ../dmd/generated/linux/release/64/dmd -od$T -conf= -I../druntime/import  -w -de -dip25 -m64 -fPIC -transition=complex -O -release -dip1000  -main -unittest generated/linux/release/64/libphobos2.a -defaultlib= -debuglib= -L-ldl -cov -run std/algorithm/searching.d ;     \
    RET=$? ; rm -rf $T ; exit $RET                                                                   \
  )
std/algorithm/searching.d(2099): Error: @safe function std.algorithm.searching.__unittest_L2086_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2099): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2099): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2100): Error: @safe function std.algorithm.searching.__unittest_L2086_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2100): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2100): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2101): Error: @safe function std.algorithm.searching.__unittest_L2086_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2101): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2101): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2102): Error: @safe function std.algorithm.searching.__unittest_L2086_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2103): Error: @safe function std.algorithm.searching.__unittest_L2086_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2104): Error: @safe function std.algorithm.searching.__unittest_L2086_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find

It compiles for me, when I add these 2 patches:
The first one is included in #6377 already:

diff --git a/std/range/package.d b/std/range/package.d
index 0177a90..658abdd 100644
--- a/std/range/package.d
+++ b/std/range/package.d
@@ -9806,7 +9806,7 @@ if (isInputRange!Range)
     {
         return predFun(rhs, lhs);
     }
-    private Range _input;
+    /*private*/ Range _input;
 
     // Undocummented because a clearer way to invoke is by calling
     // assumeSorted.

The second:

diff --git a/std/algorithm/searching.d b/std/algorithm/searching.d                                                                                         
index 0a355ca..dd23fa7 100644                                                                                                                              
--- a/std/algorithm/searching.d                                                                                                                            
+++ b/std/algorithm/searching.d                                                                                                                            
@@ -1837,7 +1837,7 @@ if (isInputRange!InputRange)                                                                                                         
 }                                                                                                                                                         
                                                                                                                                                           
 /// ditto                                                                                                                                                 
-R1 find(alias pred = "a == b", R1, R2)(R1 haystack, scope R2 needle)
+R1 find(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle)
 if (isForwardRange!R1 && isForwardRange!R2
         && is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))
 {

@wilzbach
Copy link
Contributor Author

I get these errors when running: make -f posix.mak std/algorithm/searching.test
...

FYI: Yes, I'm aware, I tried to fix that before, but ran intro troubles with tuple not working well in scope.
Anyhow, as mentioned in my earlier comment I believe that instead of removing scope from needle, we should add it to mismatch and thus to tuple.

@wilzbach
Copy link
Contributor Author

(Also you can use ```diff for color-highlighted diffs)

@wilzbach wilzbach force-pushed the searching-dip1000 branch from 82c8ba1 to 31dfc84 Compare April 6, 2018 03:01
@wilzbach wilzbach added the Review:Trivial typos, formatting, comments label Apr 6, 2018
@wilzbach wilzbach force-pushed the searching-dip1000 branch from 31dfc84 to e9e6ca4 Compare April 6, 2018 03:15
@wilzbach wilzbach changed the title Prepare std.algorithm.{searching,sorting} for -dip1000 Prepare std.algorithm.sorting for -dip1000 Apr 6, 2018
@wilzbach
Copy link
Contributor Author

wilzbach commented Apr 6, 2018

Okay I rebased this, s.t. it now only contains the first "trivial" fix for std.algorithm.sorting and thus can be merged right now. Fixing the find with a scoped needle -> mismatch -> tuple problem needs to be done in another PR anyhow.

@dlang-bot dlang-bot merged commit ee293aa into dlang:master Apr 6, 2018
@wilzbach wilzbach deleted the searching-dip1000 branch April 10, 2018 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:auto-merge Review:Trivial typos, formatting, comments Review:Vision Vision Plan https://wiki.dlang.org/Vision/2018H1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants