Commit Graph

50 Commits

Author SHA1 Message Date
Anthony Latsis
b5aec4cc34 [test] Remove pre-rebranch nocapture matches
These were added in https://github.com/swiftlang/swift/pull/81375 (and
several other follow-up PRs because we missed a few places) and
are no longer needed.
2025-10-24 02:07:22 +01:00
Anthony Latsis
55e5618eab [test] Match nocapture to succeed both on main and rebranch
Both the syntax and relative order of the LLVM `nocapture` parameter
attribute changed upstream in 29441e4f5fa5f5c7709f7cf180815ba97f611297.
To reduce conflicts with rebranch, adjust FileCheck patterns to expect
both syntaxes and orders anywhere the presence of the attribute is not
critical to the test. These changes are temporary and will be cleaned
up once rebranch is merged into main.
2025-05-08 23:52:43 +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
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
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04: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
Doug Gregor
ee6ac0433c Fix FileCheck to account for 32-bit platforms 2019-02-06 13:13:58 -08:00
Doug Gregor
229ddf570f [IRGen] Metadata for the conforming type in a witness table access need not be complete.
When calling a witness table accessor, IRGen was forcing the
conforming type to have complete metadata, even though only abstract
metadata is required for that query. This could cause cyclic metadata
dependencies when checking conditional conformances.

Fixes SR-5958.
2019-02-05 22:02:49 -08:00
Michael Gottesman
fd4828e40a Eliminate -assume-parsing-unqualified-ownership-sil from tests.
I am doing this separately from the actual change to eliminate the option to
make it easier to review.
2018-12-19 12:54:13 -08:00
Doug Gregor
81909f24ff [IRGen] Update IRGen test cases for swift_getWitnessTable(). 2018-10-25 20:35:27 -07: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
Saleem Abdulrasool
d746a6d1db tests: annotate dllstorage on IRGen tests
This adds the dllstorage annotations on the tests.  This first pass gets
most of the IRGen tests passing on Windows (though has dependencies on
other changes).  However, this allows for the changes to be merged more
easily as we cannot regress other platforms here.
2018-04-23 20:21:10 -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
Huon Wilson
43196c27ac [IRGen] 'void **' -> 'void ***' in swift_getGenericWitnessTable.
This is simpler, because the native form of that last argument is: a
pointer to a buffer (*) of pointers (*) to witness tables, which is
modelled as a buffer of void *s. Thus, void ***.
2018-03-06 00:22:05 +11: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
Slava Pestov
7401aa607f IRGen: Fix runtime crash with default implementation of protocol requirement with a generic class
If the 'self' type is abstract, we still have to consider it as
a source of type metadata, because it might be a class-bound
generic parameter and the class might have generic parameters.

Fixes <rdar://problem/36093833>.
2017-12-21 17:28:52 -08:00
Huon Wilson
306c0dafdd fixup! [IRGen] Dynamically fill in conditional conformance wtables. 2017-11-08 17:02:50 -08:00
Huon Wilson
b9336c7389 [IRGen] Dynamically fill in conditional conformance wtables.
This requires the witness table accessor function to gain two new parameters: a
pointer to an array of witness tables and their count. These are then passed down
to the instantiation function which reads them out of the array and writes them
into the newly-allocated witness table.

We use the count to assert that the number of conditional witness tables passed
in is what the protocol conformance expects, which is especially useful while
the feature is still experimental: it is a compiler/runtime bug if an incorrect
number is passed.
2017-11-08 17:02:50 -08:00
Huon Wilson
44045e24da [test] Update SIL printing/parsing tests for 'witness_method: <protocol>'. 2017-11-01 11:33:27 -07:00
Doug Gregor
55b8698613 [Mangling] Mangle generic signature of a conformance relative to the nominal type.
Conformance manglings, which are used for witness tables and related witness
thunks, mangle the generic signature of the conformance. Since conformances
also describe the conforming type, mangle the conformances's generic signature
relative to the conforming type's generic signature.

