Commit Graph

75 Commits

Author SHA1 Message Date
Dave Abrahams
94965036d5 [stdlib] Move ObjC Mirrors out of Foundation
These mirrors are the default mirrors that get used for all objective-C
object, including some that aren't defined in Foundation:

  import Dispatch
  println(dispatch_get_global_queue(0,0))

This example isn't fixed yet, because we need to pull all the string
bridging goop out of Foundation and into the core standard library.

Swift SVN r25012
2015-02-05 19:18:33 +00:00
Enrico Granata
1099342fcd Fix an issue with my previous patch, where I didn't correctly add the new Float and Double cases in all code paths; and as a result I could get away with assigning a double value to a supposedly float payload without issue
Swift SVN r24377
2015-01-12 23:33:29 +00:00
Enrico Granata
729b90e087 Split the floating-point QuickLook object in two: Float and Double for respectively single and double precision values
This allows reflection clients a more detailed perspective on what precision values they are inspecting, and is largely meant to support improvements to the way Xcode represents floating point numbers in the playgrounds UI (rdar://19124310)



Swift SVN r24372
2015-01-12 19:54:58 +00:00
John McCall
6a91f7a172 Various improvements to the function-type ABI.
Teach IRGen and the runtime about the extra inhabitants
of function pointers, and take advantage of that in
thin and thick function types.

Also add runtime entrypoints for thin function type
metadata.

Swift SVN r24346
2015-01-10 01:45:37 +00:00
Joe Groff
f229161b9b Runtime: Fix memory management in swift_ClassMirror_quickLookObject.
rdar://problem/18513769. Add tests that exercise all the code paths to ensure we keep everything balanced.

Swift SVN r23773
2014-12-07 20:55:24 +00:00
Joe Groff
ee5adc1f6e Runtime: Provide reflection for metatypes.
Metatypes have no user-visible structure, but can at least summarize as their type names. This gives us reasonable ad-hoc Printable behavior (thought debugPrint is still wrong, since a type name isn't parsable without being .self'ed).

Swift SVN r23745
2014-12-05 22:58:44 +00:00
Joe Groff
1cf1b4172b Runtime: Use full demangled names when reflecting values.
Use the recursive demangled name generation I implemented in _typeName for metatypes in _stdlib_getDemangledType as well, so that we get fully-qualified generic names and other goodness.

Swift SVN r23743
2014-12-05 21:25:50 +00:00
Joe Groff
58945f3186 Reflection: Drill through artificial subclasses.
Fixes a crash when KVO-observed objects were reflect()ed, and the magic mirror tried to peep the artificial subclass's nonexistent nominal type descriptor. rdar://problem/19060227

Swift SVN r23628
2014-12-03 02:00:01 +00:00
Joe Groff
08fe138808 Runtime: Generate a human-understandable name for Any.Type.
Expose this in the stdlib as _typeName(Any.Type) -> String, pending API review.

Swift SVN r23254
2014-11-11 23:38:24 +00:00
Graham Batty
d15c24e25b Changes to runtime library to support non-objc targets
Swift SVN r23122
2014-11-05 23:17:07 +00:00
Joe Groff
0bafa4d05b Restore the module context and generic parameter list to protocol conformance mangling.
We don't need to game the mangling to be easily predictable by conformsToProtocol anymore.

Swift SVN r23089
2014-11-03 21:56:54 +00:00
Joe Groff
90cb504b75 Runtime: Switch swift_conformsToProtocol over to the new implementation.
Swift SVN r23083
2014-11-03 06:12:18 +00:00
Joe Groff
93cb4dd83e Runtime: Remove dead HeapArrayMetadata kind.
Swift SVN r22294
2014-09-26 03:12:21 +00:00
Enrico Granata
4a45129d45 Remove the workaround for the malformed fieldNames field in JITed code. Now that the JIT is doing the right thing again, we can restore full reflection support. Fixes rdar://18007839
Swift SVN r21374
2014-08-21 21:32:48 +00:00
Enrico Granata
7f87bcef46 This patch works around an issue with JIT relocations in LLDB generated modules by avoiding access to the fieldNames pointer of the nominal type descriptor. Fixes rdar://18007819
Swift SVN r21180
2014-08-13 19:25:48 +00:00
John McCall
77ea35ab46 Introduce a flag to mark classes with Swift-native
refcounting and take advantage of it.

Also, set the Swift1 flag in classes we generate.

Also, initialize a global cache of the non-pointer-isa
mask and use that instead of object_getClass, at least
within the runtime.

Also, centralize the runtime on a _swift_getSuperclass
function and make that use a direct access while we
await word from Greg on the desired ABI requirements.

Swift SVN r21077
2014-08-06 21:51:45 +00:00
Dmitri Hrybenko
30749d9f69 stdlib/Reflection: really fix a leak when reflecting a class (turned out to be
in swift_ObjCMirror_count)

rdar://17840810


Swift SVN r20821
2014-07-31 13:11:55 +00:00
Dmitri Hrybenko
9c8d30ea11 stdlib/Reflection: fix over-release that I introduced in r20671 trying to fix a
leak.  The release was valid only for some code paths.

Added some comments explaining ownership and parameter passing conventions.

Fixes rdar://17855302, restores half of the leak in rdar://17840810 (only for
objects that inherit from NSObject).


