Commit Graph

1047 Commits

Author SHA1 Message Date
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
George Karpenkov
efe143c2f4 Adding support for -sanitize=fuzzer flag (#11381)
Similarly to Clang, the flag enables coverage instrumentation, and links
`libLLVMFuzzer.a` to the produced binary.
Additionally, this change affects the driver logic, and enables the
concurrent usage of multiple sanitizers.
2017-08-07 18:16:51 -07:00
Arnold Schwaighofer
f4a810f7e4 IRGen: AttributeList related fixes for master next 2017-07-31 11:17:51 -07:00
John McCall
a0f20f673d Switch all of the indirect-call code in IRGen to FunctionPointer.
To make this stick, I've disallowed direct use of that overload of
CreateCall.  I've left the Constant overloads available, but eventually
we might want to consider fixing those, too, just to get all of this
code out of the business of manually remembering to pass around
attributes and calling conventions.

The test changes reflect the fact that we weren't really setting
attributes consistently at all, in this case on value witnesses.
2017-07-28 23:26:35 -04: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
Joe Groff
101788dbd4 IRGen: Support for computed properties with dependent generic context.
Use the KeyPath implementation's new support for instantiating and dealing with captures to lower the generic context required to dispatch computed accessors with dependent generics.
2017-07-06 20:07:41 -07:00
Arnold Schwaighofer
d8f6c8e57e IRGen: Bind metatypes from captured or regular arguments in partial apply
forwarding thunks

We omit passing some metatype parameters if they can be reconstructed from
regular arguments. However, the partial apply forwarder so far did not
reconstructing them from such arguments.

SR-4854
rdar://32134723
2017-05-24 11:36:11 -07:00
Jordan Rose
aeb0fedad1 Handle missing members in protocols as well.
This means both not crashing when we deserialize the protocol but
also emitting correct offsets for dynamic dispatch through the
protocol's witness table.

Also fix a bug with vtable and witness table slots for
materializeForSet accessors for properties that can't be
imported. Because materializeForSet doesn't have the type of the
property in its signature, it was taking a different failure path from
everything else, and that failure path didn't properly set the name or
flags for the missing member.

Finishes rdar://problem/31878396
2017-05-10 13:43:33 -06:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
Jordan Rose
e575d2d5ba [ClangImporter] Error structs from enums are not imported decls.
Enums with the ns_error_domain attribute represent codes for NSError,
which means Swift developers will expect to interact with them in
terms of Error. SE-0112 improved bridging for these enums to generate
a struct with the following form:

    struct MyError: Error {
      @objc enum Code: RawRepresentable {
        case outOfMemory
        case fileNotFound
      }
      var userInfo: [NSObject: AnyObject] { get }
      static var outOfMemory: Code { get }
      static var fileNotFound: Code { get }
    }

where MyError.Code corresponds to the original MyError enum defined in
Objective-C. Until recently, both the enum and the synthesized struct
were marked as having the original enum as their "Clang node", but
that leads to problems: the struct isn't really ObjC-compatible, and
the two decls have the same USR. (The latter had already been worked
around.)

This commit changes the struct to be merely considered a synthesized
"external definition", with no associated Clang node. This meant
auditing everywhere that's looking for a Clang node and seeing which
ones applied to external definitions in general.

There is one regression in quality here: the generated struct is no
longer printed as part of the Swift interface for a header file, since
it's not actually a decl with a corresponding Clang node. The previous
change to AST printing mitigates this a little by at least indicating
that the enum has become a nested "Code" type.
2017-04-24 09:57:41 -07:00
Joe Groff
aaddafa55b IRGen: Support for generic key path patterns. 2017-04-17 17:50:57 -07:00
Joe Groff
25eaa09463 wip irgen generic/computed key paths 2017-04-17 11:34:31 -07:00
Huon Wilson
31b92b1b46 Merge pull request #8473 from huonw/symbol-list-2
Remove dependency on IRGenModule of some linkage computations
2017-04-05 16:39:04 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Huon Wilson
3105c6ed00 [IRGen] Expose LinkInfo publicly, like LinkEntity. 2017-04-05 09:54:19 -07:00
Doug Gregor
5e3fac1e76 Stop using ProtocolConformance::getInheritedConformances() 2017-04-04 22:03:32 -07:00
Slava Pestov
6f57167380 IRGen: Small simplification 2017-03-27 00:25:12 -07:00
John McCall
720481d2f6 IRGen's archetype access path hack is now dead code, RIP. NFC. 2017-03-14 22:00:27 -04: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