Commit Graph

816 Commits

Author SHA1 Message Date
Arnold Schwaighofer
c40447bcd5 IRGen: Fix witness-table accessors for conditional conformances
rdar://38624842
2018-03-21 09:26:13 -07:00
John McCall
aaa40ee82b Move metadata-accessing IRGen out of GenMeta. NFC.
Abstract type/heap metadata access goes into MetadataRequest.
Metadata access starting from a heap object goes into GenHeap.
Accessing various components of class metadata goes into GenClass
or MetadataLayout.
2018-03-18 23:53:11 -04: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
10eb1785e5 IRGen: Clean up FIXME in emitConditionalConformancesBuffer() 2018-03-13 01:34:55 -07:00
Huon Wilson
216e69e810 Merge pull request #14973 from huonw/no-dynamic-count
[IRGen] Cond. conformance witness table count isn't needed dynamically.
2018-03-05 16:07:14 -08: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
Huon Wilson
ce1bb8b13c [IRGen] Cond. conformance witness table count isn't needed dynamically.
The count of the number of witness tables was designed to be an
assertion/check that we've hooked up all the infrastructure
correctly. Everything is now implemented, and the assertion has never
triggered, so it can be removed, saving some work.

Fixes rdar://problem/38038928.
2018-03-06 00:22:05 +11:00
hamishknight
31a2bc7bfc [IRGen] Always get the CanType of a conformance's contextual type (#14928)
The conformance type's contextual type might not be canonical, such as in the case of substituting a `typealias` type for a generic placeholder, so ensure we get the canonical type for the conformance.
2018-03-02 11:10:42 -08:00
Vedant Kumar
132bb19274 [IRGen] Avoid generating mergeable traps
Factor out and reuse logic in the lowering of CondFailInst to emit
non-mergeable traps, everywhere we emit traps. This should address a
debugging quality issue with ambiguous ud2 instructions.

rdar://32772768
2018-02-20 13:40:40 -08:00
Doug Gregor
817c0b368e [WIP] Emit nominal type access functions for imported types.
Emit nominal type access functions for imported types. These access
functions work with non-unique metadata references, so they perform
uniquing through the runtime on first access.

Fixes rdar://problem/36430234.
2018-01-19 23:11:50 -08:00
Doug Gregor
39f8965325 [IRGen] Don't add a dummy WitnessTableEntry for the conformance descriptor.
The dummy WitnessTableEntry for the protocol conformance descriptor
was used to ensure that the witness indices were offset by 1 (to
account for the protocol conformance descriptor), but it led to some
odd index adjustments. Instead, make the index adjustments explicit
when we're passing a WitnessIndex off to be loaded for a witness
table.
2018-01-18 22:30:32 -08: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
Doug Gregor
e766473ed9 [ABI] Emit separate symbols for protocol conformance descriptors.
Emit protocol conformance descriptors as separate symbols, rather than
inlining them within the section for protocol conformance records. We
want separate symbols for protocol conformances both because it is easier
to make them variable-length (as required for conditional
conformances) and because we want to reference them from witness
tables (both of which are coming up).
2018-01-17 10:35:16 -08:00
Slava Pestov
9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Slava Pestov
3595c92da5 IRGen: Refactor emitWitnessMethodValue() 2018-01-10 13:52:32 -08:00
Slava Pestov
2bd4f9bf66 IRGen: Fix formatting 2018-01-10 13:48:30 -08:00
Doug Gregor
e0255467cb [Runtime] Never use type metadata references in conformance records.
Only foreign classes and other imported types were making use of the
type metadata reference form in conformance records. Switch those over
to using nominal type descriptors, so we're using nominal type
descriptors for everything possible.

Only Objective-C-defined classes use a different representation now.
2018-01-04 12:52:42 -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
Arnold Schwaighofer
493a4e9bc9 IRGen: Fix a compiler memory leak by using the right parameter in a local function
No test case. Caught by the LSAN bot.

