Commit Graph

140 Commits

Author SHA1 Message Date
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
e3c2c863d1 stdlib: define WIN32_LEAN_AND_MEAN and NOMINMAX
`WIN32_LEAN_AND_MEAN` prevents "rarely-used" headers from being pulled in.  This
significantly reduced preprocessor pressure, speeding up compile.  It also
reduces the amount of cruft pulled in by the Windows.h.

`NOMINMAX` ensures that the `min` and `max` macros are not defined.  These
macros collide with the use of `min` and `max` from C++ in certain cases: e.g.
`std::limits<T>`.
2016-06-16 07:34:17 -07:00
Han Sangjin
e6ecc9a3ec Modified for some reviews 2016-06-10 06:26:47 +09:00
Han Sangjin
198441bee9 stdlib/msvc: Runtime with MSVC library
This patch is for libswiftCore.lib, linking with the library set of Visual Studio 2015. Clang with the option -fms-extension is used to build.
2016-06-04 05:16:41 +09:00
Brian Gesiak
fd641cdbca Merge pull request #2363 from compnerd/unused-function
stdlib: remove an unused-function
2016-05-03 09:51:57 -07:00
John McCall
51feb0095e Fix race condition in MetadataAllocator. 2016-05-02 16:10:57 -07:00
Saleem Abdulrasool
a35843c49a stdlib: remove an unused-function
This function is only used in the ObjC interop case.  Control it via the
preprocesor.
2016-05-01 18:52:11 -07:00
Dmitri Gribenko
82509cbd74 Merge pull request #1731 from shawnce/SR-946
SR-946 - Unify mutexes in the Swift runtime
2016-03-29 08:56:39 -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
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
Shawn Erickson
3292124f87 [runtime] - switched most runtime code to use swift::Mutex and swift::Condition (see SR-946) 2016-03-20 22:56:48 -07:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
David Farler
cd65a8e0b0 Template metadata structures
- Add RuntimeTarget template This will allow for converting between
  metadata structures for native host and remote target architectures.

- Create InProcess and External templates for stored pointers

Add a few more types to abstract pointer access in the runtime
structures but keep native in-process pointer access the same as that
with a plain old pointer type.

There is now a notion of a "stored pointer", which is just the raw value
of the pointer, and the actual pointer type, which is used for loads.
Decoupling these allows us to fork the behavior when looking at metadata
in an external process, but keep things the same for the in-process
case.

There are two basic "runtime targets" that you can use to work with
metadata:

InProcess: Defines the pointer to be trivially a T* and stored as a
uintptr_t. A Metadata * is exactly as it was before, but defined via
AbstractMetadata<InProcess>.

External: A template that requires a target to specify its pointer size.

ExternalPointer: An opaque pointer in another address space that can't
(and shouldn't) be indirected with operator* or operator->.  The memory
reader will fetch the data explicitly.
2016-03-02 21:25:04 -08:00
swiftix
2573782c8b Merge pull request #1357 from swiftix/wip-runtime-calling-convention
Prepare the ground for using a new calling convention for functions from the runtime library
2016-03-01 16:22:37 -08:00
Max Moiseev
488b464f10 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-25 12:21:56 -08:00
John McCall
3ce1ba3e65 Only store the minimal requirements in generic metadata, where
"minimal" is defined as the set of requirements that would be
passed to a function with the type's generic signature that
takes the thick metadata of the parent type as its only argument.
2016-02-25 10:33:33 -08:00
Roman Levenstein
99fd8b6080 Rename some macros based on the PR review comments.
- use  the SWIFT prefix for all macros
- make names of some macros shorter
2016-02-25 05:31:00 -08:00
Roman Levenstein
de3b850ce8 Use more descriptive names for calling conventions.
Rename RuntimeCC into DefaultCC
Rename RuntimeCC1 into RegisterPreservingCC
Remove RuntimeCC0 because it was identical to DefaultCC.
2016-02-25 05:31:00 -08:00
Roman Levenstein
68b6181642 Annotate runtime functions using the newly introduced annotations from runtime/Config.h.
This makes sure that runtime functions use proper calling conventions, get the required visibility, etc.

We annotate the most popular runtime functions in terms of how often they are invoked from Swift code.
- Almost all variants of retain/release functions are annotated to use the new calling convention.
- Some popular non-reference counting functions like swift_getGenericMetadata or swift_dynamicCast are annotated as well.

The set of runtime functions annotated to use the new calling convention should exactly match the definitions in RuntimeFunctions.def!
2016-02-25 05:30:59 -08:00
Max Moiseev
0b759a409c Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-23 14:26:14 -08:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Joe Groff
32872cb74a IRGen/Runtime: Relative-reference the nominal type descriptor and parent type from metadata.
Save a couple relocations per concrete value type, leaving only the value witness table as an absolute symbol.
2016-02-09 15:17:03 -08:00
Joe Groff
f7291b21ec Runtime: Build with -fvisibility=hidden.
...and explicitly mark symbols we export, either for use by executables or for runtime-stdlib interaction. Until the stdlib supports resilience we have to allow programs to link to these SPI symbols.
2016-02-08 08:06:02 -08:00
Slava Pestov
3624b1fc6b Runtime: Support for resiliently adding protocol requirements with default implementations
This is the first patch in a series that will allow new protocol
requirements to be added resiliently, with the runtime filling in
default implementations in witness tables.

First, this adds a new flag to the protocol descriptor indicating
that the protocol is resilient. In this case, there are two
additional fields, MinimumWitnessTableSizeInWords and
DefaultWitnessTableSizeInWords, followed by tail-allocated
default witnesses.

The swift_getGenericWitnessTable() entry point now fills in the
default witnesses from the protocol if the given witness table
template is smaller than the expected witness table size.

This also changes the layout of instantiated witness tables to move
the address point to the end of private data. Previously the private
data came after the requirements, but this meant that adding new
requirements would require sliding the private data at runtime and
accessing it indirectly. It is much simpler to access it from
negative offsets instead.

I updated IRGen to emit the new metadata, but currently all protocols
are flagged as not resilient, and default witnesses are not emitted;
this will come in a subsequent patch once some more plumbing is
in place.

To avoid generating GOT entries for references to protocols defined
in the current module, I had to add some hacks to the existing hack
for this. I'll hopefully clean this up in a principled manner later.
2016-02-04 17:34:55 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Harlan Haskins
b55d8d9c3c [Runtime] Add backtrace reporting on fatalError in debug builds 2016-01-29 13:42:06 -08:00
Slava Pestov
19fe31fde9 IRGen: Emit and use accessors for generic type metadata
Instead of directly emitting calls to swift_getGenericMetadata*() and
referencing metadata templates, call a metadata accessor function
corresponding to the UnboundGenericType of the NominalTypeDecl.

The body of this accessor forwards arguments to a runtime metadata
instantiation function, together with the template.

Also, move some code around, so that metadata accesses which are
only done as part of the body of a metadata accessor function are
handled separately in emitTypeMetadataAccessFunction().

Apart from protocol conformances, this means metadata templates are
no longer referenced from outside the module where they were defined.
2016-01-26 16:00:54 -08:00
Joe Groff
638e4b0984 IRGen/Runtime: Use relative addresses in nominal type descriptors.
Decrease the size of nominal type descriptors and make them true-const by relative-addressing the other metadata they need to reference, which should all be included in the same image as the descriptor itself. Relative-referencing string constants exposes a bug in the Apple linker, which crashes when resolving relative relocations to coalesceable symbols (rdar://problem/22674524); work around this for now by revoking the `unnamed_addr`-ness of string constants that we take relative references to. (I haven't tested whether GNU ld or gold also have this problem on Linux; it may be possible to conditionalize the workaround to only apply to Darwin targets for now.)
2016-01-20 14:41:53 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
John McCall
8f30faa4c1 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.

This speculatively re-applies 7576a91009,
i.e. reverts commit 11ab3d537f.
We have not been able to duplicate the build failure in
independent testing; it might have been spurious or unrelated.
2015-12-29 12:14:40 -08:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
Dmitri Gribenko
11ab3d537f Revert "Include access functions for the metadata and witness tables"
This reverts commit 7576a91009.
It broke the testsuite for swift-corelibs-foundation.
2015-12-25 19:17:50 +02:00
John McCall
7576a91009 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.

This reverts commit 6528ec2887, i.e.
it reapplies b1e3120a28, with a fix
to unbreak release builds.
2015-12-24 20:21:17 -08:00
Slava Pestov
ed8ca25fb7 Runtime: Clean up logic for setting Objective-C name of generic classes
We're not currently doing it, but we will soon be able to use
swift_initializeSuperclass() for class layouts which are not
dependent on generic parameters. In this case, we still need
to set the Objective-C class name.

On the other hand, if we're doing resilient layout for a
non-generic class, we don't need to set the Objective-C class
name.

NFC since this isn't hooked up completely yet.
2015-12-24 02:11:15 -08:00
Sean Callanan
6528ec2887 Revert "Include access functions for the metadata and witness tables"
This reverts commit b1e3120a28.

Reverting because this patch uses WitnessTableBuilder::PI in NDEBUG code.
That field only exists when NDEBUG is not defined, but now NextCacheIndex, a
field that exists regardless, is being updated based on information from PI.

This problem means that Release builds do not work.
2015-12-23 15:42:10 -08:00
Joe Groff
1092704f78 Remove unused static function. 2015-12-23 13:34:47 -08:00
Joe Groff
8edde2c503 Runtime: Push swift_demangleSimpleClass into XCTest overlay.
The only place it's used.
2015-12-23 11:19:42 -08:00
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -08:00
John McCall
b1e3120a28 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.
2015-12-23 00:37:24 -08:00
Slava Pestov
e0451c8f70 IRGen: Redo concrete subclasses of generic classes
Now, such classes will emit a metadata pattern and use the
generic metadata instantiation logic.

This was all wired up to handle the case of no generic
parameters previously, to support resilient struct layout
in the runtime.

The swift_initializeSuperclass() entry point still exists,
providing a fast path for when there's no field layout to
do, which is currently always true if we have a concrete
class.

This entry point no longer needs the global lock, since
now we get a per-class lock from the metadata cache.
Also, previously we would call the superclass accessor
function on every access of class metadata for a concrete
subclass of a generic class. Now that we re-use the
existing metadata cache logic, this extra call only occurs
during initialization.

Both swift_initializeSuperclass() and
swift_initClassMetadata_UniversalStrategy() used to take
the superclass as a parameter, but this isn't really
necessary, since it was loaded out of the class metadata
immediately prior to the call by the caller. Removing
this parameter makes the ABI a little simpler.

Once class layout supports resilient types, we will also
use swift_initClassMetadata_UniversalStrategy() to lay
out classes with resilient types as fields.

Singleton metadata caches will still allocate a copy of
the template, which is a slight performance regression
from the previous implementation of concrete subclasses
of generic classes. This will be optimized soon.

Right now, the template can always be modified in place;
in the future, it will be possible to modify in place as
long as the superclass is fixed-layout; a resilient superclass
might add or remove fields, thus we cannot leave room for
it in the metadata of the subclass, and will need to grow
the metadata and slide field offsets at runtime using a
new entry point.

Also, the representation of the cache itself could be
optimized to handle the singleton case, since all we
really need here is a lock without any kind of mapping
table.
2015-12-22 15:30:17 -08:00
Max Moiseev
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
Slava Pestov
c35d9bd092 IRGen: Simplify generated code for generic class metadata instantiation
Move the following from IRGen to runtime:

- Copying generic parameters from superclass to subclass
- Copying field offsets from superclass to subclass
- Initializing the Objective-C runtime name of the subclass

This eliminates some duplication between the generic subclass and
concrete subclass of a generic class cases.

Also this should reduce generated code size and have no impact on
performance (the instantiation logic only runs once per substituted
type).
2015-12-22 02:09:03 -08:00
Slava Pestov
1368db7872 IRGen: Fix layout of concrete subclasses of generic subclasses of imported Objective-C classes
class B<T> : NSFoo {}
class A : B<Int> {}

IRGen computes the ivar layout starting from offset zero, since
the size of the 'NSFoo' is unknown and we rely on the Objective-C
runtime to slide the ivar offsets.

The instantiated metadata for B<Int> would contain a field offset
vector with the correct offsets, because of how
swift_initClassMetadata_UniversalStrategy() works.

However, A's metadata is emitted statically, and this includes a
copy of the field offset vector from the superclass. A's metadata
was initialized by swift_initializeSuperclass(), which did not
copy the field offset vector over from A<Int>. And since the
Objective-C runtime only slides the immediate ivars of a class,
the field offsets corresponding to A<Int>'s fields in B's type
metadata were never slid, resulting in problems when an instance
of B was passed to a function operating on an A<T> generically.

Fixes <rdar://problem/23200051>.
2015-12-21 16:23:39 -08:00
Joe Groff
fd457fb343 Revert "IRGen/Runtime: Use relative addresses in nominal type descriptors."
This reverts commit fbb832665a. It causes LLVM to complain with
"Cannot represent a subtraction with a weak symbol" when targeting Linux.
2015-12-11 15:41:11 -08:00