Commit Graph

478 Commits

Author SHA1 Message Date
Michael Gottesman
a047bb7564 Revert "Fix the build."
This reverts commit dc24c2bd34.

Turns out Chris fixed the build but when I was looking at the bots, his fix had
not been tested yet, so I thought the tree was still red and was trying to
revert to green.
2016-07-17 16:29:18 -07:00
Michael Gottesman
dc24c2bd34 Fix the build.
This reverts commit b4cba58330.
This reverts commit a602927c75.
This reverts commit 55fbe5a763.
2016-07-17 16:17:15 -07:00
Chris Lattner
55fbe5a763 Remove Boolean as a special, privileged type used by Sema, and instead
use the concrete Bool type.  This eliminates a bunch of complexity and
makes diagnostics more concrete.
2016-07-17 15:14:24 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Doug Gregor
b86b8126a7 [SE-0112] Import an Objective-C error enum as a struct wrapping NSError.
A given Objective-C error enum, which is effectively an NS_ENUM that
specifies its corresponding error domain, will now be mapped to an
ErrorProtocol-conforming struct that wraps an NSError, much like
NSCocoaError does. The actual enum is mapped to a nested "Code"
enum. For example, CoreLocation's CLError becomes:

  struct CLError : ErrorProtocol {
    let _nsError: NSError
    // ...
   @objc enum Code : Int {
     case ...
   }
  }

This implements bullet (2) in the proposed solution of SE-0112, so
that Cocoa error types are mapped into structures that maintain the
underlying NSError to allow more information to be extracted from it.
2016-07-12 10:53:52 -07:00
Saleem Abdulrasool
7352392830 IRGen: add support for DLL Storage semantics
Add initial support for modelling DLL Storage semantics for global values.  This
is needed to support the indirect addressing mechanism used on Windows.
2016-07-06 18:03:57 -07:00
Slava Pestov
b9eb24ebc2 IRGen: Emit remote reflection metadata for @objc protocols
I noticed even with multi-payload enum layout working, remote
reflection could not understand Set and Dictionary, because of
issues with Objective-C protocols in the standard library that
are used in the representation of those types.

The problem is that we were taking a different code path and
not emitting a field descriptor. A field descriptor is necessary
to differentiate Objective-C, class-bound and opaque protocols
from each other, so that existentials can use the correct
representation.
2016-07-01 01:29:19 -07:00
Jordan Rose
3b6e40c030 Use ClassDecl::ForeignKind to model Clang's objc_runtime_visible.
We're now correctly checking for inheritance, adding @objc methods,
and adding @objc protocols for both CF types and objc_runtime_visible
classes (those without visible symbols). The latter is used for some
of the types in Dispatch, which has exposed some of the classes that
were considered implementation details on past OSs.

We still don't properly implement using 'as?' to check conformance to
a Swift protocol for a CF or objc_runtime_visible type, but we can do
that later.

rdar://problem/26850367
2016-06-30 11:20:58 -07:00
Jordan Rose
53118e9a5f Split the "Foreign" flag into a ForeignKind enum.
This flag tracks whether we have a special kind of imported class
that has limitations in what you can do with it. Currently it's
used for two things: CF classes, and the magic "Protocol" class used
to represent Objective-C protocol metadata. I'm planning to add a
third to handle classes with the recently-added objc_runtime_visible
attribute, which describes an Objective-C class whose runtime symbols
are hidden (forcibly preventing categories and subclassing). This is
used for some of the types in Dispatch, which has exposed some of the
classes that were considered implementation details on past OSs.

I'm splitting the flag into an enum rather than just marking the
Dispatch classes with the existing flag because we still need to
be able to /cast/ to the Dispatch types (which you can't do with CF
types today) and because they deserve better than to be lumped in
with CF for diagnostic purposes.

