Commit Graph

1242 Commits

Author SHA1 Message Date
Jordan Rose
e1f46b5a26 [ClangImporter] Handle subscript getters redeclared in subclasses (#13470)
Objective-C subscripts don't have special declarations like
properties; they're just specially-named methods (or method pairs),
and we have to make an independent SubscriptDecl in Swift. This means
that when a subclass wants to make a subscript settable, they just add
the appropriately-named setter method.

Swift handled this by detecting when the getter and setter weren't
declared in the same type, and assuming this meant it was a subclass
adding a setter. Unfortunately, the same condition /also/ picked up
the case where the getter (and only the getter) is /redeclared/ in a
subclass (perhaps to add an attribute), and the new subscript was
getting added to the base class instead of the subclass.

The fix relies on the fact that the original decl we provide is what
we use to look up the other accessor. If the getter and setter are in
different types, whichever one we started with must be the
more-derived one. So the final change is just "did we start with the
setter?" rather than "is there a setter at all?".

I'm not sure why this is only just now causing problems, given that we
seem to have been getting this wrong for years, but it definitely
/was/ wrong and now it's not.

rdar://problem/36033356
2017-12-18 11:01:34 -08:00
Slava Pestov
1f1fa3b91d AST: Remove NominalTypeDecl::hasDelayedMembers() 2017-12-12 14:01:55 -08:00
Slava Pestov
db7aa52c5c ClangImporter: Simplify finishPendingActions() 2017-12-12 14:01:54 -08:00
Graydon Hoare
eba924b1c2 [ClangImporter] call addImplicitDestructor() on imported CF types. 2017-12-01 16:52:25 -08:00
Arnold Schwaighofer
eba12a7c3e Revert "Finish and default-enable named lazy member loading" 2017-12-01 07:25:54 -08:00
swift-ci
7e6f7e1c04 Merge pull request #12843 from graydon/force-on-named-lazy-member-loading 2017-12-01 02:32:10 -08:00
Graydon Hoare
0e3bde6744 [ClangImporter] call addImplicitDestructor() on imported CF types. 2017-11-30 22:01:06 -08:00
Jordan Rose
f5989d2f6f [ClangImporter] Don't use instance methods to suppress class methods (#13100)
(and vice versa)

Inadvertant fallout from 7725e38d96, which concerned accidental ambiguity
when mirroring protocol methods onto an implementing class.

https://bugs.swift.org/browse/SR-5959
2017-11-28 08:53:08 -08:00
Doug Gregor
7ec8512b11 Merge pull request #12970 from DougGregor/conformance-interface-type
[AST] Store only interface types in NormalProtocolConformances.
2017-11-17 07:52:59 -08:00
Slava Pestov
ca1586d667 ClangImporter: Don't synthesize zero initializer body if we finished type checking 2017-11-16 21:11:41 -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
Slava Pestov
29279afd9b Merge pull request #12940 from slavapestov/clang-importer-type-checked-ast
ClangImporter: Synthesize fully-type checked AST for common functions
2017-11-15 16:23:20 -08:00
Slava Pestov
415fce274b ClangImporter: Synthesize fully-type checked AST for common functions
These kinds of synthesized declarations no longer need to go
through the constraint solver, since they have simple enough
bodies that we can construct type checked AST directly:

- rawValue getter and init(rawValue:)
- memberwise struct initializer
- zero struct initializer
2017-11-14 21:52:29 -08:00
Graydon Hoare
c179431724 [ClangImporter] Use ClassDecl::addImplicitDestructor more thoroughly. 2017-11-06 14:59:51 -08:00
Graydon Hoare
7e363ff97a [AST] Add implicit dtors outside typechecking, rdar://35198678 2017-11-04 02:59:52 -07:00
Jordan Rose
85ccbb4990 [ClangImporter] Bridging can happen even without full bridgeability
Partially reverts f4f8349 (from July!) which caused us to start
importing global blocks with unbridged parameters, breaking source
compatibility. I'm still investigating whether there's an actual hole
in the logic; see next few commits.

rdar://problem/34913634
2017-11-02 14:40:39 -07:00
Slava Pestov
ea5aa0b992 ClangImporter: Remove redundant calls to ValueDecl::setValidationStarted()
createDeclWithClangNode() was already doing this.
2017-10-23 18:50:15 -07:00
Slava Pestov
2834dcbc7c ClangImporter: Call setValidationStarted() on synthesized declarations
This avoids doing unnecessary work in validateDecl().
2017-10-22 20:05:00 -07:00
Jordan Rose
2f932ff3ea [ClangImporter] Handle property with getter that returns instancetype (#12414)
We just import this as a property, and Swift doesn't support
properties with dynamic Self type, even if they are read-only. Don't
mark the getter as returning dynamic Self in this case.

(This was only a problem in builds with the AST verifier turned on.)

https://bugs.swift.org/browse/SR-5684
2017-10-16 10:18:14 -07:00
Doug Gregor
936a701b15 [AST] Stop uniquing canonical GSBs based on the module.
Now that the GenericSignatureBuilder is no longer sensitive to the input
module, stop uniquing the canonical GSBs based on that module. The main
win here is when deserializing a generic environment: we would end up 
creating a canonical GSB in the module we deserialized and another
canonical GSB in the module in which it is used.
2017-10-10 09:41:23 -07:00
Doug Gregor
ef542ffd8a [GSB] Eliminate the stored LookupConformanceFn to the GSB.
Implement a module-agnostic conformance lookup operation within the GSB
itself, so it does not need to be supplied by the code constructing the
generic signature builder. This makes the generic signature builder
(closer to) being module-agnostic.
2017-10-10 09:41:23 -07:00
Doug Gregor
a846724a60 [Clang importer] Replace a use of getMembers() with a lookup(). 2017-09-29 16:52:39 -07:00
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
David Ungar
443ab7d950 git-clang-format 2017-09-26 18:02:35 -07:00
David Ungar
90b456b116 Use if (auto for getting Stats 2017-09-26 17:32:38 -07:00
David Ungar
a41a3c9fa5 compiles using movable guards 2017-09-26 17:22:58 -07:00
David Ungar
2af86f5cac First compiling run, WIP 2017-09-26 16:07:07 -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
d417281ed9 Merge pull request #12097 from DougGregor/gsb-nested-type-lookup
[GSB] Centralize, clean up, and cache nested type name lookup
2017-09-25 12:32:16 -07:00
Jordan Rose
adac80fa02 [ClangImporter] Handle inheritance from a class/protocol composition (#12067)
This is legal Objective-C code:

    typedef NSBar <NSFooing> BarAndFoo
    @interface MyBaz : BarAndFoo
    @end

    // Equivalent
    @interface MyBaz : NSBar <NSFooing>
    @end

In Swift 3, we usually handled these by just dropping the protocol
part, making everything appear to work. (The protocols get added to
the class later, without looking at sugar.) However, in Swift 4, we
started supporting these compositions directly* and suddenly
inheriting from them didn't work (read: crashed the compiler). As an
extra twist, even Swift 3 can hit the problem case when the base type
is NSObject, because we figured 'id <NSObject, NSFooing>' was a better
approximation of 'NSObject <NSFooing> *' than 'NSObject *' was.

Fix this by just ignoring protocols when looking for a superclass. As
mentioned, we attach those separately anyway, so we aren't losing any
information.

* This isn't exactly true; there's still a difference between
'NSBar <NSFooing>' and 'NSBar <NSFooing> *'. Jacopo Andrea Giola fixed
a previous issue with this in a598277ad. But Swift doesn't do anything
meaningful with the first form, so it usually just pretends it's the
second.

rdar://problem/34586035
2017-09-25 11:33:17 -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
David Ungar
d4cf2d4a24 Merge pull request #11656 from davidungar/addingTimers
Refactoring performSema in order to add timers
2017-09-22 20:31:06 -07:00
Doug Gregor
eccdedaf97 Merge pull request #12062 from DougGregor/make-fewer-gsbs
Create fewer generic signature builders
2017-09-22 18:38:27 -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
Slava Pestov
93bbe223d6 ClangImporter: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:28 -07:00
Jordan Rose
82fa3627a8 Merge pull request #11867 from jrose-apple/ClangImporter-episode-V
[ClangImporter] Support Swift 5 API notes
2017-09-15 16:34:27 -07:00
Jordan Rose
9a04bee421 [ClangImporter] Turn ImportNameVersion into a struct.
...so that we don't have to keep coming back to update it every major
release. And also so we can actually put methods on it instead of
using free functions.

No intended behavior change (yet).
2017-09-15 14:30:24 -07:00
Jordan Rose
90f728a68e [ClangImporter] Check for failure in forEachDistinctName
forEachDistinctName might produce the same name for Swift 4 and Swift
5, but it's possible that for some reason the name will only work in
one mode or the other. In that case, even though we're trying the
"same" name again, we still want to invoke the callback once more.
Add a boolean return to the callback to support this.

Tests to come at the end of this patch series -- this shows up when in
Swift 3 mode and the canonical version for types is set to Swift 5.
2017-09-15 14:30:24 -07:00
David Ungar
0c2dfb511d add timer to ClangImporter::Implementation::loadAllMembers 2017-09-14 16:19:43 -07:00
Slava Pestov
9df82e18cf ClangImporter: Don't create redundant inheritance clause entries
If an imported type conforms to a protocol with a synthesized
conformance, we only add a SynthesizedProtocolAttr, without
adding an entry to the inheritance clause. Otherwise the
ConformanceLookupTable records an explicit conformance and the
LazyConformanceLoader is lost.
2017-09-14 01:14:24 -07:00
Slava Pestov
f166adaad4 ClangImporter: Compute requirement signature in finishNormalConformance() 2017-09-13 23:12:11 -07:00
Slava Pestov
20d834cc07 ClangImporter: Fix conformsToProtocolInOriginalModule() to walk SynthesizedProtocolAttrs 2017-09-13 23:12:11 -07:00
Slava Pestov
c624ff50ee ClangImporter: Fix finishTypeWitnesses() to work with protocol typealiases 2017-09-13 23:11:26 -07:00
Slava Pestov
1023b1c0ad ClangImporter: Fix finishSignatureConformances() to support associated types 2017-09-13 23:11:26 -07:00
Slava Pestov
ae5d6fd3b7 ClangImporter: Clean up inheritance clause synthesis
There was some duplicate code for adding protocols to inheritance
clauses and constructing the SynthesizedProtocolAttrs that indicate
a conformance should have a LazyConformanceLoader.

Clean this up to make it less error-prone.

NFC for now, until further changes land.
2017-09-12 22:40:21 -07:00
Slava Pestov
e26949d3fd ClangImporter: Find type witnesses in finishNormalConformance() 2017-09-12 22:31:25 -07:00
Slava Pestov
6d3ea57310 ClangImporter: Split up finishNormalConformance() 2017-09-12 16:36:54 -07:00