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

Remove std::ranges::view_interface visualizer. #4835

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

fsb4000
Copy link
Contributor

@fsb4000 fsb4000 commented Jul 12, 2024

Fixes #4830

Actually I tested it and I think std::ranges::view_interface natvis may be useless.

My test code:

#include <iostream>
#include <ranges>
#include <vector>
#include <sstream>

template<class T, class A>
class VectorView : public std::ranges::view_interface<VectorView<T, A>>
{
public:
    VectorView() = default;

    VectorView(const std::vector<T, A>& vec) :
        m_begin(vec.cbegin()), m_end(vec.cend())
    {}

    auto begin() const { return m_begin; }

    auto end() const { return m_end; }

private:
    typename std::vector<T, A>::const_iterator m_begin{}, m_end{};
};

int main()
{
    std::vector<int> v = { 1, 4, 9, 16 };

    VectorView view1{ v };
    view1.size();
    view1.front();
    view1.empty();
    view1.back();
    view1.data();

    auto words = std::istringstream{ "today is yesterday’s tomorrow" };
    auto istream_view = std::views::istream<std::string>(words);;
    std::ranges::view_interface<std::ranges::basic_istream_view<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::char_traits<char> > > view2 = istream_view;

    return 0;
}

For std::ranges::view_interface without size() I used istream_view.

For std::ranges::view_interface withsize() I used VectorView from https://en.cppreference.com/w/cpp/ranges/view_interface
I also called size(), front(), empty(), back(), data() because the compiler didn't generate these methods by default and Natvis showed unknown size.

My results:
изображение

As I can see Natvis never calls methods. It works great only for memory variables and intrinsics.
iota_view example:

<Intrinsic Optional="true" Name="size" Expression="(size_t)(_Bound - _Value)" />

And because std::ranges::view_interface is dependent from _Derived, we can't create an intrinsic for its size.
Am I correct and we always will receive "???" or "This expression has side effects and will not be evaluate"?

@fsb4000 fsb4000 requested a review from a team as a code owner July 12, 2024 09:07
@StephanTLavavej StephanTLavavej added bug Something isn't working visualizer How the VS debugger displays STL types labels Jul 17, 2024
@StephanTLavavej
Copy link
Member

Hmm, this does seem like an inherently not-useful/not-implementable visualizer. I think we should simply remove it, and then if someone identifies a scenario in which it can be usefully implemented, we can add a working version later.

@fsb4000 fsb4000 changed the title size() is optional method for ranges::view_interface Remove std::ranges::view_interface visualizer. Jul 19, 2024
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 5573054 into microsoft:main Aug 8, 2024
39 checks passed
@StephanTLavavej
Copy link
Member

Thanks for fixing this! We still need to triple-mirror this into VS so it'll take effect, but this gets us one step closer. 👀 🪄 😸

@fsb4000 fsb4000 deleted the fix4830 branch August 10, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working visualizer How the VS debugger displays STL types
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

STL.natvis: ranges::view_interface doesn't always have size()
2 participants