Groundwork for rdar://problem/26850367, which is that Swift will
happily let you extend the new Dispatch classes but then fails to find
the symbols at link-time.
2016-06-29 14:20:21 -07:00
Adrian Prantl
935b702a07 Add an assertion to IRBuilder to prevent function calls with no debug location
It is not valid LLVM IR to have a function call without a location to an
inlinable function inside a function with debug info — this makes it impossible
to construct inline information.

This patch adds an assertion and fixes up several places across IRGen where
such a situation could happen.

rdar://problem/26955467
2016-06-27 19:04:51 -07:00
Slava Pestov
4aa1aa7202 IRGen: Preliminary support for nested generic types
For now, just run the existing SILGen test to completion. I'll work on
more tests later, I wanted to check this stuff in before it bitrots
any further.
2016-06-23 00:01:41 -07:00
Slava Pestov
7e6ece6799 IRGen: It appears parent type metadata is filled in correctly now 2016-06-23 00:01:40 -07:00
practicalswift
4485f76794 [gardening] Use consistent capitalization for "Objective-C". 2016-06-14 22:24:43 +02:00
Slava Pestov
98a0e73b02 AST: Merge BoundGenericType::getSubstitutions() with TypeBase::gatherAllSubstitutions(), NFC 2016-06-13 00:57:09 -07:00
practicalswift
8df3859ce7 [gardening] Fix recently introduced typos. 2016-06-05 11:11:44 +02:00
Saleem Abdulrasool
dcbeb01abc IRGen: address a TODO in the type metadata emission
Mark the explicit section for the nominal type metadata being emitted.  This is
constant data (post-relocation).  Map this to __TEXT,__const on MachO, .rodata
on ELF and .rdata on COFF.  Add the cases for COFF and ELF, and change the
switch to be covered.
2016-06-04 11:47:33 -07:00
Joe Groff
25465bdb63 Revert "IRGen: address a TODO in the type metadata emission"
This reverts commit b9066c9f2c. It is still triggering relocation-
related errors on some CI configurations.
2016-05-27 12:01:02 -07:00
Joe Groff
29bd44b06f Merge pull request #2475 from compnerd/metadata-section
IRGen: address a TODO in the type metadata emission
2016-05-27 11:42:52 -07:00
Slava Pestov
60dff01093 Reflection: Simplify associated type metadata emission
Instead of hooking into nominal type and extension emission
and walking all conformances of those declarations, let's
just directly hook into the logic for emitting conformances.

This fixes an issue where we would apparently emit duplicate
conformances, as well as unnecessary conformances that are
defined elsewhere.
2016-05-26 19:33:00 -07:00
Bryan Chan
9c620863ed The instance alignment mask in the class metadata is a 16-bit field, and must be loaded with a 16-bit load instruction for correctness on big-endian systems. 2016-05-24 20:03:54 -04:00
Anna Zaks
93c68c8f3c [tsan] Avoid false positives in type metadata lookups
Hide the writes in the instrumentation when building for TSan to avoid false positives.

This patch relies on the following commit into the compiler-rt repo:
r269855: [tsan] Ensure mmap respects ignore_interceptors_accesses
2016-05-23 09:44:54 -07:00
Saleem Abdulrasool
b9066c9f2c IRGen: address a TODO in the type metadata emission
Mark the explicit section for the nominal type metadata being emitted.  This is
constant data (post-relocation).  Map this to __TEXT,__const on MachO, .rodata
on ELF and .rdata on COFF.  Add the cases for COFF and ELF, and change the
switch to be covered.
2016-05-11 14:58:13 -07:00
Doug Gregor
b4a58650dd [SE-0033] Add _SwiftNewtypeWrapper protocol for swift_newtype'd types.
This protocol lets us identify swift_newtype'd types. More
importantly, use protocol extensions to make it easy to transfer
specific conformances from the underlying type to the wrapper
type. So, for example, if the underlying type is Hashable, make the
wrapper type Hashable as well. Do the same for Equatable, Comparable,
and _ObjectiveCBridgeable. Fixes rdar://problem/26010804.
2016-05-08 22:34:39 -07:00
David Farler
a1ff1e6a7b Eagerly emit reflection metadata as decls are emitted
Rather than collection nominal type and extension decls and emit
reflection metadata records in one go, we can emit them as they
are encountered and instead collection builtin types referenced
by those at the end.
2016-04-29 17:07:55 -07:00
John McCall
6c92c324f6 Rename IRGenModuleDispatcher to just IRGenerator and transfer
ownership of some of the basic structures to it.
2016-04-27 09:42:03 -07:00
Slava Pestov
00e0c89b30 IRGen: Emit reflection info for protocols
For now, just enough for lowering.

