Commit Graph

21 Commits

Author SHA1 Message Date
Arnold Schwaighofer
ad6f6dec6e IRGen: We cannot call destroy through metadata of private types of non-copyable fields
So call the destroy on the closing type instead.

Amends the concepts areFieldsABIAccessible/isABIAccessible to take metadata
accessibility of non-copyable types into account.

rdar://133990500
2024-08-21 11:22:30 -07: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
Evan Wilde
8ce6ee8dd1 Updating API usages
LLVM deprecated, renamed, and removed a bunch of APIs. This patch
contains a lot of the changes needed to deal with that.

The SetVector type changed the template parameters.

APInt updated multiple names, countPopulation became popcount,
getAllOnesValue became getAllOnes, getNullValue became getZero, etc...

Clang type nullability check stopped taking a clang AST context.

The LLVM IRGen Function type stopped exposing basic block list directly,
but gained enough API surface that the translation isn't too bad.
(GenControl.cpp, LLVMMergeFunctions.cpp)

llvm::Optional had a transform function. That was being used in a couple
of places, so I've added a new implementation under STLExtras that
transforms valid optionals, otherwise it returns nullopt.
2023-07-17 10:53:42 -07:00
Joe Groff
03a2393a6c IRGen: Track IsCopyable through type infos.
And use the new bit to ensure we don't try to lower move-only types
with common layout value witness surrogates. Take a bit in the runtime
value witness flags to represent types that are not copyable.
2023-02-27 18:52:50 -08:00
Joe Groff
a572c3f491 IRGen: Rename internal 'POD' references to 'TriviallyDestroyable'.
Noncopyable types aren't really "POD", but the bit is still useful to track
whether a noncopyable type has a no-op destroy operation, so rename the
existing bit to be more specific within IRGen's implementation.

