Commit Graph

10994 Commits

Author SHA1 Message Date
Hamish Knight
b55f97250d [IRGen] Update coverage mapping for version 6
The coverage format version we use is automatically
set to whatever the latest version LLVM has. This
resulting in us outputting version 6 as our
format without having made the changes necessary
to reflect the new format. Update the emission
logic to take account for [the new changes in
version 6][1] (we need to include the current
working directory as the first element of the list
of files we output). Additionally, add a
`static_assert` so we don't get caught out by
version bumps in the future. Note we can't pin our
version, as it must stay in sync with the version
Clang is using.

[1]: https://llvm.org/docs/CoverageMappingFormat.html#llvm-ir-representation
2023-05-20 00:32:21 +01:00
Konrad `ktoso` Malawski
0104f2b324 formatting 2023-05-19 23:41:58 +02:00
Konrad `ktoso` Malawski
cd3e243ff8 [Distributed] Ensure decoded classes get refcounted down to 0 from decoding 2023-05-19 23:29:49 +02:00
nate-chandler
efe762de0b Merge pull request #66014 from nate-chandler/rdar109540863
[IRGen] Cast dynamic alloca to appropriate type.
2023-05-19 07:00:08 -07:00
Nate Chandler
4b46622e49 [IRGen] Cast dynamic alloca to appropriate type.
Fix the type of the `alloca` created by `GenPack`'s for type metadata
and witness tables by fixing its callee, `emitDynamicAlloca` to always
return a `StackAddress` whose `Address`' type is the one specified by
the caller.

rdar://109540863
2023-05-18 20:51:54 -07:00
Arnold Schwaighofer
1483be0444 Merge pull request #65951 from aschwaighofer/another_opaque_ptr_fix
IRGen: Another fix for opaque pointers
2023-05-17 11:35:01 -07:00
Artem Chikin
99f545a8eb Merge pull request #65930 from artemcm/SeparateClangTargetHandlingForIRGen
[Explicit Module Builds] Ensure IRGen uses Swift compiler's target triple when '-clang-target' is set.
2023-05-16 15:29:02 -07:00
Arnold Schwaighofer
f5b17bd1a1 IRGen: Another fix for opaque pointers 2023-05-16 12:13:12 -07:00
Artem Chikin
f2cf55a472 [Explicit Module Builds] Ensure IRGen uses Swift compiler's target triple when '-clang-target' is set.
The Clang importer's Clang instance may be configured with a different (higher)
OS version than the compilation target itself in order to be able to load
pre-compiled Clang modules that are aligned with the broader SDK, and match the
SDK deployment target against which Swift modules are also built. In this case,
we must use the Swift compiler's OS version triple in order to generate the
binary as-requested.

This change makes 'ClangImporter' 'Implementation' keep track of a distinct
'TargetInfo' and 'CodeGenOpts' containers that are meant to be used by clients
in IRGen. When '-clang-target' is not set, they are defined to be copies of the
'ClangImporter's built-in module-loading Clang instance. When '-clang-target' is
set, they are configured with the Swift compilation's target triple and OS
version (but otherwise identical) instead. To distinguish IRGen clients from
module loading clients, 'getModuleAvailabilityTarget' is added for module
loading clients of 'ClangImporter'.

The notion of using a different triple for loading Clang modules arises for the
following reason:
- Swift is able to load Swift modules built against a different target triple
  than the source module that is being compiled. Swift relies on availability
  annotations on the API within the loaded modules to ensure that compilation
  for the current target only uses appropriately-available API from its
  dependencies.
- Clang, in contrast, requires that compilation only ever load modules (.pcm)
  that are precisely aligned to the current source compilation. Because the
  target triple (OS version in particular) between Swift source compilation and
  Swift dependency module compilation may differ, this would otherwise result in
  builtin multiple copies of the same Clang module, against different OS
  versions, once for each different triple in the build graph.
Instead, with Explicitly-Built Modules, Swift sets a '-clang-target' argument
that ensures that all Clang modules participating in the build are built against
the SDK deployment target, matching the Swift modules in the SDK, which allows
them to expose a maximally-available API surface as required by
potentially-depending Swift modules' target OS version.
--------------------------------------------
For example:
Suppose we are building a source module 'Foo', targeting 'macosx10.0', using an
SDK with a deployment target of 'macosx12.0'. Swift modules in said SDK will be
built for 'macosx12.0' (as hard-coded in their textual interfaces), meaning they
may reference symbols expected to be present in dependency Clang modules at that
target OS version.