Swift SVN r20820
2014-07-31 11:49:43 +00:00
John McCall
934527a029 Eliminate all uses of the typeof value witness.
Swift SVN r20734
2014-07-30 04:40:58 +00:00
Dmitri Hrybenko
a0c8140529 Reflection: fix a leak in TupleMirror
rdar://17840810


Swift SVN r20671
2014-07-29 15:08:48 +00:00
Dmitri Hrybenko
09561ae6fa stdlib/Printing: when printing objects without Printable conformances, print
demangled names

rdar://16929868


Swift SVN r20386
2014-07-23 11:01:51 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Enrico Granata
da4044a4b0 I have a theory that the logger is getting malformed strings in some cases because this table of metadatakind to string is incomplete, and as such sometimes garbled data ends up being logged. Even though MagicMirror should only be generated in a few controlled cases, it seems possible that there are more such cases than I initially envisioned - hence the issue. This is my attempt at a fix here
Swift SVN r18986
2014-06-18 22:57:21 +00:00
Enrico Granata
2122984ad9 This adds NSString to the list of quicklookable types in playgrounds
This patch allows people to define a func quickLookObject() that returns an NSString, and have the playgrounds pick that up for the sidebar

Fixes rdar://16730829 (or at least gets us through WWDC)



Swift SVN r18629
2014-05-25 23:16:04 +00:00
Joe Groff
1efc2d9fae Reflection: Fall back to using ObjC metadata to get field offsets in ObjC-derived class mirrors.
Our runtime doesn't fix up class field offset vectors for resilient ObjC base classes, causing the offsets to be wrong if the actual size of the base class differs from its compile-time claimed size. Use the ObjC runtime's ivar records instead if the class has ObjC heritage. We can't do this all the time because the ObjC ivar records aren't yet trustworthy for generic classes, but we don't fully support the mix of ObjC heritage and genericity very well anyway yet. Fixes <rdar://problem/17027510> in the short term.

Swift SVN r18622
2014-05-24 23:14:10 +00:00
Enrico Granata
0134c6d197 Allow user-defined Swift classes to implement our API for QuickLooks, and have the result of that API be picked up by the Mirrors
This is our public API for how quicklooks work in the debugger, and the plan is to have this same API work in playgrounds as well

Fixes rdar://17023157


Swift SVN r18609
2014-05-24 01:00:46 +00:00
Enrico Granata
22329b3ac2 Extend the _OpaqueMirror to produce summaries that at least reflect the broad category of value being reflected
The <opaque> output is clearly useless, and annoying to see scattered around playgrounds

We don't have bandwidth right now to produce detailed useful reflection information, but at least show a basic understanding of data

Fixes part of rdar://17018392



Swift SVN r18607
2014-05-23 23:23:43 +00:00
Joe Groff
8c60c4af1f IRGen/Runtime: Emit distinct type metadata for block types.
Blocks need their own type metadata with value witnesses appropriate to the block representation. Fixes <rdar://problem/16918740> and <rdar://problem/16981126>.

Swift SVN r18508
2014-05-21 20:24:11 +00:00
Dmitri Hrybenko
2cc8fe40d4 stdlib/printing: replace four printing systems with one new one
The old ones were:

- print/println
- printAny
- printf
- Console

The new printing story is just print/println.  Every object can be printed.
You can customize the way it is printed by adopting Printable protocol.  Full
details in comments inside stdlib/core/OutputStream.swift.

Printing is not completely finished yet.  We still have ReplPrintable, which
should be removed, string interpolation still uses String constructors, and
printing objects that don't conform to Printable will result in printing
mangled names.


Swift SVN r18001
2014-05-13 13:07:59 +00:00
Enrico Granata
720478bf96 Add a URL case to QuickLookObject
This is to be used by playgrounds to provide a better sidebar representation of web pages than simply showing the URL text

Part of rdar://16799088



Swift SVN r17710
2014-05-08 19:15:36 +00:00
Enrico Granata
46780871a8 Add a separate .Sprite quickLookObject type for SpriteKit objects
We still want to send out image data for those, but UI consumers need to be able to differentiate - should they so desire - a true image from a software sprite rendered in pictorial form

Part of the fix for rdar://16806238



Swift SVN r17471
2014-05-05 18:17:12 +00:00
John McCall
bafeb84a56 Generate unique type metadata for foreign classes.
Swift SVN r17430
2014-05-05 06:45:42 +00:00
Enrico Granata
88e841ce10 Mis-ordering of cases - thanks Joe!
Swift SVN r17391
2014-05-04 18:05:46 +00:00
Enrico Granata
cb53af1bd1 Add a View tag to the QuickLookObject enum
This tag is meant to trade in image data, but be explicit about the fact that this is a "screenshot" of a UI view rather than a plain ol' picture

Fixes the swift library part of rdar://16796532



Swift SVN r17390
2014-05-04 18:03:13 +00:00
Enrico Granata
4fb2175901 The default Mirror implementation used to have a special case for NSString-typed things, such that they would quicklook as their own string data
However, this broke for Swift subclasses of NSString because the Swift mirror took precedence over the ObjC NSString choice
Notably, it broke for NSContiguousString

This patch fixes that by explicitly making NSString reflectable, so that its subclasses will automagically do the right thing here

Fixes rdar://16758974



Swift SVN r17059
2014-04-30 00:06:54 +00:00
Enrico Granata
39a45d8004 Add a custom Mirror for NSRange, and export a Range(UInt64, UInt64) as the quicklook object for it
This is the last chunk of stdlib work for rdar://16681498


Swift SVN r17040
2014-04-29 19:11:07 +00:00
Enrico Granata
9ab5cea296 Add a new case to the QuickLookObject enum: Logical(Bool)
This is meant to represent to UI consumers the notion of a logical truth value
Previously, we were using a String case to represent such values, but that loses potentially useful information to UI layers

This fixes rdar://16719431



Swift SVN r17037
2014-04-29 16:36:40 +00:00
Joe Groff
5c2bd67459 Runtime: Sync QuickLookObject in the runtime with recent stdlib additions.
Swift SVN r16823
2014-04-25 15:00:08 +00:00
Greg Parker
b691055649 Fix an incorrect use of Swift metadata in an ObjC class. Add assertions to
catch such uses in the future.


Swift SVN r16695
2014-04-23 08:55:02 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Joe Groff
ebe5f4620c Don't include the module in protocol conformance manglings.
The cost of hacks to swift_conformsToProtocol is starting to outweigh any benefit to being principled here. We'll get a linker error now if multiple modules declare a conformance for the same type to the same protocol, but that's arguably a good thing for 1.0 anyway, since we aren't set up to get that right in other ways.

Swift SVN r16554
2014-04-18 23:13:40 +00:00
Joe Groff
e5bb7741f4 #if out function that's unused without objc ivar introspection.
Swift SVN r16533
2014-04-18 17:23:07 +00:00
Joe Groff
a57e955635 Reflection: Disable visiting objc ivars in the default mirror.
We can't do this reliably without crashing, because framework types often lie about their layout and/or leave junk pointers in ivars.

Swift SVN r16491
2014-04-18 03:22:56 +00:00
Dave Zarzycki
211afa943f Runtime: better crash debugging/reporting
Swift SVN r16426
2014-04-16 21:37:16 +00:00
John McCall
862d50ac1c Change the layout of opaque existentials so that
the value buffer comes first.

The motivation for doing this is similar to the
motivation for moving it for class existentials:
it eliminates the need for an offset for the most
common accesses, which is particularly important
for the generic value witnesses.

Also try to hard-code that layout in fewer places,
or at least static_assert the places that have to
do so.

Swift SVN r16279
2014-04-13 07:43:08 +00:00
Joe Groff
d1121a3d86 Reflection: Blacklist NSURL from default mirror functionality.
Its layout information in the ObjC runtime is a complete lie, so we crash if we try to use it to introspect the object. Fixes <rdar://problem/16592777>.

Swift SVN r16228
2014-04-11 21:05:34 +00:00
Joe Groff
f57de31a04 Reflection: Quell some build warnings.
Swift SVN r16172
2014-04-10 22:35:35 +00:00
Joe Groff
3455688cd1 Reflection: Resize our stub Array type.
The new Array is one word, not three. Fixes <rdar://problem/16533371>.

Swift SVN r15993
2014-04-06 01:36:16 +00:00
Joe Groff
18f6e950a6 Reflection: Look through existential containers.
When we reflect an existential container, reflect the contained value as its dynamic type. Implements <rdar://problem/16427022>.

Swift SVN r15952
2014-04-04 20:16:47 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00