Commit Graph

20496 Commits

Author SHA1 Message Date
Pavel Yaskevich
ede7df67fc Merge pull request #72558 from xedin/improve-diag-for-same-type-req-in-opaque
[CSDiagnostics] Add a diagnostic for same-type/supertype requirement failures in…
2024-03-27 09:58:25 -07:00
Meghana Gupta
44b2c4d405 Merge pull request #72569 from meg-gupta/fixlifetime
Updates on lifetime dependence
2024-03-27 09:53:25 -07:00
Alejandro Alonso
5d0deaa4a3 Add Builtin.addressOfRawLayout 2024-03-27 09:47:01 -07:00
Allan Shortlidge
1e4549961c Merge pull request #72604 from tshortli/disallow-feature-suppression-attr
AST: Introduce `@_disallowFeatureSuppression` attribute
2024-03-26 21:57:58 -07:00
Meghana Gupta
11d5179587 Allow lifetime dependence inference on implicit initializers 2024-03-26 21:51:50 -07:00
fummicc1
4dda7efc0f [AST] Improve diagnostics message for swift users.
Use `initializer` instead of `constructor` because it is more official word to express its meaning.
2024-03-27 12:32:25 +09:00
Allan Shortlidge
b249503a2b AST: Introduce @_disallowFeatureSuppression attribute.
This attribute is the inverse of the existing `@_allowFeatureSuppression`
attribute.

Part of rdar://125138945
2024-03-26 17:27:57 -07:00
Meghana Gupta
a77b1e0b23 Update some lifetime dependence diagnostic messages 2024-03-26 14:56:56 -07:00
Pavel Yaskevich
25ce6604cd [CSDiagnostics] Add a diagnostic for superclass requirement failure in opaque return type 2024-03-26 12:07:14 -07:00
Pavel Yaskevich
08e93825d2 [CSDiagnostics] Add a diagnostic for same-type requirement failure in opaque return type
Follow-up to https://github.com/apple/swift/pull/72493
2024-03-26 11:11:30 -07:00
Michael Gottesman
d0d2f2d9b2 [region-isolation] Change the transfer non-transferrable value due to capture by an isolated closure diagnostic to be a named diagnostic.
rdar://125372790
2024-03-25 20:17:26 -07:00
Alex Lorenz
327b07bb0f Merge pull request #72534 from hyp/eng/win-dbg-trapz
[debuginfo][codeview] avoid using line zero artificial location for t…
2024-03-25 19:11:14 -07:00
Allan Shortlidge
ed77b8ff32 AST: #if hasAttribute(retroactive) should evaluate true.
The implementation of `#if hasAttribute(...)` only accepted declaration
attributes. It should also accept type attributes, like `@retroactive`.

Resolves rdar://125195051
2024-03-25 14:03:00 -07:00
Rintaro Ishizaki
c0d423a5f8 Merge pull request #72553 from rintaro/sourcekit-iterfacegen-newline
[SourceKit] Adjust newlines between decls
2024-03-26 06:00:11 +09:00
Alex Lorenz
8484c61f19 [debuginfo][codeview] avoid using line zero artificial location for traps when emitting codeview
This fixes an issue where the debug locations for Swift traps were dropped in the produced PDB files, as they were pointing to line 0

I validated this on a sample project using WinDbgx, which can now correctly trap on the same line in multiple places
2024-03-25 13:35:24 -07:00
Kuba (Brecka) Mracek
89cd62604b Merge pull request #72472 from kubamracek/embedded-keypaths
[embedded] Compile-time (literal) KeyPaths for Embedded Swift
2024-03-25 10:58:51 -07:00
Rintaro Ishizaki
7b3738d1d0 [SourceKit] Adjust newlines between decls
Previously, Clang modules didn't have empty lines between top-level
decls. This was inconsistent with Swift module.
2024-03-25 22:07:50 +09:00
Rintaro Ishizaki
b019fd0c1b Merge pull request #72420 from rintaro/sourcekit-clang-printer-rdar93731287
[SourceKit] Stop printing normal comments in clang generated interface
2024-03-25 17:29:45 +09:00
Meghana Gupta
0c2425ff25 Merge pull request #72506 from meg-gupta/changesyntax
Update lifetime dependence syntax and inference
2024-03-24 14:42:03 -07:00
Michael Gottesman
7d07fb5a11 [region-isolation] Add a named variant of the transfer via closure capture diagnostic.
Just converting another diagnostic to its final named form.
2024-03-23 21:17:41 -07:00
Michael Gottesman
5580bb4ba7 [region-isolation] Add a named variant of the use after pass via strongly transfering parameter.
Specifically, I added a named version of the diagnostic:

 func testSimpleTransferLet() {
   let k = Klass()
-  transferArg(k) // expected-warning {{binding of non-Sendable type 'Klass' accessed after being transferred; later accesses could race}}
+  transferArg(k) // expected-warning {{transferring 'k' may cause a race}}
+  // expected-note @-1 {{'k' used after being passed as a transferring parameter}}
   useValue(k) // expected-note {{use here could race}}
 }

