Commit Graph

555 Commits

Author SHA1 Message Date
Doug Gregor
d93bed5ed1 [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-28 16:19:08 -07:00
Doug Gregor
0a1583fb87 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-28 14:27:15 -07:00
Doug Gregor
8f5d8aa7f9 Revert "[GSB] Centralize, clean up, and cache nested type name lookup" 2017-09-25 13:43:10 -07:00
Doug Gregor
a048194041 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-25 08:47:40 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
Doug Gregor
76a532b3af [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-22 17:11:05 -07:00
Doug Gregor
115d81a327 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-22 11:32:26 -07:00
Andrew Trick
c6f82f8f85 [sil-opaque-values] Fix SIL ownership in reabstraction thunks.
Emit a borrow scope whenever exploding tuples in to a list of arguments.

I spent a lot of time attempting to refactor the reabstraction thunk generation
code with code that handles RValue. However, there is a subtle difference in how
tuples are handled when they are packed into a single "RValue" as opposed to a
list of arguments.

Eventually, I ditched that effort because of subtle complexity and fell back on
Michael's suggestion of handling the extra thunk-sepcific work inside
Scope.popPreservingValues. This will just go away though once we have the
'destructure' instruction.
2017-09-10 16:01:35 -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
0ee80f4f1e SILGen: More ownership refactoring
Use the ManagedValue forms of the SILInstruction constructors
where possible. This ensures that after emitting an instruction
such as an upcast, we rewrite the value's cleanup to destroy
the new value, and not the old value. This is important because
the ownership verifier asserts that instructions dominated by
a destroy cannot use the destroyed value.

Should be NFC, since the ownership verifier is off by default
for now.
2017-08-26 01:56:09 -07:00
Slava Pestov
e4d26a2eb2 SILGen: Use the ManagedValue form of createUncheckedRefCast() where possible 2017-08-25 23:50:52 -07:00
Andrew Trick
d4f043c90e Cleanup SILGen code paths for handling ownership during thunk emission. 2017-08-23 22:15:10 -07:00
Andrew Trick
0a36f9dee7 Fix SIL ownership for open_existential_value.
CoW existentials means that we can't forward ownership.
2017-08-23 22:15:10 -07:00
Michael Gottesman
bdb032d941 [silgen] gen => SGF.
In a previous commit, I got rid of all SILGenFunction &gen. But looks like I
missed SILGenFunction gen(...). This fixes 3 such cases.
2017-08-11 09:50:36 -07:00
Michael Gottesman
bd32f9eaea [silgen] Perform last gen => SGF. Now SILGen always uses SGF. 2017-08-10 22:55:42 -07:00
Michael Gottesman
7cf4cdf9d9 [silgen] Verify that all ManagedValues in all RValues that are loadable are actual loaded (i.e. have object type).
This is already an RValue invariant that used to be enforced upon RValue
construction. We put in a hack to work around a bug where that was not occuring
and changed RValue constructors to instead load stored objects when they needed
to. But the problem is that since then we have added more constructors that
provide other manners to create such an invalid RValue.

I added verification to many parts of RValue and exposed an additional verify
method that we can invoke at the end of emitRValue() eventually to verify our
invariants. This will give me the comfort to make that assumption in other parts
of SILGen without worry.

I also performed a small amount of cleanup of RValue construction.

rdar://33358110
2017-08-08 00:43:33 -07:00
Andrew Trick
92a3ad0810 [sil-opaque-values] SILGen/ownership support for protocol thunks. 2017-07-26 17:42:08 -07:00
Joe Groff
e6b356ad4d SILGen: The allocator entry point for an initializer is never dynamic.
The allocating thunk handles the `dynamic`-ness of the initializing entry point, which maps to an underlying `-initWith*:` ObjC method, and cannot itself be treated as `dynamic`. Fixes SR-5223 | rdar://problem/32778104.
2017-07-21 15:53:25 -07:00
Andrew Trick
f657ad2d3a Rename *ExistentialOpaque instructions to *ExistentialValue.
These instructions have the same semantics as the *ExistentialAddr instructions
but operate directly on the existential value, not its address.

This is in preparation for adding ExistentialBoxValue instructions.
The previous name would cause impossible confusion with "opaque existentials"
and "opaque existential boxes".
2017-07-17 23:46:41 -07:00
John McCall
7f22faf968 Substantially rework how SILGen handles bridging as part of laying the
ground work for the syntactic bridging peephole.

- Pass source and dest formal types to the bridging routines in addition
  to the dest lowered type.  The dest lowered type is still necessary
  in order to handle non-standard abstraction patterns for the dest type.

- Change bridging abstraction patterns to store bridged formal types
  instead of the formal type.

- Improve how SIL type lowering deals with import-as-member patterns.

- Fix some AST bugs where inadequate information was being stored in
  various expressions.

- Introduce the idea of a converting SGFContext and use it to regularize
  the existing id-as-Any conversion peephole.

- Improve various places in SILGen to emit directly into contexts.
2017-07-11 12:45:13 -04:00
Robert Widmann
a4bf57f9d1 Move HasInOut bit out of recursive type properties
In anticipation of removing this bit, move it from the
recursive type property into TupleType - its only real
user.  This necessitates uglifying a bit of logic in the
short term that used to speak broadly of materializability
to instead speak about LValues and Tuples of InOut values
independently.
2017-06-14 09:54:19 -07:00
John McCall
44fda629aa Teach SILGen to handle more bridging cases and thread SGFContexts
through a few places.

This patch should be NFC for existing patterns, but it's preparing for
using SILGen's built-in bridging capabilities for more things.
2017-06-11 01:39:51 -04:00
John McCall
f4a181bc21 Various improvements to RValue. 2017-06-11 01:39:50 -04:00
Doug Gregor
fef69478f6 [GSB] Introduce computeGenericSignature() for generic signature creation.
The GenericSignatureBuilder requires `finalize()` to be called before a
generic signature can be retrieved with `getGenericSignature()`. Most of the former isn’t strictly needed unless you want a generic signature, and the 
latter is potentially expensive. `computeGenericSignature()` combines the two
operations together, since they are conceptually related. Update most of the
callers to the former two functions to use `computeGenericSignature()`.
2017-05-15 17:16:50 -07: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
Slava Pestov
0290c2d5d8 AST: Make GenericSignature and GenericEnvironment SubstitutionMaps interchangable
SubstitutionMap::lookupConformance() would map archetypes out
of context to compute a conformance path. Do the same thing
in SubstitutionMap::lookupSubstitution().

The DenseMap of replacement types in a SubstitutionMap now
always has GenericTypeParamTypes as keys.

This simplifies some code and brings us one step closer to
a more efficient representation of SubstitutionMaps.
2017-04-24 14:12:36 -07:00
practicalswift
a596961187 [gardening] Make parameter name comments match actual parameter names 2017-04-20 13:47:10 +02:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Doug Gregor
faa0401598 [GSB] Allow requirement inference for synthesized requirements. 2017-04-14 17:19:02 -07:00
Slava Pestov
4da14393fa SILGen: Catch an unnecessary mapTypeIntoContext() call 2017-04-13 13:45:54 -07:00
Slava Pestov
4cd5eb708a Fix a memory error introduced by recent changes
ExistentialLayout::getProtocols() can return an interior
pointer if the layout describes a single protocol type.

In this case we must not hold on to the result after
the layout goes out of scope.

Fix a few places where this was happening, which should
address a test failure we've been seeing.

Fixes <rdar://problem/31586433>.
2017-04-13 07:22:54 -07:00
Slava Pestov
67ec712457 SIL: Type lowering for subclass existentials 2017-04-12 00:07:30 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Slava Pestov
53759f7126 Use ValueDecl::isDynamic() instead of getAttrs().hasAttribute<DynamicAttr>() 2017-03-29 00:46:43 -07:00
Slava Pestov
2dc819d1d1 AST: Introduce new form of TypeBase::getCanonicalType()
I've fixed a few bugs recently where I had to switch
a getCanonicalType() call to instead use the stronger
GenericSignature::getCanonicalTypeInContext().

Avoid the 'if (genericSig = ...)' dance by adding a new
form of TypeBase::getCanonicalType() which takes a
signature, and if it's null, just falls back to the
standard getCanonicalType().
2017-03-27 00:18:26 -07:00
Joe Shajrawi
69bd3ca9f8 Fix opaque value corner-cases for classes and vtables 2017-03-24 12:28:52 -07:00
Joe Shajrawi
e7773ba167 Support a corner case of tuple transformation with opaque value types 2017-03-23 18:28:23 -07:00
Joe Shajrawi
b0bf93eb43 Support translateAndImplodeIntoAny under opaque value mode 2017-03-20 15:39:57 -07:00
Joe Shajrawi
951f6d9e8e Refactor supporting tuple to any reabstraction: avoid alloc_box and support non-empty tuples 2017-03-17 16:48:57 -07:00
Joe Shajrawi
7effefcaef Add support for reabstraction of () to Any under opaque value mode 2017-03-17 12:43:55 -07:00
Joe Shajrawi
f2cf6d26fa Add support for Translating a single opaque value with an indirect ParameterConvention under opaque value mode 2017-03-16 16:21:15 -07:00
Slava Pestov
64adf7495e SILGen: Change ArchetypeOpenings map to be keyed by ArchetypeType * and not CanType 2017-03-14 17:46:54 -07:00
John McCall
3c5de5fa0a Preserve type canonicality better in several places and
idiomatize some uses of SILType::getSwiftRValueType().
2017-03-14 14:59:43 -04:00
Joe Shajrawi
534bb6b172 conditional checked cast instruction for opaque value types: add support for generic types + change docs per review 2017-03-09 17:51:42 -08:00
Joe Shajrawi
1f626304f1 Add support for conditional checked cast instruction for opaque value types + SILGen support for it 2017-03-06 16:35:27 -08:00
Doug Gregor
2d430d8324 [GSB] Always pass a root potential archetype to a requirement source.
Whenever we create a (root) requirement source, associate it with the
potential archetype on which the requirement is written. This lets us
follow a requirement source from the (stated or implied) requirement on
the root potential archetype to the effective requirement on the
resulting potential archetype.

Introduce FloatingRequirementSource for the cases where we need to
state what the root source is, but don't yet have a potential
archetype to attach it to. These get internally resolved to
RequirementSources as soon as possible.
2017-02-28 09:47:02 -08:00
Doug Gregor
40a813bc8d [GenericSigBuilder] Sink RequirementSource into GenericSignatureBuilder. 2017-02-28 09:41:23 -08:00
practicalswift
26e07a2870 [gardening] Make sure parameter name in comment match actual name 2017-02-24 09:38:00 +01:00