haskell / happy

The Happy parser generator for Haskell
Other
276 stars 84 forks source link

qualify Prelude functions in templates #156

Closed jvoigtlaender closed 4 years ago

jvoigtlaender commented 4 years ago

This is a less ambitious resolution to https://github.com/simonmar/happy/issues/131 than https://github.com/simonmar/happy/pull/135 was.

The compiler construction course in which the underlying issue arose last year is due to start again now. I see that making a more comprehensive fix, which would prevent problems like this from arising in happy again in the future, is stalled in discussion between @Kellador and @simonmar over in https://github.com/simonmar/happy/pull/135. CC'ing @owestphal, who would have to deal with students' problems arising from name clashes between Prelude functions and own functions in the practical part of the course.

The pull request here does the minimal thing. No interface changes (that is, no new cli options) to happy, no preprocessor magic, no changes to the test suite. Just adding Prelude to all places where it is necessary to prevent happy not working with grammar files that include

import Prelude hiding (... something ...)
import qualified Prelude

(Where "all places" is defined as the list of locations that https://github.com/simonmar/happy/pull/135 found necessary to change. Since that over there compiles, I think there is a guarantee here that no relevant place was missed.)

I don't see any possibility of problems with this pull request concerning any current use of Happy, since it is a completely conservative change.

A more complete fix can still be attempted later, but I hope this here is acceptable.

jvoigtlaender commented 4 years ago

Additional note: It is "a completely conservative change" except for grammar files that deliberately rely on Happy not qualifiying its uses of Prelude functions, to inject other functions into calls made from inside Happy-generated code. I don't know wheter such grammar files exist out there, but if so, I would say they are conceptually broken, since they shouldn't rely on specific code being generated by Happy.

simonmar commented 4 years ago

Ok, let's go with this. Thanks!