Commit Graph

420 Commits

Author SHA1 Message Date
swift-ci
979e18fbf8 Merge remote-tracking branch 'origin/master' into master-next 2017-05-19 08:28:38 -07:00
Arnold Schwaighofer
8efc47fbae IRGen: Fix Objective-C class allocation path
We need to cast the returned pointer to the class type. Heed John's advice and
sink the bitcast into the allocation function.

rdar://32264626
2017-05-19 07:43:11 -07:00
swift-ci
305ff2de6b Merge remote-tracking branch 'origin/master' into master-next 2017-05-18 21:48:38 -07:00
Slava Pestov
e272cf420e IRGen: Fix 'super.' calls to objc-dispatched static methods from generic classes
If a class has runtime-initialized metadata, we cannot just
reference its metaclass symbol statically, and instead we must
realize the metadata and load its isa pointer at runtime.

Fixes <rdar://problem/23715486>.
2017-05-18 20:16:29 -07:00
swift-ci
a4826b809e Merge remote-tracking branch 'origin/master' into master-next 2017-05-11 19:48:32 -07:00
Joe Groff
9830f394c1 SILGen/IRGen/KeyPaths: Components for ObjC properties need to be identified by selector.
A property imported from Objective-C, or marked in Swift with the `dynamic` keyword, doesn't have a vtable slot, so can't be identified that way. Use the ObjC selector as the unique identifier to ascribe equality to such components. Fixes rdar://problem/31768669. (While we're here, throw some more execution tests and a changelog note in.)
2017-05-11 14:28:19 -07:00
swift-ci
4ebe4afe2a Merge remote-tracking branch 'origin/master' into master-next 2017-05-09 13:28:49 -07:00
Slava Pestov
59ed555b09 SIL: Simplify SILDeclRef constructor usages 2017-05-09 00:16:47 -07:00
Bob Wilson
e24a6f1d30 Adjust addAttributes calls for LLVM r301981
These now take an AttrBuilder argument instead of an AttributeList.
2017-05-06 21:37:22 -07:00
swift-ci
1378be1c6d Merge remote-tracking branch 'origin/master' into master-next 2017-05-01 15:55:31 -07:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
Bob Wilson
c6e37c1f0a Merge remote-tracking branch 'origin/master' into master-next 2017-04-05 17:26:52 -07:00
Huon Wilson
3105c6ed00 [IRGen] Expose LinkInfo publicly, like LinkEntity. 2017-04-05 09:54:19 -07:00
Saleem Abdulrasool
15565c116a Adjust for SVN r298393 2017-03-22 07:44:03 -07:00
John McCall
897f5ab7c5 Restore CanType-based micro-optimizations.
This reverts commit 5036806e5a.
However, it preserves a pair of changes to the SIL optimizer
relating to walking through optional types.
2017-03-14 11:38:11 -04:00
Slava Pestov
5036806e5a AST: Remove some unnecessary getCanonicalType() calls 2017-03-13 02:24:36 -07:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
John McCall
d61d966451 Use ConstantInitBuilder in most kinds of metadata emission.
This is NFC in intent, but I had to restructure the code to emit more
of the lists "inline", which means I inevitably altered some IRGen
emission patterns in ways that are visible to tests:

- GenClass emits property/ivar/whatever descriptors in a somewhat
  different order.

- An ext method type list is now emitted as just an array, not a struct
  containing only that array.

- Protocol descriptors are no longer emitted as packed structs.

I was sorely tempted to stop using packed structs for all the metadata
emission, but didn't really want to update that many tests in one go.
2017-03-06 14:18:47 -05:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Andrew Trick
978b2fc80b Fix terminology. There's no such thing as a "formal SIL type".
Formal types are defined by the language's type system. SIL types are
lowered. They are no longer part of that type system.

The important distinction here is between the SIL storage type and the SIL value
type. To make this distinction clear, I refer to the SILFunctionTypes "formal"
conventions. These conventions dictate the SIL storage type but *not* the SIL
value type. I call them "formal" conventions because they are an immutable
characteristic of the function's type and made explicit via qualifiers on the
function type's parameters and results. This is in contrast to to SIL
conventions which depend on the SIL stage, and in the short term whether the
opaque values flag is enabled.
2017-01-26 15:35:48 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Michael Gottesman
d944930591 Remove the deallocating convention.
This is dead code and can be re-added if it is needed. Right now though there
really isnt a ValueOwnershipKind that corresponds to deallocating and I do not
want to add a new ValueOwnershipKind for dead code.
2017-01-10 17:32:17 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Kevin Ballard
f3e946872d Stop using islower()
`islower` is locale-sensitive, we should be using `clang::isLowercase`
instead.
2016-12-21 17:52:19 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Erik Eckstein
7dbab5a54e Mangling: symbol macro for objc partial apply forwarder 2016-12-09 09:05:19 -08:00
Slava Pestov
cb0126a306 IRGen: Remove some dead code 2016-12-01 13:00:17 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
9a5a26b20c Merge pull request #5180 from gregomni/2875
[IRGen] Emit calls to objc_allocWithZone(cls) when allocating obj-c objects.
2016-10-11 12:57:19 -07:00
gregomni
b634aedb3c Emit calls to objc_allocWithZone(cls) when allocating obj-c objects. 2016-10-07 12:17:53 -07:00
Arnold Schwaighofer
e8937fbad9 IRGen: partial_applies of ObjC methods must emit loads from loadable arguments that are passed indirectly
rdar://28464766
2016-10-05 14:16:07 -07:00
Doug Gregor
ab70291b82 [IRGen] Handle 'super' method sends in ObjC partial application forwarders.
The Objective-C partial application forwarder that one gets when
using, e.g., "super.foo" as a function value was doing a normal
objc_msgSend. Fix the miscompile by threading all of the information
about the Objective-C message send through the forwarder.

