Commit Graph

562 Commits

Author SHA1 Message Date
Slava Pestov
3ab5b6fa19 IRGen/Runtime: Remove parent field from type metadata
We no longer need this for anything, so remove it from metadata
altogether. This simplifies logic for emitting type metadata and
makes type metadata smaller.

We still pass the parent metadata pointer to type constructors;
removing that is a separate change.
2017-09-25 15:45:17 -07:00
Slava Pestov
5c0c660727 IRGen: Emit nested generic context information in the nominal type descriptor
Once generic type metadata includes arguments from all outer contexts,
we need to know how many arguments there are at each nesting depth in
order to properly reconstruct the type name from metadata.
2017-09-25 15:45:16 -07:00
Saleem Abdulrasool
635bb00d61 runtime: make LLP64 clean
This is a blanket pass replacing use of `__LP64__` with
`__POINTER_WIDTH__ == 64`.  The latter is more expressive and also LLP64
clean.  This change is needed to enable support for Windows x86_64 which
is a LLP64 environment.
2017-09-17 18:41:10 -07:00
Robert Widmann
edb3872c35 [NFC] Remove old forward declarations 2017-09-06 03:23:02 -04:00
Greg Parker
dd38ace506 [runtime] Fix more const cast warnings. (#11725)
* [runtime] Fix more const cast warnings.
2017-09-05 13:13:01 -07:00
John McCall
10689a0e3f Add per-method flags to the v-table in class nominal type descriptors.
For now, just store a kind and whether the method was dynamic.
2017-08-26 01:44:10 -04:00
John McCall
936f8ddddb Use void* as the target pointer type for relative references to
opaque functions.
2017-08-25 20:02:57 -04:00
John McCall
9a228e96e1 Change the structure of emitted protocol and generic-wtable metadata:
- Always include an array of requirement descriptors in the protocol
  descriptor.  For now, this doesn't contain anything except a general
  requirement kind and an optional default implementation, but eventually
  this can be augmented with type / name metadata.  This array is always
  emitted as constant.

- Guarantee the value of the extent fields in a protocol descriptor and
  slightly tweak their meaning.

- Move the private-data field out of line in a generic witness table
  descriptor so that the main descriptor can be emitted as constant.

- Rely on IRGen's notion of the witness-table layout instead of assuming
  that SILWitnessTable and SILDefaultWitnessTable match the actual
  physical layout.

This version of the patch uses a hack in which we assign internal rather
than private linkage to certain symbols in order to work around a Darwin
linker bug.
2017-08-25 01:42:44 -04:00
Slava Pestov
d73712d79b IRGen/Runtime: Initialize generic and resilient class vtables from nominal type descriptor
Previous patches changed the runtime to copy the vtable from the
superclass rather than IRGen emitting it statically for generic
and resilient classes.

However for generic classes we would still copy the vtable entries
for methods defined in the immediate class from the template.

Instead, store them in the nominal type descriptor, where they use
less space since we can use relative pointers, and copy them out of
there.

This will allow us to 'slim down' generic class templates eventually.
2017-08-24 15:42:08 -07:00
Slava Pestov
ed8ced5665 IRGen/Runtime: Use relative pointers in default witness table entries
This to shrink the size of the protocol descriptor, removes a 32-bit
padding field, and reduces the number of relocations.
2017-08-24 04:31:24 -07:00
John McCall
9f8093f376 Create a central x-macro database of value witnesses. NFC. 2017-08-21 20:17:02 -04:00
Slava Pestov
35004ce96a IRGen: Emit vtable offset and size in NominalTypeDescriptor 2017-08-16 15:36:59 -04:00
Slava Pestov
9555a593ec IRGen: Refactor swift_initClassMetadata_UniversalStrategy() to use TypeLayout
Both swift_init{Struct,Class}Metadata_UniversalStrategy() wish to
avoid instantiating type metadata for field types if possible.

The struct version took an array of the more general TypeLayout objects,
whereas the class version was implemented earlier and took an array
of size/alignment pairs.

Since we can emit static TypeLayouts for all fixed-size types,
the class version can use the more general TypeLayout type also.
2017-08-09 01:07:09 -07:00
Arnold Schwaighofer
48e889b51b IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums (#10326)
* IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums

We map nil to the .None case of Optional. Instead use a singleton object.

SR-5148
rdar://32618580
2017-06-17 09:33:41 -07:00
Arnold Schwaighofer
ca63326e1b Delete unused existential value witnesses from the old existential
implementation

And remove the SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS flag.
2017-06-02 14:34:41 -07:00
Slava Pestov
58f2f35313 Runtime: Add superclass constraint to existential type metadata 2017-04-25 01:32:44 -07:00
John McCall
7a4c761426 Merge pull request #8821 from rjmccall/dynamic-enforcement-vol-1
Basic dynamic enforcement of exclusivity
2017-04-18 13:57:54 -04:00
John McCall
2c40b39f26 Move runtime functions for casting into their own header. 2017-04-17 17:16:13 -04:00
Arnold Schwaighofer
1d2e46bbec Runtime: Add support for Builtin.Int512
rdar://31540879
2017-04-17 09:58:42 -07:00
Slava Pestov
a5a40c7fc7 Runtime/IRGen: Preliminary plumbing for subclass existentials 2017-04-13 21:29:57 -07:00
Arnold Schwaighofer
d5cbb0bd62 Runtime changes for the copy-on-write existential implementation
Adds the runtime implementation for copy-on-write existentials. This support is
enabled if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is defined. Focus is on
correctness -- not performance yet.

Don't use allocate/deallocate/projectBuffer witnesses for globals in cow
existential mode.

Use SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS configuration to set the default for
SILOptions.

This includes an IRGen fix to use the right projection in
emitMetatypeOfOpaqueExistential if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is set.

Use unknownRetain instead of native retain in dynamicCastToExistential.
2017-03-15 14:54:55 -07:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Hugh Bellamy
8d40749f6a Misc fixes to the runtime for MSVC compatability with it's public headers 2017-03-02 19:47:24 +07:00
Hugh Bellamy
941392267b Use initializer list instead of copy constructor in ExtraInhabitantsValueWitnessTable constructor 2017-02-25 11:45:26 +07:00
Greg Parker
ae1c984920 New refcount representation (#5282)
New refcount representation and weak variable implementation. See SwiftShims/RefCount.h for details.
2017-02-24 14:19:11 -08:00
Hugh Bellamy
a570f6b87b Merge pull request #7405 from hughbe/visual-studio-bug
Work around Visual Studio bug inferring type of auto
2017-02-18 09:26:40 +07:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
Hugh Bellamy
e9a6cbfeff Fix misc Visual Studio squiggly 2017-02-12 09:30:02 +07:00
Hugh Bellamy
818099ecbe Rename swift_unreachable to swift_runtime_unreachable 2017-01-26 15:31:34 +00:00
Hugh Bellamy
5a59971b95 Move Unreachable.h from include/Basic to include/Runtime 2017-01-26 15:31:33 +00:00
Hugh Bellamy
a5a4880075 Remove extern "C" uses of SWIFT_RT_ENTRY_VISIBILITY 2017-01-22 18:32:17 +00:00
Hugh Bellamy
05a50fd978 Remove extern "C" from uses of SWIFT_RUNTIME_STDLIB_INTERFACE 2017-01-22 18:32:17 +00:00
Hugh Bellamy
63cf2d561e Remove extern "C" from uses of SWIFT_RUNTIME_EXPORT 2017-01-22 18:32:17 +00:00
Hugh Bellamy
42a7ff6caa Fix reinterpret cast warning of unsigned to void* in Metadata.h (#6814) 2017-01-14 12:33:21 -08:00
Hugh Bellamy
9b38b0a9d5 Fix MSVC errors compiling GenMeta.cpp 2017-01-09 22:16:19 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Saleem Abdulrasool
75533d9dac Merge pull request #6385 from hughbe/runtime
Fix building the runtime from Windows
2016-12-21 10:02:22 -08:00
Joe Groff
2e0cb9c0a2 Runtime: getDynamicType can't drill into existentials when producing a concrete metatype.
For a value of an opaque generic type `<T> x: T`, the language currently defines `type(of: x)` and `T.self` as both producing a type `T.Type`, and the result of substituting an existential type by `T == P` gives `P.Protocol`, so the `type(of:)` operation on `x` can only give the concrete protocol metatype when `x` is an existential in this case. The optimizer understood this rule, but the runtime did not, causing SR-3304.
2016-12-19 11:03:52 -08:00
Hugh Bellamy
7b66b579b1 Add various unreachable annotations to the runtime 2016-12-19 15:54:50 +00:00
Greg Parker
361d026080 [runtime] Use memory_order_consume hack on 32-bit arm architectures. (#6259) 2016-12-14 15:42:21 -08:00
Erik Eckstein
9f8b68ae11 Mangling: use macros instead of hard-coded swift symbol names.
This makes it easier to switch between the old and new mangling scheme.
2016-12-02 15:55:30 -08: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
Greg Parker
5817ca7381 [stdlib] Fix assertion failures in SwiftRuntimeTests (aka unittests/runtime). 2016-08-31 18:55:31 -07:00
David Farler
f0609a612b Make a temporary existential when reflecting weak properties
When getting a mirror child that is a class existential, there
may be witness tables for the protocol composition to copy. Don't
just take the address of a class instance pointer from the stack -
make a temporary existential-like before calling into the Mirror
constructor.

This now correctly covers reflecting weak optional class types, and weak
optional class existential types, along with fixing a stack buffer
overflow reported by the Address Sanitizer (thanks, ASan!).

Tests were also updated to check for the validity of the child's data.

rdar://problem/27348445
2016-08-19 15:30:35 -07:00
John McCall
a6e1e87585 Add implicit conversions and casts from T:Hashable <-> AnyHashable.
rdar://27615802
2016-08-04 23:13:27 -07:00
Dmitri Gribenko
4e7cc0d938 SwiftShims: remove C++ code and unprefixed names from RuntimeShims.h 2016-08-01 16:53:11 -07:00
Dmitri Gribenko
53c424409d stdlib: add AnyHashable
Implements SE-0131 "Add AnyHashable to the standard library".
2016-07-26 03:10:52 -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
Roman Levenstein
40b8fd58fe Remove copy constructors and assignment operators from RelativeDirectPointerImpl.
There were places were RelativeDirectPointers were copied using bitwise copies, which is semantically wrong. This patch makes sure it cannot happen anymore.
2016-06-29 17:20:12 -07:00
Saleem Abdulrasool
2f2d448f2f Runtime: add an explicit cast; NFC
This adds an explicit cast of the atomic type to the contained type prior to
comparing it to nullptr.  This is generally unnecessary, however, the Windows
C++ library (msvcprt) from Visual Studio 2014 (WinSDK 10.0.10586.0) has
extensions which makes the conversion ambiguous.  Simply cast the value on all
targets.

In order to reduce the duplication of the type, create a local typedef for the
constant runtime-uniqued metadata pointer type.
2016-06-18 18:19:13 -07:00