Suppose the source module 'Foo' depends on Swift module 'Bar', which then
depends on Clang module `Baz`. 'Bar' must be built targeting 'macosx12.0'
(SDK-matching deployment target is hard-coded into its textual interface). Which
means that 'Bar' expects 'Baz' to expose symbols that may only be available when
targeting at least 'macosx12.0'. e.g. 'Baz' may have symbols guarded with
'__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_12_0'. For this reason, we use
'-clang-target' to ensure 'Baz' is built targeting 'macosx12.0', and can be
loaded by both 'Foo' and 'Bar'.

As a result, we cannot direclty use the Clang instance's target triple here and
must check if we need to instead use the triple of the Swift compiler instance.

Resolves rdar://109228963
2023-05-16 09:42:30 -07:00
Erik Eckstein
82b24ba165 IRGen: fix async vtable stubs
For deleted async vtable methods we need to create a async function pointer.

Fixes a missing-symbol linker error
rdar://108924001
2023-05-16 11:49:11 +02:00
Pavel Yaskevich
cb51359adb Merge pull request #65874 from xedin/rdar-109207043
[IRGen] Distributed: Destroy loaded arguments after the call
2023-05-16 00:13:23 -07:00
Pavel Yaskevich
8569c9d081 [IRGen] Distributed: Destroy loaded arguments after the call
Arguments that have been loaded due to underlying method conversion
have to be destroyed after the call otherwise they are going to leak.

Resolves: https://github.com/apple/swift/issues/65853
Resolves: rdar://109207043
2023-05-15 14:46:19 -07:00
Slava Pestov
c2338aa0f6 Backward deployment shim for swift_allocate{Metadata,WitnessTable}Pack() 2023-05-12 15:44:12 -04:00
Arnold Schwaighofer
7646e04bf2 IRGen: Another fix for compiling under opaque pointers 2023-05-11 11:33:48 -07:00
Arnold Schwaighofer
27731bd61a IRGen: Another fix for compiling LLVM opaque pointers
Use the signature to get the function type when getting Swift function pointer callees.
This is okay because there is a previous call to cast to that type using the Signature
2023-05-10 13:40:33 -07:00
Arnold Schwaighofer
218e4f9f7c IRGen: Fix lowering of static async function pointers under opaque-pointers
Read the pointer type off the signature rather than the global value
2023-05-08 07:59:30 -07:00
Egor Zhdan
9a496e80ae Merge pull request #65652 from apple/egorzhdan/cxx-requires-irgen
[cxx-interop] Do not emit IR for C++20 requires expr
2023-05-05 19:58:15 +01:00
Dario Rexin
6d031cbada [IRGen] Respect optionality of unowned(unsafe) reference properties (#65663)
* [IRGen] Respect optionality of unowned(unsafe) reference properties

rdar://108705703

When generating the type info for fields marked unowned(unsafe) of an optional reference (e.g. AnyObject?), we dropped the fact that it was optional along the way. This caused incorrect tags to be returned when on object of the type was stored in an optional itself and the unowned property contained `nil`. In those cases the outer optional appeared to be `nil` as well, even if it in fact contained a value.

* Fix additional case
2023-05-05 09:37:46 -07:00
Egor Zhdan
21745e52c4 [cxx-interop] Do not emit IR for C++20 requires expr
This fixes a compiler crash when emitting IR for a for-in loop over a C++ `std::vector` in C++20 mode.

rdar://108810356
2023-05-05 17:21:38 +01:00
Becca Royal-Gordon
14665f9d53 Merge pull request #65641 from beccadax/objc-impl-protocols
Two @objcImpl protocol fixes
2023-05-04 19:34:06 -07:00
nate-chandler
74cbe264ca Merge pull request #65636 from nate-chandler/rdar108614878
[IRGen] Check for nil in final class cast opt.
2023-05-04 07:08:37 -07:00
Becca Royal-Gordon
bd4108c6be Emit imported @objcImpl conformances
Fixes rdar://108482165.
2023-05-03 19:26:42 -07:00
Nate Chandler
70cfa6a05c [IRGen] Check for nil in final class cast opt.
As an optimization, there is a fast-cast to non-final classes that just
compares isa pointers.  If the source of the cast is an Optional<class>,
though, it's not allowed to "directly compare the isa-pointer"; because
the source might be Optional.none, i.e. null.

Add a check for nil when emitting the fast class cast.

rdar://108614878
2023-05-03 18:39:08 -07:00
Adrian Prantl
85dcd50605 Emit debug info for count arguments of variadic generic types.
rdar://107491524
2023-05-02 17:35:28 -07:00
Arnold Schwaighofer
441b151ba3 Merge pull request #65549 from aschwaighofer/guard_using_clang_for_objc_protocols_by_deploy_target_2nd
IRGen: Only use clang protocol emission on newer deployment targets
2023-05-02 06:47:15 -07:00
Slava Pestov
9c68aaac2d Merge pull request #65466 from slavapestov/irgen-vanishing-tuple
IRGen: Unwrap one-element tuple metadata in emitDynamicTupleTypeMetadataRef()
2023-05-01 18:15:12 -04:00
Arnold Schwaighofer
086bc944f0 IRGen: Only use clang protocol emission on newer deployment targets
We started using clang to emit the _OBJC_PROTOCOL_ definition.

But we would use a different name for the proto_list definition than clang.

"OBJC_LABEL_PROTOCOL$" (objc)
|--> OBJC_PROTOCOL
"\01l_OBJC_LABEL_PROTOCOL$_" (swift)
|--> OBJC_PROTOCOL

If an Objective C object also emitted the same protocol definition you could
end up in a situation where both clang's and swift's proto_list definitions
point to the same protocol definition.

Older linkers don't like that.

rdar://108505376
2023-05-01 13:49:17 -07:00
Slava Pestov
75cea742a5 IRGen: Unwrap one-element tuple metadata in emitDynamicTupleTypeMetadataRef()
This matches the static behavior of Type::subst() and the SIL optimizer.
2023-05-01 14:46:04 -04:00
Arnold Schwaighofer
f403e55a1d Revert "Merge pull request #65516 from aschwaighofer/guard_using_clang_for_objc_protocols_by_deploy_target"
This reverts commit 1a7f342a4e, reversing
changes made to 404b925d8b.
2023-05-01 07:43:56 -07:00
Arnold Schwaighofer
4416cb3f9b IRGen: only use clang protocol emission on newer deployment targets
Older linkers seemed to have a problem with clang emitted definitions.

rdar://108505376
2023-04-28 15:10:47 -07:00
Erik Eckstein
40a7527b67 LoadableByAddress: convert types of functions which are contained in structs inside global static initializers
We missed converting such types inside static initializers of global variables.
This results in ptrauth crashes when ptrauth is enabled.

rdar://108165425
2023-04-28 08:46:08 +02:00
Adrian Prantl
debb455e0a Merge pull request #65402 from adrian-prantl/108323748
Add support for nested ASTScopes inside of macro expansions.  … @adrian-prantl
2023-04-25 16:01:35 -07:00
Adrian Prantl
3901219eeb Add support for nested ASTScopes inside of macro expansions.
Before this patch the parents of SILDebugScopes representing macro expansions
were missing the inlinedAt field, which resulted in incorrent LLVM IR being
produced. This is fixed by first computing the inlined call site for a macro
expansion and then computing the nested SILDebugScope for the ASTScope of the
expanded nodes; adding the inlinedAt field to all of levels of parent scopes.

rdar://108323748
2023-04-24 14:11:19 -07:00
Erik Eckstein
f5a0519289 fix Builtin.sizeof et al for metatypes
Those builtins always need to assume a thick metatype which is a pointer.
In other words the builtins need to use the maximally abstracted type.

rdar://108308786
2023-04-21 21:08:49 +02:00
Slava Pestov
24a1d011d8 Merge pull request #65340 from slavapestov/bind-element-archetype-fix
Fix issues with binding local element archetypes, and misc other stuff
2023-04-21 07:52:31 -04:00
Slava Pestov
0d1e50705e IRGen: Clean up some crusty old code 2023-04-20 22:05:46 -04:00
Slava Pestov
8d8fdb7062 IRGen: Make bindArchetype() a static helper in GenExistential.cpp to discourage future use 2023-04-20 22:05:46 -04:00
Slava Pestov
a892b9196b IRGen: bindOpenedElementArchetypesAtIndex() should use bindGenericRequirement()
Fixes rdar://problem/107852985.
2023-04-20 22:05:34 -04:00
Dario Rexin
022311e438 [IRGen] Fix layout string generation for pre-specialized metadata (#65162)
* [IRGen] Fix layout string generation for pre-specialized metadata

rdar://108012057

Pre-specialized metadata has to be specifically handled by using the bound generic type instead of the unbound one. All the necessary information is already being passed down as BoundGenericTypeCharacteristics, we just need to apply them when present.

* Add tests and a few fixes

* Fixes after rebase

* Attempt to fix Windows linker issue in test
2023-04-20 13:26:41 -07:00
Slava Pestov
563ebdeb93 IRGen: Try harder not to emit calls to swift_getExtendedExistentialTypeMetadata()
This entry point doesn't exist on older runtimes. Sema enforces
that constrained existentials don't appear in substitution maps,
however IRGen would sometimes try to instantiate metadata even
if the user didn't do that.

Fixes #64657.
2023-04-18 14:11:07 -04:00
Slava Pestov
30c9981d41 IRGen: Centralize check for local archetypes when outlining copy and destroy 2023-04-18 12:54:49 -04:00
Slava Pestov
74941d3c26 IRGen: Remove some duplicate code 2023-04-18 12:54:49 -04:00
Holly Borla
ae32673553 [Macros] Fix visiting nested conformance macro declarations in SIL and IRGen.
When expanding a conformance macro, the generated extension decls are added to
the TopLevelDecls vector of the synthesized file unit to expose them to
sf->getSynthesizedFile()->getTopLevelDecls(). There are two problems with this:

  1. These decls are also visited via visitAuxiliaryDecls() for the purpose of
     type checking. This causes problems in code generation because the extensions
     are visited separately, and because SIL and IRGen assume nested auxiliary decls
     are members.
  2. SILGen only emits top-level decls directly from the source file rather than its
     synthesized file. Auxiliary decls are visited here, but this doesn't work for
     nested conformance macros because the attached-to decl is not at the top-level,
     so macro-generated conformances for nested types never emit their descriptor.

To fix this in the short term, visit top-level decls in the synthesized file that are
generated by conformance macros, and skip auxiliary extension decls when emitting type
members. This fix is narrowly scoped to only impact macros, but in the future this
warrants a more structural fix to better handle top-level decls in the synthesized file.
2023-04-17 10:33:25 -07:00
Juergen Ributzka
17c5010d0b [swift][AutoLinkExtract] Don't add autolink hint for frameworks. (#65051)
Default system linkers on non-Darwin platforms do not support the `-framework`
argument for framework linking. This change updates autolinking to not emit
`-framework` into the .o _swift1_autolink_entries metadata when there is no
native linker support.

This is related to rdar://106578342.
2023-04-14 09:15:05 -07:00
Dario Rexin
883750e908 [IRGen] Reject enums with inaccessible tpye metadata in layout string… (#65016)
* [IRGen] Reject enums with inaccessible tpye metadata in layout string generation

rdar://107679697

Because we are currently handling most enums in layout strings by going through the metadata, we have to ensure that the metadata is accessible from the current module and reject the enum otherwise.

* Use proper mechanism to create and reference dylib in test

* Fix linking

* Add rpath to test dylib
2023-04-13 17:19:31 -07:00
Slava Pestov
a05019454c Merge pull request #65119 from slavapestov/sil-optimizer-peepholes-for-packs
Simple SILOptimizer peepholes for packs
2023-04-13 15:27:35 -04:00
Slava Pestov
fa28d14518 IRGen: Small fix for opaque return types with variadic types 2023-04-13 11:48:02 -04:00
Slava Pestov
da1b210479 IRGen: Add missing return to getSingletonPackExpansionParameter() 2023-04-12 17:32:54 -04:00
Augusto Noronha
dbaf5e53f0 Emit cxx interop into DW_AT_APPLE_flags
When compiling with interop enabled, emit the C++ interop compiler flag
into the DW_AT_APPLE_flags, to make it so LLDB can accurately match the
C++ interop mode when initializing its compiler instance.

rdar://97610458
(cherry picked from commit b1dbb0a321)
2023-04-11 10:40:09 -07:00
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00