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

Dyno: Default initializers for classes that inherit #26028

Merged
merged 13 commits into from
Oct 2, 2024

Conversation

benharsh
Copy link
Member

@benharsh benharsh commented Oct 2, 2024

This PR changes the frontend to start generating uAST for default initializers, which allows us to support default initializers on classes that inherit.

This PR replaces the current signature-based implementation for default initializers with uAST for a Function. This Function's body contains the suitable statements to initialize each field, as well as a "super.init" call if applicable. This code currently lacks suitable init-expressions for default-initializable formals, which is left as future work.

An UntypedFnSignature is built manually so that we can force resolution to accept non-existent default values for each formal, regardless of whether it has an init-expression or not.

The resulting TypedFnSignature is created with typedSignatureInitial. This might be overkill, but it keeps the code cleaner for the time being.


Now that default initializers have actual bodies, the frontend is attempting to resolve various assignment operators only defined in the internal/standard modules. This was initially a problem for the dedicated frontend tests, which do not generally load the internal modules in which basic assignment operators are implemented. This PR updates the frontend to generate assignment operators for primitive types, tuples, and classes when the standard library is not available.

Testing:

  • test-dyno

This commit replaces the current signature-based implementation for
default initializers with uAST for a Function. This Function's body
contains the suitable statements to initialize each field, as well as a
"super.init" call if applicable. This code currently lacks suitable
init-expressions for default-initializable formals, which is left as
future work.

An UntypedFnSignature is built manually so that we can force resolution
to accept non-existent default values for each formal, regardless of
whether it has an init-expression or not.

The resulting TypedFnSignature is created with `typedSignatureInitial`.
This might be overkill, but it keeps the code cleaner for the time
being.

Signed-off-by: Ben Harshbarger <[email protected]>
Now that default initializers have actual bodies, the frontend is
attempting to resolve various assignment operators only defined in the
internal/standard modules. This commit updates the frontend to generate
assignment operators for primitive types, tuples, and classes when the
standard library is not available.

Signed-off-by: Ben Harshbarger <[email protected]>
@benharsh
Copy link
Member Author

benharsh commented Oct 2, 2024

Note for reviewer: this might be easier to review commit-by-commit

frontend/lib/resolution/default-functions.cpp Outdated Show resolved Hide resolved
@benharsh benharsh merged commit 6086616 into chapel-lang:main Oct 2, 2024
7 checks passed
@bradcray
Copy link
Member

bradcray commented Oct 2, 2024

Nice!

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.

3 participants