Skip to content

Simplify augmentations. #4357

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Simplify augmentations. #4357

wants to merge 3 commits into from

Conversation

munificent
Copy link
Member

  • Remove references to macros.
  • Don't allow augmentations to wrap or replace code. Remove support for augmented expressions. Disallow an augmentation from providing a body to a declaration that already has one.
  • Remove support for augmenting variables.
  • Simplify constructor augmentations: no concatenating initializers or merging initializers from one augmentation and a body from another.
  • Remove support for augmenting typedefs.
  • Remove support for augmenting redirecting constructors.
  • Allow a function augmentation to have an external body.

There are still more changes I'd like to make. In particular, the grammar for members seems pretty hairy and I suspect could be refactored to be simpler, but I'm not sure if that will cause problems for other people who rely on the existing grammar rules.

- Remove references to macros.
- Don't allow augmentations to wrap or replace code. Remove support for `augmented` expressions. Disallow an augmentation from providing a body to a declaration that already has one.
- Remove support for augmenting variables.
- Simplify constructor augmentations: no concatenating initializers or merging initializers from one augmentation and a body from another.
- Remove support for augmenting typedefs.
- Remove support for augmenting redirecting constructors.
- Allow a function augmentation to have an `external` body.

There are still more changes I'd like to make. In particular, the grammar for members seems pretty hairy and I suspect could be refactored to be simpler, but I'm not sure if that will cause problems for other people who rely on the existing grammar rules.
@munificent munificent requested review from lrhn and eernstg May 6, 2025 03:17
Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More shorter, more better!
I have a gazillion nitpicks and some questions (which might suggest that something could be said to answer that question, or which might suggest that I only read the changed parts and therefore lacked some context.).
And some comments that are better left for later.

Good clean-up!

@munificent
Copy link
Member Author

cc @johnniwinther @scheglov in case you have thoughts on how this would affect the implementation.

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this is great! In particular, I appreciate the amount of regularization and simplification which is achieved by omitting some well-chosen elements.

Added a bunch of comments, of course. In particular, I think we should split out the discussions about the scoping (and possibly handle them during updates of the 'Part files with imports' feature spec).

Likewise, if an introductory class declaration has a generative constructor,
then the reader assumes they can inherit from that class and call that as a
superclass constructor. Therefore, an augmentation of the class is prohibited
from changing the constructor to a factory.

## Syntax

The grammar changes are fairly simple. The grammar is modified to allow an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true that the spec parser contains all language features (such that it can be used to find syntax errors in tests involving features during their implementation). This ensures that it has been tested with new code which has been considered by authors/reviewers of tests, and also by implementation teams.

In other words, the spec parser is a rather practical tool when we need to ensure alignment with the current implementation.

There is no explicit marking of parts of Dart.g that are part of specific language versioned updates. The commit log in the topmost comment in Dart.g does have a reference to a language feature when it is introduced, but some language features have given rise to multiple updates (because the feature evolved in the meantime).

I think it makes sense to use Dart.g (this seems to be the case already), and thus include some features (like class modifiers), even though this doesn't map directly back to the grammar in the currently committed version of dartLangSpec.tex.

Another possibility could be to switch to PR #2605 (the proposed null safety update of the language specification) and run tools/plaintext_grammar.dart on that version of dartLangSpec.tex. However, this introduces yet another level of potential change before that PR is landed, and it doesn't have the ongoing sanity check relative to the implementation.


## Dynamic semantics

The application of augmentation declarations to an augmented declaration
produces something that looks and behaves like a single declaration: It has
a single name, a single type or function signature, and its what all
a single name, a single type or function signature, and it's what all
references to the *name* refers to inside and outside of the library.

Unlike before, that single *semantic declaration* now consists of multiple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on line 896, but I think it would be a good idea to replace non-augmenting by introductory, for consistency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 928 ends in "the C doe". That sentence needs to be revised and completed. Also, the occurrence of abstract (in code font) in a description of an "abstract method" is confusing: The method is abstract, but it can't contain the keyword abstract.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, I'm not even really sure what this "Dynamic Semantics" section is all about. As far as I'm concerned, all we need to do is specified how augmentations are applied and then the resulting declaration's dynamic semantics are exactly as if you had written everything in one declaration (modulo scoping across part files, of course).

This looks like @lrhn's writing style. (@kallentu and I were coincidentally discussing today how we can tell who wrote each part of a spec 😄 ). @lrhn, do you know what this is supposed to be completed with? Do we need this section at all?

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.

6 participants