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

Add Cursor documentation #721

Merged
merged 8 commits into from
Oct 16, 2024
Merged

Add Cursor documentation #721

merged 8 commits into from
Oct 16, 2024

Conversation

yamaguchi1024
Copy link
Member

No description provided.

Copy link

codecov bot commented Oct 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.95%. Comparing base (3541352) to head (c6904a8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #721   +/-   ##
=======================================
  Coverage   87.95%   87.95%           
=======================================
  Files          86       86           
  Lines       20922    20922           
=======================================
  Hits        18402    18402           
  Misses       2520     2520           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

docs/Cursors.md Outdated

All `Cursor` types provide these common methods:

- `c.parents()`: Returns cursor to parent node in Exo IR
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be c.parent()? Also, per-cursor-type semantics should be defined. For example, that the parent of a gap cursor is not the anchor statement.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks!!

- `delta_lo`/`delta_hi` specify statements to add at start/end; `None` means expand fully
- Ex. in `s1; s2; s3`, if `c` is a `BlockCursor` pointing `s1; s2`, then `c.expand(0, 1)` returns a new `BlockCursor` pointing `s1; s2; s3`
- `BlockCursor.before()`: Returns `GapCursor` before block's first statement
- `BlockCursor.after()`: Returns `GapCursor` after block's last statement
Copy link
Contributor

Choose a reason for hiding this comment

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

Also c.body(), c.orelse(), and indexing and slicing BlockCursor. (I know the body and orelse are described later but I feel it logically should be repeated here as at least for me the navigation section is where I'd intuitively first look, not the specific per-subclass documentation).

Copy link
Member Author

Choose a reason for hiding this comment

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

c.body(), c.orelse() are navigations on ForCursor not on BlockCursor though? Index slicing is a great point!

Copy link
Contributor

Choose a reason for hiding this comment

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

Right this could go in the StmtCursor documentation. Ideal level-of-detail is probably to mention c.body() works for for and if statements, c.orelse() only works for if statements with an else clause. And defer the detail about subtypes and the InvalidCursor for c.orelse() until later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok will do!

docs/Cursors.md Outdated
else:
orelse
```
Returns an invalid cursor if `orelse` isn't present.
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 specific to the orelse() method, I'd cut this sentence and explain this in the orelse documentation

docs/Cursors.md Outdated

To forward a cursor `c` from `p` to `p'`, you can use the `forward` method on the new procedure:
```python
c' = p'.forward(c)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if the c-prime, p-prime notation is required by convention, but it causes weird syntax highlighting for me (the assignment is highlighted in the string literal color).

- `c.before()`: Returns `GapCursor` to space immediately before this statement
- `c.after()`: Returns `GapCursor` to space immediately after this statement
- `c.as_block()`: Returns a `BlockCursor` containing only this one statement

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also advertise the StmtCursor.expand() shorthand here. It's actually quite useful for correctly handling the else case (when learning cursors I didn't know about expand and hacked together StmtCursor.parent().body() which is incorrect when the StmtCursor points inside an orelse).

- `cond() -> ExprCursor`: Returns a cursor to the if condition expression.
- `body() -> BlockCursor`: Returns a cursor to the if body block.
- `orelse() -> Cursor`: Returns a cursor to the else block (if present).

Copy link
Contributor

Choose a reason for hiding this comment

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

orelse() -> BlockCursor | InvalidCursor: Returns a cursor to the else block if present, otherwise returns an invalid cursor.


So in summary, `p.forward(c)` computes and applies the composite forwarding function to map cursor `c` from its original procedure to the corresponding location in procedure `p`.


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 overall really clear documentation, thank you!

@yamaguchi1024 yamaguchi1024 marked this pull request as ready for review October 16, 2024 00:14
@yamaguchi1024
Copy link
Member Author

@akeley98 I addressed your comments and also added more texts, can you take a look again?

Copy link
Contributor

@akeley98 akeley98 left a comment

Choose a reason for hiding this comment

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

Good improvements! After fixing the typo ("InvalidCurso"), I think this is good to merge.

docs/Cursors.md Outdated
Methods:
- `cond() -> ExprCursor`: Returns a cursor to the if condition expression.
- `body() -> BlockCursor`: Returns a cursor to the if body block.
- `orelse() -> BlockCursor | InvalidCurso`: Returns a cursor to the else block if present, otherwise returns an invalid cursor.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing 'r'

@yamaguchi1024 yamaguchi1024 enabled auto-merge (squash) October 16, 2024 18:45
@yamaguchi1024 yamaguchi1024 merged commit 36a8ec4 into main Oct 16, 2024
9 checks passed
@yamaguchi1024 yamaguchi1024 deleted the docs branch October 16, 2024 20:01
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.

2 participants