Commit Graph

6583 Commits

Author SHA1 Message Date
Slava Pestov
ad5697778e Merge pull request #69430 from slavapestov/silgen-typed-throws-wip
Preliminary SILGen support for address-only typed throws
2023-10-27 21:00:51 -04:00
Slava Pestov
eac491ccd2 SIL: Fix memory lifetime verifier check for the thrown error result 2023-10-27 17:37:43 -04:00
Slava Pestov
1d05c356c4 SIL: AbstractionPattern support for typed throws 2023-10-27 17:37:43 -04:00
Michael Gottesman
b99a4f89d9 Merge pull request #69453 from gottesmm/pr-2fef04440592fb93039bb726507eb8897c2b8e47
[region-isolation] Make sure that we treat Sendable functions as Sendable
2023-10-27 14:37:06 -07:00
Michael Gottesman
dc8e4794a8 [region-isolation] Make sure that we treat Sendable functions as Sendable.
The reason for this issue is that we were originally checking in our NonSendable
type oracle just if a type conformed to Sendable. But function types do not
conform to protocols, so this would fail for protocols. To fix this, I added
some helper methods to call swift::isSendableType on SILType, called that in our
oracle, and then I added support in swift::isSendableType for both
SILFunctionType and AnyFunctionType so that we correctly handle them depending
on their sendability.

There was also a question if we also handled function conversions correctly. I
added a test case that shows that we do not error in either of the cases.

Another nice aspect of this change is that we no longer need to stash a pointer
to a looked up Sendable protocol to perform the check since that just happens
naturally inside SILType::isSendable() when it calls isSendableType. This is a
better separation of concerns.

rdar://116525224
2023-10-27 11:13:35 -07:00
Erik Eckstein
b6938475b9 Optimizer: add simplification for the convert_escape_to_noescape instruction
Including the required bridging stuff.

  %2 = thin_to_thick_function %1 to $() -> ()
  %3 = convert_escape_to_noescape %2 : $() -> () to $@noescape () -> ()
->
  %3 = thin_to_thick_function %1 to $@noescape () -> ()
2023-10-27 10:47:07 +02: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
Michael Gottesman
bf647116e0 Merge pull request #69342 from gottesmm/small-region-isolation-fixes
[region-based-isolation] Stack of smaller fixes before a larger fix
2023-10-24 10:18:47 -07:00
Yuta Saito
4f0e3bf3ea Merge pull request #69207 from kateinoigakukun/yt/cdecl-without-body
Introduce `@extern(c)` to declare C function without Clang module
2023-10-23 12:48:12 -07:00
Michael Gottesman
d598da596a [sil] Implement SILType::isActor().
Just a helper that calls getASTType()->isActorType().

I also updated the two places in SNS that we use this.
2023-10-23 12:24:17 -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
83620827fb [rebranch] Move SILBuilder::substituteAnonymousArgs out of the header
An attempt to fix an undefined reference to `std::_Construct` that we're
hitting on Ubuntu 22.04 and UBI 9.
2023-10-20 11:15:21 -07:00
Andrew Trick
f1bec99705 Merge pull request #69250 from atrick/fix-deserialize-access
Fix deserialization to avoid invoking a pass N times per function
2023-10-20 11:02:25 -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
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
Andrew Trick
ef29250dcb Fix deserialization to avoid invoking a pass N times per function
Deserialization is calling AccessMarkerElimination repeatedly on the
same function.

The bug was introduced here:

commit 872bf40e17
Date:   Mon Aug 13 10:24:20 2018

    [sil-optimizer] Centralize how we send out serialization notifications.

Where the code that uniques the deserialization callbacks was simply
removed!

As a result, this pass was being invoked a number of times equal to
the number of functions in the module *multiplied* by the number of
functions being deserialized.