Perhaps we should have a way to always just get this information
from metadata instead, since protocol metadata is always static
and not instantiated.

This would require the static "object file" interface used by
swift-reflection-dump to take a callback for symbol lookup.
2016-04-25 20:08:48 -07:00
John McCall
812557ca24 Reorganization within RemoteAST. Basic error propagation.
Initial stabs towards reading foreign class metadata, although
these do not yet successfully resolve the declaration.
2016-04-25 16:57:19 -07:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
Joe Groff
66d5971f42 Merge pull request #2086 from jckarter/generic-objc-subclass
Allow subclasses of specific instantiations of ObjC generic classes.
2016-04-07 08:42:40 -07:00
practicalswift
66183cdbf7 [gardening] Fix unjustified spacing 2016-04-07 10:10:24 +02:00
John McCall
7097facbd4 Fix the code pattern with which we access ObjC classes to correctly
use classrefs instead of accessing the symbol directly.

This might be a very nasty bug to work around.
2016-04-06 21:53:02 -07:00
Joe Groff
9c5564f808 Allow subclasses of specific instantiations of ObjC generic classes.
If a subclass grounds all the type parameters from its base class, we don't have to worry about any erasure edge cases. We should be able to support this, giving existing code that subclasses the nongeneric form of the class a migration path. Spot-fix some places in IRGen where we assume we can't emit static references to ObjC generic classes or metaclasses.
2016-04-06 21:19:11 -07:00
Anna Zaks
d81c6ba1f2 [tsan] Suppress a benign race during metadata cache lookup
This data race is benign and should not occur on the platforms we currently care about. However, do set the ordering appropriately when built with TSan to avoid reporting races from Swift code. The metadata lookup code relies on these orderings for synchronization.
2016-04-06 11:54:12 -07:00
Doug Gregor
7d1a2e8339 Reinstate "Implement support for Clang's objc_runtime_visible attribute."
When a Clang-defined Objective-C class has the objc_runtime_visible
attribute, use objc_lookUpClass to get the Objective-C class object
rather than referencing the symbol directly. Also, ban subclassing of
Objective-C-runtime-visible classes as well as @objc on members of
extensions of such classes.

As a drive-by needed for this test, make
ClassDecl::getObjCRuntimeName() respect the Clang objc_runtime_name
attribute.

Fixes rdar://problem/25494454.

Fix an i32 vs. 64 issue in the IR matching for the IR generation test.

This reverts commit 09973e6956.
2016-04-02 20:10:32 -07:00
Ted Kremenek
09973e6956 Revert "Implement support for Clang's objc_runtime_visible attribute."
This reverts commit 2c1f19a547.

This appears to be breaking all the iOS bots.
2016-04-02 07:33:14 -07:00
Doug Gregor
2c1f19a547 Implement support for Clang's objc_runtime_visible attribute.
When a Clang-defined Objective-C class has the objc_runtime_visible
attribute, use objc_lookUpClass to get the Objective-C class object
rather than referencing the symbol directly. Also, ban subclassing of
Objective-C-runtime-visible classes as well as @objc on members of
extensions of such classes.

As a drive-by needed for this test, make
ClassDecl::getObjCRuntimeName() respect the Clang objc_runtime_name
attribute.

Fixes rdar://problem/25494454.
2016-04-01 23:07:21 -07:00
practicalswift
bbef13a050 [gardening] Fix recently introduced typo: "attribtue" → "attribute"
[gardening] Fix recently introduced typo: "delinated" → "delineated"

