Commit Graph

577 Commits

Author SHA1 Message Date
Erik Eckstein
8229b374b1 Performance annotations: add attributes @_noLocks and @_noAllocation 2021-10-28 18:43:14 +02:00
Mishal Shah
c2fd49cebb Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2021-10-11 09:00:51 -07:00
Erik Eckstein
30a74f6284 SIL: remove the private_external SILLinkage
This was a relict from the -sil-serialize-all days. This linkage doesn't make any sense because a private function cannot be referenced from another module (or file, in case of non-wmo compilation).
2021-10-10 19:52:40 +02:00
Erik Eckstein
b4966a4efa SIL: Don't serialize SILFunction declarations in witness tables if they don't have a valid linkage for "fragile ref".
E.g. a serialized witness table must not reference a private function. Just like a serialized function must not reference a private function.
2021-10-10 19:52:40 +02:00
Erik Eckstein
7849f09e52 SIL: remove the unused alloc_value_buffer, project_value_buffer and dealloc_value_buffer instructions.
Those instructions were use for the materializeForSet implementation, which was replaced by modify-coroutines.
2021-10-07 07:41:54 +02:00
Arnold Schwaighofer
c2b2f1331f SIL representation 2021-10-06 04:54:49 -07:00
swift-ci
cc4b94b790 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-16 13:34:05 -07:00
Nate Chandler
b4291916f2 Merge branch 'main' into rebranch
Conflicts:
        include/swift/SIL/SILBuilder.h
2021-09-15 13:30:12 -07:00
Nate Chandler
f833b68d3b [SIL] Changed spelling of lifetime flags.
Changed the frontend flag to -enable-experimental-lexical-lifetimes from
-enable-experimental-defined-lifetimes.

Changed the attribute on begin_borrow from [defined] to [lexical].
2021-09-14 08:49:30 -07:00
nate-chandler
c3e762680e Merge pull request #39291 from nate-chandler/lexical_lifetimes/alloc_stack/lexical_flag
[SIL] Added lexical flag to alloc_stack.
2021-09-14 08:47:50 -07:00
Nate Chandler
b57b222b54 [SIL] Added lexical flag to alloc_stack.
The new flag will be used to track whether a borrow scope corresponds to
a source-level lexical scope.  Here, the flag is just documented, added
to the instruction, represented in textual and serialized SIL, and
cloned.
2021-09-13 17:14:28 -07:00
swift-ci
0fd4d30f55 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-13 13:33:27 -07:00
Andrew Trick
4828285944 Add pointer_to_address [align=] option.
Support for addresses with arbitrary alignment as opposed to their
element type's natural in-memory alignment.

Required for bytestream encoding/decoding without resorting to memcpy.

SIL instruction flag, documentation, printing, parsing, serialization,
and IRGen.
2021-09-13 10:26:14 -07:00
swift-ci
ebc9a3d560 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-12 15:14:17 -07:00
Michael Gottesman
5590c7b526 [sil] Add a move_value instruction.
This is a new instruction that can be used by SILGen to perform a semantic move
in between two entities that are considered separate variables at the AST
level. I am going to use it to implement an experimental borrow checker.

This PR contains the following:

1. I define move_value, setup parsing, printing, serializing, deserializing,
   cloning, and filled in all of the visitors as appropriate.
2. I added createMoveValue and emitMoveValueOperation SILBuilder
   APIs. createMoveValue always creates a move and asserts is passed a trivial
   type. emitMoveValueOperation in contrast, will short circuit if passed a
   trivial value and just return the trivial value.
3. I added IRGen tests to show that we can push this through the entire system.

