Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.algorithm.searching: Fix a -dip1000 compilable issue #6246

Merged
merged 1 commit into from
Mar 28, 2018
Merged

std.algorithm.searching: Fix a -dip1000 compilable issue #6246

merged 1 commit into from
Mar 28, 2018

Conversation

carblue
Copy link
Contributor

@carblue carblue commented Mar 5, 2018

Eliminates an error from std.algorithm.searching (the remaining errors are from std.algorithm.comparison and std.uni):

make -f posix.mak std/algorithm/searching.test [-dip1000 for std.algorithm.searching.d (the posix.mak I'm using is master+ https://github.com//pull/6195] + -dip1000 for searching.d; master at Latest commit 4820a49)]:

std/algorithm/searching.d(2101): Error: @safe function std.algorithm.searching.__unittest_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2102): Error: @safe function std.algorithm.searching.__unittest_L2088_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_L2088_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_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2105): Error: @safe function std.algorithm.searching.__unittest_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2106): Error: @safe function std.algorithm.searching.__unittest_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2424): Error: @safe function std.algorithm.searching.__unittest_L2416_C7 cannot call @system function std.algorithm.searching.find!(string, binaryFun, string).find
std/algorithm/searching.d(2436): Error: @safe function std.algorithm.searching.__unittest_L2430_C7 cannot call @system function std.algorithm.searching.find!(int[], binaryFun, int[]).find
std/algorithm/searching.d(2437): Error: @safe function std.algorithm.searching.__unittest_L2430_C7 cannot call @system function std.algorithm.searching.find!(int[], binaryFun, int[]).find
std/algorithm/searching.d(2443): Error: @safe function std.algorithm.searching.__unittest_L2440_C7 cannot call @system function std.algorithm.searching.find!(string, binaryFun, string).find

PR applied and function
R1 find(alias pred = "a == b", R1, R2)(R1 haystack, scope R2 needle)
temporarily attributed @safe, results in:

std/algorithm/searching.d(1969): Error: scope variable needle assigned to non-scope parameter r2 calling std.algorithm.comparison.mismatch!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).mismatch
std/algorithm/searching.d(2101): Error: template instance `std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b"))` error instantiating
std/uni.d(2553): Error: reference to local variable __tmpfordtor1666 assigned to non-scope parameter this calling std.uni.InversionList!(GcPolicy).InversionList.byInterval
std/uni.d(1976): Error: template instance `std.uni.InversionList!(GcPolicy)` error instantiating

@dlang-bot
Copy link
Contributor

dlang-bot commented Mar 5, 2018

Thanks for your pull request and interest in making D better, @carblue! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

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.

@@ -297,7 +297,7 @@ private:
ptrdiff_t[ElementType!(Range)] occ; // GC allocated
Range needle;

ptrdiff_t occurrence(ElementType!(Range) c)
ptrdiff_t occurrence(ElementType!(Range) c) scope
{
auto p = c in occ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should better leave this to inference as opHash or opEquals of the element type could possibly escape a reference to one of the keys of the occ hash table. Somewhat unlikely but still possible, e.g. some cache of expensive hashing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like rejection of PR, thus I will close it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinNowak PR reopened:
I didn't gratuitously add scope, because for the implicit this parameter, it doesn't get inferred currently, as this will show. Temporarily apply these changes:

diff --git a/std/algorithm/searching.d b/std/algorithm/searching.d
index 42e128f..084bfc0 100644
--- a/std/algorithm/searching.d
+++ b/std/algorithm/searching.d
@@ -360,7 +360,7 @@ public:
     }
 
     ///
-    Range beFound(Range haystack)
+    Range beFound(Range haystack) @safe
     {
         import std.algorithm.comparison : max;
 
@@ -1839,7 +1839,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, scope R2 needle) @safe
 if (isForwardRange!R1 && isForwardRange!R2
         && is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))
 {
@@ -2408,7 +2408,7 @@ if (Ranges.length > 1 && is(typeof(startsWith!pred(haystack, needles))))
  * such position exists, returns `haystack` advanced to termination).
  */
 RandomAccessRange find(RandomAccessRange, alias pred, InputRange)(
-    RandomAccessRange haystack, scope BoyerMooreFinder!(pred, InputRange) needle)
+    RandomAccessRange haystack, scope BoyerMooreFinder!(pred, InputRange) needle) @safe
 {
     return needle.beFound(haystack);
 }
diff --git a/std/range/package.d b/std/range/package.d
index b179f98..e1609cc 100644
--- a/std/range/package.d
+++ b/std/range/package.d
@@ -9715,7 +9715,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.

