Commit Graph

89 Commits

Author SHA1 Message Date
Anthony Latsis
17fc00f8a7 [test] IRGen: Adjust FileCheck patterns for new nuw attribute in upstream LLVM
This attribute was introduced in
7eca38ce76d5d1915f4ab7e665964062c0b37697 (llvm-project).

Match it using a wildcard regex, since it is not relevant to these
tests.

This is intended to reduce future conflicts with rebranch.
2025-05-04 03:28:56 +01:00
Alex Lorenz
4858cb6225 [IRGen][interop] do not add 'nocapture' to not bitwise takable types
The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687
2023-09-25 17:43:34 -07:00
Arnold Schwaighofer
fc766a39d3 Fix some more tests 2023-06-29 16:16:56 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Arnold Schwaighofer
1f16f7ad8a Adjust to LLVM change that requires sret parameter attributes to be
annotated with the pointee type.

rdar://71808491
2020-12-03 09:39:41 -08:00
Arnold Schwaighofer
9ee12db2a9 Fix tests for LLVM change that added anonymous parameter labeling
Fix for r367755.
2019-08-15 14:57:24 -07:00
Joe Groff
b3ac66aeeb IRGen: Leave frame pointers off SIL functions marked [thunk]. 2019-08-07 14:16:45 -07:00
Joe Groff
bce1f5ef4a Runtime: Provide ABI space for source location info in unconditional casts.
Currently ignored, but this will allow future compilers to pass down source location information for cast
failure runtime errors without backward deployment constraints.
2018-12-06 14:58:14 -08:00
Arnold Schwaighofer
e2a83006ea IRGen: Consider the superclass bound of archetypes in searchTypeMetadata
We need to search the type metadata of superclass bounds to handle signatures like:

class K<T> {}

 $@convention(witness_method: A2) <τ_0_0><τ_1_0 where τ_0_0 : K<τ_1_0>, τ_1_0 : C> (@in_guaranteed τ_0_0) -> ()

rdar://46173958
SR-9305
2018-11-28 07:48:00 -08:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Adrian Prantl
9cb0b8ef25 Zero-initialize -Onone debug shadow copies for exploded values
and simplify the initialization code by emitting a memset intrinsic.

rdar://problem/43566087
2018-09-14 17:20:11 -07:00
Mike Ash
46309d9794 [Runtime] Rename swift_unknown* functions to swift_unknownObject*.
These functions don't accept local variable heap memory, although the names make it sound like they work on anything. When you try, they mistakenly identify such things as ObjC objects, call through to the equivalent objc_* function, and crash confusingly. This adds Object to the name of each one to make it more clear what they accept.

rdar://problem/37285743
2018-08-15 17:48:23 -04:00
Adrian Prantl
a95791c1b8 Fix bugs that caused IRGen to behave differently when debug info was enabled.
It hass been a longstanding principle in LLVM that the presence of
debug info shall not affect code generation. This patch brings the
Swift frontend closer to this ideal:

- unconditionally emit shadow copies
- unconditionally bind type metadata

The extra allocas, bitcasts, geps, and stores being emitted get
optimized away when compiling at anything but -Onone. There are few
use-cases for compiling at -Onone without -g, so this shouldn't affect
performance for any real-world use-cases.
2018-06-01 11:17:39 -07:00
Saleem Abdulrasool
dabbdad811 test: enable additional tests on Linux
Un-XFAIL tests on Linux now that ObjC interop is controllable.  There
are a couple of tests that remain which are dependent on Foundation.
Fix a configuration issue that resulted in a number of tests failing on
Linux.
2018-04-24 11:21:21 -07:00
Michael Gottesman
cb80f65f1e Remove plus_zero_test,plus_one_test from lit tests since they are no longer needed.
I am going to leave in the infrastructure around this just in case. But there is
no reason to keep this in the tests themselves. I can always just revert this
and I don't think merge conflicts are likely due to previous work I did around
the tooling for this.
2018-03-21 20:49:52 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
John McCall
31f2eec044 Change type metadata accessors to support incomplete metadata.
This includes global generic and non-generic global access
functions, protocol associated type access functions,
swift_getGenericMetadata, and generic type completion functions.