rdar://35646380
2017-11-29 17:01:23 -08:00
Doug Gregor
7f17f44472 [IRGen] Pass the appropriate conformance down for witness table access. 2017-11-27 17:24:19 -08:00
Doug Gregor
9b9923bd2e [IRGen] Bind conditional requirements in generic witness table instantiation function.
A witness table instantiation function can end up referring to
conditional requirements to, e.g., fill in base witness tables. Store
the conditional requirements first, and also bind the witness tables
for conditional requirements within the local scope so they can be
used directly. Fixes SR-6478.
2017-11-27 17:24:05 -08:00
Doug Gregor
8329616e31 [IRGen] Bind conditional requirements for witness table accessors.
When emitting a witness table accessor (e.g., an associated type metadata
or associated type conformance accessor) for a conditional conformance,
bind the conditional requirements so we can refer to them within that
accessor. Witness methods get this behavior already through the SelfWitnessTable parameter, but everything the witness table needs it.

Fixes most of SR-6478.
2017-11-27 17:24:05 -08:00
Doug Gregor
966f543003 [IRGen] Factor out binding of local type metadata for self witness tables.
We'll need to re-use this logic for witness table accessors.
2017-11-27 17:24:05 -08:00
Doug Gregor
9ff4d7b936 Cleanups for interface types in normal conformances.
Fix some line breaks, remove some unnecessary code, and fix a
crash in printing synthesized extensions.
2017-11-16 22:42:44 -08:00
Huon Wilson
5f70f68c0d [AST] Store only interface types in NormalProtocolConformances.
Rather than storing contextual types in the type witnesses and associated
conformances of NormalProtocolConformance, store only interface types.

@huonw did most of the work here, and @DougGregor patched things up to
complete the change.
2017-11-16 11:45:18 -08:00
Erik Eckstein
90c21be191 Unify the implementation of optimization mode in various option classes.
This commit is mostly refactoring.

*) Introduce a new OptimizationMode enum and use that in SILOptions and IRGenOptions
*) Allow the optimization mode also be specified for specific SILFunctions. This is not used in this commit yet and thus still a NFC.

Also, fixes a minor bug: we didn’t run mandatory IRGen passes for functions with @_semantics("optimize.sil.never")
2017-11-14 11:25:02 -08:00
Huon Wilson
6dd8bec47e [AST] Unify computation of 'has arguments?' for witness table accessors. 2017-11-09 17:51:48 -08:00
Huon Wilson
901bd35e5a [IRGen] Pass witness tables for conditional conformances to witness table accessor.
When calling an accessor, one has to pull the witness tables for each
conditional conformance requirement into a(n appropriately ordered) buffer that
is passed to the accessor. This is simple enough, if the appropriate
specialization of the relevant conformances are known, which the compiler didn't
track deep enough until now.
2017-11-08 17:02:50 -08:00
Huon Wilson
4743b8ae5c [IRGen] Pull witness tables out of self witness table in witness_method thunks.
These are passed down to the "true" function, and so need to be made available.
2017-11-08 17:02:50 -08:00
Huon Wilson
bdff7aa3f4 [IRGen] Polymorphic convention needs to consider conditional requirements from the self witness table.
Conditional requirements shouldn't appear in witness_method's (IR) signature,
since they differ from conformance to conformance. PolymorphicConvention just
needs to consider these fulfilled by the self witness table, since they
can/should be pulled out of there.
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
4f53475dd9 [IRGen] Support fulfilling conformances from conditional requirements.
A concrete conformance may involve conditional conformances, which are witness
tables that we can access from the original conformance's one. We need to track
metadata and be able to follow it in a metadata path.
2017-11-08 17:02:50 -08:00
Huon Wilson
51bea6b575 [IRGen] Reserve witness table private data space for conditional conformance tables.
Pointers to the witness tables of any conditional conformances are placed into
private data, closest to the base pointer, i.e. wtable_ptr[-1] will be the
first (if any) conditional conformance witness table. These always need to be
provided by the context, and copied in when the witness table is instantiated,
making reserving space easy: increment the size of the private data section.
2017-11-08 17:02:50 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -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
Slava Pestov
15bbf2c246 IRGen: Fulfill generic parameters from class-constrained archetypes 2017-09-25 22:15:46 -07:00
Slava Pestov
8b73de60a9 IRGen: Remove GenericTypeRequirements::ParentType
Finally, remove the parent type metadata argument from type
constructors.

Now that type constructors don't take a parent metadata pointer,
we can hit some asserts concerning type constructors that do not
have any parameters. This happens when you define a concrete type
in a fully-constrained extension of a generic type.

