Skip to content

Make the "typechecked function body" request more central and resilient #70027

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 4 commits into from
Nov 27, 2023

Conversation

DougGregor
Copy link
Member

The "typechecked function body" request was defined to type-check a
function body that is known to be present, and not skipped, and would
assert these conditions, requiring its users to check whether a body
was expected. Often, this means that callers would use getBody()
instead, which retrieves the underlying value in whatever form it
happens to be, and assume it has been mutated appropriately.

Make the "typechecked function body" request, triggered by
getTypecheckedBody(), more resilient and central. A NULL result is
now acceptable, signifying that there is no body. Clients will need to
tolerate NULL results.

  • When there is no body but should be one, produce an appropriate
    error.
  • When there shouldn't be a body but is, produce an appropriate error
  • Handle skipping of function bodies here, rather than elsewhere.

Over time, we should move clients off of getBody and hasBody
entirely, and toward getTypecheckedBody or some yet-to-be-introduced
forms like getBodyAsWritten for the pre-typechecked body.

Yet more preprocessor metaprogramming to eliminate per-macro-role boilerplate
in the compiler. This time, focused on mangling, demangling, and remangling
of the accessor macro roles.
The "typechecked function body" request was defined to type-check a
function body that is known to be present, and not skipped, and would
assert these conditions, requiring its users to check whether a body
was expected. Often, this means that callers would use `getBody()`
instead, which retrieves the underlying value in whatever form it
happens to be, and assume it has been mutated appropriately.

Make the "typechecked function body" request, triggered by
`getTypecheckedBody()`, more resilient and central. A `NULL` result is
now acceptable, signifying that there is no body. Clients will need to
tolerate NULL results.

* When there is no body but should be one, produce an appropriate
error.
* When there shouldn't be a body but is, produce an appropriate error
* Handle skipping of function bodies here, rather than elsewhere.

Over time, we should move clients off of `getBody` and `hasBody`
entirely, and toward `getTypecheckedBody` or some yet-to-be-introduced
forms like `getBodyAsWritten` for the pre-typechecked body.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 3f06b5e into swiftlang:main Nov 27, 2023
@DougGregor DougGregor deleted the typechecked-function-body branch November 27, 2023 04:57
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.

1 participant