The main part of this change is that the functions now need to take
a MetadataRequest and return a MetadataResponse, which is capable
of expressing that the request can fail.  The state of the returned
metadata is reported as an second, independent return value; this
allows the caller to easily check the possibility of failure without
having to mask it out from the returned metadata pointer, as well
as allowing it to be easily ignored.

Also, change metadata access functions to use swiftcc to ensure that
this return value is indeed returned in two separate registers.

Also, change protocol associated conformance access functions to use
swiftcc.  This isn't really related, but for some reason it snuck in.
Since it's clearly the right thing to do, and since I really didn't
want to retroactively tease that back out from all the rest of the
test changes, I've left it in.

Also, change generic metadata access functions to either pass all
the generic arguments directly or pass them all indirectly.  I don't
know how we ended up with the hybrid approach.  I needed to change all
the code-generation and calls here anyway in order to pass the request
parameter, and I figured I might as well change the ABI to something
sensible.
2018-03-18 21:38:08 -04:00
Slava Pestov
d118654fa8 Sema: Peephole for 'nil' literal of Optional type 2018-03-18 00:13:55 -07:00
Michael Gottesman
b00966e247 [+0-all-args] Add more module_names to tests to enable running their plus_zero variants.
rdar://34222540
2018-03-13 19:47:50 -07:00
Michael Gottesman
8dd5ea9b60 [+0-all-args] Add a space after REQUIRES: plus_one_runtime to eliminate avoidable merge conflicts when editing other parts of the file.
This helps my tooling for enabling +0.
2018-03-11 16:19:09 -07:00
Michael Gottesman
e6e55df5ea [+0-all-args] Mark all tests that will need updates for +0 as requiring a plus_one_runtime. 2018-03-10 02:37:51 -08:00
John McCall
dff0031b02 Apply generic metadata patterns to all types and change their layout.
The layout changes to become relative-address based.  For this to be
truly immutable (at least on Darwin), things like the RO data patterns
must be moved out of the pattern header.  Additionally, compress the
pattern header so that we do not include metadata about patterns that
are not needed for the type.

Value metadata patterns just include the metadata kind and VWT.

The design here is meant to accomodate non-default instantiation
patterns should that become an interesting thing to support in the
future, e.g. for v-table specialization.
2018-03-05 19:05:41 -05:00
Doug Gregor
40283f9b73 [ABI] Add the protocol conformance descriptor into a witness table.
Extend witness tables with a pointer to the protocol conformance
descriptor from which the witness table was generated. This will allow
us to determine (for example) whether two witness tables were
generated from the same (or equivalent) conformances in the future, as
well as discover more information about the witness table itself.

Fixes rdar://problem/36287959.
2018-01-18 17:13:13 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Pavel Yaskevich
0133827e55 [Mangling/ABI] NFC: Fix IRGen tests to reflect label mangling changes 2017-12-18 15:45:50 -08:00
Slava Pestov
2a0cb060f8 SILGen: Look up the callee method after evaluating arguments 2017-11-08 01:31:55 -08:00
Slava Pestov
15bbf2c246 IRGen: Fulfill generic parameters from class-constrained archetypes 2017-09-25 22:15:46 -07:00
Arnold Schwaighofer
3ae6d7cb4d runtime/IRGen: return the argument from swift_retain family of functions
On architectures where the calling convention uses the same argument register as
return register this allows the argument register to be live through the calls.

We use LLVM's 'returned' attribute on the parameter to facilitate this.

We used to perform this optimization via an optimization pass. This was ripped
out some time ago around commit 955e4ed652.
By using LLVM's 'returned' attribute on swift_*retain, we get the same
optimization from the LLVM backend.
2017-09-19 07:16:37 -07:00
John McCall
750d397909 Substantially rework how IRGen handles function pointers.
The goals here are four-fold:
  - provide cleaner internal abstractions
  - avoid IR bloat from extra bitcasts
  - avoid recomputing function-type lowering information
  - allow more information to be propagated from the function
    access site (e.g. class_method) to the call site

Use this framework immediately for class and protocol methods.
2017-07-20 14:33:18 -04:00
Erik Eckstein
c4a11f4c92 tests: remove the now unused option -new-mangling-for-tests 2017-03-22 11:28:43 -07:00
John McCall
22382f7e15 Reimplement associated conformance IRGen using Doug's conformance
access path work.

Having done so, simplify archetype TypeInfos by removing a now-
unnecessary layer of abstraction.
2017-03-14 03:48:10 -04:00
Slava Pestov
18550b171d IRGen: witness_method function values no longer carry witness table
This was an unnecessary complication and didn't make a lot of
logical sense, because we can recover the witness table from
substitutions when we call a @convention(witness_method) anyway.

Also, to fix materializeForSet for generic subscripts, I want the
materializeForSet *callback* of a protocol witness to have
@convention(witness_method), which requires representing such
functions as a single function pointer in IRGen.
2017-02-25 16:42:51 -08:00
Erik Eckstein
8e3b05d2f4 IRGen: Use new mangling for llvm type names.
This should have no effect on the generated binary.
2017-02-22 09:19:10 -08: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
Erik Eckstein
1d3724666f tests: convert about 400 tests to the new mangling by using the -new-mangling-for-tests option
When the new mangling is enabled permanently, the option can be removed from the RUN command lines again.
2017-01-24 15:27:45 -08:00
Michael Gottesman
20dd563efb [semantic-arc] Update tests for qualified/unqualified ownership and SILGen emission of copy_value, destroy_value. 2016-10-29 20:11:09 -07:00
Arnold Schwaighofer
2d73b3cef2 IRGen: Cast the type of class pointer to the storage type
We can run into an opaque pointer type.

rdar://28684642
2016-10-25 09:34:35 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Robert Widmann
4f465224ea Polish off uses of dynamicType in tests 2016-07-29 16:59:14 -07:00
Joe
3938d5682a [SE-0095] [Runtime], [Demangler], & AST printer updated to new composition syntax
- All parts of the compiler now use ‘P1 & P2’ syntax
- The demangler and AST printer wrap the composition in parens if it is
in a metatype lookup
- IRGen mangles compositions differently
    - “protocol<>” is now “swift.Any”
    - “protocol<_TP1P,_TP1Q>” is now “_TP1P&_TP1Q”
- Tests cases are updated and added to test the new syntax and mangling
2016-07-19 12:01:37 -07:00
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Slava Pestov
60f437abe1 IRGen: Change witness_method calling convention to take a witness table
This is another incremental step toward protocol resilience.

To support resiliently adding requirements with default implementations,
we need to emit the witness thunk for each default requirement once,
and share it between conformances.

However, the body of the witness thunk can call witness methods from
the conformance of <Self : P>. Formerly, witness thunks were only emitted
with a concrete Self type, so any calls were resolved statically.

Now that Self can be abstract in a witness thunk signature, we have to
pass in the witness table and do the necessary gymnastics on both sides
of the call.

At the call site, the witness table is either abstract, concrete, or
undefined, as follows:

- If the unsubstituted Self type is concrete in the witness method
  signature, no witness table is necessary; this is the case of a
  concrete (non-default) witness thunk.

- If the unsubstituted Self type is abstract and the substituted Self
  type is concrete, the witness table is accessed via direct reference.

- If the unsubstituted Self type is abstract and the substituted Self
  type is also abstract, the witness table comes from type metadata
  that was passed in to the function where the call is taking place.

Inside the body of the witness method thunk, we only bind the witness
table if Self is an abstract type; this rules out the first case above,
where the witness table is not needed and cannot be provided by the
caller.