In practice, this means that we don't mangle any part of the generic signature
into a conformance mangling now, so we see a decent win: 2.3% smaller
trie and 6.4% smaller strings section in the standard library binary.
When conditional conformances land, we'll see some generic signatures
mangling again (for the additional requirements of the constrained
extension).
2017-10-12 10:15:17 -07:00
Slava Pestov
e1b33b1a91 IRGen: Fix bug in @convention(witness_method) 'Self' metadata fulfillment
Fixes <rdar://problem/34889823>.
2017-10-09 19:53:50 -07:00
Greg Parker
b7f744c302 [test] Replace CPU=i386_or_x86_64 with CPU=i386 || CPU=x86_64. (#11889) 2017-09-12 19:34:08 -07:00
Erik Eckstein
c4a11f4c92 tests: remove the now unused option -new-mangling-for-tests 2017-03-22 11:28:43 -07:00
Slava Pestov
ab6f7c4a21 IRGen: Cache concrete witness tables using the local metadata mechanism
Fixes <rdar://problem/30765842>.
2017-02-28 18:15:23 -08:00
Greg Parker
6295f3d8b3 Revert "[test] Remove CPU=i386_or_x86_64 hack."
Swift master uses LLVM swift-4.0-branch, which does not yet have
the lit change implementing this syntax.

This reverts commit dfd10ae485.
2017-02-28 14:59:31 -08:00
Greg Parker
935d7b4d4a [test] Temporarily disable test IRGen/witness_method.sil. 2017-02-28 13:36:10 -08:00
Erik Eckstein
1282c6ae78 tests: convert more tests to use new mangling for llvm types
Those tests were missed because they are not executed currently by mistake (rdar://problem/30762030)
2017-02-28 12:33:27 -08:00
Greg Parker
dfd10ae485 [test] Remove CPU=i386_or_x86_64 hack.
LLVM lit now supports boolean expressions in REQUIRES: directives.
2017-02-16 16:27:15 -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
Slava Pestov
e617517487 AST: Drop types with no explicit requirements from substitution lists
Recently I changed the ArchetypeBuilder is minimize requirements
in generic signatures. However substitution lists still contained
all recursively-expanded nested types.

With recursive conformances, this list becomes potentially
infinite, so we can't expand it out anymore. Also, it is just
a waste of time to have them there.
2016-11-08 16:11:29 -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
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
John McCall
12b8a92e9d In generic functions, derive local type data for associated types
from the witness tables for their associations rather than passing
them separately.

This drastically reduces the number of physical arguments required
to invoke a generic function with a complex protocol hierarchy.  It's
also an important step towards allowing recursive protocol
constraints.  However, it may cause some performance problems in
generic code that we'll have to figure out ways to remediate.

There are still a few places in IRGen that rely on recursive eager
expansion of associated types and protocol witnesses.  For example,
passing generic arguments requires us to map from a dependent type
back to an index into the all-dependent-types list in order to
find the right Substitution; that's something we'll need to fix
more generally.  Specific to IRGen, there are still a few abstractions
like NecessaryBindings that use recursive expansion and are therefore
probably extremely expensive under this patch; I intend to fix those
up in follow-ups to the greatest extent possible.

There are also still a few things that could be made lazier about
type fulfillment; for example, we eagerly project the dynamic type
metadata of class parameters rather than waiting for the first place
we actually need to do so.  We should be able to be lazier about
that, at least when the parameter is @guaranteed.

Technical notes follow.  Most of the basic infrastructure I set up
for this over the last few months stood up, although there were
some unanticipated complexities:

The first is that the all-dependent-types list still does not
reliably contain all the dependent types in the minimized signature,
even with my last patch, because the primary type parameters aren't
necessarily representatives.  It is, unfortunately, important to
give the witness marker to the primary type parameter because
otherwise substitution won't be able to replace that parameter at all.
There are better representations for all of that, but it's not
something I wanted to condition this patch on; therefore, we have to
do a significantly more expensive check in order to figure out a
dependent type's index in the all-dependent-types list.

The second is that the ability to add requirements to associated
types in protocol refinements means that we have to find the *right*
associatedtype declaration in order to find the associated witness
table.  There seems to be relatively poor AST support for this
operation; maybe I just missed it.

The third complexity (so far) is that the association between an
archetype and its parent isn't particularly more important than
any other association it has.  We need to be able to recover
witness tables linked with *all* of the associations that lead
to an archetype.  This is, again, not particularly well-supported
by the AST, and we may run into problems here when we eliminate
recursive associated type expansion in signatures.

Finally, it's a known fault that this potentially leaves debug
info in a bit of a mess, since we won't have any informaton for
a type parameter unless we actually needed it somewhere.
2016-02-22 01:02:31 -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
Slava Pestov
284c4f8b97 IRGen: Fix Linux build -- non-external functions have protected linkage 2016-02-16 02:16:41 -08: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
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
John McCall
94ebcb847b Handle inherited concrete conformances correctly on witness_method instructions.
rdar://24141848
2016-01-12 23:36:21 -08:00
Joe Groff
2f56073145 IRGen: Slather attributes on indirect arguments.
@inout parameters can be nocapture and dereferenceable. @in, @in_guaranteed, and indirected @direct parameters can be noalias, nocapture, and dereferenceable.

Swift SVN r29353
2015-06-09 01:19:17 +00:00
Manman Ren
e94aae06da [Function Attribute] add target-cpu and target-features sets if they're non-null.
All llvm::Functions created during IRGen will have target-cpu and target-features
attributes if they are non-null.

Update testing cases to expect the attribute in function definition.
Add testing case function-target-features.swift to verify target-cpu and
target-features.

rdar://20772331


Swift SVN r28186
2015-05-05 23:19:48 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Dmitri Hrybenko
ab5dfa0cd0 Adjust tests for the upstream changes in the LLVM IR syntax
Swift SVN r25655
2015-03-01 09:28:51 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Ted Kremenek
d075f06573 Require a minimum deployment target of iOS 7 or OSX 10.9
Implements <rdar://problem/17532113>

Swift SVN r19451
2014-07-02 06:23:38 +00:00
Manman Ren
8e64b2a170 SILParser: parsing generic code.
Do not print '.Archetype' property of Substitution in SILPrinter.
Update testing cases accordingly.

We assume the order of substitions matchs the order of AllArchetypes for
the generic param list.

rdar://14443287


Swift SVN r15090
2014-03-14 23:13:55 +00:00
Joe Groff
d12fb5a20b IRGen: Accept the existence of init requirements in protocols.
Make WitnessVisitor not freak out when it sees an init requirement, allowing 'init' requirements to be used in non-@objc protocols. Fixes <rdar://problem/13695680>.

Swift SVN r14744
2014-03-06 19:24:37 +00:00