This is all just scaffolding for the instruction to live in SIL land and as of
this PR doesn't actually do anything.
2021-09-12 11:07:42 -07:00
swift-ci
59ef57cb03 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 22:34:30 -07:00
eeckstein
c0485b81be Merge pull request #39203 from eeckstein/fix-serialization
Serialization: include global variables in the worklist-processing
2021-09-09 07:26:16 +02:00
swift-ci
a34e4eb804 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 16:32:59 -07:00
Erik Eckstein
fa8d7828b3 Serialization: include global variables in the worklist-processing
It's not sufficient to first serialize all functions and then serialize all globals, because a function can be referenced from the initializer expression of a global.
Therefore the worklist processing must include both, functions and globals.

This fixes a crash in the serializer, which is exposed through cross-module-optimization.

https://bugs.swift.org/browse/SR-15162
rdar://82827256
2021-09-08 17:10:33 +02:00
Andrew Trick
33fecc9b21 Serialize SIL forwarding ownership on terminators. 2021-09-07 10:20:14 -07:00
swift-ci
ebad328a4f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-01 09:14:57 -07:00
Min-Yih Hsu
343d842394 [SIL][DebugInfo] PATCH 3/3: Deprecate debug_value_addr SIL instruciton
This patch removes all references to DebugValueAddrInst class and
debug_value_addr instruction in textual SIL files.
2021-08-31 12:01:04 -07:00
swift-ci
caf9d4e699 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-26 07:34:13 -07:00
Nate Chandler
f3b7706329 [SIL] Added defined flag to begin_borrow.
The new flag will be used to track whether a borrow scope corresponds to
a source-level lexical scope.  Here, the flag is just added to the
instruction and represented in textual and serialized SIL.
2021-08-25 16:41:49 -07:00
swift-ci
1fc44750c3 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-28 13:54:07 -07:00
Azoy
20cc067844 [AST] Introduce BuiltinProtocolConformance 2021-07-27 23:49:27 -07:00
swift-ci
fd87ebc401 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-23 07:13:34 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
Evan Wilde
9597eebcd9 Merge pull request #38230 from etcwilde/ewilde/swift-next/fix-sil-writing
[Swift Next] Fix SIL writing
2021-07-08 17:46:56 -07:00
Evan Wilde
9bd93db2be Update all the APInt toStrings
Just went through and updated the rest of the APInt toString calls.
This should take care of them, I hope.
2021-06-25 10:44:13 -07:00
Evan Wilde
99237f6a65 Fixed call to APInt::toString in SerializeSIL
The toString has been updated so that it doesn't return a std::string
anymore. Instead, you have to pass the memory buffer in. This patch
cleans that up.
2021-06-24 17:05:30 -07:00
Andrew Trick
c4f1f56ea7 Add Builtin.hopToActor
SILGen this builtin to a mandatory hop_to_executor with an actor type
operand.

e.g.

    Task.detached {
      Builtin.hopToActor(MainActor.shared)
      await suspend()
    }

Required to fix a bug in _runAsyncMain.
2021-06-13 23:44:30 -07:00
Saleem Abdulrasool
25f437e17d mark some switches as covered (NFCI)
Unfortunately, MSVC does not detect covered switches as clang.  Mark
some of the switches as covered to avoid an unnecessary warning from
MSVC.
2021-06-05 15:30:25 -07:00
Doug Gregor
e77a27e8ed [Concurrency] Introduce runtime detection of data races.
Through various means, it is possible for a synchronous actor-isolated
function to escape to another concurrency domain and be called from
outside the actor. The problem existed previously, but has become far
easier to trigger now that `@escaping` closures and local functions
can be actor-isolated.

Introduce runtime detection of such data races, where a synchronous
actor-isolated function ends up being called from the wrong executor.
Do this by emitting an executor check in actor-isolated synchronous
functions, where we query the executor in thread-local storage and
ensure that it is what we expect. If it isn't, the runtime complains.
The runtime's complaints can be controlled with the environment
variable `SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL`:

  0 - disable checking
  1 - warn when a data race is detected
  2 - error and abort when a data race is detected

