FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Remove commented, old definition of the types context and pretty by mdesharnais · Pull Request #276 · polyml/polyml · GitHub

/ polyml Public

Remove commented, old definition of the types context and pretty - #276

Open
mdesharnais wants to merge 1 commit into
polyml:masterfrom
mdesharnais:refactor-pretty
Open

Remove commented, old definition of the types context and pretty#276
mdesharnais wants to merge 1 commit into
polyml:masterfrom
mdesharnais:refactor-pretty

Conversation

Copy link
Copy Markdown
Contributor

Hi @dcjm,
I was reading the PRETTY signature and at first confused why the definition of the types context and pretty was commented. I then understood that the types are kept abstract with type context and type pretty and that functions (two for context and three for pretty) are provided to build values of theses types. As the functions looked the same as in the comment, I wondered why the comment was kept there. I searched the Git log and found the following:

Commit 320ea5c (2009-12-19) replaced the datatypes context and pretty by definitions based on the type address. The new definition was kept abstract in the signature PRETTY (then called PRETTYSIG). The commit messages states that this "removes the requirement that the representation of a datatype must be the same in the compiler that compiled the compiler as in the compiler itself." The original datatype declarations were kept in a comment.

Commit 10e0dd0 (2016-06-28) changed the interface of the pretty type by replacing int by FixedInt.int. This changed was not performed in the old, commented datatype declaration.

I propose to remove the comments. The code of the current definition is quite readable and, as of now, the reader must compare the commented definitions with the actual code to which point they are the same. Removing the comments also avoids the comment getting out of sync with the code.

dcjm commented May 18, 2026

Copy link
Copy Markdown
Contributor

There is an explanatory comment in Pretty.sml at line 50 which says:

This is complicated because the data structures we use here will be exported into
the code produced by the compiler. We can't assume that the same representations
will be used by this version of the compiler as are used by the compiler that is
compiling this code. We use an explicit representation here which must be kept in
synch with the representation used in DATATYPE_REP.ML

I think it's useful to have the original definition commented out to indicate what the more abstract definition is intended to produce. The representation of datatypes has changed over time and there was a recent change (0694cd9) to the representation of datatypes with a single constructor with a recursive type.

Having said that, though, there is a case for removing this and reverting to using a straightforward datatype in both the signature and the structure. At the time of 320ea5c bootstrapping the compiler was a one-step process. Nowadays the bootstrap process involves compiling the compiler several times so the compiler used to compile the final compiler will use the same representation.

dcjm commented May 18, 2026

Copy link
Copy Markdown
Contributor

To add some further explanation: pretty and context are in effect defined in two different places. There is the definition in the PRETTY signature and Pretty structure but there is also a definition in the DATATYPE_REP functor (line 577 onwards). The former definition is used within the compiler, for example when it creates print functions for new types, and the latter definition is exported into ML code through INITIALISE_.ML and used by code compiled by the compiler e.g. user-written print functions. Clearly these need to use the same represention of the datatypes but there's no easy way to ensure that.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL