Commit Graph

26 Commits

Author SHA1 Message Date
Joe Groff
439d5d6e41 Runtime: swift_getExistentialTypeMetadata should trust the compiler's ordering of protocols in compositions.
The compiler pre-canonicalizes protocol composition types by minimizing constraints and sorting the remaining protocols by module + name, which ought to be globally stable within a program (assuming there aren't multiple modules with the same name, in which case we'll have bigger problems…). The compiler also statically lays out existential types according to its conception of the canonical composition ordering, so the runtime's own attempts to form a stable ordering lead to layout inconsistencies between runtime and compile-time layout, leading to crashes like SR-4477.
2017-05-09 13:32:02 -07:00
Jordan Rose
c8d3506e55 Revert "[Mangling] Uniformly use "So" for imported decls." (#9233)
This reverts commit 25985cb764. For now,
we're trying to avoid spurious non-structural changes to the mangling,
so that the /old/ mangling doesn't appear to change. That doesn't mean
no changes at all, but we can save this one for later.
2017-05-03 16:13:29 -07:00
Slava Pestov
7e6fcc83f2 Runtime: Fix _swift_buildDemanglingForMetadata() for explicit AnyObject 2017-05-01 17:32:53 -07:00
Slava Pestov
e032d916f9 Runtime: Update _swift_buildDemanglingForMetadata() for subclass existentials 2017-04-27 20:46:36 -07:00
Jordan Rose
25985cb764 [Mangling] Uniformly use "So" for imported decls.
...and repurpose "SC" for (C)lang-importer-synthesized decls, instead
of just decls that are C-like instead of ObjC-like. (See next commits.)
2017-04-24 09:57:30 -07:00
Erik Eckstein
e427ded6c9 Mangling: refactoring: clean up tuple nodes
Replace VariadicTuple and NonVariadicTuple with a single Tuple node.
The variadic property is now part of the tuple element and not of the whole tuple.
2017-03-25 19:07:52 -07:00
Erik Eckstein
b398098dcb libraries: instead of including all demangler sources into a single C++ source file, list them in the cmake file 2017-03-09 19:56:40 -08: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
Erik Eckstein
002beb8e4f runtime: don’t use the old demangler for demangling ObjC class+protocol names.
Instead use  the new Demangler:: demangleObjCTypeName function
2017-03-09 13:05:15 -08:00
Erik Eckstein
7d7dc5aaac Demangler: Use a bump-pointer allocator for node allocation.
This makes the demangler about 10 times faster.
It also changes the lifetimes of nodes. Previously nodes were reference-counted.
Now the returned demangle  node-tree is owned by the Demangler class and it’s lifetime ends with the lifetime of the Demangler.

Therefore the old (and already deprecated) global functions demangleSymbolAsNode and demangleTypeAsNode are no longer available.

Another change is that the demangling for reflection now only supports the new mangling (which should be no problem because
we are generating only new mangled names for reflection).
2017-02-24 19:04:13 -08:00
Erik Eckstein
2d127e4192 Reinstate ”Use the new mangling for reflection."
It also uses the new mangling for type names in meta-data (except for top-level non-generic classes).
lldb has now support for new mangled metadata type names.

This reinstates commit 21ba292943.
2017-02-15 09:47:22 -08:00
Erik Eckstein
254f36aba5 Revert "Use the new mangling for reflection."
This needs some changes in lldb.
Disabled for now until lldb supports the new mangling.

This reverts commit 21ba292943.
2017-02-08 09:01:51 -08:00
Erik Eckstein
21ba292943 Use the new mangling for reflection.
For this we are linking the new re-mangler instead of the old one into the swift runtime library.
Also we are linking the new de-mangling into the swift runtime library.

It also switches to the new mangling for class names of generic swift classes in the metadata.
Note that for non-generic class we still have to use the old mangling, because the ObjC runtime in the OS depends on it (it de-mangles the class names).
But names of generic classes are not handled by the ObjC runtime anyway, so there should be no problem to change the mangling for those.
The reason for this change is that it avoids linking the old re-mangler into the runtime library.
2017-02-07 08:36:21 -08:00
Joe Groff
ecfa78a3cc Runtime: Look through artificial ObjC subclasses when building demangle trees for classes.
Fixes rdar://problem/29962114, a regression in presenting the stringified names of ObjC classes that have been dynamically subclassed by KVO.
2017-01-11 20:12:16 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
Slava Pestov
b3bc749d35 stdlib: Linux build fix 2016-11-18 01:13:54 -08:00
Slava Pestov
4e4d281aa7 stdlib: Rework swift_typeName() to use _swift_buildDemanglingForMetadata()
Previously we had two separate mechanisms to turn a metatype
into a string. The swift_typeName() function was used to print
the metatype in a human-readable fashion, whereas the
_swift_buildDemanglingForMetadata() was used when naming
generated generic Objective-C classes.

Unify them, since what swift_typeName() does is redundant;
instead of going directly from the metatype to a human-readable
string, we can get the mangling, and print that using the
demangler.

This fixes some issues with unnecessary parenthesis when
printing function types, and also allows Objective-C classes
to be instantiated with nested generic types as parameters.
2016-11-18 00:39:14 -08:00
John McCall
17d72f558b Simplify and optimize the structural type metadata caches to use ConcurrentMap directly.
Previously, these were all using MetadataCache.  MetadataCache is a
more heavyweight structure which acquires a lock before building the
metadata.  This is appropriate if building the metadata is very
expensive or might have semantic side-effects which cannot be rolled
back.  It's also useful when there's a risk of re-entrance, since it
can diagnose such things instead of simply dead-locking or infinitely
recursing.  However, it's necessary for structural cases like tuple
and function types, and instead we can just use ConcurrentMap, which
does a compare-and-swap to publish the constructed metadata and
potentially destroys it if another thread successfully won the race.

This is an optimization which we could not previously attempt.

As part of this, fix tuple metadata uniquing to consider the label
string correctly.  This exposes a bug where the runtime demangling
of tuple metadata nodes doesn't preserve labels; fix this as well.
2016-08-31 18:53:54 -07:00
Greg Parker
e0656515b9 Revert "Metadata cache optimizations" 2016-08-29 19:03:40 -07:00
John McCall
b7bd752946 Simplify and optimize the structural type metadata caches to use ConcurrentMap directly.
Previously, these were all using MetadataCache.  MetadataCache is a
more heavyweight structure which acquires a lock before building the
metadata.  This is appropriate if building the metadata is very
expensive or might have semantic side-effects which cannot be rolled
back.  It's also useful when there's a risk of re-entrance, since it
can diagnose such things instead of simply dead-locking or infinitely
recursing.  However, it's necessary for structural cases like tuple
and function types, and instead we can just use ConcurrentMap, which
does a compare-and-swap to publish the constructed metadata and
potentially destroys it if another thread successfully won the race.

This is an optimization which we could not previously attempt.

As part of this, fix tuple metadata uniquing to consider the label
string correctly.  This exposes a bug where the runtime demangling
of tuple metadata nodes doesn't preserve labels; fix this as well.
2016-08-25 22:27:17 -07:00
Luke Howard
7b1ecbe794 [SR-558] Only build _swift_buildDemanglingForMetadata() for ObjC
_swift_buildDemanglingForMetadata() is being built for the non-ObjC interop
case as a result of a change introduced in an earlier version of the patch for
SR-381 that was not correctly backed out.
2016-01-15 19:50:34 -08:00
Luke Howard
70c5755adb [SR-381]: runtime resolution of type metadata from a name
replace ProtocolConformanceTypeKind with TypeMetadataRecordKind

metadata reference does not need to be indirectable

more efficient check for protocol conformances

remove swift_getMangledTypeName(), not needed yet

kill off Remangle.cpp for non-ObjC builds

cleanup

cleanup

cleanup comments
2016-01-15 17:48:42 +11: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
Dmitri Hrybenko
350248dae5 Reorganize the directory structure under 'stdlib'
The standard library has grown significantly, and we need a new
directory structure that clearly reflects the role of the APIs, and
allows future growth.

See stdlib/{public,internal,private}/README.txt for more information.

Swift SVN r25876
2015-03-09 05:26:05 +00:00