Skip to content

Comments

Convert range primitives to CNF like a boss#5613

Merged
dlang-bot merged 1 commit intodlang:masterfrom
andralex:cnf
Jul 15, 2017
Merged

Convert range primitives to CNF like a boss#5613
dlang-bot merged 1 commit intodlang:masterfrom
andralex:cnf

Conversation

@wilzbach
Copy link
Contributor

#5461, but this time hopefully without CI weirdness

@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.

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

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

Love this, I need to approve my own PR :)

@dlang-bot dlang-bot merged commit afc7d47 into dlang:master Jul 15, 2017
@quickfur
Copy link
Member

quickfur commented Jul 17, 2017

This PR caused a regression:

// Compile with -dip25 and -dip1000
import std.range.primitives;
struct C {
    private S* impl;
}
struct S {
    bool empty;
    @property C front() return { return C(&this); }
    void popFront() { }

    static assert(isInputRange!S); // FAILS
}

The reason this fails is because the new isInputRange condition contains the lambda typeof((R r) => r.front), which is not annotated with return and therefore fails the escaping reference check in the compiler. The old check passes because it assigns the value of front to a local variable.

One might argue that the above code is bad because .front should not escape this like that, but the problem is that S is a private struct returned by a helper function that always allocates it on the heap, so the escaping reference is actually valid. Besides, since front is annotated with return, this usage ought to be allowed; it is incorrect for isInputRange to reject S just because of this.

enum bool isInputRange(R) =
is(typeof(R.init) == R)
&& is(ReturnType!((R r) => r.empty) == bool)
&& is(typeof((R r) => r.front))
Copy link
Member

Choose a reason for hiding this comment

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

This line fails if the range being tested has a front method annotated with return.

@quickfur
Copy link
Member

Filed an issue for this regression: https://issues.dlang.org/show_bug.cgi?id=17661

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants