Commit Graph

1510 Commits

Author SHA1 Message Date
Ellie Shin
0e8ffef6cd Merge pull request #70897 from apple/es-pkg-fx
Change effectiveAccessLevel of `package` decls from `public` to `package`.
2024-01-24 07:35:13 +09:00
Ellie Shin
ab3b5add3a Currently decls defined with package access level have a different
access level for optimization: `public`. It requires an extra check for
the actual access level that was declared when determining serialization
since the behavior should be different.

This PR sets its effective access level to `package` as originally defined,
updates call sites to make appropriate acces level comparisons, and removes
`package` specific checks.
2024-01-23 11:02:49 -08:00
Doug Gregor
97ea19d191 Introduce a builtin and API for getting the local actor from a distributed one
When an actual instance of a distributed actor is on the local node, it is
has the capabilities of `Actor`. This isn't expressible directly in the type
system, because not all `DistributedActor`s are `Actor`s, nor is the
opposite true.

Instead, provide an API `DistributedActor.asLocalActor` that can only
be executed when the distributed actor is known to be local (because
this API is not itself `distributed`), and produces an existential
`any Actor` referencing that actor. The resulting existential value
carries with it a special witness table that adapts any type
conforming to the DistributedActor protocol into a type that conforms
to the Actor protocol. It is "as if" one had written something like this:

    extension DistributedActor: Actor { }

which, of course, is not permitted in the language. Nonetheless, we
lovingly craft such a witness table:

* The "type" being extended is represented as an extension context,
rather than as a type context. This hasn't been done before, all Swift
runtimes support it uniformly.

* A special witness is provided in the Distributed library to implement
the `Actor.unownedExecutor` operation. This witness back-deploys to the
Swift version were distributed actors were introduced (5.7). On Swift
5.9 runtimes (and newer), it will use
`DistributedActor.unownedExecutor` to support custom executors.

* The conformance of `Self: DistributedActor` is represented as a
conditional requirement, which gets satisfied by the witness table
that makes the type a `DistributedActor`. This makes the special
witness work.

* The witness table is *not* visible via any of the normal runtime
lookup tables, because doing so would allow any
`DistributedActor`-conforming type to conform to `Actor`, which would
break the safety model.

* The witness table is emitted on demand in any client that needs it.
In back-deployment configurations, there may be several witness tables
for the same concrete distributed actor conforming to `Actor`.
However, this duplication can only be observed under fairly extreme
circumstances (where one is opening the returned existential and
instantiating generic types with the distributed actor type as an
`Actor`, then performing dynamic type equivalence checks), and will
not be present with a new Swift runtime.

