Skip to content

docs: Overhaul the documentation for SIL and add a new SIL printing mode #77714

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

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Nov 19, 2024

The main changes in the documentation are:

  • Created a new directory docs/SIL and moved all SIL-related files into this directory.

  • Converted rst files to markdown.

  • Extracted sections from SIL.md which go into very much detail - including the instruction reference - into separate files: Types.md, Ownership.md, FunctionAttributes.md, Instructions.md. Those files are referenced from SIL.md at the relevant places.

  • Rewrote and updated the OSSA part in SIL.md

  • Removed a few sections, which are not relevant anymore, like "Value dependency" (which is replaced by ownership concepts).

  • Fixed and improved a lot of small things.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Just some small flow comments.

- `@owned`: A value that exists independently of any other value and is
consumed exactly once along all control flow paths through a function.
"Consuming" the value means that it is either destroyed (via `destroy_value`)
or consumed by a consuming instruction (e.g. stored to memory with `store`).
Copy link
Contributor

Choose a reason for hiding this comment

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

e.g. -> e.x.

e.g. means that is... I think you mean for example which is e.x.

Copy link
Contributor

@nate-chandler nate-chandler Nov 20, 2024

Choose a reason for hiding this comment

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

e.g. -- for example ( https://en.wiktionary.org/wiki/e.g. )
i.e. -- that is ( https://en.wiktionary.org/wiki/i.e. )

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 alarmed to see e.x. anywhere in our docs. what is that?

docs/SIL/SIL.md Outdated

- Forwarding instructions end owned lifetimes and immediately produce a new
owned value, which introduces a separate lifetime. The combined lifetimes over
all forwarding instructions is called _forward-extended_ lifetime.
Copy link
Contributor

Choose a reason for hiding this comment

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

"the forward-extended lifetime of the value". Or something like that.

On another note, I like the diagram below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A forward-extended lifetime does not refer to a single value. It involves multiple values, even multiple definitions (producers).
I think this is important to know and I added a paragraph+example for this.


### Lexical Lifetimes and Deinit Barriers

The optimizer is free to shrink lifetimes (e.g. by hoisting `destroy_value`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is another case where you mean e.x. instead of e.g.


```
+------+
+-------- | None | ---------+
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe ignore the merging comment I made, since we talk about it here.

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

💯 on

  • -emit-pure-sil
  • documentation structure
  • OSSA examples (they look familiar, good to have them in the docs)

I don't think we need to worry about typos here or there in this PR

@eeckstein eeckstein force-pushed the improve-sil-doc branch 2 times, most recently from ecdef76 to 4b98fb5 Compare November 20, 2024 12:56
@rjmccall
Copy link
Contributor

rjmccall commented Nov 20, 2024

I love the SIL documentation restructuring, that seems great.

Having a SIL printing mode that suppresses all the theoretically-helpful comments feels like a totally reasonable feature, albeit one that should be added in a separate PR from the docs rework. I don't like the idea of having multiple dialects of SIL itself, though — if we agree that this is a better way to write SIL, we should just change SIL. (We can probably write a script to mass-update the tests.)

The idea of removing types from printed operands is interesting. A lot of instructions already avoid operand types when they're redundant with other information in the instruction, and that's something we could pretty easily just do more of without dramatically changing how we parse SIL. If we want to do it in general by propagating type information from the value definition, we're going to run into the problem that basic blocks are not required to appear in an order consistent with dominance — SILGen usually (always?) emits them this way, but CFG optimizations can definitely mess that up. The general solution to that problem is to introduce a parse tree, although I suppose we could also just recognize that we're processing out of order and skip tokens until we reach the next block. Or we could make operand types optional and then only print them when blocks are rendered out of order? Or maybe when we've already rendered that instruction — the difference being that we'd sometimes still print operand types when rendering a subset of the function, e.g. when dumping a single instruction or basic block.

With a focus on updating the documentation of Ownership SSA.

The main changes are:

* Created a new directory `docs/SIL` and  moved all SIL-related files into this directory.

* Converted `rst` files to markdown.

* Extracted sections from `SIL.md` which go into very much detail - including the instruction reference - into separate files: `Types.md`, `Ownership.md`, `FunctionAttributes.md`, `Instructions.md`. Those files are referenced from `SIL.md` at the relevant places.

* Rewrote and updated the OSSA part in `SIL.md`

* Removed a few sections, which are not relevant anymore, like "Value dependency" (which is replaced by ownership concepts).

* Fixed and improved a lot of small things.
@eeckstein
Copy link
Contributor Author

one that should be added in a separate PR from the docs rework.

Yes, that makes sense. I removed the SIL printing commit and will put it into a separate PR.

@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein enabled auto-merge November 21, 2024 07:57
@eeckstein eeckstein merged commit 214d3e3 into swiftlang:main Nov 21, 2024
3 checks passed
@eeckstein eeckstein deleted the improve-sil-doc branch November 21, 2024 14:35
NinjaLikesCheez added a commit to NinjaLikesCheez/swift-org-website that referenced this pull request Jan 9, 2025
0xTim pushed a commit to swiftlang/swift-org-website that referenced this pull request Jan 9, 2025
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.

5 participants