At an implementation level, this introduces a new concurrency runtime
entry point `_checkExpectedExecutor` that checks the given executor
(on which the function should always have been called) against the
executor on which is called (which is in thread-local storage). There
is a special carve-out here for `@MainActor` code, where we check
against the OS's notion of "main thread" as well, so that `@MainActor`
code can be called via (e.g.) the Dispatch library's
`DispatchQueue.main.async`.

The new SIL instruction `extract_executor` performs the lowering of an
actor down to its executor, which is implicit in the `hop_to_executor`
instruction. Extend the LowerHopToExecutor pass to perform said
lowering.
2021-04-12 15:19:51 -07:00
Slava Pestov
4769f215e3 Merge pull request #36224 from slavapestov/reasync-sil-codegen
SIL: Preliminary support for 'apply [noasync]' calls
2021-03-05 12:46:55 -05:00
Slava Pestov
7ccc41a7b7 SIL: Preliminary support for 'apply [noasync]' calls
Refactor SILGen's ApplyOptions into an OptionSet, add a
DoesNotAwait flag to go with DoesNotThrow, and sink it
all down into SILInstruction.h.

Then, replace the isNonThrowing() flag in ApplyInst and
BeginApplyInst with getApplyOptions(), and plumb it
through to TryApplyInst as well.

Set the flag when SILGen emits a sync call to a reasync
function.

When set, this disables the SIL verifier check against
calling async functions from sync functions.

Finally, this allows us to add end-to-end tests for
rdar://problem/71098795.
2021-03-04 22:41:46 -05:00
Andrew Trick
e0a440c036 Add a poison flag to SIL destroy_value.
When the IRGen side is implemented, this will overwrite shadow debug
variables with a poison sentinel for all references within the value.
2021-03-04 17:26:18 -08:00
Richard Wei
e494df2ee6 [AutoDiff] Add differentiability kind to differentiability witnesses and mangle them.
Differentiability witnesses are now keyed by the original function name, the differentiability kind, and the autodiff config.

Updated SIL syntax:
```
differentiability-kind ::= 'forward' | 'reverse' | 'normal' | 'linear'
sil-differentiability-witness ::=
    'sil_differentiability_witness'
    sil-linkage?
    '[' differentiability-kind ']'
    '[' 'parameters' sil-differentiability-witness-function-index-list ']'
    '[' 'results' sil-differentiability-witness-function-index-list ']'
    generic-parameter-clause?
    sil-function-name ':' sil-type
    sil-differentiability-witness-body?
sil-instruction ::=
    'differentiability_witness_function'
    '[' sil-differentiability-witness-function-kind ']'
    '[' differentiability-kind ']'
    '[' 'parameters' sil-differentiability-witness-function-index-list ']'
    '[' 'results' sil-differentiability-witness-function-index-list ']'
    generic-parameter-clause?
    sil-function-name ':' sil-type
```
```console
sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T: Differentiable> @foo : <T> $(T) -> T
differentiability_witness_function [vjp] [reverse] [parameters 0] [results 0] <T where T: Differentiable> @foo : $(T) -> T
```

New mangling:
```swift
  global ::= global generic-signature? 'WJ' DIFFERENTIABILITY-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // differentiability witness
```
```console
$s13test_mangling3fooyS2f_S2ftFWJrSpSr ---> reverse differentiability witness for test_mangling.foo(Swift.Float, Swift.Float, Swift.Float) -> Swift.Float with respect to parameters {0} and results {0}
```

Resolves rdar://74380324.
2021-02-17 18:27:42 -05:00
Erik Eckstein
542a378436 SIL: add FunctionRefInst::getReferencedFunction()
If we know that we have a FunctionRefInst (and not another variant of FunctionRefBaseInst), we know that getting the referenced function will not be null (in contrast to FunctionRefBaseInst::getReferencedFunctionOrNull).

