Commit Graph

398 Commits

Author SHA1 Message Date
Arnold Schwaighofer
eb32194e97 Refactor to use RuntimeAvailability 2019-06-14 13:21:35 -07:00
Arnold Schwaighofer
5003c15079 stdlib: Add backward deployment versions for the
dynamic-replacement runtime functions.

The recent change of how we do dynamic replacements added 2 new runtime
functions. This patch adds those functions to the Compatibility50 static
archive.

This will allow backward deployment to a swift 5.0 runtime.

Patch by Erik Eckstein with a modification to call the standard
libraries implementation (marked as weak) when it is available.

This ensures we can change the implementation in the future and are not
ABI locked.

rdar://problem/51601233
2019-06-14 10:53:26 -07:00
Joe Groff
2ade303387 IRGen: Weak-link opaque type entry points.
When backward deploying to an OS that may not have these entry points, weak-link them so that they
can be used conditionally in availability contexts that check for them.

rdar://problem/50731151
2019-05-15 20:40:54 -07:00
Slava Pestov
3b6ec6c651 IRGen: Move some deployment target checks to LangOptions 2019-05-01 15:13:12 -04:00
Arnold Schwaighofer
e2d3f533d6 IRGen: Intialize single case enum extrainhabitant value witness in generated code
Older Swift runtimes miss this initialization in the swift_initEnumMetadataSingleCase runtime call.

rdar://49786768
2019-04-25 14:19:56 -07:00
Saleem Abdulrasool
68ca11bb2a IRGen: do not use WeakImport on PE/COFF
PE/COFF does not provide weak import semantics.  Fallback to strong
import semantics on PE/COFF.
2019-04-24 20:55:42 -07:00
Bob Wilson
dd94a9f90f References to _swift_FORCE_LOAD* symbols should be weak
When Swift always copied the overlay dylibs into app bundles, it was OK
for these symbol references to be non-weak, but with the overlays now
part of the OS on Apple platforms, we need to handle backward deployment
scenarios where a new overlay does not exist on an old OS version.
A weak reference will serve to pull in the overlay dylib if it exists,
without causing a fatal error if it does not. rdar://problem/50110036
2019-04-24 09:45:07 -07:00
Joe Groff
09ca7a784b IRGen: Emit runtime calls to fetch opaque type metadata.
Introduce code to emit runtime calls to get the type metadata for the underlying type of an opaque type and to get its conformances.
2019-04-17 14:43:32 -07:00
Slava Pestov
4ec1e83385 IRGen: Assert if its too late to queue up lazy emission 2019-04-12 01:46:22 -04:00
Slava Pestov
4207738e17 Add mangling and IRGen LinkEntity for Objective-C resilient class stubs 2019-03-26 18:44:44 -04:00
Mishal Shah
345e9881d1 Merge pull request #22699 from apple/stable-update-5.1
Update Swift:master to work with new stable re-branch from swift-5.1-branch
2019-02-20 12:22:00 -08:00
Slava Pestov
69d1cafd1c AST: Add AvailabilityContext parameter to Decl::isWeakImported()
For now, it's not used, but we do try to pass the right value down from
our various call sites.

Progress on <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Saleem Abdulrasool
437cfa7fa2 IRGen: adjust for SVN r348827
CodeGenOptions.h was moved from Frontend to Basic.
2019-02-08 14:22:57 -08:00
Saleem Abdulrasool
7f005414dd Merge pull request #21639 from compnerd/tinkering-linkering
ApplyIRLinkage cleanups
2019-01-04 15:26:11 -08:00
Saleem Abdulrasool
d3efed2943 IRGen: use ApplyIRLinkage more aggressively (NFC)
Use `ApplyIRLinkage` rather than manually applying the DLLStorage.  This
makes it much more apparent as to the desired semantic linkage desired.
2019-01-04 10:39:03 -08:00
Saleem Abdulrasool
02dfb509ba IRGen: create new External{Im,Ex}port named linkages
Create two new semantic names: `ExternalImport` and `ExternalExport`.
These are for symbols which are either imported from an external module
or exported for consumption by external modules.
2019-01-04 10:39:03 -08:00
Saleem Abdulrasool
9546cc2413 IRGen: always provide DLLStorage
Now that DLLStorage is only applied when needed, always pass the correct
DLLStorage.  The IRLinkage applicator will determine if the DLLStorage
should be applied or not.
2019-01-04 10:39:03 -08:00
Saleem Abdulrasool
a6df0469cf IRGen: create InternalWeakODR named IRLinkage (NFC)
Create a new named IRLinkage type: `InternalWeakODR`.  This just gives
the IRLinkage a semantic name rather than the computed value.  NFC.
2019-01-04 10:39:03 -08:00
Daniel Dunbar
8980213f7c Merge pull request #20687 from ddunbar/swasm-allow-wasm-object-format
[Swift+WASM] Allow Wasm object format.
2019-01-04 08:34:43 -08:00
Saleem Abdulrasool
e6354fe206 IRGen: COMDAT the force load thunks
Use `ApplyIRLinkage` to the force load thunks to permit multiple
emissions to be COMDATed on Windows.  The multi-module tests would emit
the symbols multiply and would fail to link.
2018-12-27 18:43:28 -08:00
Slava Pestov
0c6ac60688 IRGen: Don't deserialize witness tables accidentally
This is actually NFC: We should have already deserialized everything
we need at this point, and because of large loadable types and
address lowering, deserializing more stuff in IRGen is not valid,
and in fact we check for this and refuse to deserialize.
2018-12-20 17:36:38 -05:00
John McCall
2ba7090fe8 Remove the extra-inhabitant value witness functions.
This is essentially a long-belated follow-up to Arnold's #12606.
The key observation here is that the enum-tag-single-payload witnesses
are strictly more powerful than the XI witnesses: you can simulate
the XI witnesses by using an extra case count that's <= the XI count.
Of course the result is less efficient than the XI witnesses, but
that's less important than overall code size, and we can work on
fast-paths for that.