Fixes rdar://117141871 (Building spends most of its time in
AccessMarkerElimination)
2023-10-18 10:32:04 -07:00
Andrew Trick
ca7253a25c Add the @_unsafeNonEscapableResult function
This will allow NonEscapable types to be returned from a function.
2023-10-17 12:44:31 -07:00
Andrew Trick
045253e614 Add SILType::isEscapable 2023-10-17 12:44:31 -07:00
Evan Wilde
312bd47f4c Merge remote-tracking branch 'main' into 'rebranch' 2023-10-16 23:00:12 -07:00
Joe Groff
25061fb281 Merge pull request #69169 from jckarter/store-borrow-lifetime-nesting
SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes.
2023-10-16 13:51:40 -07:00
Joe Groff
1dcf271fe0 SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes.
When rewriting uses of a noncopyable value, the move-only checker failed to take into account
the scope of borrowing uses when establishing the final lifetimes of values. One way this
manifested was when borrowed values get reabstracted from value to in-memory representations,
using a store_borrow instruction, the lifetime of the original borrow would be ended immediately
after the store_borrow begins rather than after the matching end_borrow. Fix this by, first,
changing `store_borrow` to be treated as a borrowing use of its source rather than an
interior-pointer use; this should be more accurate overall since `store_borrow` borrows the
entire source value for a well-scoped duration balanced by `end_borrow` instructions. That done,
change MoveOnlyBorrowToDestructureUtils so that when it sees a borrow use, it ends the borrow
at the end(s) of the use's borrow scope, instead of immediately after the beginning of the use.
2023-10-16 09:12:25 -07:00
Mishal Shah
3594f8ecaf Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	test/IRGen/opaque-pointer-llvm.swift
2023-10-15 23:49:40 -07:00
Arnold Schwaighofer
0a5cb1e93f Merge pull request #69160 from aschwaighofer/wip_partial_sil_support_for_generic_throws
Preliminary SIL and IRGen support for error_indirect
2023-10-13 09:34:44 -07:00
swift-ci
f1380f2eb8 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-12 19:34:24 -07:00
Arnold Schwaighofer
9482b0c86b Preliminary SIL and IRGen support for error_indirect
IRGen lowering of non-fixed-sized typed errors and the SIL support necessary to
spell out IRGen test cases.
2023-10-12 18:09:52 -07:00
Andrew Trick
3f6751a75e Add SWIFT_IMPORT_UNSAFE to new SIL bridging 2023-10-12 15:44:28 -07:00
Andrew Trick
d7c1c50d9b SwiftCompilerSources: VarDecl bridging for SIL. 2023-10-12 14:33:37 -07:00
Andrew Trick
e2333cdcfc SwiftCompilerSources: diagnostics bridging. 2023-10-12 14:33:37 -07:00
swift-ci
d432ad3f51 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-12 10:54:41 -07:00
Allan Shortlidge
229398c01d Merge pull request #69141 from tshortli/silgen-lazy-typecheck
SILGen: Introduce option to skip non-exportable declarations
2023-10-12 10:49:06 -07:00
swift-ci
13417f9331 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-12 09:35:04 -07:00
Yuta Saito
051bf4dd43 Merge pull request #69107 from kateinoigakukun/yt/extern-wasm-sym
[wasm] Add @_extern(wasm) attribute support
2023-10-12 09:29:13 -07:00
Allan Shortlidge
17f6f4e7a4 SILGen: Introduce and adopt SILGenModule::shouldSkipDecl().
This method centralizes the logic for determining whether to skip emission of
SIL associated with a Decl.
2023-10-11 22:41:30 -07:00
swift-ci
2ff419323a Merge remote-tracking branch 'origin/main' into rebranch 2023-10-11 09:14:46 -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
Andrew Trick
727ff71476 Rename FunctionTest::getInvocation.
The test invocation is something completely different in this context.
2023-10-10 13:40:02 -07:00
swift-ci
46c67c20cf Merge remote-tracking branch 'origin/main' into rebranch 2023-10-10 02:35:18 -07:00
Hamish Knight
03b6623f72 Merge pull request #69074 from hamishknight/over-extended 2023-10-10 10:25:57 +01: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
Hamish Knight
ccd32eb452 NFC: Remove ClangModuleLoader.h include from ExtInfo.h
This was unnecessarily pulling in a whole bunch
of Clang headers when all was needed was a
forward declaration.
2023-10-09 20:29:03 +01:00
swift-ci
44307996e3 Merge pull request #69071 from eeckstein/bridging-followup
Follow-up on the bridging rework
2023-10-09 10:52:40 -07:00
Andrew Trick
e04abee2e9 Merge pull request #69049 from apple/fix-select-enum
Fix ownership of select_enum instruction
2023-10-09 10:02:34 -07:00
Erik Eckstein
f57bc64852 Builder Bridging: some refactoring to simplify the code
NFC
2023-10-09 17:43:22 +02:00
Erik Eckstein
2dbd6cc56b SwiftCompilerSources: rework bridging
Introduce two modes of bridging:
* inline mode: this is basically how it worked so far. Using full C++ interop which allows bridging functions to be inlined.
* pure mode: bridging functions are not inlined but compiled in a cpp file. This allows to reduce the C++ interop requirements to a minimum. No std/llvm/swift headers are imported.

This change requires a major refactoring of bridging sources. The implementation of bridging functions go to two separate files: SILBridgingImpl.h and OptimizerBridgingImpl.h.
Depending on the mode, those files are either included in the corresponding header files (inline mode), or included in the c++ file (pure mode).

The mode can be selected with the BRIDGING_MODE cmake variable. By default it is set to the inline mode (= existing behavior). The pure mode is only selected in certain configurations to work around C++ interop issues:
* In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
* On windows to workaround a build problem.
2023-10-09 09:52:52 +02:00
Andrew Trick
69a884565a Fix ownership of select_enum instruction
This instruction was given forwarding ownership in the original OSSA
implementation. That will obviously lead to memory leaks. Remove
ownership from this instruction and verify that it is never used for
non-trivial types.
2023-10-08 01:34:48 -07:00
swift-ci
0ebccdfdd4 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-07 23:34:08 -07:00
swift-ci
f6afa76a3b Merge remote-tracking branch 'origin/main' into rebranch 2023-10-07 21:33:50 -07:00
Nate Chandler
ae1f950315 [SwiftCompilerSources] Moved Test into Optimizer.
And changed the type of the context argument to FunctionPassContext.
2023-10-07 21:23:13 -07:00
nate-chandler
18ce3ab465 Merge pull request #69007 from nate-chandler/swiftcompilersources/test-bridging-registration-cleanup
[SwiftCompilerSources] Simplified test registration.
2023-10-07 21:22:04 -07:00