Commit Graph

1426 Commits

Author SHA1 Message Date
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
Slava Pestov
7432bd70a2 ClangImporter: Compute signature conformances upfront in finishNormalConformance()
We will need them even if the protocol is not @objc.
2017-09-12 16:23:16 -07:00
Slava Pestov
526b42658b ClangImporter: Use existing protocol ordering in finishNormalConformance() 2017-09-12 16:23:11 -07:00
Slava Pestov
c7aa831363 AST: Push conformance state change down into implementations of finishNormalConformance() 2017-09-12 16:22:35 -07:00
Slava Pestov
f6d9693de9 AST: Store a LazyConformanceLoader inside the SynthesizedProtocolAttr 2017-09-11 22:34:43 -07:00
Slava Pestov
defb9cd5b6 AST: Add ASTContext::Id_ArrayLiteralElement 2017-09-11 21:48:01 -07:00
Jordan Rose
ff31714b69 [ClangImporter] ImportedName doesn't need to know its version.
Preparation for making ImportNameVersion a generalized struct rather
than an enum. We could have kept cramming it into a bitfield, sure,
but we don't actually need this.

No intended functionality change.
2017-09-11 18:06:35 -07:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04: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
405b641246 ClangImporter: Synthesize typealiases instead of relying on associated type inference
Right now the ClangImporter relies on Sema to synthesize typealiases
in some cases, which doesn't work if a Sema instance is not available,
for example when the ClangImporter is asked to import a declaration
while deserializing SIL during optimization.

Begin addressing this by synthesizing typealiases for the following
conformances:

- ExpressibleByArrayLiteral.ArrayLiteralElement while importing
  OptionSets.

- RawRepresentable.RawValue while importing raw-valued enums.

- ObjectiveCBridgeable._ObjectiveCType while importing bridged
  newtypes.

Until further changes land, this is mostly NFC, except for a change
in generated interface printing where the new typealiases are now
explicitly shown.

Note that non-bridged newtypes whose raw type is ObjectiveCBridgeable
still rely on associated type inference, because the ClangImporter
cannot safely "copy" the _ObjectiveCType typealias from the raw type
to the newtype, for various reasons mostly having to do with
circularity. Subsequent patches will address this, in a rather novel
fashion that will shock you.
2017-09-07 00:30:44 -07:00
Slava Pestov
d575324e4c ClangImporter: 'ASTContext' should be abbreviated as 'ctx' not 'cxt' 2017-09-07 00:24:12 -07:00
Ben Langmuir
b083020759 Revert "Normalize version tuples in availability attributes coming from clang to use "."" 2017-09-05 14:03:31 -07:00
Ben Langmuir
f1c48daf70 Normalize version tuples in availability attributes coming from clang to use "."
Seen as @available attributes being printed with "_" in interface
generation, but fixing it in the importer means they can't leak into
anywhere else.

rdar://problem/30451293
2017-09-01 16:24:21 -07:00
Jacopo Andrea Giola
a598277ad3 Fix SR-5614, add check if importType succeds (#11698)
SwiftDeclConverter::importSwiftNewtype now check if the
storedUnderlyingType is null and return a nullptr
2017-09-01 13:41:48 -07:00
Slava Pestov
4a08fc6cc3 ClangImporter: Fix an unused variable warning 2017-09-01 02:04:22 -07:00
Jordan Rose
f8b7db4e76 Excise the terms "blacklist" and "whitelist" from Swift source. (#11687)
The etymology of these terms isn't about race, but "black" = "blocked"
and "white" = "allowed" isn't really a good look these days. In most
cases we weren't using these terms particularly precisely anyway, so
the rephrasing is actually an improvement.
2017-08-30 09:28:00 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00