All of these tricks together mean that we need no runtime changes, and
`asLocalActor` back-deploys as far as distributed actors, allowing it's
use in `#isolation` and the async for...in loop.
2024-01-22 17:27:31 -08:00
Hamish Knight
fd97268393 Merge pull request #70983 from hamishknight/another-cleanup
[AST] Remove SerializedLocalDeclContext
2024-01-22 18:49:42 +00:00
Alex Lorenz
ed7ed2d233 Merge pull request #70977 from hyp/eng/clang-nom-type-descr-local
[IRGen][WMO] type descriptors generated for an imported Clang types a…
2024-01-19 14:51:33 -08:00
Alex Lorenz
57f3d2386f [IRGen][WMO] type descriptors generated for an imported Clang types are always known local declarations
This fixes a LNK4217 linker warning when building code on Windows
2024-01-19 08:01:50 -08:00
Hamish Knight
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Erik Eckstein
eaabcfd933 IRGen: restrict generation of read-only static objects to Array buffers
Currently only arrays can be put into a read-only data section.
"Regular" classes have dynamically initialized metadata, which needs to be stored into the isa field at runtime.
2024-01-10 09:33:17 +01:00
Rintaro Ishizaki
f7e35cb835 [AST] Requestify local type declarations
Instead of recording local type declarations while parsing, make a
request to collect them from the AST. This reduces the side effect of
parsing.
2024-01-05 13:26:55 -08:00
Kuba Mracek
282e65170e [embedded] Do not emit entry point data (__swift5_entry) in embedded Swift 2023-12-20 20:05:28 +01:00
Becca Royal-Gordon
e9672194b4 Merge pull request #69468 from beccadax/c-implementation
Make @objcImpl work with @_cdecl
2023-12-14 00:36:12 -08:00
Becca Royal-Gordon
8651af4325 Make @objcImpl work with @_cdecl
No real diagnostics yet, but we’re emitting mostly correct code.
2023-12-13 11:09:49 -08:00
Erik Eckstein
df9f480cdc IRGen: handle vector and alloc_vector in global initializers 2023-12-09 18:49:57 +01:00
Kavon Farvardin
a9c64baaa3 [Sema] refactor TypeDecl::isNoncopyable
In preparation for reporting whether the inverse marking on a TypeDecl
was inferred instead of explicit.
2023-11-06 15:40:12 -08:00
Saleem Abdulrasool
1cb0099901 IRGen,Serialization: account for transitive dynamic linkage
When building complex projects, there may cases of static libraries
which expose `@inlinable` functions which reference functions from
dynamically linked dependencies. In such a case, we need to consider the
provenance of the `function_ref` when determining the DLL storage for
linkage. We would previously use the deserialised metadata on the
`SILFunction` as there are entities where the `DeclContext` may not be
deserialised. However, this leaves us in a state where we are unable to
determine the actual provenance correctly in some cases. By simply
accessing the parent module directly from the `SILFunction` we ensure
that we properly identify the origin of the function allowing us to
query the DLL storage property. This further allows us to remove the
extra storage required for whether the `SILFunction` is statically
linked.
2023-10-26 18:03:45 -07:00
Mishal Shah
aa6a588f45 Merge pull request #69163 from apple/rebranch
Merge `rebranch` into `main` to support `stable/20230725` llvm-project branch
2023-10-23 09:26:37 -07:00
Ben Barham
360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Erik Eckstein
3e8921e1ec IRGen: remove a wrong assert for global variable initialization
The assert was wrong because in case a global variable reference another global variable, it can be the case that the other variable is first generated as declaration and then "converted" to a definition by adding the constant initializer.

rdar://117189962
2023-10-19 20:29:58 +02:00
Kavon Farvardin
148897ac1a [nfc] refactor ValueDecl::isMoveOnly
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.

Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
2023-10-18 13:45:50 -07:00
swift-ci
13417f9331 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-12 09:35:04 -07:00
Yuta Saito
bd898b0e7e [wasm] add @_extern(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "import"ed from host environment. It's equivalent of Clang's
`__attribute__((import_module("module"), import_name("field")))`
2023-10-10 22:42:08 +00:00
Evan Wilde
24d0db249b Merge remote-tracking branch 'main' into 'rebranch'
Conflicts:
  CMakeLists.txt
    Take new BRIDGING_MODE

  SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
    Take new
2023-10-09 17:21:23 -07:00
Augusto Noronha
efc86aafb5 Merge pull request #68843 from augusto2112/keep-funcs-for-deb-tests
Keep certain function that are potentially used in the debugger
2023-10-09 13:58:21 -07:00
Yuta Saito
5763741bb5 [IRGen] Use addCompactFunctionReference for dynamic replacement
This repairs dynamic_replaceable_opaque_return_type_parameter.swift test
on WebAssembly.
2023-10-09 05:30:13 +00:00
swift-ci
048b1babd7 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-08 09:14:00 -07:00
Slava Pestov
f321dd3321 Merge pull request #66247 from karwa/nested-protocols
Allow protocols to be nested in non-generic contexts
2023-10-08 12:00:46 -04:00
swift-ci
5b72fbae64 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-06 17:15:26 -07:00
Karl Wagner
ab4f80ed95 [SE-0404] Allow protocols to be nested in non-generic contexts 2023-10-06 21:04:03 +02:00
Kuba Mracek
7da86b1148 [embedded] Serialize+deserialize vtables, fix using non-generic classes from other modules in embedded Swift 2023-10-06 10:25:22 -07:00
Augusto Noronha
ef45991a2a Keep certain function that are potentially used in the debugger
Currently, when compiling with no optimizations on, we still delete
functions that are sometimes used in the debugger. For example, users
might want to call functions which are unused, or compiler generated
setters/getters.

rdar://101046198
2023-10-04 10:16:31 -07:00
swift-ci
ddbe38ec7b Merge remote-tracking branch 'origin/main' into rebranch 2023-09-28 09:38:05 -07:00
Yuta Saito
8cfcc245b5 Merge pull request #68524 from kateinoigakukun/katei/expose-wasm-sym
[wasm] Add `@_expose(wasm)` attribute for top-level functions
2023-09-28 09:17:48 -07:00
swift-ci
2e6b1cd2f7 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-28 07:13:53 -07:00
Kuba Mracek
d78482270d [embedded] Move loweredFunctionHasGenericArguments to .isGeneric() on SILFunction 2023-09-27 10:00:39 -07:00
Kuba Mracek
325bc94cd6 [embedded] abort(0) -> llvm_unreachable 2023-09-27 09:19:42 -07:00
Kuba Mracek
b049319487 [embedded] Remove unspecialized functions before running IRGen 2023-09-26 22:25:37 -07:00
Yuta Saito
6d378a3ec3 [wasm] add @_expose(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "export"ed from this .wasm module. It's equivalent of Clang's
`__attribute__((export_name("name")))`
2023-09-26 14:13:33 +00:00
swift-ci
c211e09c5a Merge remote-tracking branch 'origin/main' into rebranch 2023-09-25 01:17:00 -07:00
Kuba Mracek
2babc5d67f [embedded] Use ASTContext directly from IRGenModule 2023-09-24 20:51:51 -07:00
Kuba Mracek
211f613e10 [embedded] Stop emitting metadata for extensions 2023-09-24 20:49:10 -07:00
Evan Wilde
ae6057984f Revert "Keep certain function that are potentially used in the debugger" 2023-09-20 13:06:12 -07:00
Augusto Noronha
3bc42c865e Merge pull request #68558 from augusto2112/keep-funcs-for-debugger
Keep certain function that are potentially used in the debugger
2023-09-20 08:23:46 -07:00
Augusto Noronha
e06ba23c75 Keep certain function that are potentially used in the debugger
Currently, when compiling with no optimizations on, we still delete
functions that are sometimes used in the debugger. For example, users
might want to call functions which are unused, or compiler generated
setters/getters.

rdar://101046198
2023-09-18 13:51:56 -07:00
swift-ci
0d132bc4a7 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-18 10:14:22 -07:00
Kuba Mracek
a5d5621398 [embedded] Fix compiler asserts when building closures 2023-09-15 18:40:39 -07:00
swift-ci
ae30cba296 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-13 10:20:48 -07:00
Kuba Mracek
6ad968467f [embedded] only track specialized class metadata in embedded mode 2023-09-12 22:34:21 -07:00
Kuba Mracek
56085205d8 [embedded] specialize generic classes based on MetatypeInst too, fix lazy emit assert 2023-09-12 21:24:14 -07:00
Kuba Mracek
d0c2a4ccf8 [embedded] Initial support for generic classes in embedded Swift
- VTableSpecializer, a new pass that synthesizes a new vtable per each observed concrete type used
- Don't use full type metadata refs in embedded Swift
- Lazily emit specialized class metadata (LazySpecializedClassMetadata) in IRGen
- Don't emit regular class metadata for a class decl if it's generic (only emit the specialized metadata)
2023-09-12 09:44:54 -07:00
swift-ci
9977c4ec7f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-11 17:55:02 -07:00