It appears we were only using this to see if an associated type was
derived or defaulted. This code didn't mesh well with the other stuff
I was doing for default implementations, so I'd rather rip it out and
just rely on calling 'isImplicit' to check for derived associated
types instead.
Note that there's a small change of behavior -- if an associated type
is derived for one conformance, and then used as a witness in another,
we were previously only marking it as defaulted in the first one,
but now it is marked as defaulted in both. I do not believe this has
any meaningful consequences.
Migrate the check for whether a given type is representable in
Objective-C, which is currently used to verify when @objc can be
inferred or verify that an explicitly-written @objc is well-formed,
from Sema into a set of queries on the Type within the AST library, so
it can be used in other parts of the compiler.
As part of this refactoring, clean up and improve a number of aspects
of this code:
* Unify the "trivially representable" and "representable" code paths
into a single code path that covers these cases. Clarify the
different levels of "representable" we have in both the code and
in comments.
* Distinguish between representation in C vs. representation in
Objective-C. While we aren't using this now, I'm anticipating it
being useful to allow exporting C interfaces via @_cdecl (or
similar).
* Eliminate the special cases for bridging String/Array/Dictionary/Set
with their Foundation counterparts; we now consult
_ObjectiveCBridgeable conformances exclusively to get this
information.
* Cache foreign-representation information on the ASTContext in a
manner that will let us more easily get the right answer across
different contexts while providing more sharing than the TypeChecker
version.
Annoyingly, this only seemed to fix a small class of error where we
were permitting Unsafe(Mutable)Pointer<T> to be representable in
Objective-C when T was representable but not trivially representable,
e.g., T=String or T=AnyObject.Type.
In many places, we're interested in whether a type with archetypes *might be* a superclass of another type with the right bindings, particularly in the optimizer. Provide a separate Type::isBindableToSuperclassOf method that performs this check. Use it in the devirtualizer to fix rdar://problem/24993618. Using it might unblock other places where the optimizer is conservative, but we can fix those separately.
Fix some interface type/context type confusion in the AST synthesis from the previous patch, add a unique private mangling for behavior protocol conformances, and set up SILGen to emit the conformances when property declarations with behaviors are visited. Disable synthesis of the struct memberwise initializer if any instance properties use behaviors; codegen will need to be redesigned here.
There's a group of methods in `DeclContext` with names that start with *is*,
such as `isClassOrClassExtensionContext()`. These names suggests a boolean
return value, while the methods actually return a type declaration. This
patch replaces the *is* prefix with *getAs* to better reflect their interface.
This eliminates some minor overheads, but mostly it eliminates
a lot of conceptual complexity due to the overhead basically
appearing outside of its context.
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.
Apart from being general compile-time goodness, this helps break a
circularity issue involving serialization cross-references and the
Clang importer.
The test is being added to validation-tests because it relies on
several levels of non-laziness in the compiler, all of which we'd
like to fix. It's making sure we don't regress here, but it isn't
actually verifying this change in particular.
rdar://problem/22364953
Swift SVN r31455
Now that we have the inheritance lists hanging around, use them: it
makes the conformance lookup table use the same code whether we're
deserializing the conformances or parsing them.
Swift SVN r31383
It'll soon have to deal with the "inheritance" clauses of abstract
type parameter declarations (generic type parameters and associated
types). NFC at the moment, however.
Swift SVN r31295
This allows any type to conform to ErrorType without having to
implement any requirements, so the requirements can remain
underscored. Implements rdar://problem/21867608.
Swift SVN r30342
In insanely-hard-to-reproduce recursion walks of the extensions of a
nominal type within the conformance lookup table, make sure that we
don't visit an extension twice by checking our state each time. Fixes
rdar://problem/21861932.
Swift SVN r30280
Instead of requiring the user to disambiguate where an implied
protocol conformance goes---which they really, really don't care
about---just pick an arbitrary-but-deterministic location for the
conformance, which corresponds to the file unit in which the witness
table will be emitted. Fixes rdar://problem/21538899.
Swift SVN r30168
Specifically track when we're resolving type witnesses for a given
conformance, and refuse to recursively attempt to resolve those type
witnesses. The standard library patch in rdar://problem/21789238
triggers this, and isolating it in a small test case has proven
illusive.
Swift SVN r30160
The isDependentType() query is woefully misunderstood. Some places
seem to want it to mean "a generic type parameter of dependent member
type", which corresponds to what is effectively a type parameter in
the language, while others want it to mean "contains a type parameter
anywhere in the type". Tease out these two meanings in
isTypeParameter() and hasTypeParameter(), respectively, and sort out
the callers.
Swift SVN r29945
This means that we prefer conformances implied by explicit
conformances (ones that the user wrote) over conformances implied by
synthesized conformances (those that the compiler would
generate). This resolves the ambiguity causing rdar://problem/21007417.
Swift SVN r28880
This may not be the right solution. Even if it is, there are SourceKit tests
that need updating.
This reverts commit r28849 / rdar://problem/21007417.
Swift SVN r28852
Previously, we'd warn on this code:
enum Suit { case Spades, Hearts, Clubs, Diamonds }
extension Suit : Comparable {}
func <(...) {...}
because both Comparable and the synthesized conformance to Hashable imply
a conformance to Equatable. However, that's silly: Suit already has a
synthesized conformance to Equatable associated with the main 'enum'
declaration, not the extension. These compiler-provided conformances are
part of the language and something people rely on, so rank them higher than
conformances implied by conforming to a refined protocol.
rdar://problem/21007417
Swift SVN r28849
This allows @objc enum error types produced in Objective-C (e.g., via
+[NSError errorWithDomain:code:userInfo:]) to be bridged back to their
original enum types in Swift via pattern matching/catch blocks.
This finishes rdar://problem/20577517.
Swift SVN r28803
When deserializing a protocol, the conformance lookup table would not
contain entries for the inherited protocols of that protocol. They
were stashed in the "Protocols" array in TypeDecl (which will
eventually go away), but since there are no conformances for a
protocol, the conformance lookup table never got updated.
Nothing important seems to query this now; that will change soon.
Swift SVN r27967
If we try to visit a parsed extension (to find its protocol
conformances) when we don't have a resolver, we would get no
information out of the extension and never revisit it. Queue up these
extensions to be processed later, when we do have a resolver.
I’ve only ever seen this happen when building the standard library,
where verifying imported modules after checking a source file can
cause otherwise-unused extensions to get skipped, although they would
be needed later. The following commit depends on this, but this issue
is separable.
Swift SVN r27945
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
This eliminates nonsensical recursion when working with protocol
conformances, and makes their checking more lazy. Start to improve
name lookup to deal with protocol witnesses more lazily, generalizing
the solution we had to all protocol conformances and making it more
directed. We're not done here, as the FIXMEs in the code completion
test imply: this replace-the-requirement-with-the-witness behavior
needs to be sunk down into the AST level so it also applies to
unqualified lookup, visible-decl lookup, etc.
Swift SVN r27639
Move the map that keeps track of conforming decl -> requirement from ASTContext
to a nominal type's ConformanceLookupTable, and populate it lazily.
This allows getSatisfiedProtocolRequirements() to work with declarations from module files.
Test on the SourceKit side.
Part of rdar://20526240.
Swift SVN r27353
Another step toward using the conformance lookup table for
everything. This uncovered a tricky little bug in the conformance
lookup table's filtering logic (when asking for only those
conformances explicitly specified within a particular context) that
would end up dropping non-explicit conformances from the table (rather
than just the result).
Ween a few tests off of -enable-source-import, because they'll break
otherwise.
Swift SVN r27021
When we print the name of a protocol conformance, we normally use the generic parameters as written. However, since some requirements may be inferred (particularly by an extension of a generic type), it's better for the SIL printer to use the generic signature, which is fully expanded and will also be correct, e.g., when working with a deserialized conformance.
Swift SVN r26437
We now access the conformances of a nominal type through the
conformance lookup table, so there is no reason to continue storing
conformances directly on the nominal type declaration, which was
error-prone regardless. This mirrors the change to ExtensionDecl from
my previous commit.
Swift SVN r26354