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

Replace private modifier node with field on supporting types #11346

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

kazcw
Copy link
Contributor

@kazcw kazcw commented Oct 16, 2024

Pull Request Description

Eliminate private modifier-node: private is a field in supporting types, or a single-token node in the case of private declarations.

Important Notes

  • Rust parser tests: Switch to a builder-style API for defining expected Function ASTs to allow further changes to Function fields without rewriting all the tests again.
  • TreeToIr: Fix discarded module-level diag; add a test that covers module diagnostics.
  • Syntax: Disallow private methods in function blocks. (Previously this was enforced in the compiler.)

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@kazcw kazcw self-assigned this Oct 16, 2024
@kazcw kazcw added the CI: No changelog needed Do not require a changelog entry for this PR. label Oct 16, 2024
@kazcw kazcw marked this pull request as ready for review October 16, 2024 22:29
… types.

Also:
- Rust parser tests: Switch to a builder-style API for defining expected
  `Function` ASTs to allow further changes to `Function` fields without
  rewriting all the tests again.
- TreeToIr: Fix discarded module-level `diag`; add a test that covers module
  diagnostics.
- Syntax: Disallow `private` methods in function blocks.
private
private
""");
assertSingleSyntaxError(
Copy link
Member

Choose a reason for hiding this comment

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

Can we (should we) verify:

private

private plus x y = x + y

works? CCing @AdRiley.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no risk of rejecting this due to the one-private-declaration-per-module rule--the second private is not a declaration but a field of the Function.

Comment on lines +193 to +199
Some(statement) => Tree::app(
private.with_error(match visibility_context {
VisibilityContext::Public => SyntaxError::StmtUnexpectedPrivateSubject,
VisibilityContext::Private => SyntaxError::StmtUnexpectedPrivateContext,
}),
statement,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

It took me a good while to understand, why do we always set error here. I assumed that the responsibility of this function is to make statement a private object, not that it is already applied and any excessive private is an error. Please rename/add short docs for this function.

Comment on lines 96 to 99
fn into_private_keyword(item: Item) -> token::PrivateKeyword {
let Item::Token(keyword) = item else { unreachable!() };
let token::Variant::PrivateKeyword(variant) = keyword.variant else { unreachable!() };
keyword.with_variant(variant)
Copy link
Contributor

Choose a reason for hiding this comment

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

The same function is in statement.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented some downcasting helpers so we don't need a special function for this case.

Comment on lines 130 to 133
for token in keywords {
let Item::Token(keyword) = token else { unreachable!() };
let token::Variant::PrivateKeyword(variant) = keyword.variant else { unreachable!() };
let keyword = keyword.with_variant(variant);
Copy link
Contributor

Choose a reason for hiding this comment

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

Another into_private_keyword logic

Comment on lines 107 to 109
/// A `private` declaration.
Private {
pub keyword: token::Private<'s>,
pub body: Option<Tree<'s>>,
pub keyword: token::PrivateKeyword<'s>,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is for making a module private, right? I would then add this info here.

@kazcw kazcw added the CI: Ready to merge This PR is eligible for automatic merge label Oct 22, 2024
@mergify mergify bot merged commit d278ad6 into develop Oct 22, 2024
41 of 42 checks passed
@mergify mergify bot deleted the wip/kw/private-field branch October 22, 2024 16:26
mergify bot pushed a commit that referenced this pull request Oct 22, 2024
Move type-signature lines into `Function` field. Also implements #11293.

Stacked on #11346.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants