Commit Graph

123 Commits

Author SHA1 Message Date
Anthony Latsis
17fc00f8a7 [test] IRGen: Adjust FileCheck patterns for new nuw attribute in upstream LLVM
This attribute was introduced in
7eca38ce76d5d1915f4ab7e665964062c0b37697 (llvm-project).

Match it using a wildcard regex, since it is not relevant to these
tests.

This is intended to reduce future conflicts with rebranch.
2025-05-04 03:28:56 +01:00
Ben Langmuir
7d11d43d6d [test] Add explicit targets to tests depending on the default
Add specific deployment target versions to some tests that need to test
10.x-specific behaviours and are currently depending on the default
deployment target.

Certain tests were only checking either the stable or unstable ABI
depending on the platform the test was running. In those cases I doubled
up the checks so that we would test both cases on platforms that
supported it. This might use a bit of extra time on targets that only
support the stable ABI, but it seemed worth it for the additional
coverage in CI.
2024-08-29 07:55:14 -07:00
Yuta Saito
5f684ec75f [wasm][test] Add objc_codegen feature to exclude enable-objc-interop tests
Clang does not accept `-x objective-c` with WebAssembly target and it
crashes with "Objective-C support is unimplemented for object file
format" for now. `-enable-objc-interop` can work without the objc
runtime support (which is indicated by `objc_interop` feature), so this
adds a new `objc_codegen` feature to require Objective-C support only
at compile-time.
2023-10-11 00:51:17 +00:00
Arnold Schwaighofer
3b5ebaa46c Fix some tests in IRGen folder 2023-06-21 10:10:32 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07: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
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
d7f8e11a79 tests: LLVM optimizes away internal globals that are not referenced otherwise 2022-07-26 17:07:45 -07:00
Arnold Schwaighofer
66ce0ee901 Fix tests 2021-11-29 14:01:21 -08:00
Saleem Abdulrasool
5bd27db2ee IRGen: correct decoration handling for x86
When building the label for the IAT synthetic, we need to pre-decorate
the symbol before we apply the synthetic symbol prefix lest we end up
placing the user-label prefix over the synthetic symbol rather than the
actual symbol.  This is required to correctly resolve symbols when
building the standard library for x86.
2020-12-06 21:35:23 -08:00
Saleem Abdulrasool
2c17600154 test: account for indirect imports
Adjust the test to accommodate environments which do indirect imports,
which use the singleton strategy, relying on the runtime initialization
of fields which are imported.
2020-05-22 15:16:24 -07:00
David Zarzycki
97c89d8d3a Remove three ObjC fields from non-ObjC runtime 2020-05-22 09:21:21 -07:00
David Zarzycki
3c414894e2 [IRGen testing] Reapply: Fix bogus FileCheck check-prefix "-SAME" usage
The correct usage of "-SAME" is after the check-prefix, not in the
middle. I've updated the constants to what is emitted today.

Now with verified 32-bit fixes.
2020-05-18 09:04:22 -04:00
Saleem Abdulrasool
6a1c4f0fdd Revert "[IRGen testing] Fix bogus FileCheck check-prefix "-SAME" usage" 2020-05-16 13:43:21 -07:00
David Zarzycki
2d3daad72e [IRGen testing] Fix bogus FileCheck check-prefix "-SAME" usage
The correct usage of "-SAME" is after the check-prefix, not in the
middle. I've updated the constants to what is emitted today.
2020-05-16 10:16:12 -04:00
Kuba (Brecka) Mracek
c728d7a4d2 Fix failing IRGen arm64e tests (#30296) 2020-03-10 11:22:54 -07:00
Kuba Mracek
1bd425da67 [arm64e] Test changes to support arm64e 2020-02-27 16:10:48 -08:00
Arnold Schwaighofer
9ee12db2a9 Fix tests for LLVM change that added anonymous parameter labeling
Fix for r367755.
2019-08-15 14:57:24 -07:00
Joe Groff
77b012af1d SIL: Add an [exact_self_class] function attribute.
This indicates that the "self" argument to the current function is always dynamically of the exact
static base class type, allowing metadata accesses in IRGen to use the local self metadata to answer
metadata requests for the class type. Set this attribute on allocating entry points of designated
inits, which is one of the most common places where we emit redundant metadata accesses.
2019-08-08 14:03:07 -07:00
Joe Groff
b3ac66aeeb IRGen: Leave frame pointers off SIL functions marked [thunk]. 2019-08-07 14:16:45 -07:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -04:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05:00
John McCall
7f55a4a4f0 Always give known-empty class properties a zero offset in the static layout.
Field offset vectors are always filled out with either zero or the static layout's offset, depending on the metadata initialization strategy.  This change means that the static layout's offset will only be non-zero for properties with a statically-known layout.  Existing runtimes doing dynamic class layout assign class properties a zero offset if the field offset vector entry is zero and the property is zero-sized.  So this effectively brings the compiler into accord with the runtime (for all newly-compiled Swift code, which will eventually be all Swift code because the current public releases of Swift 5 are not yet considered ABI-stable) and guarantees a zero value for the offset everywhere.

Since the runtime will agree with the compiler about the zero value of the offset, the compiler can continue to emit such offset variables as constant.  The exception to this rule is if the class has non-fragile ObjC ancestry, in which case the ObjC runtime (which is not aware of this special rule for empty fields) will attempt to slide it along with everything else.

Fixes rdar://48031465, in which the `FixedClassMetadataBuilder` for a class with a legacy-fixed layout was writing a non-zero offset for an empty field into the field offset vector, causing the runtime to not apply the special case and thus to compute a non-zero offset, which it then attempted to copy into the global field offset variable, which the compiler had emitted as a true-constant zero.
2019-02-20 00:53:11 -05:00
Slava Pestov
b64db715a8 IRGen: Remove -enable-class-resilience staging flag 2019-02-08 14:22:00 -05:00
John McCall
79d15816c4 Fix a race condition with the initialization of class metadata.
In our initial approach for resolving metadata dependency cycles with classes, non-transitively complete superclass metadata was fetched by the subclass's metadata completion function and passed to `swift_initClassMetadata`. That could mean generating quite a lot of code in the completion function, and so we fairly recently changed it so that `swift_initClassMetadata` instead fetched the superclass metadata via a demangling. Unfortunately, the metadata demangler only fetches _abstract_ metadata by default, and class metadata cannot be considered even non-transitively complete when its superclass reference not at that stage.  If the superclass metadata is being completed on one thread, and a subclass is being completed on another, and the subclass installs the incomplete superclass metadata in its superclass field and attempts to register the subclass with the Objective-C runtime, the runtime may crash reading the incompletely-initialized superclass.

The proper fix is to make `swift_initClassMetadata` fetch non-transitively complete metadata for the superclass, delaying completion if that metadata is unavailable. Unfortunately, that can't actually be implemented on top of `swift_initClassMetadata` because that function has no means of reporting an unsatisfied dependency to its caller, and we can no longer simply change its signature without worrying about a small of internal code that might still be using it. We cannot simply perform a blocking metadata request in `swift_initClassMetadata` because it is deeply problematic to block within a metadata completion function. The solution is therefore to add a `swift_initClassMetadata2` which has the ability to report unsatisfied dependencies. That was done in #22386; this patch builds on that by teaching the compiler to generate code to actually use it. It is therefore not safe to use this patch if you might be running on an OS that only provides the old runtime function, but that should be a temporary Apple-internal problem.

Fixes rdar://47549859.
2019-02-05 23:28:57 -05:00
Saleem Abdulrasool
d7f9e04dbc test: address portability concerns for Windows
Update the IRGen tests for Windows IRGen.  This is an improvement over
what we have currently, but is not sufficient to get all the IRGen tests
passing yet.
2019-01-15 11:03:37 -08:00
Slava Pestov
1023f27d67 Revert "IRGen: Use an invariant load to load metadata base offset" 2018-12-03 20:49:54 -05:00
Slava Pestov
1649188d86 IRGen: Use an invariant load to load metadata base offset 2018-12-02 18:42:01 -05:00
Slava Pestov
ff09603f30 IRGen: @_fixed_layout classes still have resilient metadata 2018-11-29 23:20:02 -05:00
Slava Pestov
09027413bc IRGen: Emit field offsets before vtable entries
We want to be able to define classes with a fixed storage layout,
but a resilient (opaque) vtable. If the class is also generic,
we still have to load field offsets from the metadata if they
are dependent.

So put the field offsets after the generic arguments and before
the vtable.

This is an ABI break for @_fixed_layout classes, which are
defined by the stdlib.
2018-11-29 23:20:02 -05:00
Slava Pestov
76dce7c5e0 Runtime: The class metadata relocation function can be null
IRGen always just emits a simple implementation that immediately
calls swift_relocateClassMetadata(); so allow the function to be
null in this case to save on code size.
2018-11-26 21:22:48 -05:00
Slava Pestov
3b10ed5eaf SIL: Non-final public methods of resilient classes don't need public linkage
Part of <rdar://problem/40432647>.
2018-11-15 14:55:44 -05:00
Doug Gregor
2b44e8578f [ABI] Use mangled superclass names from class context descriptors.
Rather than rely on the metadata initialization function to compute and
fill in the superclass, use the mangled superclass name to construct the
superclass metadata.
2018-10-04 15:43:24 -07:00
Doug Gregor
a24729afb8 [ABI] Add a mangled superclass type to class context descriptors.
This allows us to recover the complete superclass type from metadata.
Currently unused, but we want to stub out the space in the ABI.
2018-10-03 20:55:17 -07:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Joe Groff
77a0923ca6 SILGen: Emit convenience initializers as allocating entry points.
And only dispatch designated inits by their allocating entry points. rdar://problem/29634243
2018-09-13 12:31:23 -07:00
Slava Pestov
3808ae0d58 IRGen: Use method lookup function for resilient super method calls
Fixes <https://bugs.swift.org/browse/SR-3928>, <rdar://problem/31411193>.
2018-09-07 21:57:16 -07:00
Slava Pestov
9347a072e5 IRGen: Emit method lookup function 2018-09-07 21:50:58 -07:00
Slava Pestov
100679aa1e IRGen: Use a method descriptor to identify methods where possible
This eliminates the 'non-resilient class' case here entirely since
all class methods have method descriptors.
2018-09-07 12:15:24 -07:00
Slava Pestov
b7449d5621 IRGen/Runtime: Method override descriptors 2018-09-04 14:46:34 -07:00
Slava Pestov
b3060d8836 IRGen: Emit dispatch thunks while emitting nominal type descriptor 2018-08-31 00:20:38 -06:00
Slava Pestov
8be09fef74 IRGen/Runtime: Rename "InPlaceMetadata" to "SingletonMetadata"
It's not actually "in-place" for resilient classes, which have a
pattern with an allocation function.
2018-08-24 00:52:36 -07:00
Slava Pestov
03cb6d1ff4 IRGen/Runtime: Use a true-const pattern to initialize non-generic resilient class metadata
Previously we would emit class metadata for classes with resilient
ancestry, and relocate it at runtime once the correct size was known.

However most of the fields were blank, so it makes more sense to
construct the metadata from scratch, and store the few bits that we
do need in a true-const pattern where we can use relative pointers.
2018-08-23 23:40:08 -07:00
Slava Pestov
120be251db IRGen: Metadata patterns are always true-const
They were, already, but remove the isConstant parameter to
getAddrOfTypeMetadataPattern(), and just assert that its true for
patterns in defineTypeMetadata() instead.

Also, metadata patterns are i8*, not i8**. In fact they don't contain any
absolute pointers at all.

Should be NFC other than the LLVM type change.
2018-08-23 23:40:08 -07:00
Slava Pestov
6150e34508 Runtime/IRGen: Two-phase metadata initialization for resilient classes
Similar to the non-resilient case, except we also emit a 'relocation
function'. The class descriptor now contains this relocation function
if the class has resilient ancestry, and the relocation function
calls the runtime's swift_relocateClassMetadata() entry point.

The metadata completion function calls swift_initClassMetadata() and
does layout, just like the non-resilient case.

Fixes <rdar://problem/40810002>.
2018-08-20 16:26:47 -07:00
Slava Pestov
50a037d8ed Runtime: Set the superclass in swift_initClassMetadata()
Now that we don't need the superclass before calling
swift_relocateClassMetadata(), it seems simpler to set it
here instead of doing it in various places in IRGen.
2018-08-20 16:23:07 -07:00
Slava Pestov
3256ee43c0 Runtime: swift_relocateClassMetadata() calculates metadata bounds from the class descriptor
Using the superclass metadata here no longer makes sense with two-phase
init, in case the superclass metadata depends on the class being
instantiated.

It would also be nice to rework the resilient class metadata 'pattern'
to be its own data structure that's true const, instead of just the
prefix of a real class metadata, but for now let's keep the existing
crappy design.
2018-08-20 16:23:07 -07:00
Slava Pestov
a86a71de1e Runtime/IRGen: Two-phase metadata initialization for non-resilient classes
Note that this patch also consolidates the recursive metadata tests
into one place while adding an execution test.
2018-08-20 16:23:07 -07:00
Slava Pestov
24a9a5156c IRGen: In-place initialization for classes with generic ancestry and resiliently-sized fields
If a class has generic ancestry or resiliently-sized fields, but is
itself not generic and does not have resilient ancestry, we must
perform runtime metadata initialization, but we can initialize
the metadata in-place.

As with generic classes or classes with resilient ancestry, we
copy generic requirements and field offset vectors from the
superclass. We also calculate the layout of the class's direct
fields at runtime.

Unlike the fully resilient case, we don't copy vtable entries
from the superclass, or install the direct class's vtable
entries from the type context descriptor. Instead, we statically
emit the vtable as with fixed-size class metadata.

Both the in-place and resilient case call the same runtime
entry point to initialize class metadata; the new HasStaticVTable
flag in ClassLayoutFlags is used to select between the two
behaviors concerning the vtable.
2018-08-20 16:22:35 -07:00