Fixes rdar://problem/28140758.
2016-09-14 21:12:45 -07:00
Michael Gottesman
fa1bb95923 Merge remote-tracking branch 'origin/master' into master-next 2016-08-30 19:50:12 -07:00
Slava Pestov
75bd88968b SILGen: Allow extensions to define designated initializers of generic types
Previously, if a generic type had a stored property with
a generic type and an initializer expression, we would
emit the expression directly in the body of each designated
initializer.

This is a problem if the designated initializer is defined
within an extension (even in the same source file), because
extensions have a different set of generic parameters and
archetypes.

Also, we've had bugs in the past where emitting an
expression multiple times didn't work properly. While these
might currently all be fixed, this is a tricky case to test
and it would be best to avoid it.

Fix both problems by emitting the initializer expression
inside its own function at the SIL level, and call the
initializer function from each designated initializer.

I'm using the existing 'variable initializer' mangling for this;
it doesn't seem to be used for anything else right now.

Currently, the default memberwise initializer does not use
this, because the machinery for emitting it is somewhat
duplicated and separate from the initializer expressions in
user-defined constructors. I'll clean this up in an upcoming
patch.

Fixes <https://bugs.swift.org/browse/SR-488>.
2016-08-03 01:03:08 -07:00
Slava Pestov
57c58176bc AST: Remove noreturn bit from function types 2016-07-24 00:15:34 -07:00
Michael Gottesman
3c603ab18b Merge remote-tracking branch 'origin/master' into master-next 2016-07-01 18:44:21 -07:00
Adrian Prantl
935b702a07 Add an assertion to IRBuilder to prevent function calls with no debug location
It is not valid LLVM IR to have a function call without a location to an
inlinable function inside a function with debug info — this makes it impossible
to construct inline information.

This patch adds an assertion and fixes up several places across IRGen where
such a situation could happen.

rdar://problem/26955467
2016-06-27 19:04:51 -07:00
Vedant Kumar
1409a445d9 [stable-merge] Adopt new setUnnamedAddr API 2016-06-27 11:12:28 -07:00
John McCall
6328f3fe0b Explicitly represent "pseudo-generic" functions in SIL, which do
not have access to their type arguments at runtime.  Use this to
fix the emission of native thunks for imported ObjC-generic
initializers, since they may need to perform bridging.

For now, pseudo-genericity is all-or-nothing, but we may want to
make it apply only to certain type arguments.

Also, clean up some code that was using dead mangling nodes.
2016-06-01 11:41:27 -07:00
John McCall
6c92c324f6 Rename IRGenModuleDispatcher to just IRGenerator and transfer
ownership of some of the basic structures to it.
2016-04-27 09:42:03 -07:00
David Farler
09d0cfee8d Hang closure capture descriptors from their heap metadata
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.

A closure capture descriptor has the following:

- The number of captures.
- The number of sources of metadata reachable from the closure.
  This is important for substituting generics at runtime since we
  can't know precisely what will get captured until we observe a
  closure.
- The number of types in the NecessaryBindings structure.
  This is a holding tank in a closure for sources of metadata that
  can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
  source of metadata for every generic argument needed to perform
  substitution at runtime.
  Key: The typeref for the generic parameter visible from the closure
  in the Swift source.
  Value: The metadata source, which describes how to crawl the heap from
  the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.

Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.

rdar://problem/24989531
2016-04-22 19:09:06 -07:00
swiftix
2573782c8b Merge pull request #1357 from swiftix/wip-runtime-calling-convention
Prepare the ground for using a new calling convention for functions from the runtime library
2016-03-01 16:22:37 -08:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
Roman Levenstein
ec04b22145 Properly propagate the calling convention into LLVM's call instructions.
Each runtime function definition in RuntimeFunctions.def states which calling convention
should be used for this runtime function.  But IRGen and LLVMPasses were not always
properly propagating this declared calling convention all the way down to llvm's Call instructions.
In many cases, the standard C convention was set for the call irrespective of the actual calling
convention defined for a given runtime function. As a result, incorrect code was generated.

This commit tries to fix all those places, where such a mismatch was found. In many cases this is
achieved by defining a helper function CreateCall in such a way that makes sure that the call instruction
gets the same calling convention as the one used by its callee operand.
2016-02-25 05:30:59 -08:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Joe Groff
8cb1175e49 IRGen: Emit public definitions with protected visibility on ELF.
This prevents the linker from trying to emit relative relocations to locally-defined public symbols into dynamic libraries, which gives ld.so heartache.
2016-02-08 13:09:27 -08:00
Doug Gregor
89834f8d5f [ObjC IRGen] Clean up emission of Objective-C selectors.
Make sure to set the linkage correctly, treat the selector data as
non-constant, note that it is externally-initialized, and add it to
llvm.compiler.used rather than llvm.used.
2016-01-27 13:57:40 -08:00
practicalswift
71e00fefa1 [gardening] Fix typos: "word word" (two spaces) → "word word" (one space) 2016-01-24 21:27:16 +01:00