Commit Graph

41 Commits

Author SHA1 Message Date
Roman Levenstein
049ba39da4 Address review comments 2017-04-14 22:17:55 -07:00
Slava Pestov
de2f5f78ac AST: Remove Substitution::subst()
I want to get rid of Substitution entirely, and now we have
the right abstractions to do everything with SubstitutionMap.
2017-03-07 16:04:54 -08:00
Slava Pestov
61b6cc823e AST: Add ProtocolConformanceRef::subst()
Extract this from Substitution::subst(), which is going away.
2017-03-07 16:04:33 -08:00
Slava Pestov
c040c71ea9 AST: Remove some unnecessary SubstitutionList copies
ASTContext::getSpecializedConformance() already copies the
substitutions, so remove some AllocateCopy() calls.

Also, add a new overload taking a SubstitutionMap instead.
This allows removing some gatherAllSubstitutions() calls,
which have an allocation inside them.

Finally, remove the now-unused ModuleDecl parameter from
ProtocolConformance::subst() and make it public.
2017-03-07 15:59:05 -08:00
swift-ci
b1c2719a0a Merge pull request #7461 from swiftix/substitutions-fixes 2017-02-14 10:03:48 -08:00
Roman Levenstein
ccac2a5678 Handle archetypes inside Substitution::subst
With inlining of generics we run into cases, where a replacement can be an archetype with a class requirement or an archetype with a superclass.
2017-02-14 08:27:18 -08:00
Jordan Rose
1c60910198 Revert "Merge pull request #6092 from swiftix/wip-generics-inlining-flag-4"
This reverts commit 1b3d29a163, reversing
changes made to b32424953e.

We're seeing a handful of issues from turning on inlining of generics,
so I'm reverting to unblock the bots.
2017-02-13 10:52:17 -08:00
Slava Pestov
3cd7bb2571 AST: Tighten up some assertions 2017-02-12 01:42:35 -08:00
Roman Levenstein
e4af4e1c42 Handle archetypes inside Substitution::subst
With inlining of generics we run into cases, where a replacement can be an archetype with a class requirement or an archetype with a superclass.
2017-02-10 18:07:30 -08:00
Slava Pestov
b22f9ea487 AST: Remove SubstitutionMap::getMap()
We don't want to expose the fact that SubstitutionMaps are
backed by a DenseMap, since that's going to change soon.
2017-02-06 19:43:33 -08:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Slava Pestov
7731d4c6cb Sema: Remove some unnecessary calls to getCanonicalType() 2017-01-08 21:01:13 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Joe Groff
4444d83756 SIL: Lower captures to boxes with an appropriate generic context.
Officially kick SILBoxType over to be "nominal" in its layout, with generic layouts structurally parameterized only by formal types. Change SIL to lower a capture to a nongeneric box when possible, or a box capturing the enclosing generic context when necessary.
2016-12-16 20:23:25 -08:00
Joe Groff
6fa0c97e08 Provide a callback-based variation of Substitution::subst.
This is needed if we want to use Substitution::subst from inside Type::subst, which will be necessary for SILBoxTypes and maybe some day BoundGenericTypes. NFC yet.
2016-12-15 14:53:14 -08:00
Slava Pestov
3eabc2139b AST: Remove TypeBase::hasDependentProtocolConformances()
Another oddly-named utility function with poorly-defined behavior.

It returned true for archetypes, generic parameters, existential
types, and metatypes of existential types.

However, it would return false for dependent member types, or
metatypes of archetypes, and so on.

All the callers were doing something bad to begin with, so
changing them over to more precise predicates improved the code.

In particular, this simplifies substitution construction in
the SIL parser, and makes it stricter, which turned up a couple
of mistakes in the SIL tests where we were doing stuff with
non-conforming types.
2016-12-04 21:15:03 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
58f013ea73 SILGen: Create new archetypes for witness thunks instead of using the conformance
Sema produces a weird mix of requirement and witness archetypes when
it builds witness substitutions. Instead of hacking around this in
SILGen, just build new archetypes, since we already have to use an
ArchetypeBuilder to get the correct generic signature on the interface
type.

