-
Notifications
You must be signed in to change notification settings - Fork 217
Simplify Extended_ast vs Std_ast #2791
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
hhugo
wants to merge
11
commits into
main
Choose a base branch
from
simplify-extended-std-ast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
214d208
Remove unused functions from Extended_ast and Normalize_extended_ast
hhugo aa17389
Break Source -> Extended_ast dependency cycle
hhugo 5c8d11f
Break Normalize_std_ast -> Normalize_extended_ast dependency
hhugo 5676b8c
Add paired GADT to Extended_ast
hhugo 7706073
Add equivalent, dump, dump_normalized, get_std to Extended_ast
hhugo 8868a7d
Absorb Parse_with_comments into Extended_ast, simplify Translation_unit
hhugo 0a0a0f5
Clean up Std_ast: remove Repl_file, Documentation, of_syntax, any_t
hhugo 9c3fbe0
Document why Std_ast exists
hhugo b2aaca5
Add doc comment to the paired type in Extended_ast
hhugo 6c9173a
Misc: fmt
hhugo 9fd00b4
Move parsing logic from Extended_ast back to Parse_with_comments
hhugo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand what this type provides. Do we want to keep the two AST paired anywhere outside of
Translation_unit?What are the benefits from moving the code from
Parse_with_commentsintoExtended_ast?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parse_with_comments.parse should only be used for "ocaml code", code parsed by the ocaml parser/lexer. It should not be used for
Documentationfor instance (it's wrong in the main branch).We need to dispatch on the syntax to call it only when appropriate, the dispatch is already done in Extended_ast, it feels natural to move it there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to minimize behavior changes in the PR.
We could probably parse the Std_ast only when needed in
equivalent, saving the parsing for files already properly formatted. If we go that direction, we would need to have access to the source as string so that we can parse the std_ast.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have the source as string in
Translation_unit, both before and after formatting. PerhapsParse_with_commentscould be extended with the dispatch ? (and possibly renamed)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can possible move back some parsing logic into Parse_with_comments. But I'm not sure it gives much benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added back Parse_with_comments.. Let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to see the point of keeping both
Parse_with_commentsand thepairedtype. I think I prefer to keepParse_with_commentsbecause otherwise, we just add a lot of code intoExtended_astthat in fact work with something else than the extended ast.I don't think the
equivalentfunction make much sense. It should be'a Std_ast.t -> ... -> 'a -> 'a -> ast_check_resultand not work with the extended AST at all.It also can reasonably be
string -> string -> ..and we could unifyStd_ast.tandExtended_ast.t:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The equivalent signature you propose forces to parse the same string multiple time when iterating to find a fix point. This is something Ive optimized long time ago in the early days of ocamlformat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equivalentcan't take a 'std because not all format have one.The Std_ast is pretty much an implementation detail of the check of some of the file format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Julow, think more about this. I wonder if we should inline fields from the "with_comment" record into Extended_ast.t.
The change would mean that an Extended_ast.t contains every thing needed for printing and checking.