In every screenplay, the first ten pages or so tell the audience what sort of picture they're going to see. They set a tone that alerts the audience whether this is a movie that is going to end happily or sadly or if it is the sort of movie that could go either way. The first ten minutes creates a "contract" with the audience. If you violate this contract, no matter how good the rest of your movie is, it will fail.
In movie cameras, each reel of film is about ten minutes long, so show people often refer to "reels" as shorthand for chunks of ten minutes. So this contract may be called the "First Reel Contract."
The contract sets up the film's tone and the generic ("genre") expectations the audience or the reader will have. Ten minutes into a good movie, you know whether you're dealing with a Hollywood romance or an art film. The rest of the movie is going to have to deliver the goods on the contract. Put a quirky art film ending on a Hollywood romance and the audience will leave feeling depressed, not uplifted; put a broad Hollywood ending on an art film and the audience feels cheated. If you set up a romantic contract, the boy had better get the girl. On the other hand, if you set up a dramatic contract, the boy can lose or give up the girl, the girl can get murdered, the boy can get murdered, or they can retire to Florida after a long, happy life, just so long as you have some kind of dramatic climax.
A comedy had better start funny. A tragic movie requires a serious opening. An action movie wants an action sequence in the first ten minutes. A romantic comedy will typically start relatively more funny and end more romantic, but it's hard to satisfy the audience if you start romantic and end funny.
You'll notice that in a lot of movies with tragic endings, the filmmakers choose to start with the tragic end, and then flash back to the beginning. If your film is a tragedy, you want your audience to be prepared for it. In the play Romeo and Juliet, the spoken prologue tells us that the lovers are "star-cross'd" and will be dead by the end of the play; that way you don't get your hopes up. In Easy Rider, we have a fragmentary flash-forward in the first reel of what we'll eventually realize is the heros getting murdered.
More subtly than a flash-forward, the beginning can foreshadow the tragic ending. If your movie is about an outlaw who gets hanged at the end of the movie, you might begin with the hanging of another outlaw. Elizabeth ends with Queen Elizabeth sacrificing herself to England: she becomes a virgin again, denying herself personal happiness in order to rule her realm in safety. The opening sequence foreshadows that, showing three Protestant martyrs being burned for their faith.
You don't have to foreshadow your tragic ending. But if you have a light-hearted opening to a tragedy, there must be some hint of doom; otherwise the audience is going to feel cheated when the tone changes. In All That Jazz, the title sequence contains a brief shot of Joe Gideon, the hero, falling off a tightrope. Cabaret starts with a light-hearted burlesque routine, but the movie opens with a disturbingly distorted reflection of the audience watching the routine. It's enough to tell you that you're not here to enjoy the show.
I'm not saying that you should be able to predict the ending from the beginning. That would make the movie predictable - it would fail to surprise. I'm saying that the ending must be of a piece with the beginning. The seeds of the ending must be contained in the beginning. The ending must deliver the goods on the beginning.