Then, we just have to map the witnessSubs provided by Sema to use our
new archetypes.

This unblocks some work on generic inlining.

Fixes <rdar://problem/28765006>.
2016-10-18 01:03:28 -07:00
Slava Pestov
185921f6ab AST: Remove slow version of Substitution::subst()
When applying substitutions to substitution lists in SIL, we would
unpack the ArrayRef<Substitution> into a SubstitutionMap on each
iteration over the original ArrayRef<Substitution>. Discourage
this sort of thing by removing the API in question and refactoring
surrounding code.
2016-09-13 22:58:58 -07:00
Slava Pestov
b677a2e6a7 AST: Use the new Type::subst() in a few places
SILType substitutions are still done with the old form, and until
BoundGenericTypes hold conformances, we still have to pass around
a ModuleDecl in a few places we really shouldn't, but one step
at a time.
2016-09-08 21:59:13 -07:00
Slava Pestov
a993e36c06 AST: Add a new SubstitutionMap data structure
This replaces the TypeSubstitutionMap / ConformanceMap pair that
has been appearing more and more lately.
2016-09-08 21:59:11 -07:00
Slava Pestov
9cba638c04 AST: Fix derivation of conformances in Substitution::subst() in the presence of same-type constraints
Applying a substitution list to a Substitution is done in two
steps:

1) First, apply the substitution list to the original replacement
   type R to get the substituted replacement type R'.

2) Second, for each abstract conformance of R from the original
   substitution, look up a concrete conformance of R' from the
   substitution list.

With minimized generic signatures, we would omit conformances of
a nested type T.A if they could be derived from some other
conformance already in the substitution list.

However, the derivation process was incorrect, because it would
only look at the canonical parent type T, and not any other parent
type that had a child A which was same-type equivalent to T.A.

For example, consider the following code:

protocol P1 { associatedtype A : P3 }
protocol P2 { associatedtype A : P4 }

protocol P3 {}
protocol P4 {}

func doSomething<T : P4>(...) {}
func doSomethingElse<T1 : P1, T2 : P2>(...) where T1.A == T2.A {
  doSomething(...)
}

If we specialize doSomethingElse() with a pair of concrete types
to replace T1 and T2, we would need to find a concrete conformance
to replace the abstract conformance T2.A : P4 in the call to
doSomething().

Since the conformance of T2.A : P4 is a redundant requirement,
it does not appear in the conformance map; furthermore, T1.A and
T2.A are same-type equivalent, so they map to the same archetype.

We would therefore look at the canonical parent of T2.A, which is
T1, and look up the conformance of T1 : P1 in the substitution list.

However, the only requirement P1 imposes on A is the conformance
A : P3. There's no conformance A : P4 inside T1 : P1, so we would
hit an assertion.

Indeed, the conformance T1.A : P4 must be recovered from the
conformance of T2 : P2, because P2 requires that A : P4.

This patch ensures that the conformance can be found by changing
the ArchetypeConformanceMap from a simple mapping of archetypes
to conformances into a structure that records same-type constraints
as well.

So instead of just looking at the canonical parent of the archetype
T1.A, we consult the structure to check all archetypes that have
T1.A as a child, in this case both T1 and T2.

T2 : P2 contains the conformance we need, allowing the above code
to be specialized correctly.
2016-09-08 01:51:46 -07:00
Slava Pestov
fbe9573598 AST: Add some utility methods to GenericSignature
These will be more useful once substitutions in protocol conformances
are moved to use interface types.