NFC
2021-02-09 19:56:43 +01:00
Dan Zheng
126f1ac6fb [AutoDiff] Disable differentiable_function_extract explicit type as… (#35239)
`differentiability_function_extract` instruction has an optional explicit
extractee type. This is currently used by TypeSubstCloner and the
LoadableByAddress transform to rewrite `differentiability_function_extract`
instructions while preserving `@differentiable` function type invariants.

There is an assertion that `differentiability_function_extract` instructions do
not have explicit extractee types outside of canonical/lowered SIL. However,
this does not handle the SIL deserialization case above: when a function
containing a `differentiable_function_extract` instruction with an explicit type
is deserialized into a raw SIL module (which happens when optimizations are
enabled).

Removing the assertion unblocks this encountered use case.

A more robust longer-term solution may be to change SIL `@differentiable`
function types to explicitly store component original/JVP/VJP function types.

Also fix `differentiable_function_extract` extractee type serialization.

Resolves SR-14004.
2021-01-04 18:40:11 -05:00
Slava Pestov
a2dbdecdab SIL: Refactor get_async_continuation[_addr] to return a RawUnsafeContinuation 2020-12-01 20:04:09 -05:00
Michael Gottesman
611284fcc2 [sil] Element shadowing of SILInstruction::getKind() by renaming MarkUninitializedInst::get{,MarkUninitialized}Kind().
Interestingly this problem can only occur if one invokes
MarkUninitializedInst::getKind() directly. Once our instruction is just a
SILInstruction, we call the appropriate method so we didn't notice it.

I used Xcode's refactoring functionality to find all of the invocation
locations.
2020-11-17 21:25:57 -08:00
Michael Gottesman
c026e95cce [ownership] Extract out SILOwnershipKind from ValueOwnershipKind into its own type and rename Invalid -> Any.
This makes it easier to understand conceptually why a ValueOwnershipKind with
Any ownership is invalid and also allowed me to explicitly document the lattice
that relates ownership constraints/value ownership kinds.
2020-11-10 14:29:11 -08:00
Michael Gottesman
f36e8561f1 [ownership] Use a new ADT SwitchEnumBranch instead of SwitchEnumInstBase for generic operations on SwitchEnum{,Addr}Inst.
I have a need to have SwitchEnum{,Addr}Inst have different base classes
(TermInst, OwnershipForwardingTermInst). To do this I need to add a template to
SwitchEnumInstBase so I can switch that BaseTy. Sadly since we are using
SwitchEnumInstBase as an ADT type as well as an actual base type for
Instructions, this is impossible to do without introducing a template in a ton
of places.

Rather than doing that, I changed the code that was using SwitchEnumInstBase as
an ADT to instead use a proper ADT SwitchEnumBranch. I am happy to change the
name as possible see fit (maybe SwitchEnumTerm?).
2020-11-08 19:52:02 -08:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Erik Eckstein
f18a9b8ee8 [Concurrency] SIL: add hop_to_executor instruction
This instructions ensures that all instructions, which need to run on the specified executor actually run on that executor.
For details see the description in SIL.rst.
2020-10-28 18:17:43 +01:00
Azoy
f21a306ae5 [AST] Introduce BuiltinProtocolConformance 2020-10-22 18:24:27 -04:00
Alexis Laferrière
e509d6883a Revert "[Sema] Fix availability checking in inlinable code" 2020-10-14 10:52:11 -07:00
Alexis Laferrière
9249186b15 Merge pull request #33855 from xymus/availability-inlinable
[Sema] Fix availability checking in inlinable code
2020-10-13 09:14:57 -07:00
Arnold Schwaighofer
2a2cf91dcd Add support for marking a _specialize attribute as SPI
```
  @_specialize(exported: true, spi: SPIGroupName, where T == Int)
  public func myFunc() { }
```

The specialized entry point is only visible for modules that import
using `_spi(SPIGroupName) import ModuleDefiningMyFunc `.

rdar://64993425
2020-10-12 09:19:29 -07:00