The result of a SIL witness_method instruction now lowers as an
explosion containing two values, the function pointer itself and
the witness table.

Similarly, partial application thunks now grab the witness table and
package it up in the context.

Special care is taken to support function_ref + apply and
function_ref + partial_apply of @convention(witness_method) callees;
here, we can hit the case where we don't know the original conformance
because the callee is concrete, in which case we just pass in a null
pointer as the witness table.

Witness thunks with an abstract Self currently only work for protocols
without any associated type requirements; to support those, we need
to be able to fulfill associated type metadata from the witness
table for the <Self : P> conformance. This will be addressed as part
of @rjmccall's calling convention work.

Also I didn't make any attempt to support this for @objc protocols that
do not have a witness table. In this case, the extra parameter is not
necessary since we can perform dynamic dispatch on the 'self' value to
call requirements; however, @objc protocols will not support default
implementations, at least not in the near-term.
2016-02-16 01:46:18 -08:00
Slava Pestov
1d77d810fd Re-apply "Sema: Always synthesize accessors for structs, unless they were imported from Clang"
This reverts commit 24a70e17ea.
2016-01-20 15:04:10 -08:00
Mark Lacey
24a70e17ea Revert "Sema: Always synthesize accessors for structs, unless they were imported from Clang"
This reverts commit 2b6ab633fc because it
at least breaks:
    Swift :: stdlib/SequenceType.swift.gyb
and possibly also results in some or all of these failures:
    Swift :: compiler_crashers/27944-swift-astvisitor.swift
    Swift :: compiler_crashers/28200-swift-typebase-getdesugaredtype.swift
    Swift :: stdlib/CollectionType.swift.gyb
    Swift :: stdlib/MicroStdlib.swift
2016-01-20 08:32:39 -08:00
Slava Pestov
2b6ab633fc Sema: Always synthesize accessors for structs, unless they were imported from Clang
This fixes the issue that "SILGen: Correctly emit accessors synthesized to
witness protocol requirements" was meant to solve, but in a simpler way.

A better fix would be to first address the issue where @_transparent
function bodies are not serialized in some cases, and then only emit
synthesized accessors as needed, in the original version of this patch.
To fix the duplicate symbol issues, we would emit the synthesized
accessors with shared linkage, which would always work once serialized
bodies were available.

For resilient structs of course, we'll always need to emit accessors
anyway.
2016-01-20 02:11:53 -08:00
Ge Sen
7ac02d54ba Erase redundant whitespaces. 2015-12-10 13:35:06 +08:00
John McCall
4d1b6e2eb6 Reform the runtime interface for unowned reference-counting.
This is a bit of a hodge-podge of related changes that I decided
weren't quite worth teasing apart:

First, rename the weak{Retain,Release} entrypoints to
unowned{Retain,Release} to better reflect their actual use
from generated code.

Second, standardize the names of the rest of the entrypoints around
unowned{operation}.

Third, standardize IRGen's internal naming scheme and API for
reference-counting so that (1) there are generic functions for
emitting operations using a given reference-counting style and
(2) all operations explicitly call out the kind and style of
reference counting.

Finally, implement a number of new entrypoints for unknown unowned
reference-counting.  These entrypoints use a completely different
and incompatible scheme for working with ObjC references.  The
primary difference is that the new scheme abandons the flawed idea
(which I take responsibility for) that we can simulate an unowned
reference count for ObjC references, and instead moves towards an
address-only scheme when the reference might store an ObjC reference.
(The current implementation is still trivially takable, but that is
not something we should be relying on.)  These will be tested in a
follow-up commit.  For now, we still rely on the bad assumption of
reference-countability.
2015-12-04 13:18:14 -08:00
Slava Pestov
54dd7892e8 SIL: Emit native ivar destroyer and store it in class metadata
Swift SVN r32644
2015-10-13 00:27:57 +00:00