Commit Graph

10994 Commits

Author SHA1 Message Date
Michael Gottesman
29672c503a Merge pull request #66381 from gottesmm/noimplicitcopy-borrow-consuming
[borrowing/consuming] Make borrowing and consuming parameters no implicit copy.
2023-06-06 21:41:18 -04:00
Slava Pestov
c30f7dcdd8 Merge pull request #66096 from slavapestov/pack-element-type
Preliminary support for substitution with nested pack expansions
2023-06-06 19:11:52 -04:00
Andrew Trick
4325c0ae0b Merge pull request #66314 from atrick/fix-dropdeinit
[move-only] Fix SIL representation and SILOptimizer to preserve value deinits
2023-06-06 12:09:34 -07:00
Michael Gottesman
70ab38d9da [move-only] Add a new instruction: moveonlywrapper_to_copyable_box.
I am going to use this to unwrap ${ @moveOnly T } so that I can pass it to
partial_apply that expect a ${ T }
2023-06-06 14:26:22 -04:00
Slava Pestov
be218f5e16 AST: Use PackElementType to model references to pack elements of outer expansions 2023-06-06 14:18:37 -04:00
Alastair Houghton
d3d345bb23 Merge pull request #66333 from al45tair/eng/PR-110260855
[Backtracing][IRGen] Add a semantic attribute to force frame pointer.
2023-06-06 17:51:20 +01:00
Michael Gottesman
611e6760f5 [borrowing/consuming] Add a new instruction called copyable_to_moveonlywrapper_addr.
Just the $*T -> $*@moveOnly T variant for addresses. Unlike the object version
this acts like a cast rather than something that provides semantics from the
frontend to the optimizer.
2023-06-06 12:42:23 -04:00
Michael Gottesman
43f42e2c04 [borrowing/consuming] Add new instruction: moveonlywrapper_to_copyable_addr.
The reason why I am using a different instruction for addresses and objects here
is that the object checker doesnt have to deal with things like initialization.
2023-06-06 12:42:23 -04:00
Andrew Trick
521f0ffc9e [move-only] Verify drop_deinit
drop_deinit only exists in ownership SIL. Remove IRGen support.

A drop_deinit can only ever be destroyed or destructured.

A destructure of a struct-with-deinit requires a drop_deinit operand.
2023-06-06 09:17:53 -07:00
swift-ci
4ef135cc10 Merge pull request #66201 from nate-chandler/dealloc-on-stack-packs
[IRGen] Dealloc on-stack metadata/wtable packs on the dominance frontier.
2023-06-05 13:30:18 -07:00
Nate Chandler
2af114cf17 [IRGen] NFC: Assert cleanups for metadata emits.
In debug builds, before SIL function emission, pass over the function to
collect cleanups.  After emitting an instruction for which an on-stack
metadata/wtable pack was emitted, assert that there were cleanups for
it in the function.
2023-06-05 08:11:28 -07:00
Nate Chandler
d1ec1e6693 [IRGen] Dealloc metadata packs on dom frontier.
Deallocate dynamic allocas done for metadata/wtable packs.  These
stackrestore calls are inserted on the dominance frontier and then stack
nesting is fixed up.  That was achieved as follows:

Added a new IRGen pass PackMetadataMarkerInserter; it
- determines if there are any instructions which might allocate on-stack
  pack metadata
- if there aren't, no changes are made
- if there are, alloc_pack_metadata just before instructions that could
  allocate pack metadata on the stack and dealloc_pack_metadata on the
  dominance frontier of those instructions
- fixup stack nesting

