Commit Graph

184 Commits

Author SHA1 Message Date
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Hugh Bellamy
137b2ab295 Fix errors and warnings building swift/reflection on Windows with MSVC 2016-12-11 10:00:32 +00:00
Erik Eckstein
5e6c5a70d7 Mangling: Let the demangler handle the new mangling scheme 2016-12-02 15:55:30 -08:00
practicalswift
5bc293cc09 [gardening] Add missing licensing headers. 2016-11-28 21:40:06 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
1c7a50dcc5 Reflection: Fix class layout, again
There were a few problems here with subclasses of Objective-C classes.
Use the InstanceStart field from rodata to correctly lay out instance
variables, and verify the results match with dynamic and static layout.

Better fix for <rdar://problem/27932061>.
2016-11-16 19:31:18 -08:00
Slava Pestov
db79762c3b Reflection: Fix class layout start offset calculations
Fixes <rdar://problem/29115967>.
2016-11-11 03:13:22 -08:00
Slava Pestov
83692bb398 Reflection: Fix bug where presence of a no-payload enum resets field offsets back to zero for subsequent fields
The alignment was set to 0, which messed up the record layout
computations. Add an assert to catch this in the future.

Fixes <rdar://problem/29115967>.
2016-11-10 22:43:15 -08:00
Slava Pestov
5e632f8e86 Reflection: Walk up the superclass chain when resolving associated types
Now that IRGen emits the right metadata, we can make use of it to fix
associated type lookup.

Fixes <rdar://problem/28331935>.
2016-09-24 02:17:46 -07:00
Slava Pestov
154a228a2a Reflection: Gracefully handle missing associated type metadata
Previously we would crash if we couldn't look up an associated
type witness for a concrete type.

Instead, propagate the failure up to type lowering, which returns
nullptr to the caller, just like when other metadata is missing.
2016-09-24 02:17:45 -07:00
Erik Eckstein
c710b04dbf IRGen: Let the stride of a type be at least one, even for zero-sized types like the empty tuple.
This affects the computed stride for fixed-sized types in IRGen as well as the stored stride in value witness tables.
The reason is to let comparisons and difference operations work for pointers to zero-sized types.
(Currently this is achieved by using Builtin.strideof_nonzero in MemoryLayout.stride, but this requires a std::max(1, stride) operation after loading the stride)
2016-09-14 13:24:19 -07:00
Slava Pestov
2e6e2c2b17 Reflection: Fix crash in single-payload enum layout if payload type could not be lowered
Fixes <rdar://problem/27906876>.
2016-08-23 18:30:00 -07:00
Michael Gottesman
06a70d3942 [cmake] Add cmake support for only applying tsan to the swift stdlib/runtime. 2016-08-03 17:53:57 -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
practicalswift
dd93d551df [gardening] Fix recently introduced typos 2016-07-01 19:28:34 +02:00
Slava Pestov
12d9cc2498 Reflection: Add a DEBUG_TYPE_LOWERING #ifdef for diagnosing problems
To avoid crashing tools, we just propagate failure instead of
asserting. This makes debugging more difficult, though. When
this macro is enabled, messages are printed to standard error
to pinpoint the exact reason that type lowering bailed out.
2016-07-01 01:39:21 -07:00
Slava Pestov
95bc009e3e Reflection: Multi-payload enum layout
The approach here is to split this into two cases:

- If all case payloads have a fixed size, spare bits may be
  potentially used to differentiate between cases, and the
  remote reflection library does not have enough information to
  compute the layout itself.

  However, the total size must be fixed, so IRGen just emits a
  builtin type descriptor (which I need to rename to 'fixed type
  descriptor' since these are also used for imported value types,
  and now, certain enums).

- If at least one case has a size that depends on a generic
  parameter or is a resilient type, IRGen does not know the size,
  but this means fancy tricks with spare bits cannot be used either.
  The remote reflection library uses the same approach as the
  runtime, basically taking the maximum of the payload size and
  alignment, and adding a tag byte.

As with single-payload enums, we produce a new kind of
RecordTypeInfo, this time with a field for every enum case.
All cases start at offset zero (but of course this might change,
if for example we put the enum tag before the address point).

Also, just as with single-payload enums, there is no remote
'project case index' operation on ReflectionContext yet.

So the the main benefit from this change is that we don't entirely
give up when doing layout of class instances containing enums;
however, tools still cannot look inside the enum values themselves,
except in the simplest cases involving optionals.

Notably, the remote reflection library finally understands all
of the standard library's collection types -- Array, Character,
Dictionary, Set, and String.
2016-07-01 01:31:25 -07:00
Slava Pestov
48c928938a Reflection: Single-payload enum layout
Attempt to lay out single-payload enums, using knowledge of extra
inhabitants where possible.

- The extra inhabitants of an aggregate are the extra inhabitants of
  the first field. If the first field is empty, there are no extra
  inhabitants, and subsequent fields do not affect anything.

- Function pointers and metatypes have different extra inhabitants
  than Builtin.RawPointer, so have IRGen emit distinct builtin type
  descriptors for those.

- Opaque existentials do not have extra inhabitants.

- Weak references do not have extra inhabitants.

Also, fix IRGen to emit more accurate enum reflection metadata in
these two cases:

- We now record whether enum cases are indirect or not. An indirect
  case is the same as a payload case with Builtin.NativeObject.

- We now record whether a case is empty or not using the same logic
  as the rest of IRGen. Previously, we would incorrectly emit a
  payload type for a case with a payload that is an empty struct,
  for example.

At this point we don't have a way to get the currently inhabited
enum case from a value. However, this is still an improvement because
we can still reflect other fields of aggregates containing enums,
instead of just giving up.

Finally make some methods on TypeCoverter private, and use 'friend'
to allow them to be accessed from other internal classes, making the
public API simpler.
2016-06-30 12:57:14 -06:00
Slava Pestov
0823fb7207 Reflection: Add an unreachable() function instead of doing assert(false && ... 2016-06-30 12:57:13 -06:00
Brian Gesiak
328de9e280 [SR-1738] add_swift_library takes SHARED/STATIC arg
As a first step to allowing the build script to build *only*
static library versions of the stdlib, change `add_swift_library`
such that callers must pass in `SHARED`, `STATIC`, or `OBJECT_LIBRARY`.

Ideally, only these flags would be used to determine whether to
build shared, static, or object libraries, but that is not currently
the case -- `add_swift_library` also checks whether the library
`IS_STDLIB` before performing certain additional actions. This will be
cleaned up in a future commit.
2016-06-16 13:15:58 -04:00
Michael Gottesman
034441a782 [cmake] Rename the variable HOST_LIBRARY => FORCE_BUILD_FOR_HOST_SDK in add_swift_library.
HOST_LIBRARY is supposed to mean "no matter what the defaults say, also build
this library for the host". FORCE_BUILD_FOR_HOST_SDK is a less confusing name.
2016-06-10 14:02:55 -07:00
David Farler
492a26bf40 [SwiftRemoteMirror] Consider ObjCClass field descriptors when converting TypeInfos
@slava_pestov recently folded in @objc classes when building class field
descriptors - we just need to update the switch when considering records
for converting TypeRefs to TypeInfos.

rdar://problem/26594130
2016-06-02 17:39:35 -07:00
Slava Pestov
e2cf23d971 Reflection: Don't emit builtin descriptors for imported classes
Previously we would emit both a builtin descriptor and field
descriptor for imported classes, but we only need the latter.

Untangle some code and fix a crash with imported Objective-C
generics in the process.

Fixes <rdar://problem/26498484>.
2016-05-26 19:32:59 -07:00
Dmitri Gribenko
b31581ca55 CMake: rename an obscure IS_HOST flag to HOST_LIBRARY 2016-05-21 23:36:44 -07:00
David Farler
f3500e4a3c lib/SwiftReflection shouldn't link libswiftCore
Although this is a target library, it does not need to link against
the standard library, because it doesn't have any Swift content in
it. We need to add a separate build flag for having CMake content
because saying a library "IS_STDLIB" isn't correct for this case.

rdar://problem/26399625
2016-05-20 17:28:25 -07:00
David Farler
fe2872fae1 SwiftRemoteMirror: Lower types with imported / Objective-C types
- Lower Objective-C class typerefs as strong references with unknown
reference counting.
- Lower other imported C types as builtin blobs of their known
size, alignment, etc.

In the future, it might be beneficial to track which stored properties
of imported types are pointers, for better conservative scanning of
outgoing pointers to the heap.

rdar://problem/26240258
rdar://problem/26240394
2016-05-12 20:49:32 -07:00
Slava Pestov
710d7ede71 Reflection: Break out SWIFT_RAW_POINTER vs SWIFT_BUILTIN in the C API
Also, use "opaque existential" consistently to refer to non-class
existentials, and clean up some other random bits.
2016-05-12 18:27:35 -07:00
David Farler
9dddc6492b SwiftRemoteMirror: Project error existentials
Error existentials have a kind of special heap layout and can also
be compatible as NSError instances, too.
2016-05-10 12:50:31 -07:00
Slava Pestov
4fccd2f6fc Reflection: Closure context layout
This adds various MetadataReader methods to support closure layout:
- Reading generic arguments from metadata
- Reading parent metadata
- Reading capture descriptor from heap metadata

To a large extent, this is not currently taken advantage of, because
SILGen always wraps address-only captures in SIL box types.

Tests are in the next patch.
2016-05-09 13:40:58 -07:00
Slava Pestov
0dffbcb791 Reflection: Add TypeLowering::hasFixedSize() 2016-05-09 13:40:57 -07:00
Slava Pestov
5cc4ce1760 Reflection: Looking up CaptureDescriptors by remote address
Remote metadata for closure contexts points to a capture descriptor.
We have a local copy of all capture descriptors. Translate the
address by recording the local and remote start address of
reflection metadata.
2016-05-09 13:40:57 -07:00
Slava Pestov
9e9acd2dfe Reflection: Add RecordTypeInfoBuilder class to TypeLowering.h, NFC
Closure context layout uses this class.
2016-05-06 15:13:23 -07:00
practicalswift
68b148cfb1 [gardening] Fix recently introduced typos. 2016-05-06 20:31:38 +02:00
Slava Pestov
c6c6d5859d Reflection: Fixes for deriveSubstitutions() patch
Somehow ninja didn't rebuild everything, so I ended up pushing code
that didn't compile. I did a clean re-build and fixed a minor issue
in the logic, now the test passes.
2016-05-05 22:54:29 -07:00
Slava Pestov
73b1bd8f4e Reflection: Add TypeRef::deriveSubstitutions()
When deriving substitutions from closure contexts, we end up with
a problem where we have an original type and a substituted type,
and the original type is not necessarily a type parameter.
We need to decompose the original and substituted types to derive
the substitutions that produced the substitution.

For example, deriveSubstitutions(Foo<T -> Int>, Foo<String -> Int>)
will give us a substitution of T := Int.
2016-05-05 22:28:48 -07:00
Slava Pestov
a62d414086 Reflection: Add TypeRef::isConcreteAfterSubstitutions()
This is needed for closure context layout.
2016-05-05 22:28:48 -07:00
Slava Pestov
5858756651 Reflection: Correct handling of nested types in TypeRef substitution 2016-05-05 22:28:48 -07:00
Slava Pestov
27b951e1e5 Reflection: Demangling for lowered metatypes
Lowered types appear in capture descriptors.
2016-05-05 13:47:54 -07:00
Slava Pestov
86dae6850c Reflection: Add SILBoxTypeRef, which can come up in capture descriptors 2016-05-02 19:26:12 -07:00
practicalswift
06fe6b0424 Merge pull request #2358 from practicalswift/a-vs-an-fixes
[gardening] Fix "a" vs. "an" issues.
2016-05-02 23:21:15 +02:00
Slava Pestov
efca93e632 Reflection: Add dumping of capture descriptors to swift-reflection-dump
The tests show that there's some round-tripping issue; I will investigate
this next.
2016-05-02 01:16:25 -07:00
practicalswift
d804026b34 [gardening] Fix "a" vs. "an" issues. 2016-05-01 13:29:57 +02:00
Slava Pestov
1d5b9b09ac Reflection: Add instance-specific layout entry point, and do some refactoring
Closure context layout will depend on the instance itself as well
as the isa pointer, because instead of instantiating metadata for
closures that capture generic parameters, we store the substitutions
inside the context itself.

For classes, this entry point just reads the isa pointer, applies
the isa mask and proceeds down the metadata path.

For now, the only the latter is hooked up.
2016-04-29 15:39:49 -07:00
Slava Pestov
acbec3a341 Reflection: Small cleanup, NFC 2016-04-28 23:43:46 -07:00
Slava Pestov
a72773a9b4 Reflection: Use \n instead of std::endl 2016-04-28 22:56:16 -07:00
Slava Pestov
2a44b33dc2 Reflection: Use _ instead of - as word separator in metadata source s-expression output
For consistency with TypeRefs, and AST dumping.

Most Lisps use -, but we're C++ programmers here.
2016-04-28 22:56:15 -07:00
Slava Pestov
e81fca926a Reflection: Use correct starting offset and alignment in class instance layout
Also, add caching for class instance layout.
2016-04-28 22:56:15 -07:00
Slava Pestov
7a9a4dca83 Reflection: Preliminary C API entry points for class instance layout
Tested by manually running swift-reflection-test, no automated
tests yet, but coming soon.
2016-04-27 23:15:08 -07:00
Slava Pestov
95d648779b Reflection: Fix some bugs in swift-reflection-test
- Improper handling of read() returning an incomplete read
- Update SwiftReflectionTest library for new builtin types section

Only tested manually so far; automated tests coming soon.
2016-04-27 18:17:25 -07:00
Slava Pestov
75dffb79c0 Reflection: Fix accidental edit 2016-04-26 00:13:07 -07:00