Skip to content

[6.2] [Strict memory safety] Provide argument-specific diagnostics for calls #81125

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
wants to merge 6 commits into
base: release/6.2
Choose a base branch
from

Conversation

DougGregor
Copy link
Member

  • Explanation: Similar to what we do for 'throws' checking, perform argument-specific checking for unsafe call arguments. This provides more detailed diagnostics when passing values of unsafe type (identifying the specific call argument and types), makes the use of nil not be considered safe (reducing false positives), and makes it okay to call a function returning an unsafe type if there are no unsafe arguments. (The use of the return value will trigger issues when appropriate).
  • Scope: Code changes are mostly limited to effects checking (which also checks for correct try and await unexpressions). This will remove some warnings under strict memory safety mode, but otherwise should have no effect.
  • Issues: rdar://150101617
  • Original PRs: [Strict memory safety] Provide argument-specific diagnostics for calls #81120
  • Risk: Low. The changes are limited to strict memory safety mode.
  • Testing: CI, audited all "unsafe" changes to the standard library and friends.

When we look through a "self" application while decomposing a function
call in effects checking, keep track of whether we did so. Use this to
ensure that we get the right parameter types when looking at the
"self" application vs. the outer call.

This has always been wrong, but the async/throws effects don't ever
matter for the innermost application (i.e., for `x.m`), so the
inconsistency didn't come up.

(cherry picked from commit 0b264e2)
Similar to what we do for 'throws' checking, perform argument-specific
checking for unsafe call arguments. This provides more detailed failures:

```
example.swift:18:3: warning: expression uses unsafe constructs but is not
marked with 'unsafe' [#StrictMemorySafety]
16 |   x.f(a: 0, b: 17, c: nil)
17 |
18 |   x.f(a: 0, b: 17, c: &i)
   |   |                   `- note: argument 'c' in call to instance
method 'f' has unsafe type 'UnsafePointer<Int>?'
   |   `- warning: expression uses unsafe constructs but is not marked
with 'unsafe' [#StrictMemorySafety]
19 |   unsafeF()
20 | }
```

It also means that we won't complain for `nil` or `Optional.none`
arguments passed to unsafe types, which eliminates some false
positives, and won't complain about unsafe result types when there is
a call---because we'd still get complaints later about the
actually-unsafe bit, which is using those results.

Fixes rdar://149629670.

(cherry picked from commit ee9487b)
…e" in _SwiftifyImport expansions

We need to improve on the macro so it doesn't generate unnecessary
"unsafe" expressions.

(cherry picked from commit 81b68e5)
…alls

We've been missing this case forever, but it hadn't come up until
we performed "unsafe" checking on calls.

(cherry picked from commit 60f7d20)
These should not be escalated to errors when other strict memory safety
warnings are, because they aren't safety issues. They could go into a
separate group along with the corresponding try and await diagnostics.

(cherry picked from commit 02e1d11)
@DougGregor DougGregor requested a review from a team as a code owner April 26, 2025 16:07
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

For anyone looking closely, I dropped the last commit from the main PR, because I don't want to do the extra "unsafe" effects checking on 6.2 unless strict memory safety is enabled.

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