Commit Graph

131 Commits

Author SHA1 Message Date
Erik Eckstein
4fdf16de1b SIL: add CanonicalType.canBeClass
And move the implementation of `SIL.Type.canBeClass` to the AST Type. The SIL Type just calls the AST Type implementation.
Also rename `SIL.Type.canonicalASTType` -> `SIL.Type.astType`.
2024-12-19 20:53:46 +01:00
Erik Eckstein
ed67e36ce5 bridging: reduce #ifdef USED_IN_CPP_SOURCE in bridging headers
Especially avoid any constructors in `#ifdef USED_IN_CPP_SOURCE` blocks, because this breaks Windows ARM64.
2024-10-25 09:47:56 +02:00
Erik Eckstein
6ecb85a863 Swift SIL: add Operand.changeOwnership 2024-10-11 09:41:36 +02:00
Erik Eckstein
5502373018 SIL: rename AssociatedTypeProtocolWitness -> AssociatedConformanceWitness in SILWitnessTable
To be consistent with the naming convention in the AST
2024-10-02 07:10:30 +02:00
Erik Eckstein
10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00
Erik Eckstein
46d3909471 SIL: improve VTable and WitnessTable
* add missing APIs
* bridge the entries as values and not as pointers
* add lookup functions in `Context`
* make WitnessTable.Entry.Kind enum cases lower case
2024-09-25 19:32:07 +02:00
Erik Eckstein
c6f384c3b1 SIL: add some APIs to SubstitutionMap 2024-09-25 19:31:40 +02:00
Erik Eckstein
c96b196ffa SwiftCompilerSources: bridge SILLinkage
Make SILLInkage available in SIL as `SIL.Linkage`.
Also, rename the misleading Function and GlobalVariable ABI `isAvailableExternally` to `isDefinedExternally`
2024-08-22 08:56:27 +02:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Andrew Trick
a3cbc28078 SwiftCompilerSources: Add enum BeginAccess.AccessKind
So we can switch over it.
2024-02-25 10:22:06 -08:00
Erik Eckstein
68cc6c8780 SwiftCompilerSources: add all missing instruction classes
And require that all new instructions must be added and registered in SwiftCompilerSources as well.
2024-02-22 07:12:10 +01:00
Erik Eckstein
3b239b25f3 swift SIL: add Function thunk APIs
* `var thunkKind`
* `set(thunkKind:)`
2024-01-31 17:16:13 +01:00
Nate Chandler
77fd37be99 [NFC] SIL: Renamed maySynchronize.
Dropped the NotConsideringSideEffects suffix.
2024-01-08 13:35:20 -08:00
Andrew Trick
b637f06acd [SIL] Bridge findPointerEscape() and fix OnoneSimplifyable
Do not bridge the hasPointerEscape flag until it is implemented.
2023-12-18 09:16:55 -08:00
zoecarver
69498e2f2e [opt] Add three new perf annotations: @_noRuntime, @_noExistential, and @_noObjCBridging. 2023-12-01 09:13:24 -07:00
Erik Eckstein
6f6c0a5608 SwiftCompilerSources: add a few enum related APIs in Type and Builder
* `Type.getEnumCases`
* `Builder.createUncheckedTakeEnumDataAddr`
* `Builder.createSwitchEnumAddr`
2023-11-27 09:21:33 +01:00
Erik Eckstein
263f4d4cde SILBridging: remove writeCharToStderr
It's not needed
2023-11-27 09:21:33 +01:00
Nate Chandler
73d57c9012 [Test] Avoid LSAN report of leaked FunctionTest.
Avoid heap-allocating an immortal FunctionTest with `new` because it
results in LSAN reporting a leak.

In fact, the "leaked" value wasn't leaked: a reference to it was stored
in a global map when the type's constructor ran.  It was only a leak in
the sense that it was never freed, not that there was a dangling
allocation which couldn't be freed.

Work around this by storing the global instances themselves in a second
static structure.  Store pointers to the instances into the global map
as before.

rdar://118134637
2023-11-14 15:05:18 -08:00
Kuba Mracek
2936a33680 [embedded] Wrap SwiftCompilerSources initialization state into swiftModulesInitialized API 2023-11-07 10:00:53 -08:00
Kuba Mracek
f0dd174df3 [embedded] Require SwiftCompilerSources to use embedded Swift 2023-11-07 10:00:53 -08:00
Hamish Knight
5d99fe63e9 Rename get() -> unbridged() on bridging wrappers 2023-10-31 11:06:39 +00:00
Hamish Knight
5853304da1 Remove BridgingUtils.h headers
These are now empty, and it seems like generally
we ought to prefer putting the bridging logic on
the BridgedXXX wrappers.
2023-10-30 23:50:00 +00:00
Hamish Knight
cae5d33368 [AST] Move BridgedNominalTypeDecl + BridgedVarDecl to ASTBridging
And renaming OptionalBridgedVarDecl to
BridgedNullableVarDecl for consistency with the
existing nullable AST node wrappers.
2023-10-30 23:49:55 +00: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
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
Nate Chandler
ce4ba6ce2a [Test] Simplified registration.
At the cost of adding an unsafe bitcast implementation detail,
simplified the code involved to register a new FunctionTest when adding
one.

Also simplifies how Swift native `FunctionTest`s are registered with the
C++ registry.

Now, the to-be-executed thin closure for native Swift `FunctionTest`s is
stored under within the swift::test::FunctionTest instance corresponding
to it.  Because its type isn't representable in C++, `void *` is used
instead.  When the FunctionTest is invoked, a thunk is called which
takes the actual test function and bridged versions of the arguments.
That thunk unwraps the arguments, casts the stored function to the
appropriate type, and invokes it.

Thanks to Andrew Trick for the idea.
2023-10-05 18:02:35 -07:00
Andrew Trick
2a604e2ab0 Merge pull request #68814 from atrick/blockarg
SwiftCompilerSources: Replace BlockArgument with Phi and TermResult.
2023-09-29 15:51:00 -07:00
Nate Chandler
dab8c146a6 [SwiftCompilerSources] Bridged in-IR testing.
Added the bridging types involved and the basic functionality.
2023-09-28 11:33:50 -07:00
Andrew Trick
a5d8aafb23 SwiftCompilerSources: Replace BlockArgument with Phi and TermResult.
All SILArgument types are "block arguments". There are three kinds:
1. Function arguments
2. Phis
3. Terminator results

In every situation where the source of the block argument matters, we
need to distinguish between these three. Accidentally failing to
handle one of the cases is an perpetual source of compiler
bugs. Attempting to handle both phis and terminator results uniformly
is *always* a bug, especially once OSSA has phi flags. Even when all
cases are handled correctly, the code that deals with data flow across
blocks is incomprehensible without giving each case a type. This
continues to be a massive waste of time literally every time I review
code that involves cross-block control flow.

Unfortunately, we don't have these C++ types yet (nothing big is
blocking that, it just wasn't done). That's manageable because we can
use wrapper types on the Swift side for now. Wrapper types don't
create any more complexity than protocols, but they do sacrifice some
usability in switch cases.

There is no reason for a BlockArgument type. First, a function
argument is a block argument just as much as any other. BlockArgument
provides no useful information beyond Argument. And it is nearly
always a mistake to care about whether a value is a function argument
and not care whether it is a phi or terminator result.
2023-09-27 18:47:46 -07:00
Erik Eckstein
ee3d702019 Swift SIL: add NominalTypeDecl.isStructWithUnreferenceableStorage 2023-07-21 07:19:12 +02:00
Kuba Mracek
145f12f6a3 Allow using structs with trivial initializers in globals that require static initialization (e.g. @_section attribute)
Before this change, if a global variable is required to be statically initialized (e.g. due to @_section attribute), we don't allow its type to be a struct, only a scalar type works. This change improves on that by teaching MandatoryPerformanceOptimizations pass to inline struct initializer calls into initializer of globals, as long as they are simple enough so that we can be sure that we don't trigger recursive/infinite inlining.
2023-07-08 19:26:59 -07:00
Erik Eckstein
e95c6425f2 Swift SIL: add some APIs for global variables 2023-05-08 21:23:36 +02:00
Erik Eckstein
a092ecb5c2 remove SILBridgingUtils.h 2023-03-21 15:33:09 +01:00
Erik Eckstein
04c90166c4 Swift Bridging: use C++ instead of C bridging for BridgedBuilder 2023-03-21 15:33:09 +01:00
Erik Eckstein
b4510105a6 Swift Bridging: remove BridgedNode 2023-03-21 15:33:09 +01:00
Erik Eckstein
7905a9ac64 Swift Bridging: remove C bridging functions for SILDebugLocation 2023-03-21 15:33:09 +01:00
Erik Eckstein
82d9da5981 Swift Bridging: use C++ instead of C bridging for BridgedMultiValueResult 2023-03-21 15:33:09 +01:00
Erik Eckstein
47ac2d2818 Swift Bridging: use C++ instead of C bridging for BridgedArgument 2023-03-21 15:33:09 +01:00
Erik Eckstein
4445373808 Swift Bridging: use C++ instead of C bridging for BridgedInstruction 2023-03-21 15:33:09 +01:00
Erik Eckstein
c4f5bab5b7 Swift Bridging: use C++ instead of C bridging for BridgedBasicBlock 2023-03-21 15:33:09 +01:00
Erik Eckstein
c0c0b80c81 Swift Bridging: use C++ instead of C bridging for BridgedGlobalVar 2023-03-21 15:33:09 +01:00
Erik Eckstein
ae7770d911 Swift Bridging: use C++ instead of C bridging for BridgedFunction 2023-03-21 15:33:09 +01:00
Erik Eckstein
e469c16744 Swift Bridging: remove BridgedType and directly use the C++ SILType instead 2023-03-21 15:33:09 +01:00
Erik Eckstein
598644fb92 Swift Bridging: use C++ instead of C bridging for the bridged witness table classes 2023-03-21 15:33:09 +01:00
Erik Eckstein
151f09769f Swift Bridging: use C++ instead of C bridging for BridgedVTable and BridgedVTableEntry 2023-03-21 15:33:09 +01:00
Erik Eckstein
fc2ad09d4b Swift Bridging: use C++ instead of C bridging for BridgedSuccessor 2023-03-21 15:33:09 +01:00
Erik Eckstein
eecea088e7 Swift Bridging: use C++ instead of C bridging for BridgedOperand and BridgedValue 2023-03-21 15:33:09 +01:00
Erik Eckstein
318c30895f Swift Optimizer: eliminate ARC operations on types which are marked as immortal
A type (mostly classes) can be attributed with `@_semantics("arc.immortal")`.
ARC operations on values of such types are eliminated.

This is useful for the bridged SIL objects in the swift compiler sources.
2023-03-14 21:07:03 +01:00
Erik Eckstein
3fca8cd06e Swift SIL: speed up Operand.value
Instead of doing the type casts and/or conformance lookup on the swift side, do it on the C++ side.
It makes a significant performance difference because `Operand.value` is a time critical function
2023-03-14 21:07:03 +01:00
Erik Eckstein
40ed0fb388 Swift Optimizer: fix a crash when simplifying same-metatype comparisons of function types
The instance type of a metatype instruction is not necessarily a legal lowered SIL Type.
Lower the type before converting it to a SILType.

rdar://105502403
2023-02-15 21:14:32 +01:00