During IRGen, the allocations done for metadata/wtable packs are
recorded and IRGenSILFunction associates them with the instruction that
lowered.  It must be the instruction after some alloc_pack_metadata
instruction.  Then, when visiting the dealloc_pack_metadata instructions
corresponding to that alloc_pack_metadata, deallocate those packs.
2023-06-05 08:11:28 -07:00
Nate Chandler
172be49bcc [IRGen] Disable on-stack pack metadata via attr.
When lowering a SIL function, if it bears the no_onstack_pack_metadata
annotation, disable on-stack pack metadata.
2023-06-05 08:11:28 -07:00
Nate Chandler
efca4e57c8 [SIL] Added on-stack pack metadata marker insts.
The new alloc_pack_metadata and dealloc_pack_metadata are inserted as
part of IRGen lowering.  The former indicates that the next instruction
might result in on-stack pack metadata being emitted.  The latter
indicates that this is the position at which metadata emitted on behalf
of its operand should be cleaned up.
2023-06-05 08:11:28 -07:00
Nate Chandler
af4e7da286 [IRGen] Add hashable conformance to [Stack]Addr.
Provide template instantiations of llvm::DenseMapInfo at
swift::irgen::Address and swift::irgen::StackAddress.
2023-06-05 08:11:27 -07:00
Nate Chandler
db13477ec2 [IRGen] Skip metadata heapification on flag.
If the -enable-pack-metadata-stack-promotion[=true] flag is passed, skip
eager heapification.
2023-06-05 08:11:27 -07:00
nate-chandler
ba07393e42 Merge pull request #66281 from nate-chandler/rdar110123679
[GenPack] Always heapify metadata packs.
2023-06-05 07:33:03 -07:00
nate-chandler
ad6caaa881 Merge pull request #66315 from nate-chandler/rdar110195273
[IRGen] Mask off metadata pack passed to DebugInfo
2023-06-05 07:30:53 -07:00
Alastair Houghton
f8fe8b1ecc [Backtracing][IRGen] Add a semantic attribute to force frame pointer.
The Swift backtracer's frame pointer unwinder cannot work on Linux
without this change, because the compiler omits the frame pointer from
the function in libSwift_Backtracing that actually captures the stack.

rdar://110260855
2023-06-05 15:18:22 +01:00
Michael Gottesman
4450b983cf Merge pull request #66332 from gottesmm/pr-5f318bafc8cd3b8c9e6769c000956ac52bad12f8
[move-only] Add a call to indirectCleanup to make sure that we call llvm.lifetime.end when we emit a call to a deinit via the value witness table.
2023-06-05 06:42:33 -07:00
Michael Gottesman
dcc246b37f [move-only] Add a call to indirectCleanup to make sure that we call llvm.lifetime.end when we emit a call to a deinit via the value witness table. 2023-06-05 03:45:52 -07:00
Nate Chandler
0b5a233d73 [GenPack] Always heapify metadata packs.
Until the optimization to leave packs on-stack is in place.  Even then,
we'll want to keep this as a fallback.

rdar://110123679
2023-06-03 07:30:09 -07:00
Nate Chandler
6e7952b4ad [IRGen] Mask off metadata pack passed to DebugInfo
When a metadata pack is heap allocated, the pointer's LSB is set.
But lldb is expecting a real pointer.  So mask it off.

Companion PR has a test: https://github.com/apple/llvm-project/pull/6961

