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

feat(compiler)!: Remove arbitrary per-file compiler flags, add acceptable options as module attributes #1804

Merged
merged 6 commits into from Mar 4, 2024

Conversation

alex-snezhko
Copy link
Member

@alex-snezhko alex-snezhko commented Apr 6, 2023

@noPervasives
@runtimeMode
module Example

Closes #1625

Copy link
Member

@spotandjake spotandjake left a comment

Choose a reason for hiding this comment

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

Im loving how much cleaner this looks, looks like you forgot to run the formatter thats why the tests are failing the attribute looks a lot cleaner then the comment though.

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

This is great ❤️ No shocker that I have opinions on the API. I'd also like to know if you can apply this to submodules in a file, since I think that would be :chefs-kiss:

cli/__test__/index.gr Outdated Show resolved Hide resolved
compiler/src/compile.re Outdated Show resolved Hide resolved
compiler/test/input/memoryBase/asserts.gr Outdated Show resolved Hide resolved
compiler/test/suites/arrays.re Outdated Show resolved Hide resolved
compiler/test/suites/print.re Outdated Show resolved Hide resolved
@alex-snezhko alex-snezhko changed the title feat(compiler)!: Per-file compiler flags as module attribute feat(compiler)!: Remove arbitrary per-file compiler flags, add acceptable options as module attributes Apr 11, 2023
Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

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

One comment and one question, but otherwise this looks good!

compiler/src/utils/config.rei Outdated Show resolved Hide resolved
compiler/test/suites/parsing.re Outdated Show resolved Hide resolved
Copy link
Member

@spotandjake spotandjake left a comment

Choose a reason for hiding this comment

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

Looks good to me :), one small question.

stdlib/runtime/wasi.gr Show resolved Hide resolved
Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

@alex-snezhko this needs to be updated for the new formatter. We'll probably need locations on the module attributes to handle comments between them too.

@alex-snezhko alex-snezhko force-pushed the grainc-flags-attr branch 2 times, most recently from 86edd36 to c3e4c0a Compare February 25, 2024 23:40
Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Had a few questions, but overall looks great

compiler/src/formatting/fmt.re Outdated Show resolved Hide resolved
compiler/src/parsing/parser.messages Show resolved Hide resolved
compiler/src/parsing/parser_header.re Outdated Show resolved Hide resolved
compiler/src/typed/env.rei Show resolved Hide resolved
compiler/src/typed/typed_well_formedness.re Show resolved Hide resolved
compiler/src/utils/config.re Outdated Show resolved Hide resolved
// Comment after first attr
@runtimeMode
// Comment after second attr

Copy link
Member

Choose a reason for hiding this comment

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

Should this newline be removed so attributes are always "hugging" the module?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the behavior for attributes on other items as well, maybe can address in a followup?

Copy link
Member

Choose a reason for hiding this comment

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

Please open an issue

Copy link
Member

Choose a reason for hiding this comment

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

Wait, you've added the formatter changes. You can just change the line ending. Right? We still need a follow up to fix the other ones though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looked into this and I think it would require making some invasive changes to the print_comment_range function to disallow double-breaks. I think we can just defer to #2055

compiler/test/grainfmt/comments.expected.gr Outdated Show resolved Hide resolved
compiler/test/grainfmt/comments.expected.gr Outdated Show resolved Hide resolved
@phated
Copy link
Member

phated commented Feb 29, 2024

@alex-snezhko since the location fix was landed in @ospencer's PR. Can you back out your changes/resolve conflicts here?

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Few more things

@alex-snezhko alex-snezhko force-pushed the grainc-flags-attr branch 3 times, most recently from dc87d08 to c20f159 Compare March 3, 2024 20:00
Comment on lines 6 to 7
enter_attribute: (attribute, attribute_context) => unit,
leave_attribute: (attribute, attribute_context) => unit,
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that you removed these. We might want to iter attributes at some point

Comment on lines 4017 to 4019
~none=hardline,
~lead=space,
~trail=hardline,
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure that the ~none and/or ~trail being hardline here are causing your extra newline in the attributes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't look like that fixed it; I think it's the fact that print_comment_range inserts phatom_hardline ++ phantom_hardline since line_delta > 1 between the comment and module header

Comment on lines 6 to 7
enter_attribute: attribute => unit,
leave_attribute: attribute => unit,
Copy link
Member

Choose a reason for hiding this comment

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

Can you put these back please? I don't see a reason to remove them

@@ -87,6 +83,7 @@ let iter_attributes = (hooks, attrs) => {

let rec iter_parsed_program = (hooks, {statements} as program) => {
hooks.enter_parsed_program(program);
iter_attributes(hooks, program.attributes);
Copy link
Member

Choose a reason for hiding this comment

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

What's going on here?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean? It's iterating over the attributes in the same way done with expressions and toplevels

@@ -1,3 +1,9 @@
// Comment before first attr
/* Block comment before attr */@noPervasives // Line comment on attr
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. It needs to have a space between */ and @

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like in other places it actually puts the block comment on its own line, which I think I prefer here

@ospencer ospencer enabled auto-merge March 3, 2024 23:23
@ospencer ospencer added this pull request to the merge queue Mar 4, 2024
Merged via the queue into grain-lang:main with commit 72b2139 Mar 4, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

grainc-flags as module attribute
5 participants