The extra inhabitant count is stored in a 32-bit field (always present)
following the ValueWitnessFlags, which now occupy a fixed 32 bits.
This inflates non-XI VWTs on 32-bit targets by a word, but the net effect
on XI VWTs is to shrink them by two words, which is likely to be the
more important change.  Also, being able to access the XI count directly
should be a nice win.
2018-12-11 22:18:44 -05:00
Carl Peto
3d61e9fd5a Fix incompatibilities with 16 bit pointers
- fix code generation for enum types to zext or trunc 32 bit data as appropriate for the platform
- fix IR generation code to use a relative address type of 16 bit width on that platform

- correct order of statements and line up comments
2018-11-29 22:15:54 +00:00
Daniel Dunbar
1efee0c27a [Swift+WASM] Allow Wasm object format.
- This currently does nothing more than adopt the ELF conventions, but for the
   Wasm object file format.
2018-11-20 15:22:26 -07:00
John McCall
2de83cfccb Merge pull request #20607 from rjmccall/self-protocol-conformance
Support the explicit representation of self-conformances
2018-11-15 17:38:44 -05:00
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Mike Ash
0262f1dd67 [IRGen] Record the Swift major/minor version in the top two bytes of the objc_image_info flags field.
rdar://problem/44204568
2018-11-15 12:05:22 -05:00
Arnold Schwaighofer
152e8db8bb IRGen and runtime implementation for dynamic replacements 2018-11-06 09:58:36 -08:00
Arnold Schwaighofer
ebbe3aed1c IRGen: Add implementation for dynamically replaceable functions
A dynamically replaceable function calls through a global variable that
holds the function pointer.

struct ChainEntry {
   void *(funPtr)();
   struct ChainEntry *next;
}

ChainEntry dynamicallyReplaceableVar;

void dynamicallyReplaceableFunction() {
  dynamicallyReplaceableVar.funPtr()
}

dynamic replacements will be chainable so the global variable also
functions as the root entry in the chain of replacements.

A dynamic replacement functions can call the previous implementation by
going through its chain entry.

ChainEntry chainEntryOf_dynamic_replacement_for_foo;

void dynamic_replacement_for_foo() {
   // call the previous (original) implementation.
   chainEntryOf_dynamic_replacement_for_foo.funPtr();
}
2018-11-06 09:53:21 -08:00
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00
John McCall
0bb884546b Add a runtime interface for working with Builtin.IntegerLiteral values. 2018-10-31 04:58:18 -04:00
Erik Eckstein
73aabff8a2 IRGen: lazily emit shared witness tables
This avoids emitting synthesized witness tables if they are not needed.
2018-10-10 08:24:26 -07:00
Jordan Rose
d412f4b4ba [IRGen] Adopt std::unique_ptr for IRGenDebugInfo (#19369) 2018-09-18 11:10:10 -07:00
Slava Pestov
870c58e017 IRGen: Change method descriptor layout to be consistent with protocol requirements
Both now have a flags field followed by the implementation.
2018-09-04 14:46:34 -07:00
Slava Pestov
b7449d5621 IRGen/Runtime: Method override descriptors 2018-09-04 14:46:34 -07:00
Slava Pestov
44c4497ac5 IRGen/Runtime: Protocol requirement descriptors don't need to reference the dispatch thunk 2018-08-31 00:16:22 -07:00
Jordan Rose
d52dad3732 [IRGen] Extract getConformance from ProtocolInfo (#18681)
We were using this just as a convenient way to share an existing
DenseMap, but it's not really related; we don't need to compute
witness table layout just to generate a conformance reference.

I started working on this because the "Cub" source compat project was
hitting issues here, but now I can't reproduce it. Still, this is a
reasonable cleanup.
2018-08-13 17:16:41 -07:00
John McCall
436a8b273d Add runtime functions to compute tuple layouts from element layouts.
Previously, when a tuple type had non-fixed layout, we would compute
a layout by building the metadata for that tuple type and then
extracting the layout from the VWT.  This can be quite expensive
because it involves constructing the exact metadata for types like
arrays and functions despite those types being fixed-layout across
all instantiations.  It also tends to cause unnecessary recursive-type
issues, especially with enums where tuples are currently used to model
cases with mutliple payloads.  Since we just need a layout, computing
it directly from element layouts instead of constructing metadata for
the formal type lets us take advantage of all the other fast paths for
layout construction, e.g. for fixed types and single-field aggregates.

This is a good improvement overall, but it also serves to alleviate
some of the problems of rdar://40810002 / SR-7876 in a way that
might be suitable for integration to 4.2.
2018-07-29 18:27:27 -04:00
David Zarzycki
057bbb366a [IRGen] Adopt reference storage type meta-programming macros
This commit also fixes reference storage extra inhabitant bugs.
2018-06-30 11:48:47 -04:00
Ellis Hoag
c93a5a5776 Add -debug-info-format=[dwarf|codeview] option (#16888) 2018-06-20 09:52:57 -07:00
Saleem Abdulrasool
477d43ef1c Merge pull request #16142 from compnerd/irgen-dllstorage
IRGen: the runtime is compacted into the stdlib
2018-05-30 10:27:29 -07:00
Saleem Abdulrasool
283c00e41e IRGen: special case the handling for the stdlib
Because the runtime is compacted into the standard library, functions
which are normally imported are actually local definitions.  Use module
level named metadata to identify the module as being the swift standard
library.  Refactor the condition slightly to improve code readability.

This addresses SR-7107!
2018-05-29 15:39:32 -07:00
Arnold Schwaighofer
81a15fbe19 IRGen: Use clangs's LLVM datalayout
It knows better ...

rdar://40275689
2018-05-25 11:19:01 -07:00
Huon Wilson
cfc5abdaa2 [TBDGen] Emit the symbol for autolink-force-load-ing.
Fixes rdar://problem/40356032.
2018-05-23 10:56:49 +10:00
Saleem Abdulrasool
fc9de0deaf IRGen: adjust the module hash section for COFF
COFF uses 8-character section names.  Adjust the section name for the
module hash from `.swift_modhash` to `.sw5hash` to fit this restriction.
2018-05-02 17:42:56 -07:00
Jordan Rose
6af333f307 [IRGen] Be smarter about adding the FORCE_LINK symbols for overlays (#15647)
We use dummy symbols to force overlays not to get dropped when
autolinking, even if the user doesn't use anything from them
explicitly. This behavior is triggered by the semi-hidden flag
-autolink-force-load.

(It's semi-hidden because it has few legitimate uses in real life. If
you searched for "how to force autolinking to pick up a library" and
found this commit, don't just do this and move on. Come talk to me on
forums.swift.org.)

Previously we added these dummy symbols to every object file using
"common" linkage, a little-known feature added for C that ensures that
only one definition will actually get used in the final object file.
However, the way we were doing that wouldn't work so well for COFF,
and so in 1025eed64 Saleem changed this to use "weak ODR" linkage.
This has *nearly* the same effect, and avoids some other weirdness,
but has the downside of making the symbol in the final dylib "weak"
itself, meaning that some /other/ library could come along and
override it. That impacts loading time, and an Apple-internal tool
caught that as rdar://39019606.

To avoid this whole mess, "just" emit the symbol into the object file
that corresponds to the first file in the module, which allows us to
mark it as a normal public symbol.

P.S. None of this is actually important at the moment because all of
the overlays are built with single-threaded WMO, which always produces
one object file anyway. But I wanted to get it right once and for all.
2018-03-31 15:20:13 -07:00
Mark Lacey
21134efd22 Revert "IRGen: Deserialize SIL witness tables and shared-linkage definitions by need." 2018-03-30 22:14:13 -07:00
Joe Groff
ae2d2973d1 IRGen: Deserialize SIL witness tables and shared-linkage definitions by need.
Code may end up indirectly using a witness table for a Clang-imported type by inlining code that used the conformance from another module, in which case we need to ensure we have a local definition at hand in the inlining module so we can have something to link against independently. This needs to be fixed from both sides:

- During serialization, serialize not only witness tables from the current module, but from Clang-imported modules too, so that their definitions can be used by other modules that inline code from the current module
- During IRGen, when we emit a reference to a SILWitnessTable or SILFunction declaration with shared linkage, attempt to deserialize the definition on demand

Fixes rdar://problem/38687726.
2018-03-30 11:12:58 -07:00
Slava Pestov
2f0440eafe IRGen: Force witness thunks to be emitted in the same thread as the witness table
Otherwise, they might end up in a different translation unit,
and we will be unable to form a relative reference.
2018-03-29 15:23:20 -07:00
Slava Pestov
d1c6e1d24a SIL: Generalize default witness tables now that defaulted witnesses don't have to go at the end
NFC until the new witness table instantiation mechanism is enabled.
2018-03-29 14:03:58 -07:00