and I also cleaned up the typed version of the diagnostic that is used
if we fail to find a name:

 func testSimpleTransferLet() {
   let k = Klass()
-  transferArg(k) // expected-warning {{binding of non-Sendable type 'Klass' accessed after being transferred; later accesses could race}}
-  transferArg(k) // expected-warning {{value of non-Sendable type 'Klass' accessed after being transferred; later accesses could race}}
   useValue(k) // expected-note {{use here could race}}
 }

This is the 2nd to the last part of a larger effort to rework all of
the region based diagnostics to first try and use names and only go back
to the old typed diagnostics when we fail to look up a name (which should
be pretty rare, but is always possible).

At some point if I really feel confident enough with the name lookup code, I am
most likely just going to get rid of the typed diagnostic code and just emit a
compiler doesnt understand error. The user will still not be able to ship the
code but would also be told to file a bug so that we can fix the name
inference.
2024-03-23 21:17:41 -07:00
Michael Gottesman
e347365c45 Merge pull request #72544 from gottesmm/pr-9b9437a095cb67aaf6c9f66f9c77174865b39be3
[region-isolation] Wordsmith "{access,use} here could race".
2024-03-23 20:11:59 -07:00
Meghana Gupta
b5ca933002 Update lifetime dependence syntax and inference as per changes in the pitch
Pitch - https://github.com/apple/swift-evolution/pull/2305

Changes highlights:

dependsOn(paramName) and dependsOn(scoped argName) syntax

dependsOn(paramName) -> copy lifetime dependence for all parameters/self except
                         when we have Escapable parameters/self, we assign scope
                         lifetime dependence.

Allow lifetime dependence on parameters without ownership modifier.

Always infer copy lifetime dependence except when we have
Escapable parameters/self, we infer scope lifetime dependence.

Allow lifetime dependence inference on parameters without ownership modifier.
2024-03-23 18:19:47 -07:00
Michael Gottesman
2f9b519758 [region-isolation] Wordsmith "{access,use} here could race".
I am doing this since it isn't always going to be an access. We may not have
memory. We are talking about uses here!