make -f posix.mak std/algorithm/searching.test (aa[std.algorithm.searching]=-dip1000 in #6278)
results in:
...

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(1969): Error: scope variable needle assigned to non-scope parameter r2 calling std.algorithm.comparison.mismatch!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).mismatch
std/algorithm/searching.d(2101): Error: template instance `std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b"))` error instantiating
std/algorithm/searching.d(2413): Error: scope variable needle assigned to non-scope parameter this calling std.algorithm.searching.BoyerMooreFinder!(binaryFun, string).BoyerMooreFinder.beFound
std/algorithm/searching.d(2424): Error: template instance `std.algorithm.searching.find!(string, binaryFun, string)` error instantiating
std/algorithm/searching.d(2413): Error: scope variable needle assigned to non-scope parameter this calling std.algorithm.searching.BoyerMooreFinder!(binaryFun, int[]).BoyerMooreFinder.beFound
std/algorithm/searching.d(2436): Error: template instance `std.algorithm.searching.find!(int[], binaryFun, int[])` error instantiating
posix.mak:571: die Regel für Ziel „std/algorithm/searching.test“ scheiterte (the rule for target ... failed)

Thus, BoyerMooreFinder.beFound doesn't get its this parameter inferred scope.
And if You extend changes above to
Range beFound(Range haystack) scope @safe
the same is true (not inferred) for ptrdiff_t occurrence(ElementType!(Range) c):

std/algorithm/searching.d(379): Error: scope variable this assigned to non-scope parameter this calling std.algorithm.searching.BoyerMooreFinder!(binaryFun, string).BoyerMooreFinder.occurrence
std/algorithm/searching.d(1969): Error: scope variable needle assigned to non-scope parameter r2 calling std.algorithm.comparison.mismatch!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).mismatch
std/algorithm/searching.d(2101): Error: template instance `std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b"))` error instantiating
std/algorithm/searching.d(379): Error: scope variable this assigned to non-scope parameter this calling std.algorithm.searching.BoyerMooreFinder!(binaryFun, int[]).BoyerMooreFinder.occurrence
std/algorithm/searching.d(2436): Error: template instance `std.algorithm.searching.find!(int[], binaryFun, int[])` error instantiating
posix.mak:571: die Regel für Ziel „std/algorithm/searching.test“ scheiterte (the rule for target ... failed)

I'm about to push an update for this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a spontaneous idea: couldn't inout be modified to also infer scope?

Copy link
Member

@schveiguy schveiguy Mar 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, inout converts implicitly to const, it could be legally escaped. It also could be new data from the heap if returned.

@carblue carblue closed this Mar 7, 2018
@carblue carblue deleted the dip1000_7 branch March 7, 2018 03:09
@carblue carblue restored the dip1000_7 branch March 15, 2018 21:24
@carblue carblue reopened this Mar 15, 2018
@carblue
Copy link
Contributor Author

carblue commented Mar 17, 2018

Since I opened this PR 12 days ago, the errors changed to these:
make -f posix.mak std/algorithm/searching.test (aa[std.algorithm.searching]=-dip1000 in #6278):
...

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(2101): Error: @safe function std.algorithm.searching.__unittest_L2088_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_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2102): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2102): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2103): Error: @safe function std.algorithm.searching.__unittest_L2088_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: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2103): Error: struct `std.range.SortedRange!(int[], "a < b").SortedRange` member _input is not accessible from @safe code
std/algorithm/searching.d(2104): Error: @safe function std.algorithm.searching.__unittest_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2105): Error: @safe function std.algorithm.searching.__unittest_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2106): Error: @safe function std.algorithm.searching.__unittest_L2088_C7 cannot call @system function std.algorithm.searching.find!("a == b", SortedRange!(int[], "a < b"), SortedRange!(int[], "a < b")).find
std/algorithm/searching.d(2424): Error: @safe function std.algorithm.searching.__unittest_L2416_C7 cannot call @system function std.algorithm.searching.find!(string, binaryFun, string).find
std/algorithm/searching.d(2436): Error: @safe function std.algorithm.searching.__unittest_L2430_C7 cannot call @system function std.algorithm.searching.find!(int[], binaryFun, int[]).find
std/algorithm/searching.d(2437): Error: @safe function std.algorithm.searching.__unittest_L2430_C7 cannot call @system function std.algorithm.searching.find!(int[], binaryFun, int[]).find
std/algorithm/searching.d(2443): Error: @safe function std.algorithm.searching.__unittest_L2440_C7 cannot call @system function std.algorithm.searching.find!(string, binaryFun, string).find

The additional ones can be removed again by removing protection attribute private from:
std.range.package. struct SortedRange(Range, alias pred = "a < b"). private Range _input;
which is probably not the right direction to go

@WalterBright
Copy link
Member

Since this is congruent with the D vision, I added the Vision label and this is a priority issue. https://wiki.dlang.org/Vision/2018H1

@WalterBright WalterBright added the Review:Vision Vision Plan https://wiki.dlang.org/Vision/2018H1 label Mar 22, 2018
@WalterBright
Copy link
Member

If it still compiles successfully and passes the test suite after adding scope, then the addition is good to go. If that does turn out to break things, then the test suite (at least) is inadequate.

@WalterBright WalterBright merged commit 71276b2 into dlang:master Mar 28, 2018
@carblue carblue deleted the dip1000_7 branch March 28, 2018 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge:auto-merge Review:Vision Vision Plan https://wiki.dlang.org/Vision/2018H1 Severity:Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants