Commit Graph

758 Commits

Author SHA1 Message Date
Karoy Lorentey
2966dce3d9 [IRGen] Allow configuring a panic function to call instead of trapping
Add a new frontend option (called `-trap-function <name>`, similar to Clang’s existing `-ftrap-function`) that specifies a function to call instead of trapping.

When the option is used, the compiler will emit a call to the specified function every time it would have otherwise emitted a trap instruction. The function must have no parameters and it must never return.

rdar://89125883
2022-02-17 23:19:08 -08:00
Pavel Yaskevich
2bd7a49d75 [IRGen] Record generic environment associated with accessible function
Without this piece of information it wouldn't be possible to form
a call to the recorded function at runtime if it's generic.
2022-01-24 10:17:59 -08:00
swift-ci
574959ebcb Merge remote-tracking branch 'origin/main' into rebranch 2022-01-04 19:34:06 -08:00
Kuba (Brecka) Mracek
243141e8b5 [IRGen] When emitting llvm.used.conditional list, strip all pointer casts in dependencies (#40678) 2022-01-04 19:32:45 -08:00
Adrian Prantl
f0b7065169 Consistently initialize clang CodeGenOptions.DebugTypeExtRefs
on all code paths. This flag is part of the Clang module hash. Setting it on all
paths makes it easier to reason about the permutations of Clang modules that are
being built on behalf of Swift.
2021-12-20 16:48:11 -08:00
swift-ci
134e17c8ec Merge remote-tracking branch 'origin/main' into rebranch 2021-12-17 16:54:09 -08:00
Pavel Yaskevich
ef4e94ef23 [Distributed] IRGen: Define a runtime record for accessible functions
A "accessible" function that can be looked up based on a string key,
and then called through a fully-abstracted entry point whose arguments
can be constructed in code.
2021-12-17 10:52:56 -08:00
swift-ci
be79aeb3bc Merge remote-tracking branch 'origin/main' into rebranch 2021-12-14 09:34:56 -08:00
Kuba Mracek
4271edde6b Add an end-to-end test for ThinLTO (-lto=llvm-thin flag), fix compiler crashes, fix tests 2021-12-13 16:59:32 -08:00
swift-ci
ee96d2798c Merge remote-tracking branch 'origin/main' into rebranch 2021-11-30 08:33:02 -08:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Ben Barham
11f28196bc Merge pull request #40168 from bnbarham/rebranch-failures
[rebranch] Fix compilation failures
2021-11-17 08:50:11 +10:00
Ben Barham
30be5117d2 [rebranch][IRGen] Update uses of AttributeList functions
The functions in llvm-project `AttributeList` have been
renamed/refactored to help remove uses of `AttributeList::*Index`.

Update to use these new functions where possible. There's one use of
`AttrIndex` remaining as `replaceAttributeTypeAtIndex` still takes the
index and there is no `param` equivalent. We could add one locally, but
presumably that will be added eventually.
2021-11-13 17:04:29 +10:00
Ben Barham
e139a2f2ea [rebranch] Rename various functions to match new names in LLVM
llvm-project 601102d282d5e9a1429fea52ee17303aec8a7c10 renamed various
functions in `CharInfo.h` and `Lexer.h`. Rename uses in Swift.
2021-11-13 15:33:09 +10:00
Arnold Schwaighofer
2e4a86986c IRGen: Annotate runtime calls with willreturn attribute
`willreturn`
This function attribute indicates that a call of this function will
either exhibit undefined behavior or comes back and continues execution
at a point in the existing call stack that includes the current
invocation. Annotated functions may still raise an exception, i.a.,
`nounwind` is not implied. If an invocation of an annotated function does
not return control back to a point in the call stack, the behavior is
undefined.

I conservatively did not assume that the deinit is willreturn therefore
release like operations are not marked `willreturn`.

rdar://73574236
2021-11-12 07:58:11 -08:00
Evan Wilde
3e2c5a6af5 Make it LinkOnceODRLinkage
Make the little variable LinkOnceODRLinkage so that it doesn't take up
as much space.
2021-11-04 09:03:27 -07:00
Evan Wilde
1e7ce90361 Fixing the strong imported async frame pointer flags
The weakly-imported symbol was getting optimized out, then put back in
as a strongly-imported symbol. This is no good. The symbol is a
declaration though, so it can't be "used" directly. Instead, we assign
it to another global and "use" it. That avoids the optimizations and
should be fine. Even if that symbol is a nullptr because it doesn't
exist, we are taking the pointer to it, which should be fine for all
situations.
2021-11-04 09:02:17 -07:00
Erik Eckstein
ff2db93922 SIL/IRGen: analysis of runtime effects for an instruction
Define the possible runtime effects of an instruction in an enum `RuntimeEffect`.
Add a new utility `swift:getRuntimeEffect` to estimate the runtime effects of an instruction.

Also, add a mechanism to validate the correctness of the analysis in IRGen: annotate all runtime functions in RuntimeFunctions.def with the actual effect what the runtime function has or can have. Then check if the effects of emitted runtime functions for an instruction match what `getRuntimeEffect` predicts.
This check is only enabled on demand by defining the CHECK_RUNTIME_EFFECT_ANALYSIS macro in RuntimeEffect.h
2021-10-28 18:43:14 +02: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
Doug Gregor
2551a04621 Back-deploy @objc actor types.
@objc actors implicitly inherit from the new, hidden
`SwiftNativeNSObject` class that inherits from `NSObject` yet provides
Swift-native reference counting, which is important for the actor
runtime's handling of zombies. However, `SwiftNativeNSObject` is only
available in the Swift runtime in newer OS versions (e.g., macOS
12.0/iOS 15.0), and is available in the back-deployed _Concurrency
library, but there is no stable place to link against for
back-deployed code. Tricky, tricky.

When back-deploying @objc actors, record `NSObject` as the superclass
in the metadata in the binary, because we cannot reference
`SwiftNativeNSObject`. Then, emit a static initializer to
dynamically look up `SwiftNativeNSObject` by name (which will find it
in either the back-deployment library, on older systems, or in the
runtime for newer systems), then swizzle that in as the superclass of
the @objc actor.

Fixes rdar://83919973.
2021-10-05 23:04:57 -07:00
swift-ci
b736faa703 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-23 14:53:57 -07:00
Arnold Schwaighofer
4d7854f02a Use AvailabilityContext to check for concurrency availability 2021-09-23 10:34:58 -07:00
Arnold Schwaighofer
16a5d69b92 IRGen: Emit a weak reference to swift_async_extendedFramePointerFlags when neccessary
When we deploy to a minimum target that is not known to support extended
frame information the function prolog of Swift async functions will
contain a reference to swift_async_extendedFramePointerFlags. This
reference needs to be weak like any async symbols.

rdar://83412550
2021-09-23 09:21:25 -07:00
Saleem Abdulrasool
e7965cefc4 IRGen: remove ELF autolink discard gadget
The ELF autolink section was previously relying on the SHF_EXCLUDE flag
being applied through module-level assembly.  Remove this gadget and
sink the handling down into LLVM.  The latest improvements to LLVM now
cause this workaround to be insufficient as the section is explicitly
marked as SHF_ALLOC, which will implicitly negate the SHF_EXCLUDE.  As a
result, we no longer discard the metadata.  Once this is sunk into LLVM
the attribute is unnecessary.  Furthermore, due to uniquing, will
actually cause a problem as there is no uniform handling for metadata
section prefixes.

rdar://82640394
2021-09-11 12:12:20 -07:00
swift-ci
b6289f17a4 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-20 08:13:22 -07:00
Kuba (Brecka) Mracek
2fad6265fe When building stdlib, pass -prespecialize-generic-metadata from CMake, and respect the flag in IRGenModule::shouldPrespecializeGenericMetadata (#38946) 2021-08-20 07:58:39 -07:00
Arnold Schwaighofer
5a83172a55 Merge remote-tracking branch 'upstream/main' into rebranch 2021-08-05 12:04:56 -07:00
Alastair Houghton
abec55f432 [Runtime] Add ObjC support to isKnownUniquelyReferenced.
Add code to support detecting uniquely referenced Objective-C and Core
Foundation objects.

rdar://47902425
rdar://66805490
2021-07-29 16:29:48 +01:00
Evan Wilde
1e6787925f Fix IRGen datalayout
Same issue as with TBDGen. Clang doesn't hold onto the Datalayout object
anymore, but instead keeps the description string that is constructed on
the fly. This patch updates IRGen to behave the same way.
2021-07-08 16:59:11 -07:00
swift-ci
e0e2634b84 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-06 09:35:07 -07:00
Evan Wilde
0919c2cd70 StringRef ends/startswith-lower -> insensitive
Updating StringRef startswith and endswith API to use insensitive rather
than lower.

(cherry picked from commit 1b8b39e6de)
2021-07-02 10:55:17 -07:00
nate-chandler
5e0d0fb91b Merge pull request #36765 from nate-chandler/generic-metadata-prespecialization-components/generic-value-witnesses
[IRGen] Use generic value witnesses for prespecialized types.
2021-06-30 07:03:40 -07:00
Nate Chandler
dbe2a8c06e [IRGen] NFC: Removed duplicative check.
isOSDarwin is true on tvOS so there is no need to also check for isTvOS.
2021-06-25 21:04:00 -07:00
Nate Chandler
07ba7a6f3c [runtime] Exported multi payload enum witnesses.
When witness tables for enums are instantiated at runtime via

    swift::swift_initEnumMetadataMultiPayload

the witnesses

    getEnumTagSinglePayload
    storeEnumTagSinglePayload

are filled with swift_getMultiPayloadEnumTagSinglePayload (previously
getMultiPayloadEnumTagSinglePayload) and
swift_storeMultiPayloadEnumTagSinglePayload (previously
storeMultiPayloadEnumTagSinglePayload).  Concretely, that occurs when
instantiating the value witness table for a generic enum which has more
than one case with a payload, like Result<T>.  To enable the compiler to
do the same work, those functions need to be visible to it.

Here, those functions are made visible to the compiler.  Doing so
requires changing the way they are declared and adding them to
RuntimeFunctions.def which in turn requires the definition of some
functions to describe the availability of those functions.
2021-06-25 21:03:56 -07:00
Doug Gregor
e7e922ea77 Introduce a createAsyncTaskInGroup SIL builtin.
Rather than using group task options constructed from the Swift parts
of the _Concurrency library and passed through `createAsyncTask`'s
options, introduce a separate builtin that always takes a group. Move
the responsibility for creating the options structure into IRGen, so
we don't need to expose the TaskGroupTaskOptionRecord type in Swift.
2021-06-24 07:53:18 -07:00
Arnold Schwaighofer
ea5fd19b26 IRGen: Try to fix taskCreate APIs on 32bit archs 2021-06-22 07:39:49 -07:00
Konrad `ktoso` Malawski
8536100354 [Concurrency] introduce task options, and change ABI to accept them
introduce new options parameter to all task spawning

[Concurrency] ABI for asynclet start to accept options

[Concurrency] fix unittest usages of changed task creation ABI

[Concurrency] introduce constants for parameter indexes in ownership

[Concurrency] fix test/SILOptimizer/closure_lifetime_fixup_concurrency.swift
2021-06-21 13:03:50 +09:00
Mike Ash
c2df2448ec [Concurrency] Reserve two more words in Job.
Keep Task the same size by pulling two words out of OpaquePrivateStorage.

rdar://79313908
2021-06-16 16:59:25 -04:00
Richard Howell
95ea3dd261 DebugTypeExtRefs=false when DisableClangModuleSkeletonCUs=true 2021-06-08 14:39:42 -07:00
Robert Widmann
f6b2294d5a Undo Force Load + Incremental Ban on Darwin Platforms
Gather 'round to hear tell of the saga of autolinking in incremental
mode.

In the beginning, there was Swift code, and there was Objective-C code.
To make one import bind two languages, a twinned Swift module named the same as an
Objective-C module could be imported as an overlay. But all was not
well, for an overlay could be created which had no Swift content, yet
required Swift symbols. And there was much wailing and gnashing of teeth
as loaders everywhere disregarded loading these content-less Swift
libraries.

So, a solution was found - a magical symbol _swift_FORCE_LOAD_$_<MODULE>
that forced the loaders to heed the dependency on a Swift library
regardless of its content. It was a constant with common linkage, and it
was good. But, along came COFF which needed to support autolinking but
had no support for such matters. It did, however, have support for
COMDAT sections into which we placed the symbol. Immediately, a darkness
fell across the land as the windows linker loudly proclaimed it had
discovered a contradiction: "_swift_FORCE_LOAD_$_<MODULE> cannot be
a constant!", it said, gratingly, "for this value requires rebasing."
Undeterred, we switched to a function instead, and the windows linker
happily added a level of indirection to its symbol resolution procedure
and all was right with the world.

But this definition was not all right. In order to support multiple
translation units emitting it, and to prevent the linker from dead
stripping it, Weak ODR linkage was used. Weak ODR linkage has the nasty
side effect of pessimizing load times since the dynamic linker must
assume that loading a later library could produce a more definitive
definition for the symbol.

A compromise was drawn up: To keep load times low, external linkage was
used. To keep the linker from complaining about multiple strong
definitions for the same symbol, the first translation unit in the
module was nominated to recieve the magic symbol. But one final problem
remained:

Incremental builds allow for files to be added or removed during the
build procedure. The placement of the symbol was therefore dependent
entirely upon the order of files passed at the command line. This was no
good, so a decree was set forth that using -autolink-force-load and
-incremental together was a criminal offense.

So we must compromise once more: Return to a symbol with common linkage,
but only on Mach-O targets. Preserve the existing COMDAT-friendly
approach everywhere else.

This concludes our tale.

rdar://77803299
2021-05-24 15:53:13 -07:00
Fred Riss
bbda706393 [Concurrency] Add a unique Task ID to AsyncTask
This commit changes JobFlags storage to be 32bits, but leaves the runtime
API expressed in terms of size_t. This allows us to pack an Id in the
32bits we freed up.

The offset of this Id in the AsyncTask is an ABI constant. This way
introspection tools can extract the currently running task identifier
without any need for special APIs.
2021-05-11 08:28:17 -07:00
John McCall
ec5215bf4f Remove the implicit nil inhabitant of Builtin.Executor,
and traffic in Optional<Builtin.Executor> in various places.
2021-04-30 03:11:56 -04:00
Konrad `ktoso` Malawski
ba615029c7 [Concurrency] Store child record when async let child task spawned 2021-04-19 10:06:23 +09:00
John McCall
82c190af21 Merge pull request #36751 from rjmccall/two-word-executor
Change ExecutorRef and fix the actor runtime
2021-04-08 16:49:37 -04:00
John McCall
156264f8e8 Make ExecutorRef two words. 2021-04-08 12:57:12 -04:00
Saleem Abdulrasool
ffd9c76f86 IRGen: repair the IRGen on Windows
The cross-module reference must be indirected through the moral
equivalent of the GOT - the IAT.  This indirects through the import
address table, permitting the pointer to be resolved.
2021-04-07 14:07:15 -07:00
Nate Chandler
3b6c070c06 [IRGen] Added mechanism to refer to known AFPs. 2021-04-05 18:08:33 -07:00
Dario Rexin
74fce8307c [IRGen] Disable pre-specialization for 32-bit ARM on Linux
This is a temporary workaround for segfaults we observed in TargetMetadata,
caused by invalid pointers.
2021-03-30 13:38:22 -07:00
John McCall
6b36a9ac86 Remove some incorrect references to ExecutorRef 2021-03-28 22:05:37 -04:00
John McCall
98711fd628 Revise the continuation ABI.
The immediate desire is to minimize the set of ABI dependencies
on the layout of an ExecutorRef.  In addition to that, however,
I wanted to generally reduce the code size impact of an unsafe
continuation since it now requires accessing thread-local state,
and I wanted resumption to not have to create unnecessary type
metadata for the value type just to do the initialization.

Therefore, I've introduced a swift_continuation_init function
which handles the default initialization of a continuation
and returns a reference to the current task.  I've also moved
the initialization of the normal continuation result into the
caller (out of the runtime), and I've moved the resumption-side
cmpxchg into the runtime (and prior to the task being enqueued).
2021-03-28 12:58:16 -04:00