I was able to just use sed so it was an easy fix.
2024-03-23 17:19:09 -07:00
Konrad `ktoso` Malawski
6132386371 [Distributed] Complete handling of protocol calls and witnesses using adjusted mangling scheme (#72416) 2024-03-23 23:54:23 +09:00
Andrew Trick
f809d72507 Merge pull request #72504 from atrick/complete-ossa-flags
Options for complete OSSA lifetimes.
2024-03-22 16:53:42 -07:00
Michael Gottesman
9fcd80c42a Merge pull request #72510 from gottesmm/pr-380a7b07837e5ce43e7cad28e3f620a6776599f7
[region-isolation] Clean up use after transfer error to use the dynamic isolation information of the transfered operand value in its diagnostic message.
2024-03-22 16:13:51 -07:00
Michael Gottesman
357a53ab48 [region-isolation] Clean up use after transfer error to use the dynamic isolation information of the transfered operand value in its diagnostic message.
As an example of the change:

-  // expected-note @-1 {{'x' is transferred from nonisolated caller to main actor-isolated callee. Later uses in caller could race with potential uses in callee}}
+  // expected-note @-1 {{transferring disconnected 'x' to main actor-isolated callee could cause races in between callee main actor-isolated and local nonisolated uses}}

Part of the reason I am doing this is that I am going to be ensuring that we
handle a bunch more cases and I wanted to fix this diagnostic before I added
more incaranations of it to the tests.
2024-03-22 13:12:51 -07:00
Slava Pestov
336750effd Merge pull request #72495 from slavapestov/fix-protocol-superclass
AST: Remove ProtocolDecl::getSuperclass()
2024-03-22 07:40:46 -04:00
Andrew Trick
38d9557481 Options for complete OSSA lifetimes.
Adds
-disable-ossa-complete-lifetimes,
-enable-ossa-verify-complete,
-disable-ossa-verify-complete
2024-03-21 16:32:10 -07:00
Doug Gregor
b167eece42 Metadata and runtime support for suppressible protocol requirements
Introduce metadata and runtime support for describing conformances to
"suppressible" protocols such as `Copyable`. The metadata changes occur
in several different places:

* Context descriptors gain a flag bit to indicate when the type itself has
  suppressed one or more suppressible protocols (e.g., it is `~Copyable`).
  When the bit is set, the context will have a trailing
  `SuppressibleProtocolSet`, a 16-bit bitfield that records one bit for
  each suppressed protocol. Types with no suppressed conformances will
  leave the bit unset (so the metadata is unchanged), and older runtimes
  don't look at the bit, so they will ignore the extra data.
* Generic context descriptors gain a flag bit to indicate when the type
  has conditional conformances to suppressible protocols. When set,
  there will be trailing metadata containing another
  `SuppressibleProtocolSet` (a subset of the one in the main context
  descriptor) indicating which suppressible protocols have conditional
  conformances, followed by the actual lists of generic requirements
  for each of the conditional conformances. Again, if there are no
  conditional conformances to suppressible protocols, the bit won't be
  set. Old runtimes ignore the bit and any trailing metadata.
* Generic requirements get a new "kind", which provides an ignored
  protocol set (another `SuppressibleProtocolSet`) stating which
  suppressible protocols should *not* be checked for the subject type
  of the generic requirement. For example, this encodes a requirement
  like `T: ~Copyable`. These generic requirements can occur anywhere
  that there is a generic requirement list, e.g., conditional
  conformances and extended existentials. Older runtimes handle unknown
  generic requirement kinds by stating that the requirement isn't
  satisfied.

Extend the runtime to perform checking of the suppressible
conformances on generic arguments as part of checking generic
requirements. This checking follows the defaults of the language, which
is that every generic argument must conform to each of the suppressible
protocols unless there is an explicit generic requirement that states
which suppressible protocols to ignore. Thus, a generic parameter list
`<T, Y where T: ~Escapable>` will check that `T` is `Copyable` but
not that it is `Escapable`, and check that `U` is both `Copyable` and
`Escapable`. To implement this, we collect the ignored protocol sets
from these suppressed requirements while processing the generic
requirements, then check all of the generic arguments against any
conformances not suppressed.

Answering the actual question "does `X` conform to `Copyable`?" (for
any suppressible protocol) looks at the context descriptor metadata to
answer the question, e.g.,

1. If there is no "suppressed protocol set", then the type conforms.
This covers types that haven't suppressed any conformances, including
all types that predate noncopyable generics.
2. If the suppressed protocol set doesn't contain `Copyable`, then the
type conforms.
3. If the type is generic and has a conditional conformance to
`Copyable`, evaluate the generic requirements for that conditional
conformance to answer whether it conforms.

The procedure above handles the bits of a `SuppressibleProtocolSet`
opaquely, with no mapping down to specific protocols. Therefore, the
same implementation will work even with future suppressible protocols,
including back deployment.

The end result of this is that we can dynamically evaluate conditional
conformances to protocols that depend on conformances to suppressible
protocols.

Implements rdar://123466649.
2024-03-21 14:57:47 -07:00
Michael Gottesman
56a3270adc Instead of linking libswiftAST into SwiftBasicTests, define ActorIsolation::dumpForDiagnostics out of line. 2024-03-21 14:36:43 -07:00
Michael Gottesman
e6a1d83ef8 [ast] Improve the debug dump for ActorIsolation.
Specifically, I made it so that when one calls dump(), we put in a newline
afterwards so we get a nice easy to read msg in the debugger. I also defined
dumpForDiagnostics() to make it easy to dump out in the debugger how the
ActorIsolation will show up in the diagnostics.
2024-03-21 14:16:20 -07:00
Michael Gottesman
e9cd2aee1f [ast] Implement ActorIsolation::Profile(...).
This enables one to use ActorIsolation in a FoldingSetNode. I also fixed the
hash combine of the type to contain state.silParsed (which I think was an
oversight).
2024-03-21 14:16:20 -07:00
Alexis Laferrière
42991a5232 Merge pull request #72460 from xymus/deser-space-fix
Serialization: fix extra space in diagnostic
2024-03-21 13:16:48 -07:00
Slava Pestov
1a7bdb46eb AST: Shave a yak in ProtocolDecl 2024-03-21 15:17:44 -04:00
Slava Pestov
839063cab0 AST: Remove ProtocolDecl::getSuperclass()/setSuperclass() 2024-03-21 15:15:59 -04:00
Rintaro Ishizaki
c9785d955d [SourceKit] Stop printing normal comments in clang generated interface
Generated interfaces for Clang modules used to try printing normal
comments between decls extracted from the header text. That was because
doc-comment was not common in C/ObjC headers. But mainly because of
"import as member feature" Clang decls aren't printed in the order as
they appear in the header file, the logic determinig which comment
belongs to which decl was not working property. We've decided to remove
that feature and only print the proper doc-comments as it has been
getting common.

rdar://93731287
2024-03-21 11:52:32 +09:00
Kuba Mracek
b642d771be [embedded] Compile-time (literal) KeyPaths for Embedded Swift
Enable KeyPath/AnyKeyPath/PartialKeyPath/WritableKeyPath in Embedded Swift, but
for compile-time use only:

- Add keypath optimizations into the mandatory optimizations pipeline
- Allow keypath optimizations to look through begin_borrow, to make them work
  even in OSSA.
- If a use of a KeyPath doesn't optimize away, diagnose in PerformanceDiagnostics
- Make UnsafePointer.pointer(to:) transparent to allow the keypath optimization
  to happen in the callers of UnsafePointer.pointer(to:).
2024-03-20 15:35:46 -07:00
Dario Rexin
8e72a01616 [IRGen] Add ability to disable compact value witnesses from block list (#72335)
rdar://124629183

Allows usage of compact value witnesses to be disabled using a block list.
2024-03-20 12:53:35 -07:00
Alexis Laferrière
ba25c4c57f Serialization: fix extra space in diagnostic 2024-03-20 10:20:52 -07:00
Alexis Laferrière
23628fda41 Merge pull request #72439 from xymus/diag-type-mismatch
Serialization: note mismatching types when it causes a deserialization failure
2024-03-20 09:39:49 -07:00
Alexis Laferrière
cef635619a Serialization: report type mismatch when it causes a deserialization failure
Deserialization may fail if a decl in a dependency changed type between the
time a swiftmodule was built and when it was imported. This can happen because
of changes to the SDK or use of C preprocessor macros. To help understand these
problems, note the specific types causing the mismatch when it leads to a
deserialization failure.

```
.../LibWithXRef.swiftmodule:1:1: error: reference to top-level
declaration 'foo' broken by a context change; the declaration kind of
'foo' from 'A' changed since building 'LibWithXRef'
1 │ A.foo
│ │ ├─ ...
│ ├─ note: a candidate was filtered out because of a type mismatch;
expected: '() -> ()', found: '(Int) -> Float'
```
2024-03-19 18:31:11 -07:00
Meghana Gupta
992396bfd5 Merge pull request #72431 from meg-gupta/lifetimeinsil
Parse explicit lifetime dependence specifiers in SIL
2024-03-19 17:11:23 -07:00
Doug Gregor
32a5b4f9d3 Move "suppressible protocol" information into a separate .def file
We need to track suppressible protocols as part of metadata in the ABI.
2024-03-19 16:22:28 -07:00
Meghana Gupta
5ad0a8b064 Parse explicit lifetime dependence specifiers in SIL 2024-03-19 13:34:50 -07:00
Rintaro Ishizaki
46e372cc5c Merge pull request #72384 from rintaro/parse-ifconfig-argdiag-rdar124160048
[Parse] Adjust diagnostic location for platform condition arguments
2024-03-19 23:10:12 +09:00
Cal Stephens
3315cab336 Merge branch 'main' into cal--fix-70089 2024-03-18 16:44:09 -07:00
Michael Gottesman
afbcf85727 [region-isolation] Change named transfer non transferable error to use the dynamic merged IsolationRegionInfo found during dataflow.
I also eliminated the very basic "why is this task isolated" part of the warning
in favor of the larger, better, region history impl that I am going to land
soon. The diagnostic wasn't that good in the first place and also was fiddly. So
I removed it for now.

rdar://124960994
2024-03-18 12:13:36 -07:00
Michael Gottesman
18aa7d8c3c [ast] Add a helper method ActorIsolation::getActorOrNullPtr().
ActorIsolation::getActor() asserts if an actor cannot be found. This new helper
method just returns nullptr instead.
2024-03-18 12:13:30 -07:00