Don't rename it in the runtime or Builtin names yet, since doing so will
require a naming transition for compatibility.
2023-02-27 18:52:10 -08:00
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
Ben Rimmington
0b29450a3d [SE-0368] StaticBigInt (#40722) 2022-12-06 21:59:42 +00:00
Dario Rexin
3cf40ea504 [IRGen] Re-introduce TypeLayout strings (#62059)
* Introduce TypeLayout Strings

Layout strings encode the structure of a type into a byte string that can be
interpreted by a runtime function to achieve a destroy or copy. Rather than
generating ir for a destroy/assignWithCopy/etc, we instead generate a layout
string which encodes enough information for a called runtime function to
perform the operation for us. Value witness functions tend to be quite large,
so this allows us to replace them with a single call instead. This gives us the
option of making a codesize/runtime cost trade off.

* Added Attribute @_GenerateLayoutBytecode

This marks a type definition that should use generic bytecode based
value witnesses rather than generating the standard suite of
value witness functions. This should reduce the codesize of the binary
for a runtime interpretation of the bytecode cost.

* Statically link in implementation

Summary:
This creates a library to store the runtime functions in to deploy to
runtimes that do not implement bytecode layouts. Right now, that is
everything. Once these are added to the runtime itself, it can be used
to deploy to old runtimes.

* Implement Destroy at Runtime Using LayoutStrings

If GenerateLayoutBytecode is enabled, Create a layout string and use it
to call swift_generic_destroy

* Add Resilient type and Archetype Support for BytecodeLayouts

Add Resilient type and Archetype Support to Bytecode Layouts

* Implement Bytecode assign/init with copy/take

Implements swift_generic_initialize and swift_generic_assign to allow copying
types using bytecode based witnesses.

* Add EnumTag Support

* Add IRGen Bytecode Layouts Test

Added a test to ensure layouts are correct and getting generated

* Implement BytecodeLayouts ObjC retain/release

* Fix for Non static alignments in aligned groups

* Disable MultiEnums

MultiEnums currently have some correctness issues with non fixed multienum
types. Disabling them for now then going to attempt a correct implementation in
a follow up patch

* Fixes after merge

* More fixes

* Possible fix for native unowned

* Use TypeInfoeBasedTypeLayoutEntry for all scalars when ForceStructTypeLayouts is disabled

* Remove @_GenerateBytecodeLayout attribute

* Fix typelayout_based_value_witness.swift

Co-authored-by: Gwen Mittertreiner <gwenm@fb.com>
Co-authored-by: Gwen Mittertreiner <gwen.mittertreiner@gmail.com>
2022-11-29 21:05:22 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Arnold Schwaighofer
5c9de9e656 Revert "Merge pull request #40356 from gmittert/TypeLayoutFixes"
This reverts commit d27e6e1e46, reversing
changes made to f2e85a2b1f.

It causes an execution time failure in
`Interpreter/struct_extra_inhabitants.swift` with

```
ninja -C swift-macosx-x86_64 check-swift-optimize
```

rdar://86054209
2021-12-06 07:49:57 -08:00
Gwen Mittertreiner
13bb43b72e Revert "Revert "Merge pull request #37116 from gmittert/Descaling""
This reverts commit 7c7dd666c6.
2021-11-30 16:19:34 -08:00
Arnold Schwaighofer
7c7dd666c6 Revert "Merge pull request #37116 from gmittert/Descaling"
This reverts commit 5ebb1b2fc6, reversing
changes made to 76260c2235.

This commit causes compiler crashes when using protocol composition
types involving objc.

Repo:

```
import Foundation

public class SomeObject : NSObject {}

public protocol ProtoA{}

public protocol SomeProtoType { }
public typealias Composition = SomeObject & SomeProtoType

public struct Thing<T: ProtoA> {
    let a: Composition
    let b: T

    init(a: Composition,
         b: T
    ) {
        self.a = a
        self.b = b
    }
}

$ swiftc -c Repo.swift -O
```

While looking at this issue I noticed that it is not correct to use a
ScalarEntry of ObjCReference (or other ScalarKind::XXXReference) for
`AddressOnly##Name##ClassExistentialTypeInfo` types. These should be
calling the IGF.emit##Name##Destroy(addr, Refcounting); functions not
objc_release.
It is probably best to use the macro facilities in a similar fashion like
lib/IRGen/GenExistential.cpp does.

rdar://85269025
2021-11-11 11:44:09 -08: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
Gwen Mittertreiner
a3ceda653f Teach TypeLayout the Different Types of References
Summary:
As part of SR-14273, the type layout infrastructure needs to be able to be able
to differentiate between types of scalars so it knows how to release/retain
appropriately. Right now, for example, to destroy a scalar, it blindly calls
into typeInfo's irgen functions which means it's not able to generate any of
the needed information for itself.

This patch adds a field to ScalarTypeLayout to allow them to know what kind of
reference they are and strings through the machinery to provide the information
to set it.

This also moves ScalarTypeLayout::destroy to use the new information.

Test Plan: ninja check-swift

Reviewers: mren, #pika_compiler

Reviewed By: mren

Subscribers: apl, phabricatorlinter

Differential Revision: https://phabricator.intern.facebook.com/D30983093

Tasks: T100580959

Tags: swift-adoption

Signature: 30983093:1632340205:3bdd3218ae86ad6b3d199cc1b504a625e3650ec0
2021-09-29 10:40:55 -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
John McCall
dba8d2e4a9 [NFC] Simplify making trivial scalar pair types. 2021-04-08 12:57:12 -04:00
Robert Widmann
40d9cd8d3f [NFC] Give IRGenModule Exclusive Ownership of an LLVMContext Object 2020-04-16 11:57:44 -07:00
Arnold Schwaighofer
7b65768167 IRGen: Add code to compute type layouts
rdar://51988441
2020-02-19 07:12:55 -08:00
Michael Munday
bb2740e540 IRGen: fix enum bit packing on big-endian platforms.
This change modifies spare bit masks so that they are arranged in
the byte order of the target platform. It also modifies and
consolidates the code that gathers and scatters bits into enum
values.

All enum-related validation tests are now passing on IBM Z (s390x)
which is a big-endian platform.
2019-08-07 03:54:16 -04:00
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00