Commit Graph

1084 Commits

Author SHA1 Message Date
Erik Eckstein
f7aaf5874e SwiftCompilerSources: add Context.getSpecializedConformance 2024-10-07 08:49:56 +02:00
Michael Gottesman
561662d6cc [sil] Add a new instruction called ThunkInst.
For now this will only be used for HopToMainActorIfNeeded thunks. I am creating
this now since in the past there has only been one option for creating
thunks... to create the thunk in SILGen using SILGenThunk. This code is hard to
test and there is a lot of it. By using an instruction here we get a few benefits:

1. We decouple SILGen from needing to generate new kinds of thunks. This means
that SILGenThunk does not need to expand to handle more thunks.

2. All thunks implemented via ThunkInst will be easy to test in a decoupled way
with SIL tests.

3. Even though this stabilizes the patient, we still have many thunks in SILGen
and various parts of the compiler. Over time, we can swap to this model,
allowing us to hopefully eventually delete SILGenThunk.
2024-10-02 14:15:49 -07:00
eeckstein
4a069c9926 Merge pull request #76790 from eeckstein/add-ast-module
SwiftCompilerSources: introduce the AST module
2024-10-02 10:50:18 +02:00
Erik Eckstein
6fdb713e94 SwiftCompilerSources: implement WitnessTable.Entry as enum 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
fadff007a1 SwiftCompilerSources: move protocol BridgedRandomAccessCollection from the SIL to the Basic module 2024-10-02 07:10:29 +02:00
Erik Eckstein
95c2c50018 DiagnosticEngine: support StringRef as diagnostic argument 2024-10-02 07:10:29 +02:00
Erik Eckstein
701a7f7275 SwiftCompilerSources: don't make anything public in the Optimizer module
The Optimizer module is a leave module. No other modules depend on it. Therefore nothing must be public in this module.
2024-10-02 07:10:28 +02:00
Allan Shortlidge
6f91b4156c ASTGen/SIL: Suppress retroactive conformance warnings.
When building ASTGen and SIL using the Swift 6.0 compiler the compiler emits
diagnostics about various retroactive conformances. Since Swift code in the
compiler needs to remain compatible with the Swift 5.10 compiler for now, use
module qualification syntax to suppress the warning. I've also included the
`@retroactive` attribute in a comment to document the retroactive conformance
acknowledgement more explicitly.

NFC.
2024-10-01 17:07:03 -07:00
Erik Eckstein
ec44600869 SwiftCompilerSources: workaround a host-compiler crash on Windows
Workaround for https://github.com/swiftlang/swift/issues/73253
2024-09-25 19:32:15 +02:00
Erik Eckstein
4a1d6925e9 MandatoryPerformanceOptimizations: specialize witness tables to support class existentials with generic classes 2024-09-25 19:32:14 +02:00
Erik Eckstein
7ffd270008 embedded: move the VTableSpecializer pass into MandatoryPerformanceOptimizations
MandatoryPerformanceOptimizations already did most of the vtable specialization work.
So it makes sense to remove the VTableSpecializerPass completely and do everything in MandatoryPerformanceOptimizations.
2024-09-25 19:32:14 +02:00
Erik Eckstein
3775a3548e ModulePassContext: add some utility functions
* `specialize(function:)`
* `deserializeCallees(of:)`
* `createWitnessTable()`
* `createSpecializedVTable`
* `Function.set(isSerialized:)`
2024-09-25 19:32:08 +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
351d42b3b3 SIL: add some Type APIs and make Type a DiagnosticArgument 2024-09-25 19:31:40 +02:00
Erik Eckstein
7ecb407226 SwiftCompilerSources: bridge SILDeclRef
And move NominalTypeDecl and DeclRef from Type.swift into a new file Declarations.swift.
Also add some APIs to NominalTypeDecl
2024-09-25 19:31:40 +02:00
Erik Eckstein
f3a9b08e7a SwiftCompilerSources: bridged ProtocolConformance
And use that in some Builder APIs
2024-09-25 19:31:40 +02:00
Erik Eckstein
897ef2c5d4 SIL: add label to SubstitutionMap.init's bridged argument 2024-09-25 19:31:39 +02:00
Kuba (Brecka) Mracek
d3c5149714 Merge pull request #76658 from kubamracek/embedded-managed-buffer
[embedded] Add support for ManagedBuffer to Embedded Swift
2024-09-25 02:54:55 -07:00
Kuba Mracek
0b50c2155e Don't emit upcast to the same type in SimplifyAllocRefDynamic, add test, add comment 2024-09-24 08:48:51 -07:00
Kuba Mracek
df38313572 The metatype operand on AllocRefDynamicInst is not always at index 1, use getNumTailTypes() 2024-09-23 15:42:38 -07:00
Kuba Mracek
c7a5569c4f [embedded] Add support for ManagedBuffer to Embedded Swift
This makes ManagedBuffer available and usable in Embedded Swift, by:

- Removing an internal consistency check from ManagedBuffer that relies on metatypes.
- Making the .create() API transparent (to hoist the metatype to the callee).
- Adding a AllocRefDynamicInst simplification to convert `alloc_ref_dynamic` to `alloc_ref`, which removes a metatype use.
- Adding tests for the above.
2024-09-23 13:32:50 -07:00
Kuba (Brecka) Mracek
ecce6ac3a9 Merge pull request #76046 from kubamracek/fix-optimize-assert-config
Fix flipped 0/1 values in SimplifyBuiltin.optimizeAssertConfig
2024-09-18 14:18:19 -07:00
Kuba Mracek
4b164798ab Avoid return-less switch expression (doesn't compile on old Swift compilers) 2024-09-17 09:35:06 -07:00
Erik Eckstein
0ee51e4d90 StaticInitCloner: skip begin_access instructions when cloning the initial value of a global
Fixes a crash when simplifying a load of an UnsafePointer-global which points to another global.

rdar://135223354
2024-09-14 14:12:36 +02:00
eeckstein
8b1e257bc1 Merge pull request #76277 from eeckstein/fix-borrowed-from-updating
SIL: fix `Phi.init` for arguments in unreachable blocks
2024-09-06 15:02:09 +02:00
Erik Eckstein
d4221f4b2a SIL: fix Phi.init for arguments in unreachable blocks
Treat arguments in unreachable blocks like a degenerate phi so we don't consider it a terminator result.

Fixes a compiler crash.
rdar://135336430
2024-09-05 13:12:13 +02:00
Alejandro Alonso
b35ac50d3c Optimize TypeValueInst in Swift 2024-09-04 15:13:48 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Erik Eckstein
e683d7b679 ComputeSideEffects: fix a corner case with consuming indirect arguments in dead-end functions
Usually there _must_ be a read from a consuming in-argument, because the function has to consume the argument.
But in the special case if all control paths end up in an `unreachable`, the consuming read might have been dead-code eliminated.
Therefore make sure to add the read-effect in any case. Otherwise it can result in memory lifetime failures at a call site.

fixes a memory lifetime failure

rdar://134881045
2024-08-29 18:51:46 +02:00
Kuba Mracek
50fa83b237 Fix flipped 0/1 values in SimplifyBuiltin.optimizeAssertConfig 2024-08-22 14:46:02 -07:00
Erik Eckstein
b7e5ec825a MandatoryPerformanceOptimizations: force inlining of transparent functions and de-virtualization
Do this even if the function then contains references to other functions with wrong linkage. Instead fix the linkage later.
Fixes a false error in embedded swift.

rdar://134352676
2024-08-22 09:15:14 +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
Andrew Trick
e4036b970b Improve LocalVariableAccessWalker to handle switch_enum_addr. 2024-08-19 18:01:49 -07:00
Allan Shortlidge
9062271185 SILGen: Skip SIL verification and optimization if errors were emitted.
In lazy typechecking mode, errors in the program may only be discovered during
SILGen, which can leave the SIL in a bad state for subsequent stages of
compilation. If errors were detected, skip SIL verification and optimization to
prevent knock-on failures.

Partially reverts https://github.com/swiftlang/swift/pull/75428, which included
a more targeted fix for one of the possible knock-on effects of bad SIL coming
out of SILGen.

Resolves rdar://132107752.
2024-08-12 15:34:59 -07:00
Erik Eckstein
52d6ae334d DeinitDevirtualizer: don't erase the destroy instruction if the the destroyed value can't be de-virtualized
This can happen if the destroyed type is resilient.
Fixes a verifier crash.
2024-08-12 13:34:50 +02:00
Erik Eckstein
a5ef2b30f1 DeinitDevirtualizer: Don't run the pass on non-OSSA functions 2024-08-12 13:34:50 +02:00
Alexander Cyon
c18a24e499 [SwiftCompilerSources] Fix typos 2024-08-08 22:22:39 -07:00
Erik Eckstein
21fedfa61e Verifier: fix a stupid bug in borrowed-from verification
... which made the verification useless.
2024-08-07 18:02:39 +02:00
Erik Eckstein
def3b6fab0 AccessUtils: recognize addressor calls of globals as a "global" access base
Makes e.g. alias analysis more precise in the early stage of the pass pipeline where addressor calls are not inlined, yet.
2024-08-05 17:12:46 +02:00
Erik Eckstein
ac3e2cb141 EscapeUtils: handle more use types for unchecked_addr_cast
Handle `apply` and `try_apply`.
Also, improve test cases
2024-08-05 17:02:07 +02:00
Erik Eckstein
8f839f0eab AliasAnalysis: use AccessBase.isLet instead of duplicating the code
A small refactoring. NFC
2024-08-05 17:02:07 +02:00
Erik Eckstein
345f9c1dfc AliasAnalysis: handle destroy_value [dead_end] in computeMemoryEffect
We don't have to take deinit effects into acount for a `destroy_value [dead_end]`.
Such destroys are lowered to no-ops and will not call any deinit.
2024-08-05 17:02:06 +02:00
Erik Eckstein
e3de408716 Simplification: remove builtin "destroyArray" with trivial element types 2024-08-01 13:38:39 +02:00
Andrew Trick
3e98d2e232 Fix an assert in LifetimeDependenceUtils to allow all valid cases. 2024-07-31 22:58:39 -07:00
Andrew Trick
11ba799cd4 LifetimeDependence: diagnose yield and store-to-yield. 2024-07-30 16:27:48 -07:00
Andrew Trick
c8fcb722a3 LifetimeDependenceInsertion for inout dependencies. 2024-07-30 15:57:57 -07:00
Andrew Trick
11640461ef Lifetime dependence: add inferrence for setters.
A nonescapable computed property should always depend on 'newValue'. We simply
infer that now. There's no way to explicitly spell the dependence.
2024-07-30 15:57:57 -07:00
Andrew Trick
ba9f12a80f LifetimeDependenceDiagnostics support for inout reassignment.
This relies on parameter dependence targets.

i.e. dependsOn in parameter position instead of result position.
2024-07-30 15:57:57 -07:00