Commit Graph

1549 Commits

Author SHA1 Message Date
Arnold Schwaighofer
71bb9a9d73 Remove workaround for unnamed_addr constants for LLVM JIT
The JIT has been fixed in llvm r362139.

rdar://51809210
2019-12-11 08:26:16 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Saleem Abdulrasool
636564e2cd IRGen: collocate WASM/ELF handling
WASM currently is treated identically to the ELF paths.  Collocate the
types to make it easier to ensure that all the paths are correctly
handling the emission.  This adds the missed case for the module hash.
2019-12-09 09:21:04 -08:00
Varun Gandhi
13b0fa9baa [NFC] Reduce some duplication in IRGen code for method descriptors. (#28475) 2019-12-04 16:32:56 -08:00
Robert Widmann
72e80c21f1 Bump the module format version
We've changed *what* is serialized by changing the way
@_dynamicReplacement is type checked, but not *how* it's
serialized.  Bump the format so there aren't strange incompatibilities
because of this.
2019-12-03 15:30:05 -08:00
Robert Widmann
4e36fc0bd5 Replace semantic usages of DynamicReplacementAttr with the request
Complete the refactoring by splitting the semantic callers for the original decl of a dynamically replaced declaration.

There's also a change to the way this attribute is validated and placed.  The old model visited the attribute on any functions and variable declarations it encountered in the primary.  Once there, it would strip the attribute off of variables and attach the corresponding attribute to each parsed accessor, then perform some additional ObjC-related validation.

The new approach instead leaves the attribute alone.  The request exists specifically to perform the lookups and type matching required to find replaced decls, and the attribute visitor no longer needs to worry about revisiting decls it has just grafted attributes onto.  This also means that a bunch of parts of IRGen and SILGen that needed to fan out to the accessors to ask for the @_dynamicReplacement attribute to undo the work the type checker had done can just look at the storage itself.  Further, syntactic requests for the attribute will now consistently succeed, where before they would fail dependending on whether or not the type checker had run - which was generally not an issue by the time we hit SIL.
2019-12-03 15:30:04 -08:00
Erik Eckstein
a5397b434c Cross module optimization
This is a first version of cross module optimization (CMO).

The basic idea for CMO is to use the existing library evolution compiler features, but in an automated way. A new SIL module pass "annotates" functions and types with @inlinable and @usableFromInline. This results in functions being serialized into the swiftmodule file and thus available for optimizations in client modules.
The annotation is done with a worklist-algorithm, starting from public functions and continuing with entities which are used from already selected functions. A heuristic performs a preselection on which functions to consider - currently just generic functions are selected.

The serializer then writes annotated functions (including function bodies) into the swiftmodule file of the compiled module. Client modules are able to de-serialize such functions from their imported modules and use them for optimiations, like generic specialization.

The optimization is gated by a new compiler option -cross-module-optimization (also available in the swift driver).
By default this option is off. Without turning the option on, this change is (almost) a NFC.

rdar://problem/22591518
2019-12-03 14:37:01 +01:00
Michael Gottesman
8247525471 [irgen] Force emission of objc class refs for non-foreign clang objc classes whose metadata we use.
Today in far more cases we are using mangled strings to look up metadata at
runtime. If we do this for an objc class but for whatever reason we do not have
any other references to the class, the static linker will fail to link in the
relevant framework. The reason why this happens is that autolinking is treated
by the static linker as a hint that a framework may be needed rather than as a
"one must link against the framework". If there aren't any undefined symbols
needed by the app from that framework, the linker just will ignore the hint. Of
course this then causes the class lookup to fail at runtime when we use our
mangled name to try to lookup the class.

I included an Interpreter test as well as IRGen tests to make sure that we do
not regress here in the future.

NOTE: The test modifications here are due to my moving the ObjCClasses framework
out of ./test/Interpreters/Inputs => test/Inputs since I am using it in the
IRGen test along side the interpreter test.

rdar://56136123
2019-11-21 16:03:54 -08:00
swift-ci
73912924cc Merge remote-tracking branch 'origin/master' into master-next 2019-11-11 13:30:12 -08:00
Arnold Schwaighofer
7acabfe1cf IRGen: We need to emit metadata for types that are emitted with shared linkage
Otherwise one TU could only require the type descriptor without metadata
and another TU could require metadata and type descriptor. Whether the
metadata access function is available would then depend on the linking
order of the two TUs.

rdar://56929811
2019-11-11 10:00:17 -08:00
Adrian Prantl
20e2cc6046 Adapt to upstream changes. 2019-10-29 16:11:38 -07:00
swift-ci
d410fb848d Merge remote-tracking branch 'origin/master' into master-next 2019-10-07 22:09:16 -07:00
Slava Pestov
cdcb8e4f0f AST: Lazier opaque type validation 2019-10-04 22:11:07 -04:00
Shoaib Meenai
a007f646fb [IRGen] Adjust for LLVM r373054
setAlignment now takes a MaybeAlign, so construct one where needed.
2019-09-30 12:04:32 -07:00
Slava Pestov
f31bbf3a6e IRGen: Remove unnecessary cast from getOrCreateHelperFunction() 2019-09-10 16:14:45 -04:00
Mike Ash
f5e7ab866c Merge branch 'master' into master-next 2019-09-09 12:11:25 -04:00
swift-ci
f9a3c37ed6 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-06 19:03:47 -07:00
Slava Pestov
a0e160e215 AST: Refactor Decl::isWeakImported() API a little bit
First, remove the AvailabilityContext parameter; it was confusing because
we actually always want to use the deployment target here.

Then, split this method up into three methods:

- isAlwaysWeakImported(): simply checks for a @_weakLinked attribute, either
  on the declaration itself or one of its parent contexts.

- getAvailabilityForLinkage(): returns the OS version availability when
  this declaration was introduced, or if the declaration does not have
  explicit availability, check it's storage (if its an accessor), or its
  parent contexts.

- isWeakImported(ModuleDecl *fromModule): combines these two checks to
  determine if the declaration should be weak linked when referenced from
  the given module, or if it might be weak referenced from some module
  (if the module parameter is null).
2019-09-06 20:08:40 -04:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
Joe Groff
c0a9fef3cf Merge remote-tracking branch 'origin/master' into master-next 2019-08-05 10:38:17 -07:00
Joe Groff
2915d3a963 IRGen: Work around rdar://problem/53836960
On i386 Darwin, the linker appears to garble indirect symbolic references.
2019-08-02 14:28:58 -07:00
Joe Groff
f0e5e1911d IRGen: Access concrete type metadata by mangled name.
When we generate code that asks for complete metadata for a fully concrete specific type that
doesn't have trivial metadata access, like `(Int, String)` or `[String: [Any]]`,
generate a cache variable that points to a mangled name, and use a common accessor function
that turns that cache variable into a pointer to the instantiated metadata. This saves a bunch
of code size, and should have minimal runtime impact, since the demangling of any string only
has to happen once.

This mostly just works, though it exposed a couple of issues:

- Mangling a type ref including objc protocols didn't cause the objc protocol record to get
  instantiated. Fixed as part of this patch.
- The runtime type demangler doesn't correctly handle retroactive conformances. If there are
  multiple retroactive conformances in a process at runtime, then even though the mangled string
  refers to a specific conformance, the runtime still just picks one without listening to the
  mangler. This is left to fix later, rdar://problem/53828345.

There is some more follow-up work that we can do to further improve the gains:

- We could improve the runtime-provided entry points, adding versions that don't require size
  to be cached, and which can handle arbitrary metadata requests. This would allow for mangled
  names to also be used for incomplete metadata accesses and improve code size of some generic
  type accessors. However, we'd only be able to take advantage of the new entry points in
  OSes that ship a new runtime.
- We could choose to always symbolic reference all type references, which would generally reduce
  the size of mangled strings, as well as make runtime demangling more efficient, since it wouldn't
  need to hit the runtime caches. This would however require that we be able to handle symbolic
  references across files in the MetadataReader in order to avoid regressing remote mirror
  functionality.
2019-08-02 14:28:53 -07:00
swift-ci
862b18da46 Merge remote-tracking branch 'origin/master' into master-next 2019-08-01 05:09:56 -07:00
Slava Pestov
d3f65e7b4b AST: Remove SubscriptDecl::isSettable() 2019-07-31 21:26:02 -04:00
swift-ci
9d1bd7fbdb Merge remote-tracking branch 'origin/master' into master-next 2019-06-26 21:49:21 -07:00
Saleem Abdulrasool
053425a6a1 IRGen: fix multithreaded COMDAT handling for PE/COFF
Correct the COMDAT handling for the type metadata emission.  In
particular, declarations should not be emitted with COMDATs.  The
pattern used in the compiler for the metadata emission is different than
the other structures.  In particular, `getAddrOfTypeMetadata` emits the
declaration for the type metadata symbol.  The definition for the type
metadata will be emitted via `defineTypeMetadata`.  This change adjusts
the IRGen to remove the COMDAT on the declaration permitting the
definition from `defineTypeMetadata` being emitted strongly.

This exposes a bug in the LLVM MC layer which is a separate change that
will enable this to function properly.
2019-06-25 20:12:43 -07:00
swift-ci
558ca0418c Merge remote-tracking branch 'origin/master' into master-next 2019-06-20 10:50:37 -07:00
Arnold Schwaighofer
fb08153de0 Fix dynamic replacement runtime when generating replacements from multiple object files
The sections with the replacements get merged and we need to consider all replacements.

SR-10947
rdar://51913012
2019-06-19 15:11:33 -07:00
Ben Langmuir
c42b732e26 Merge remote-tracking branch 'origin/master' into master-next
Conflicts:
	lib/IRGen/IRGenModule.cpp
2019-06-18 09:35:57 -07:00
Arnold Schwaighofer
5d329464d6 Use thread private key to avoid weak linkage
We use one bit of the third reserved swift private tls key.

Also move the functionality into a separate static archive that is
always linked dependent on deployment target.
2019-06-17 15:03:45 -07:00
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
swift-ci
ed38fe6251 Merge remote-tracking branch 'origin/master' into master-next 2019-06-04 10:09:06 -07:00
Joe Groff
4ed8de10f9 Revert "Revert "Use autolinking to pull in compatibility libraries."" 2019-06-03 20:10:51 -07:00
swift-ci
fd329da063 Merge remote-tracking branch 'origin/master' into master-next 2019-06-03 14:29:47 -07:00
Joe Groff
a7cc3a38cc Revert "Use autolinking to pull in compatibility libraries." 2019-06-03 14:18:39 -07:00
swift-ci
40c3c8caa5 Merge remote-tracking branch 'origin/master' into master-next 2019-06-03 08:30:09 -07:00
Joe Groff
a740ee55b2 Merge pull request #25148 from jckarter/runtime-compatibility-autolink
Use autolinking to pull in compatibility libraries.
2019-06-03 08:22:49 -07:00
Joe Groff
dffd1b27a1 Use autolinking to pull in compatibility libraries.
Many build systems that support Swift don't use swiftc to drive the linker. To make things
easier for these build systems, also use autolinking to pull in the needed compatibility
libraries. This is less ideal than letting the driver add it at link time, since individual
compile jobs don't know whether they're building an executable or not. Introduce a
`-disable-autolink-runtime-compatibility` flag, which build systems that do drive the linker
with swiftc can pass to avoid autolinking.

rdar://problem/50057445
2019-05-31 13:11:14 -07:00
swift-ci
d4508c5de0 Merge remote-tracking branch 'origin/master' into master-next 2019-05-30 20:09:36 -07:00
Erik Eckstein
4fb4435d12 IRGen: add an option to disable runtime calls for dynamic replacements.
With the option -Xllvm -basic-dynamic-replacement the runtime functions are not called (so it works with an old swift library).
But calling the original of a replaced function is not supported in this case.
2019-05-30 15:28:16 -07:00
Erik Eckstein
2ea531c3b3 IRGen/runtime: change the code generation for dynamically replaceable functions
Instead of a thunk insert the dispatch into the original function.
If the original function should be executed the prolog just jumps to the "real" code in the function. Otherwise the replacement function is called.
There is one little complication here: when the replacement function calls the original function, the original function should not dispatch to the replacement again.
To pass this information, we use a flag in thread local storage.
The setting and reading of the flag is done in two new runtime functions.

rdar://problem/51043781
2019-05-30 15:28:16 -07:00
Davide Italiano
433f6bf516 [GenDecl] XCOFF should be treated like COFF.
Fixes a build error:

/Users/local/swift/swift/lib/IRGen/GenDecl.cpp:1323:11: error: enumeration value 'XCOFF' not handled in switch [-Werror,-Wswitch]

All the other functions in this file group XCOFF and COFF together
so I guess this is a reasonable thing to do.
2019-05-23 17:18:50 -07:00
swift-ci
eeba41345d Merge remote-tracking branch 'origin/master' into master-next 2019-05-23 16:49:10 -07:00
Arnold Schwaighofer
b127aac1ce Merge pull request #24781 from aschwaighofer/fix_some_type_dynamic_replacement
Fix dynamic replacement of some type when used with associated types
2019-05-23 16:36:32 -07:00
swift-ci
5db4e8dba9 Merge remote-tracking branch 'origin/master' into master-next 2019-05-21 19:29:13 -07:00
Joe Groff
81c7f84ec9 IRGen: Work around JIT bug with GOT equivalents.
SR-10590 | rdar://problem/50968433 appears to be caused by an LLVM JIT bug where GOT-equivalent
globals get emitted with incorrect alignment. Not marking the GOT equivalent as unnamed_addr
(which prevents it from getting folded into the GOT, or other equivalent constants) appears
to work around the issue.
2019-05-21 14:17:07 -07:00
Arnold Schwaighofer
5c3a4d329b Fix dynamic replacement of some type when used with associated types
rdar://50638228
2019-05-18 10:34:52 -07:00
swift-ci
7714b5e862 Merge remote-tracking branch 'origin/master' into master-next 2019-05-03 23:09:28 -07:00
Joe Groff
22793b4567 Fixes for opaque return types on local functions.
- In Sema, don't traverse nested declarations while deducing the opaque return type. This would
  cause returns inside nested functions to clobber the return type of the outer function.
- In IRGen, walk the list of opaque return types we keep in the SourceFile already for type
  reconstruction, instead of trying to visit them ad-hoc as part of walking the AST, since
  IRGen doesn't normally walk the bodies of function decls directly.

Fixes rdar://problem/50459091
2019-05-03 16:53:21 -07:00