I went to school in Germany, to what would be translated by dictionary to grammar school.
It wasn't perfect, but I think it is the only way that works if nothing else changes.
Putting children with different abilities all in one school requires a very different approach, and more effort from teachers.
But with every system, you have to take into consideration that the worst that can happen, will happen. Bright children being bullied for being bright? If it can happen, it will happen, and that the teachers could prevent it is no argument because there will be teachers who won't do anything about it.
School systems should be built taking into consideration that humans are flawed. If for a school to be good, you need teachers or parents or anyone else to do the right thing voluntarily, then chances are, it won't work in many cases.
For everything important, you need rules that are enforced.
The "you take a test, and depending on how your results are, you can go to a specific school" approach is not perfect, but it excludes (to some degree) the human factor, which makes it easier to work with.
Separate schools for girls and boys should not be needed, but with research having found that teachers pay more attention to boys than girls, the problem would be easiest fixed by separate schools.
I am pretty much disillusioned when it comes to teachers' motivation to do things right, and therefore lean more towards the easy solutions.
The school where everyone learns together and lots of teachers give everyone just as much attention as needed seems like an utopia that isn't very realistic in the imperfect world we live in.