Skip to content

[NFC] SILFunctionArgument and ApplySite docs and comments. #18119

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 2 commits into from
Jul 27, 2018
Merged

[NFC] SILFunctionArgument and ApplySite docs and comments. #18119

merged 2 commits into from
Jul 27, 2018

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jul 20, 2018

This is in response to recurring bugs, a recently noticed bug, and feedback that the APIs don't make sense.

@atrick
Copy link
Contributor Author

atrick commented Jul 20, 2018

@gottesmm I would appreciate your review.

@gottesmm
Copy link
Contributor

Looking at this real quick while I am waiting for xcode to install...

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.

This is a great start! Some initial feedback.

@@ -0,0 +1,159 @@
# SIL Development
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not follow the lead of the standard libraries programmer's manual: StandardLibraryProgrammersManual.md. This would then by SILProgrammersManual.md. Matching the name would make it really obvious that these are related concepts and make this document more discoverable.

`ApplySite::getCalleeArgIndexOfFirstAppliedArg()` to translate the
apply's arguments into function convention arguments.

Convenience methods exist for the most common uses, so there is
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful to have several small examples here of these convenience methods/common use cases. I don't think you state what those are anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe I am confused? Not sure.

Throughout the compiler, integer indices are used to identify argument
positions in several different contexts:

- `SILFunctionType` parameters.
Copy link
Contributor

Choose a reason for hiding this comment

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

For each of these can you provide links to the APIs for manipulated each one of these. An example of how to get this range of indices would be useful as well potentially.

- The SIL function definition's callee-side `SILFunctionArguments`,
including indirect results.

- Caller-side "applied arguments" for `apply` and `try_apply` (vs. operands).
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference in between an "applied argument" vs an operand? That is not defined anywhere.

> often copied into parts of the code where they are no longer valid; and (c)
> unlike LLVM IR, SIL is not stable and will continue evolving.

```
Copy link
Contributor

Choose a reason for hiding this comment

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

"As an example, consider the following swift code:"

One direct formal parameter and one direct formal result:

```
SILFunctionType(foo): $(0:T) -> @out T
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand what the 0 here is for but this isn't a proper sil type, no? Can you use a proper sil type and use the prose instead? Or maybe have names like FirstArgType? Not sure.

}
```

Ignoring conventions, the closure `foo` would map to the following indices...
Copy link
Contributor

Choose a reason for hiding this comment

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

"Ignoring the current compiler stage (and thus SILFunctionConventions)". It would make it clearer (for me anyways).

apply %closure(%result: $*T)
```

The mapping between SILFunctionType and SILFunctionArguments depends
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move this before the previous section? Then it would be clearer what you are trying to show.


A common mistake is to directly map the ApplySite's caller-side
arguments onto callee-side SILFunctionArguments. This happens to work
until the same code is exposed to a `partial_apply`. Always use
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the "bug" here that occurs by exposing to a partial apply.

Copy link
Contributor

Choose a reason for hiding this comment

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

(that is I think the error should be explicit in the prose).

atrick added 2 commits July 27, 2018 11:02
Document SILFunction and `apply` arguments.

Create TBD headers to give the document some form.
Use consistent terminology, clarify comments, and group APIs.
This matches the documentation in SILDevelopment.md.
@atrick
Copy link
Contributor Author

atrick commented Jul 27, 2018

@swift-ci smoke test.

@atrick
Copy link
Contributor Author

atrick commented Jul 27, 2018

@gottesmm thanks for reading the rough draft. I'm pushing this now to avoid upcoming merge conflicts on the cleanup, and I'm out of time for writing docs.

@eeckstein @shajrawi @aschwaighofer Please take a look at the SIL Programmers Guide. I want to make sure everyone working on SIL understands what's there and starts contributing to the doc.

@gottesmm
Copy link
Contributor

@atrick SGTM. What is important is that this is a first step. We can iterate.

@atrick atrick merged commit 401be14 into swiftlang:master Jul 27, 2018
@atrick atrick deleted the nfc-clarify-arg-index branch February 22, 2019 17:35
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