rdar://110195273
2023-06-03 07:30:09 -07:00
Nate Chandler
c9f79861f1 [GenPack] NFC: Stack de/alloc traffics in shapes.
When allocating, the shape is computed, and it (its constant value if
any) is needed when deallocating, so return the shape along with the
address.  And when deallocating, accept the shape, which the client
received during allocation, rather than requiring that the caller
compute the fixed size.
2023-06-03 07:30:09 -07:00
Dario Rexin
5cbf9f9641 [IRGen] Handle complex single payload enum cases (#66289)
* [IRGen] Handle complex single payload enum cases

rdar://110138498

Handles single payload enum cases with more complex bit patterns (e.g. >64 bits or scattered) by storing a relative pointer to a function that reads the tag.

* Use proper symbol for enum tag helper
2023-06-02 11:49:57 -07:00
Slava Pestov
5e7a91d62a SIL: Generalize SILType::subst() to take SubstOptions 2023-06-01 19:20:11 -04:00
Allan Shortlidge
583c8de8dd Merge pull request #66232 from tshortli/unavailable-objc-override
IRGen: Avoid emitting Obj-C method metadata for unavailable methods
2023-06-01 08:54:23 -07:00
Dario Rexin
e6fe6befe7 [IRGen] Include extra tag bytes in offset in layout strings (#66259)
rdar://110088270

When extra tag bytes are used in single payload enums, the generated layout string does not include the tag bytes in its offset after the enum payload. This causes subsequent ref count operations to use the wrong memory location.
2023-05-31 20:54:47 -07:00
Allan Shortlidge
04a22f307e IRGen: Avoid emitting Obj-C method metadata for unavailable methods.
Resolves rdar://109911571
2023-05-31 18:19:56 -07:00
Erik Eckstein
92fab06d96 IRGen: fix generation of static enums with function payloads
fixes a compiler crash

rdar://109999583
2023-05-31 14:22:48 +02:00
Dario Rexin
f4672953d8 [IRGen] Fix refcount bytes computation for single payload enums (#66216)
Nested ref count byte was accidentally counted as Int64, but should be Size
2023-05-30 14:36:11 -07:00
Michael Gottesman
8579c1924d [move-only] Make sure that we serialize deinits and if we are not able to see the value witness function, call it via the value witness function.
Some notes:

1. I put in both a swiftpm like test case and a library evolution test case. I
also updated the moveonly_deinit serialization swift test to show that we
actually serialize the deinit.

2. I changed when we emit the deinit table to only be when we have a type with
an actual value type destructor. Notably this doesn't include classes today so
as a side-effect, we no longer attempt to devirtualize moveonly class deinits.
This doesn't affect anything we are trying to actually do since we do not
support noncopyable classes today. With that in mind, I changed one test that
was showing that deinit devirtualization worked to use a struct with deinit
instead of a class.

rdar://109679168
2023-05-27 22:07:04 -07:00
Allan Shortlidge
ce452f75f3 Merge pull request #66157 from tshortli/unavailable-resilient-enum-tag
IRGen: Avoid emitting resilient tag indices for unavailable enum cases
2023-05-26 20:50:03 -07:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Slava Pestov
9b3faad523 Merge pull request #66126 from slavapestov/pack-element-refactoring
Preliminary work for introducing PackElementType
2023-05-26 09:13:53 -04:00
Allan Shortlidge
af1df92e6f IRGen: Avoid emitting resilient tag indices for unavailable enum cases.
When `-unavailable-decl-optimization=complete` is specified, skip emission of
resilient tag indices for enum cases that are marked unavailable with
`@available`.

Resolves rdar://109805050
2023-05-25 21:55:00 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Erik Eckstein
fe367e8013 Optimizer/IRGen: allow enums in static initializers of globals
The main change here is in IRGen which needs to be able to emit constant enum values.
Use `emitValueInjection` to create the enum constant.
Usually this method creates code in the current function.
But if all arguments to the enum are constant, the builder never has to emit an instruction.
Instead it can constant fold everything and just returns the final constant.

Also, create statically initialized let-globals as constant global (`constant` instead of `global`).
2023-05-25 16:28:41 +02:00
Erik Eckstein
f2a8fb52b1 IRGen: add EnumPayload.dump() for debugging 2023-05-25 16:28:41 +02:00
Erik Eckstein
24837b4d10 IRGen: change a few enum utility functions to be able to create enums in static initializers
Instead of passing `IRGenFunction`, pass the `IRGenModule` and the `IRBuilder`.
This makes enum creation not dependent on the presence of a function.

NFC, just refactoring.
2023-05-25 16:28:41 +02:00
Allan Shortlidge
a59f5257b3 Merge pull request #66069 from tshortli/unavailable-enum-payloads
IRGen: Exclude unavailable enum cases from runtime layout calculations
2023-05-24 17:22:08 -07:00
Dario Rexin
97381e6411 [IRGen] Support additional single payload enum cases in layout strings (#66042)
* [IRGen] Support additional single payload enum cases in layout strings

rdar://105837101

Adds layout string support for single payload enums with simple (non-scattered) extra inhabitant patterns

* Add more test cases
2023-05-23 13:17:51 -07:00
Hamish Knight
8da1e7377b Merge pull request #66053 from hamishknight/filing-cabinet 2023-05-23 09:00:52 +01:00
eeckstein
f5361ed68f Merge pull request #66048 from eeckstein/object-outliner
Implement the ObjectOutliner and `load` simplification in Swift
2023-05-23 07:23:06 +02:00
Allan Shortlidge
ce97377218 IRGen: Exclude unavailable enum cases from runtime layout calculations.
When `-unavailable-decl-optimization=complete` is specified, exclude
unavailable enum cases from the runtime layout of enums with payloads. Without
this, the type metadata for unavailable types may be referenced by enum cases
with unavailable payloads and cause linker failures.

Resolves rdar://107483852
2023-05-22 21:49:41 -07:00
Dario Rexin
5a28a6d5ea [IRGen] Remove some commented out code and clean up (#66056) 2023-05-22 21:34:46 -07:00
Hamish Knight
d428721ac4 [Profiler] Avoid quadratic search for coverage filename in WMO
Previously we were doing a `std::find` over the
files for each coverage mapping, which would be
quadratic for WMO. Switch to using a DenseMap
instead.
2023-05-22 17:54:17 +01:00
Erik Eckstein
a80d0cb8a7 remove now unused utilities
* StaticInitCloner
* some APIs in SILGlobalVariable
2023-05-22 15:34:26 +02:00
Erik Eckstein
54aacf64e1 SIL: don't allow upcast to be done on address types
It's not needed and just complicates the SIL
2023-05-22 15:34:26 +02:00
Hamish Knight
a06c1acc1d Merge pull request #66019 from hamishknight/cover-for-your-cover 2023-05-20 08:13:40 +01:00