A more efficient ABI would use concrete type metadata for these
cases, but that would be a bigger change that we can do later, so
for now just relax these assertions.

This resolves a runtime crasher since a circular metadata case is
no longer circular. I renamed the crasher to reference the more
specific radar since the more general issue of circular metadata
is still unresolved.
2017-09-25 15:45:17 -07:00
Slava Pestov
0fa9f761b1 IRGen: Remove NominalParent metadata path component type
This is no longer needed now that we store arguments for all
nesting depths in type metadata.
2017-09-25 15:45:17 -07:00
Slava Pestov
453a5bc431 IRGen: Remove Fulfillment::searchParentTypeMetadata()
This is no longer needed now that we store arguments for all
nesting depths in type metadata.
2017-09-25 15:45:16 -07:00
Slava Pestov
704b8566a9 IRGen: Stop fulfilling generic parameters from the parent type
This change makes it so that type metadata stores arguments
from each nesting depth. This means that parent metadata is
no longer needed to fulfill generic arguments, but we still
store a parent pointer in metadata and pass it to type
constructor functions at this point.
2017-09-25 15:45:16 -07:00
Slava Pestov
e7e5a21dce IRGen: Remove a hack that no longer seems necessary
Generally we want to avoid calls to lookupConformance() after type
checking.
2017-09-07 21:36:52 -07:00
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Slava Pestov
b362174529 IRGen: Stricter contract for emitWitnessTableRef()
Again, let's just assert that we're emitting a reference
to a witness table for the exact conformance provided.

The inherited conformance case would not have handled
indirect refinement, where R refines Q refines P, and
we're asked to emit a witness table reference for P given
a conformance to R.
2017-09-01 00:46:18 -07:00
Slava Pestov
38bf9349a0 SIL: Require exact conformances in witness_method instructions
The SIL witness_method instruction takes a protocol method and a
protocol conformance. IRGen lowers this as a load of a function
pointer from a fixed offset in the witness table for the
conformance.

IRGen also handled the case where the conformance is to a
protocol that refines the protocol containing the requirement,
by calling ProtocolConformanceRef::getInherited() to map the
conformance stored in the instruction to the correct conformance
for the protocol requirement being called.

It appears that this possibilty is not exercised through our
test suite, and if this does come up it is better to fix
SILGen and the optimizer to construct witness_method calls
using exact conformances only instead.

Furthermore, ProtocolConformanceRef::getInherited() only handles
a single level of refinement. So for example, if a protocol R
refines Q which refines R, we would crash when lowering a
witness_method instruction that calls P.foo() with a conformance
to R.

Therefore, code that emits witness_method instructions with a
conformance to a protocol that doesn't match the requirement was
likely going to do the wrong thing in this case anyway. Moving
the assertion earlier in the pipeline will help shake out these
cases.
2017-09-01 00:46:18 -07:00
John McCall
9a228e96e1 Change the structure of emitted protocol and generic-wtable metadata:
- Always include an array of requirement descriptors in the protocol
  descriptor.  For now, this doesn't contain anything except a general
  requirement kind and an optional default implementation, but eventually
  this can be augmented with type / name metadata.  This array is always
  emitted as constant.

- Guarantee the value of the extent fields in a protocol descriptor and
  slightly tweak their meaning.

- Move the private-data field out of line in a generic witness table
  descriptor so that the main descriptor can be emitted as constant.

- Rely on IRGen's notion of the witness-table layout instead of assuming
  that SILWitnessTable and SILDefaultWitnessTable match the actual
  physical layout.

This version of the patch uses a hack in which we assign internal rather
than private linkage to certain symbols in order to work around a Darwin
linker bug.
2017-08-25 01:42:44 -04:00
Arnold Schwaighofer
c05381f96e Add LLVM's noinline to metadata/witness accessor functions at Osize 2017-08-17 14:57:22 -07:00
John McCall
1c6bf687f0 Make SILWitnessVisitor traffic in SILDeclRef instead of Decl. NFC. 2017-08-10 23:25:15 -04:00
John McCall
bd8246351e Add an AST-level abstraction for representing an abstract associated
type or conformance requirement.  NFC.
2017-08-10 20:15:20 -04:00