Commit Graph

1616 Commits

Author SHA1 Message Date
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
Graydon Hoare
819275945d [Stats] Replace RecursiveSharedTimer with FrontendStatsTracer. 2018-02-21 14:49:24 -08:00
Graydon Hoare
76b82accbc [Stats] Simplify FrontendStatsTracer uses and formatter-definitions. 2018-02-21 14:49:24 -08:00
Graydon Hoare
6f46362f38 [Stats] Improve stats tracing readability a little. 2018-02-21 14:49:24 -08:00
Jordan Rose
fbe65e2bc5 [ClangImporter] Import objc_subclassing_restricted classes as 'public' (#14766)
(rather than 'open')

This attribute was originally introduced for Swift classes exposed to
Objective-C, but if it /is/ used on a pure Objective-C class Swift
should respect it. There might be an actual reason, such as a hot code
path in ContrivedExampleKit checking against the class object's
address instead of using -isKindOfClass:.

For source compatibility, only enforce this in Swift 5 mode.

rdar://problem/33971529
2018-02-21 10:14:42 -08:00
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Jordan Rose
c06cc016f9 [ClangImporter] Fix handling of bitfields in unions (#14412)
Previously this caused an assertion failure in +Asserts builds
and incorrect behavior in -Asserts builds.

rdar://problem/37242238
2018-02-05 18:12:58 -08:00
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
Jordan Rose
75dcf27896 [ClangImporter] swift_wrapper: transfer inherited synthesized protos (#14254)
That is, if the wrapped type conforms to special known protocol X via
synthesized conformance to protocol Y which inherits from X, the
wrapper should conform to X as well.

https://bugs.swift.org/browse/SR-6842
2018-01-30 08:48:17 -08:00
Graydon Hoare
9334779f33 [Stats] Reduce layering violations in FrontendStatsTracer. 2018-01-30 01:54:07 -08:00
Graydon Hoare
ff104e4f11 Merge pull request #14059 from graydon/count-stats-stacks
[Stats] Expand FrontendStatsTracer to trace multiple entity-types.
2018-01-24 17:30:26 -08:00
Jordan Rose
3f4cba25d4 Use a semantic ClangImporterSynthesizedTypeAttr for error structs
...rather than the ad hoc CustomTypeNameManglingAttr I was using
before. As John pointed out, the AST should be semantic wherever
possible.

We may someday want to get out of this being an attribute altogether,
or duplicating information that's available in the original Clang
node, by actually storing a reference to that node somewhere. This is
tricky and mixed up with deciding what hasClangNode() or
getClangDecl() would mean, though, so for now the attribute just
carries the information we need.
2018-01-24 10:57:52 -08:00
Jordan Rose
e63879dc48 [Mangling] Define "related entity" operators 'LA'...'LJ'
(and 'La'...'Lj')

Use this for the synthesized structs for error enums, as described in
the previous commit, instead of reusing the "private discriminator"
feature. I left some space in the APIs for "related entity kinds" that
are longer than a single character, but I don't actually expect to use
it any time soon. It's mostly just easier to deal with StringRef than
with a bare char.

Note that this doesn't perfectly round-trip to the old mangling; I had
it treat these nodes as private discriminators with a prefixed "$"
instead. We don't depend on that for anything, though.
2018-01-24 10:52:46 -08:00
Jordan Rose
9c1a22ad0f Mangle synthesized error structs as a variant of the imported enum
When importing a C enum with the ns_error_domain attribute, we
synthesize a struct containing an NSError object to represent errors
in that domain. That synthesized struct should have a mangled name
that ties it to the original C enum, if we want it to be stable, and
now it does.

Before: $SSC7MyErrorV (a normal struct, which is a lie)
After: $SSC11MyErrorCode13ns_error_enumLLV
  kind=Global
    kind=Structure
      kind=Module, text="__C_Synthesized"
      kind=PrivateDeclName
        kind=Identifier, text="ns_error_enum"
        kind=Identifier, text="MyErrorCode"

Using the "private discriminator" feature allows us to pack in extra
information about the declaration without changing the mangling
grammar, and without stepping on anything the importer is using.

More rdar://problem/24688918
2018-01-23 17:05:43 -08:00
Graydon Hoare
5f130a8d35 [Stats] Expand FrontendStatsTracer to trace multiple entity-types. 2018-01-21 23:37:54 -08:00
Slava Pestov
240409761b ClangImporter: Give error wrappers an explicit '@_fixed_layout' attribute
This ensures they answer false to isFormallyResilient(), without
complicating the implementation of this method with a module
context check.
2018-01-12 19:03:48 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Jordan Rose
ff41cf3c7c [ClangImporter] Don't drop CF retain/release functions with swift_name (#13834)
Swift uses ARC for CF types, so CFRetain and its variants aren't
necessary. But sometimes functions /look/ like retain/release variants
(to the compiler, anyway) but actually do useful things, like
CMBufferQueueDequeueAndRetain. Recognize this with the presence of a
swift_name attribute (either from CF_SWIFT_NAME or from API notes).

rdar://problem/23480844
2018-01-09 17:55:58 -08:00
Mark Lacey
167e484187 IUO: Use new ImportedType class rather than std::pair<Type, bool>. 2018-01-06 00:30:14 -08:00
Mark Lacey
dea38a7710 IUO: Rename some importer functions.
Minor update to improve naming.
2018-01-05 16:52:50 -08:00
Mark Lacey
0544e2a26e IUO: Fix missed update to clang importer for constructor parameters. 2018-01-05 14:40:15 -08:00
Mark Lacey
4ca3e20651 IUO: Update the ClangImporter to surface whether decls are implicitly unwrapped.
Update several functions to return a Type/bool pair with the bool
representing whether the type is one that should be implicitly
unwrapped. This bool is surfaced up to the decl importing functions,
allowing them to set the appropriate decl attribute so that the
expression type checker will consider selecting the underlying type of
the optional involved during solving if the expression doesn't type
check with the optional type.

When importing Decls, use the IUO information to set the
ImplicitlyUnwrappedOptionalAttr attribute when appropriate.

We're still generating IUO types at the moment, so this change doesn't
really have much of an affect other than the creation of those
attributes.
2018-01-04 18:23:42 -08:00
Ben Langmuir
fc556317b6 Reapply "Normalize version tuples in availability attributes coming from clang to use ".""
This reapplies f1c48daf70 with the test split up so that the
availability bits don't affect other platforms.

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
2018-01-03 13:09:21 -08:00
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