At first, these are only going to be used by the SIL optimizer.
2016-09-06 11:51:12 -07:00
Slava Pestov
247852cf6d AST: Remove unused parameter from {ProtocolConformance,Substitution}::subst() 2016-09-06 11:51:12 -07:00
Slava Pestov
ca0b548584 SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
2016-08-28 13:51:37 -07:00
Slava Pestov
c02953cd1f AST: Remove SubstitutionIterator, NFC 2016-08-22 10:45:51 -07:00
Slava Pestov
b25ea04c88 AST: Refactor Substitution::subst() to use GenericParamList::getSubstitutionMap(), NFC
Again, we now pass in a GenericSignature so that we can walk its
requirements, rather than relying on the AllArchetypes list
embedded inside the GenericParamList.
2016-08-22 10:45:51 -07:00
Joe Groff
e99961eb8f AST: Fix Substitution::subst to substitute associated types from conformance witnesses instead of by name.
Fixes a crash when property behavior uses are run through the specializer, since they set up associated type conformances that are not recoverable by name lookup.
2016-02-22 15:31:14 -08:00
Chris Lattner
89e94008a0 add newline to end of file, NFC 2016-01-09 09:47:09 -08:00
John McCall
5112864dad Remove the archetype from Substitution.
This eliminates some minor overheads, but mostly it eliminates
a lot of conceptual complexity due to the overhead basically
appearing outside of its context.
2016-01-08 15:27:13 -08:00
John McCall
2df6880617 Introduce ProtocolConformanceRef. NFC.
The main idea here is that we really, really want to be
able to recover the protocol requirement of a conformance
reference even if it's abstract due to the conforming type
being abstract (e.g. an archetype).  I've made the conversion
from ProtocolConformance* explicit to discourage casual
contamination of the Ref with a null value.

As part of this change, always make conformance arrays in
Substitutions fully parallel to the requirements, as opposed
to occasionally being empty when the conformances are abstract.

As another part of this, I've tried to proactively fix
prospective bugs with partially-concrete conformances, which I
believe can happen with concretely-bound archetypes.

In addition to just giving us stronger invariants, this is
progress towards the removal of the archetype from Substitution.
2016-01-08 00:19:59 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Doug Gregor
88258ed268 Allow substitution^2's to look up the conformance for a class to AnyObject.
AnyObject conformances are weird beasts, because we're able to
synthesize them fairly arbitrarily for classes. Do so also within
substitution into a Substitution, fixing rdar://problem/20338028.

Longer term, the AnyObject protocol needs to die.

Swift SVN r28118
2015-05-04 16:36:12 +00:00
Doug Gregor
02d25888c9 Clean up the interface to Type::subst(), NFC.
Replace the 'ignoreMissing' boolean flag with a new option set type,
SubstOptions, which is easier to extend. It is not an OptionSet<>
because a follow-on commit will introduce a non-trivial option that
will require more storage.

Also eliminate the LazyResolver parameter, which is no longer
needed. Eliminate the silly TypeChecker::substType(), whose only
purpose was to provide the resolver.

Swift SVN r27656
2015-04-23 23:36:18 +00:00
Mark Lacey
fedf1abec6 Fix assertion when substituting for class-constrained generics.
The class-constrained generic has no conformances to substitute for, so
we should just bail out early rather than expecting to find a
conformance for each thing the archetype conforms to.

Fixes rdar://problem/19336878.

Swift SVN r24583
2015-01-21 01:40:52 +00:00
Joe Groff
01da305569 Factor out a TypeBase::hasDependentProtocolConformances() method.
Make it easier to get the "do I expect null ProtocolConformance* pointers" logic right. Audit existing uses of is<ArchetypeType>() for this purpose.

Swift SVN r23479
2014-11-20 18:43:17 +00:00
Joe Groff
a247f5d98c SIL parser: Populate conformances of init_existential insns.
And fix some bugs with existential conformances, where we were creating a bogus conformance instead of just using null conformances like other code expects.

Swift SVN r23461
2014-11-20 02:43:23 +00:00
Erik Eckstein
f6c68fb1d5 SILGen: fix crash in case a function is specialized which contains an Array/Dictionary up- or downcast.
The apply insts for the call to the collection-casts were generated with substitutions w/o an ArcheType.



Swift SVN r21740
2014-09-05 14:07:25 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +00:00
John McCall
b8c2967567 Create a dedicated implementation file for Substitution. NFC.
Swift SVN r18295
2014-05-18 02:16:21 +00:00