[gardening] Fix recently introduced typo: "abstactions" → "abstractions"

[gardening] Fix recently introduced typo: "cannoted" → "cannot"

[gardening] Fix recently introduced typo: "accomodate" → "accommodate"

[gardening] Fix recently introduced typo: "bulding" → "building"

[gardening] Fix recently introduced typo: "abstactions" → "abstractions"

[gardening] Fix recently introduced typo: "intiializers" → "initializers"
2016-03-30 18:20:53 +02:00
Joe Groff
92ed4f1a71 IRGen: Erase ObjC generics before forming metadata references.
The generic parameters to an ObjC class don't exist at runtime, so when forming a metadata reference, lower them away.
2016-03-28 09:50:30 -07:00
Jordan Rose
79720bc0f2 [IRGen] Don't assume Objective-C classes won't be generic.
This showed up as a test failure under swift_test_mode=optimized.
We probably have more of these we should be worrying about.
2016-03-28 09:50:30 -07:00
Ted Kremenek
1e97da25b4 Reverts commit 8a000457b6.
Backing out the metadata change broke Linux.
2016-03-25 22:13:28 -07:00
Ted Kremenek
8a000457b6 Speculatively revert "Only define resilient metadata and VWTs as constant when they don't"
This reverts commit 893d1dc523.

This looks like a likely culprit that broke tests on the iOS Simulator:

 Failing Tests (6):
     Swift :: IRGen/class_resilience.swift
     Swift :: IRGen/concrete_inherits_generic_base.swift
     Swift :: IRGen/enum_resilience.swift
     Swift :: IRGen/foreign_types.sil
     Swift :: IRGen/nested_types.sil
     Swift :: IRGen/struct_resilience.swift
2016-03-25 21:55:30 -07:00
John McCall
9e5ce49765 Only define resilient metadata and VWTs as constant when they don't
need to be modified by the runtime, and only actually store to them
when that would change anything.

Unfortunately, Linux is considerably better than Darwin at shaking
these bugs out because Darwin will leave global data mutable after
resolving relocations in it.
2016-03-25 00:18:14 -07:00
John McCall
3561aa5fe0 Support parent types on foreign type metadata.
This will eventually be required for C++.  It is also, apparently,
required for anonymous structs that are used as the type of a
named field.

Should unblock the Linux Foundation build.
2016-03-24 17:01:28 -07:00
John McCall
0ffb7278bc Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.

Includes a fix since the earlier commit to make enum metadata
writable if they have an unfilled payload size.  This didn't show
up on Darwin because "constant" is currently unenforced there in
global data containing relocations.

This patch requires an associated LLDB change which is being
submitted in parallel.
2016-03-24 15:10:31 -07:00
John McCall
abba7f0c8b Revert "Only use metadata patterns for generic types; perform other"
This reverts commit 41efb3d4d3.
LLDB has too many tendrils into our metadata.
2016-03-23 20:26:43 -07:00
John McCall
41efb3d4d3 Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.
2016-03-23 17:04:04 -07:00
Joe Groff
43326ef1aa Remove dead code. 2016-03-21 13:33:40 -07:00
Slava Pestov
f440decd23 SILGen: Emit default witness tables for all non-@objc protocols
SILGen will now be able to look up the default implementation
corresponding to a requirement while emitting conformances, and
reference the default witness thunk instead of emitting duplicate
thunks for each conforming type.

IRGen continues to only emit resilient defaults if the protocol itself
is resilient; otherwise, it just ignores the default witness table.
2016-03-17 03:57:23 -07:00
Peter Cooper
7ec0e7348f Add more calls to the objc runtime for getting an object’s ISA.
Be more conservative in terms of masking ISAs.  This reduces tight coupling with the objc runtime.  This commit adds the required calls to IRGen and the runtime, and a test case to make sure IRGen is correct.
2016-03-10 15:07:20 -08:00