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

[DO NOT MERGE] Proposed Core reorganization for C++29 #7272

Closed
wants to merge 18 commits into from

Conversation

AlisdairM
Copy link
Contributor

@AlisdairM AlisdairM commented Sep 29, 2024

This PR, a response to #2252, shows a vision for re-ordering the Core
clauses around program construction for C++26. This is based on the
working draft of 2024/09/29. The intent is to show direction, and
submit a series of incremental PRs if positively reviewed.

The most significant changes are:

  • Rename [lex] as Program construction, as it is more than mere Lexical conventions
  • arrange the lex subclauses to better follow the phases of translation
  • group [lex] subclauses by phase, introducing new subclauses to support the groups
    • move all the preprocessor tokens (phase 3) below a new subtitle to better group them
    • MERGE [cpp] INTO PLACE AS PHASE 4
    • Move linkage (as Names and linkage) from [basic] to represent phase 8
    • Move program execution from [basic] to represent phase 9
  • split the literals subclause into 2, to reflect string literals are in the preprocessor, but arithmetic literals are phase 7
  • move overloading before classes, as it completes the notion of functions
  • redistribute exception handling, mostly into [stmt], as it completes our set of control flows

This rework moves words and sections around but, other than introducing a couple
of introductory sentences, does not change any of the text itself. Further clarification
and simplification that does edit the text could usefully follow, especially looking to
clarify further the separation of preprocessor to translation unit grammar where the
same terms are overloaded.

In addition there are a variety of small edits, improving local clarity, but again,
only by moving existing words around and not redrafting.

Overall, I find this proposed structure very helpful, as I better understood a
number of parsing issues, mostly preprocessing issues that I did not always
realise were preprocessing, but cannot be sure how much of my new understanding
comes from being involved in making the transformation itself.

@AlisdairM AlisdairM force-pushed the FULL_CORE_REWORK branch 5 times, most recently from ce857d9 to 9e4cfff Compare October 2, 2024 12:47
Per comment on issue cplusplus#5315.
Thanks to Jonathan Wakely for the notion of tautonyms.
Oops.  Clearly the section describing the diffs against C++23
was not present in C++23 itself.
…apters

This PR should show no difference in the rendered document, but
will make it much easier to refactor the Core clauses in the
future --- just as we can refactor Library clauses today.
The current contents of [basic.pre] jump between specifying
different things.  This PR moves all the specification of
names to the front, followed by the specification of entities.

There are two main benefits: (1) the specification for when
two names are the same is a list of 4 rules that correspond
to the 4 things than can form a name --- the connection is
much clearer when the paragraphs are adjacent and the list
is sorted to the same order; (2) in this form, even though
all the words are the same, the reordering and merging of
paragraphs a fit on a single page.  The very last paragraph
was forced over a page-break in the original layout.
…on unit

The definition of program at the top of [basic.link] should move to
the front of [lex.separate] so that it is defined before its first
usage, and also clarifies that the phases of translation produce.

Similarly, move the definition of the grammar production translation-unit
to the top of the first clause to actually use it, [module.unit].

Finally, retitle [basic.link] as just Linkage, rather than
prgrams and linkage.
This PR purely moves existing words around, and does not create any
new content.  It would be the precursor to a larger change set that
might integrate [cpp] into lex, or move it adjactent, and similarly
move [modules] adjactent.

This may be more significant than we want to land in C++26, but I
offer it while time is still available, and as inspiration for the
C++29 reorg otherwise.
The grammar for universal-character-name is oddly sandwiched into the
middle of the subcluase talking about the different character sets used
by the standard.  To improve the flow, extract that grammar into its own
subclause.

In the extraction, I make two other clarifying changes.  First, describe
this new subclause as 'a way to name any element of the of the tranlation
character set using just the basic character set' rather than simply
'a way to name other characters'.  Secondly, remove the 'one of' in the
grammar where there is only one option to choose.
Also, merge the sentence on where universal characters
are prohibited into the sentence describing universal
characters, to make clear that there is no contradiction
between nominating a character, and how that character
can be used.
This commit makes substantial changes to the organization of
the Core clauses, without changing wording.  Notably, [lex]
is now titled as Program construction rather than Lexical
conventions, as its contents are significatly more than mere
conventions, and with the phases of translation detail how a
program is constructed and built.

[lex] itself is now more clearly modeled after the phases of
translation for each of the level 2 subheadings, grouping the
relevant specification for how to process each phases that
needs more than the simple text in the phases themsevles.

The whole Core sections are reorganized, promoting overload
and exception handling above classes and templates.  The idea
is that overloading is relevant to understanding how functions
are called, while functions are well specified before we get
to classes and templates. Exception handling moves forward as
the last control flow, which is relevant for functions before
we get to defining classes.  Classes still precede templates,
as clearly we support both function and class templates.

For neatness, we integrate the fix for tautonyms in stable
labels. Finally, we try to disentagle some of the wording
around basic definitions of names etc.
This commit completes the planned Core reorganization by
merging the preprocessor properly into Program construction,
placed consistently for phase 4 of translation. The subclauses
of [cpp] are similarly reorganized to put the more primitive
functionality first, and putting the module related text up
front, consistent with the order of the grammar.  We finally
bring the prohibition on defining keywords as macros out of
the library introduction and directly into the specification
for keywords.

This is around the limit of what can be achieved before
rewriting text to further reduce duplication, and to make
the distinction of preprocessor-identifiers and TU-identifiers
clear.
This completes the large-scale reorganization to move the text
corresponding to the phases of translation for constructing
programs into the same clause.  Names and linkage correspond
closely to phase 8, while program execution is the essence
of phase 9.  The [basic] clause has been rearranged to reflect
the new structure.
@AlisdairM
Copy link
Contributor Author

Note that this PR introduces two new overfull hbox warning, which at least guarantees we cannot accidentally merge!

The new warning arise as [dcl] becomes clause 10 rather than clause 9, and so cross-references are ever so slightly wider.
I feel no urgency to fix these as this PR is for a direction review, rather than a specific proposal.

@AlisdairM
Copy link
Contributor Author

As this is essentially a request-for-feedback for a direction for a C++29 core clause re-org, it would merit the C++29 milestone as it is not intended to land for C++26.

However, I plan to close this PR after the editors meeting at Wrocław, so it may be too short lived for that to be worthwhile?

@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Oct 17, 2024
@jensmaurer jensmaurer added this to the C++29 milestone Oct 17, 2024
@AlisdairM
Copy link
Contributor Author

This PR was created as a proof of concept, to help inform #7399. It has served its time as it will not be maintained and continue to fall further and further behind the main branch. Closing, and future such branches will be maintained in personal forks and shared that way, rather than submitted as PRs.

@AlisdairM AlisdairM closed this Dec 7, 2024
@AlisdairM AlisdairM deleted the FULL_CORE_REWORK branch December 17, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs rebase The pull request needs a git rebase to resolve merge conflicts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants