Commit Graph

611 Commits

Author SHA1 Message Date
Pavel Yaskevich
1909b12370 [SIL] Distributed: Remove logic related to ad-hoc requirements from SILFunction
Ad-hoc requirements are now obsolete by making `remoteCall`,
`record{Argument, ReturnType}`, `decodeNextArgument` protocols
requirements and injecting witness tables for `SerializationRequirement`
conformances during IRGen.
2024-02-12 14:26:30 -08:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Meghana Gupta
a66b7b6335 Don't represent mutate lifetime dependence separately 2024-02-08 14:05:01 -08:00
Nate Cook
e317febc9d Revert "Allow normal function results of @yield_once coroutines (#69843)"
This reverts commit aa5b505014.
2024-02-07 14:57:31 -06:00
John McCall
60807a76a4 Merge pull request #71433 from rjmccall/isolated-any-typechecking
Experimental type-checking support for `@isolated(any)` function types.
2024-02-07 14:07:53 -05:00
Anton Korobeynikov
aa5b505014 Allow normal function results of @yield_once coroutines (#69843)
This adds SIL-level support and LLVM codegen for normal results of a coroutine.

The main user of this will be autodiff as VJP of a coroutine must be a coroutine itself (in order to produce the yielded result) and return a pullback closure as a normal result.

For now only direct results are supported, but this seems to be enough for autodiff purposes.
2024-02-06 22:13:15 -08:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Ellie Shin
72a7760027 Support package SIL linkage.
Decls with a package access level are currently set to public SIL
linkages. This limits the ability to have more fine-grained control
and optimize around resilience and serialization.
This PR introduces a separate SIL linkage and FormalLinkage for
package decls, pipes them down to IRGen, and updates linkage checks
at call sites to include package linkage.

Resolves rdar://121409846
2024-02-06 01:23:14 -08:00
Rintaro Ishizaki
8fdc4cc225 [AST] Split Attr.def to DeclAttr.def and TypeAttr.def 2024-02-02 09:36:49 -08:00
Meghana Gupta
2180221247 Serialize/deserialize LifetimeDependenceInfo 2024-02-01 07:39:51 -08:00
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Joe Groff
6706feaf5e Parse _borrowing x in patterns as a borrow binding.
Treat it as a contextual keyword when followed by an identifier, like our
other ownership-related declarations and operators.
2024-01-30 17:33:42 -08:00
Sophia Poirier
a72cf7302d remove unused declaration attribute IsolatedAttr 2024-01-29 21:05:49 -08:00
Arnold Schwaighofer
edd7eaa0d7 OSLog: os_log strings should be in the __oslogstring section on machO
rdar://121384422
2024-01-26 08:30:56 -08:00
John McCall
b0fb03d8c7 Create a uniform representation for function type isolation.
Not quite NFC because apparently the representation bleeds into what's
accepted in some situations where we're supposed to be warning about
conflicts and then making an arbitrary choice.  But what we're doing
is nonsense, so we definitely need to break behavior here.

This is setting up for isolated(any) and isolated(caller).  I tried
to keep that out of the patch as much as possible, though.
2024-01-25 22:11:01 -05:00
Kavon Farvardin
483b569bc8 [NCGenerics] trigger module mismatch
A swiftmodule can only be correctly ingested by a compiler
that has a matching state of using or not-using
NoncopyableGenerics.

The reason for this is fundamental: the absence of a Copyable
conformance in the swiftmodule indicates that a type is
noncopyable. Thus, if a compiler with NoncopyableGenerics
reads a swiftmodule that was not compiled with that feature,
it will think every type in that module is noncopyable.

Similarly, if a compiler with NoncopyableGenerics produces a
swiftmodule, there will be Copyable requirements on each
generic parameter that the compiler without the feature will
become confused about.

The solution here is to trigger a module mismatch, so that
the compiler re-generates the swiftmodule file using the
swiftinterface, which has been kept compatible with the compiler
regardless of whether the feature is enabled.
2024-01-23 22:42:37 -08:00
Michael Gottesman
6f3d45219a [ast] Represent a parameter's isolation at the SIL level.
I did this by adding flag on SILParamInfo.

rdar://121387872
2024-01-23 15:20:22 -08:00
Doug Gregor
698a99ecf5 Start serializing @_implements attribute
@_implements is in this odd state where it is dropped from serialization,
but persists everywhere else. Keep it in the serialized modules.
2024-01-22 17:27:30 -08:00
Michael Gottesman
9513d298ec [region-isolation] Add parsing/serialization/type system support for a transferring OwnershipSpecifier. 2024-01-18 13:20:28 -08:00
Pavel Yaskevich
a26af37ecc [Serialization] Add @preconcurrency bit to normal conformance descriptor 2024-01-16 11:51:49 -08:00
Pavel Yaskevich
233d279a5c [AST] Support @preconcurrency attribute on test/extension inheritance entries 2024-01-16 10:30:58 -08:00
Allan Shortlidge
432e4dccab Serialization: Remove Swift3Inferred field from @objc attr. 2024-01-11 15:41:11 -08:00
Artem Chikin
de626abf71 [Serialization] Always serialize module-defining '.swiftinterface', even if SDK-relative.
The clients, upon loading, will resolve the SDK-relative path to their SDK location.

Resolves rdar://120673684
2024-01-10 14:06:10 -08:00
Erik Eckstein
bc99986cf9 SIL: add a dependency token operand to global_addr
Optionally, the dependency to the initialization of the global can be specified with a dependency token `depends_on <token>`.
This is usually a `builtin "once"` which calls the initializer for the global variable.
2024-01-10 09:33:58 +01:00
Joe Groff
4011b2f53c Add methods to determine the ownership behavior of patterns.
When matching against a noncopyable value, whether the match operation can
borrow the value in-place or needs to take ownership of it is significant.
This can generally be determined from the kind of pattern being used, except
in the case of expr patterns, where it depends on type-checking the `~=`
operator that was used.
2024-01-08 18:21:33 -08:00
Andrew Trick
264cbaea42 Add mark_dependence [nonescaping] flag.
The dependent 'value' may be marked 'nonescaping', which guarantees that the
lifetime dependence is statically enforceable. In this case, the compiler
must be able to follow all values forwarded from the dependent 'value', and
recognize all final (non-forwarded, non-escaping) use points. This implies
that `findPointerEscape` is false. A diagnostic pass checks that the
incoming SIL to verify that these use points are all initially within the
'base' lifetime. Regular 'mark_dependence' semantics ensure that
optimizations cannot violate the lifetime dependence after diagnostics.
2024-01-04 14:47:35 -08:00
Michael Gottesman
1764bd2479 [sil] Change SILParameterInfo/SILResultInfo's differentiability parameter to use an OptionSet so we can add other options.
I am doing this in preparation for adding options to SILParameterInfo/
SILResultInfo that state that a parameter/result is transferring. Even though I
could have just introduced a new bit here, I instead streamlined the interface
of SILParameterInfo/SILResultInfo to use an OptionSet instead of individual bits
to make it easier to add new flags here. The reason why it is easier is that
along API (e.x.: function argument) boundaries one does not have to marshal each
field or pass each field. Instead one can just pass the whole OptionSet as an
opaque thing. Using this I was able to change serialization/deserialization of
SILParameterInfo/SILResultInfo so that one does not need to update them if one
adds new fields!

The reason why I am doing this for both SILParameterInfo/SILResultInfo in the
same commit is because they share code in the demangler that I did not want to
have to duplicate in an intervening commit. By changing them both at the same
type, I didn't have to change anything without an actual need to.

I am doing this in a separate commit from adding transferring support so I can
validate correctness using the tests for the options already supported
(currently only differentiability).
2024-01-02 15:03:05 -08:00
Meghana Gupta
d3e921dc47 Make _resultDependsOn available on SILFunctionArgument 2023-12-29 01:57:19 -08:00
Kavon Farvardin
a6b27d0f85 [NCGenerics] fix serialization of PCT
resolves rdar://118947007
2023-12-12 16:40:13 -08:00
Michael Gottesman
f328e7893b [region-isolation] Add support for representing ApplyIsolationCrossing at the SIL level on apply, begin_apply, try_apply.
Some notes:

This is not emitted by SILGen. This is just intended to be used so I can write
SIL test cases for transfer non sendable. I did this by adding an
ActorIsolationCrossing field to all FullApplySites rather than adding it into
the type system on a callee. The reason that this makes sense from a modeling
perspective is that an actor isolation crossing is a caller concept since it is
describing a difference in between the caller's and callee's isolation. As a
bonus it makes this a less viral change.

For simplicity, I made it so that the isolation is represented as an optional
modifier on the instructions:

  apply [callee_isolation=XXXX] [caller_isolation=XXXX]

where XXXX is a printed representation of the actor isolation.

When neither callee or caller isolation is specified then the
ApplyIsolationCrossing is std::nullopt. If only one is specified, we make the
other one ActorIsolation::Unspecified.

This required me to move ActorIsolationCrossing from AST/Expr.h ->
AST/ActorIsolation.h to work around compilation issues... Arguably that is where
it should exist anyways so it made sense.

rdar://118521597
2023-12-11 19:27:27 -06:00
Erik Eckstein
e652f2c92e SIL: add the alloc_vector and vector instructions
* `alloc_vector`: allocates an uninitialized vector of elements on the stack or in a statically initialized global
* `vector`: creates an initialized vector in a statically initialized global
2023-12-09 18:49:55 +01:00
Dario Rexin
36dd2c9450 [SilOpt] Add new layout type _TrivialStride and add pre-specialization suppport for it (#70308)
rdar://119329771

This layout allows adding pre-specializations for trivial types that have a different size, but the same stride. This is especially useful for collections, where the stride is the important factor.
2023-12-09 08:13:50 -08:00
Dario Rexin
df35f3327d [SilOpt] Add new layout _BridgeObject and add pre-specialization support for it (#70239)
rdar://119048001
2023-12-08 14:34:16 -08:00
Meghana Gupta
b6326f5f24 Add initial support for _resultDependsOn
These attributes are used to establish lifetime dependence between
argument and the result.

Add them under NonEscapableTypes experimental feature
2023-12-06 16:38:38 -08:00
Zhiyu Zhu/朱智语
10d672e33c Merge pull request #70249 from apple/ApolloZhu/const-extract/attribute-on-all-nominals
[Compile Time Constant Extraction] Allow attribute on all nominal decls
2023-12-06 15:11:28 -08:00
Meghana Gupta
6442e914a0 Merge pull request #70244 from meg-gupta/removeselfaccesskind
Remove SelfAccessKind::ResultDependsOnSelf
2023-12-05 18:30:32 -08:00
Apollo Zhu
a8fd83703b Allow extractConstantsFromMembers on all nominal decls 2023-11-30 18:35:17 -08:00
Meghana Gupta
fd588ab509 Remove SelfAccessKind::ResultDependsOnSelf 2023-11-29 12:11:57 -08:00
Zhiyu Zhu/朱智语
9d1a92eb72 [Compile Time Constant Extraction] Add @extractConstantsFromMembers (#69944)
Add @extractConstantsFromMembers attribute under ExtractConstantsFromMembers experimental feature flag
2023-11-29 08:49:57 -08:00
Nate Chandler
b4f783e660 [SIL] Added var_decl flag to borrows/moves. 2023-11-28 07:26:08 -08:00
Doug Gregor
ffa5ba7ce3 More macro metaprogramming for macro roles 2023-11-14 09:20:15 -08:00
Meghana Gupta
5658deae27 Add initial support for _resultDependsOnSelf
This is used to establish lifetime dependence between self and the result.

Add under NonEscapableTypes experimental feature
2023-11-08 01:48:59 -08:00
Michael Gottesman
6a65c7829e [sil] Add tuple_addr_constructor an instruction that can be used to initial a tuple in memory from individual address and object components.
This commit just introduces the instruction. In a subsequent commit, I am going
to add support to SILGen to emit this. This ensures that when we assign into a
tuple var we initialize it with one instruction instead of doing it in pieces.
The problem with doing it in pieces is that when one is emitting diagnostics it
looks semantically like SILGen actually is emitting code for initializing in
pieces which could be an error.
2023-11-06 15:32:05 -08:00
Alexis Laferrière
f2d1627656 [Serialization] Fix deserializing opaque types for computed properties and subscripts
A client shouldn't know about the underlying type of an opaque type
unless it can see the body of the naming decl. Attempting to read it can
lead to accessing a hidden dependency and a compiler crash.

This was protected by a check specific to function decls but var decls
and subscripts were not handled. To support them we have to move this
logic to the writer side where we have access to the full
AbstractStorageDecl and write in the swifmodule whether the underlying
type should be visible outside of the module.

rdar://117607906
2023-11-01 16:04:10 -07:00
Slava Pestov
05ccd9734c SIL: Introduce ThrowAddrInst 2023-10-31 16:58:54 -04:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Yuta Saito
69479933df [c-interop] Rename @_extern to @extern
Now the feature is gated by experimental feature flag.
It's not shipped in any language release, so this rename should be fine.
2023-10-20 17:37:43 +00:00
Yuta Saito
b27fd9a616 [c-interop] Add @_extern(c) attribute to declare C function in Swift 2023-10-20 15:34:08 +00:00
Becca Royal-Gordon
5c8bcfdf52 [NFC] Correct AFD::needsNewVTableEntry()
Serialization depended on a longstanding bug in NeedsNewVTableEntryRequest: For a member of a non-class, it always returned `true`, not `false`. It turns out this was because serialization was conflating the concepts of vtable entries and witness table entries, so it needed NeedsNewVTableEntryRequest to return true for members of protocols. Untangle this logic so that NeedsNewVTableEntryRequest can be given the logical behavior.
2023-10-13 14:33:44 -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