Commit Graph

43 Commits

Author SHA1 Message Date
Mike Ash
7d3451316a [Mirror] Handle fields of thin metatypes.
Fields containing metatypes with no possible subtypes are thin i.e. they have no storage. There is only one possible value they can have: the corresponding type. Mirror attempted to copy the nonexistent field value from the nonexistent storage, producing garbage. Instead, special-case thin metatypes and copy the instance type out of the metatype metadata rather than trying to copy it from the field.

rdar://108280543
2024-09-06 10:38:25 -04:00
Tim Kientzle
5251750999 Conditionalize tests to supported OSes only 2024-04-10 15:30:29 -07:00
Tim Kientzle
810792843b Fill in extended existential support for type(of:) and mirror
type(of:) now returns the dynamic type of the contents of
an extended existential (just like it does for a regular existential)

Mirror can now reflect fields of a value stored inside an extended
existential (just like it can with a regular existential).  This
requires type(of:) support, since Mirror internals use that to
determine how to reflect a value.

Resolves rdar://102906195
2024-04-09 17:37:57 -07:00
Anthony Latsis
52ce15ee9d Gardening: Migrate test suite to GH issues: stdlib 2022-09-22 03:21:39 +03:00
Nate Chandler
3439ce77da [Test] Disable stdlib/Mirror.swift for back deploy.
rdar://96520492
2022-07-06 09:12:52 -07:00
Anthony Latsis
f9b76b88f9 Add regression test to resolve #43068 2022-06-28 22:36:14 +03:00
Anthony Latsis
e487acf43b Enable additional checks in test/stdlib/Mirror.swift that used to not compile 2022-06-28 22:36:14 +03:00
Max Desiatov
372ada0e24 test: add handling for Wasm/WASI (#39519)
This change adds support for WASI in stdlib tests. Some tests that expect a crash to happen had to be disabled, since there's currently no way to observe such crash from a WASI host.
2022-01-12 14:24:50 +00:00
Karoy Lorentey
e2cfab4f28 [stdlib][test] Adopt availability macros in tests 2021-10-31 15:00:58 -07:00
Kuba (Brecka) Mracek
8b189d99e4 Turn off SWIFT_ENABLE_REFLECTION on the stdlib_minimal preset (#39030) 2021-09-12 18:54:53 -07:00
Luciano Almeida
c29fbb5528 [test] Adjusting test files where class syntax is used for protocol inheritance 2020-11-29 21:43:50 -03:00
Mishal Shah
272c466e47 Update master to build with Xcode 12 beta 2020-06-22 15:43:20 -07:00
Slava Pestov
5b6a050e80 IRGen: Fix reflection metadata for zero-sized enum cases
If an enum has a payload case with zero size, we treat it as an empty case
for ABI purposes. Unfortunately, this meant that reflection metadata was
incomplete for such cases, with a Mirror reporting that the enum value
had zero children.

Tweak the field type metadata emission slightly to preserve the payload
type for such enum cases.

Fixes <https://bugs.swift.org/browse/SR-12044> / <rdar://problem/58861157>.
2020-02-18 14:16:58 -05:00
tbkka
fdb1926421 [SR-5289] Teach Mirror how to handle unowned/unmanaged references (#28823)
SR-5289: Teach Mirror how to inspect weak, unowned, and unmanaged refs

Correctly reflect weak, unowned, and unmanaged references
to both Swift and Obj-C types (including existential references to
such types) that occur in both Swift class objects and in Swift
structs.

This includes the specific reported case (unowned reference to an
Obj-C object) and several related ones.

Related changes in this PR:

* Tweak internal bitmap used for tracking ownership modifiers
  to reject unsupported combinations.

* Move FieldType into ReflectionMirror.mm
  FieldType is really just an internal implementation detail
	of this one source file, so it does not belong in an ABI header.

* Use TypeReferenceOwnership directly to track field ownership
  This avoids bitwise copying of properties and localizes some
	of the knowledge about reference ownership

* Generate a top-level "copyFieldContents" from ReferenceStorage.def
  Adding new ownership types to ReferenceStorage.def will now
	automatically produce calls to `copy*FieldContents` - failure
	to provide a suitable implementation will fail the build.

* Add `deallocateBoxForExistentialIn` to match `allocateBoxForExistentialIn`

Caveat:  The unit tests are not as strict as I'd like.  Attempting to make them
so ran afoul of otherwise-unrelated bugs in dynamic casting.
2019-12-17 09:42:52 -08:00
Mishal Shah
ca693eeca3 Revert "SR-5289: Teach Mirror how to handle unowned/unmanaged references (#28368)"
This reverts commit 9c638ae60d.
2019-12-16 17:24:30 -08:00
tbkka
9c638ae60d SR-5289: Teach Mirror how to handle unowned/unmanaged references (#28368)
* SR-5289: Support reflecting weak, unowned, and unmanaged refs

This refactors how we handle reference ownership
when reflecting fields of struct and class objects.
There are now explicit paths for each type of reference
and some simple exhaustiveness checks to fail the build
if a new reference type is added in the future without
updating this logic.
2019-12-16 12:26:22 -08:00
Mike Ash
0345186725 [Stdlib] Skip Mirror.swift's Subclass, Fields, and Cases tests on older OSes.
rdar://problem/54754304
2019-08-28 09:57:17 -04:00
Jordan Rose
4b8068d1df [runtime] Handle same-type constraints when resolving generic params
Generic parameters for a context are normally classified as "key",
meaning they have actual metadata provided at runtime, or non-key,
meaning they're derivable from somewhere else. However, a nested
context or constrained extension can take what would be a "key"
parameter in a parent context and make it non-key in a child context.
This messes with the mapping between the (depth, index) representation
of generic parameters and the flat list of generic arguments. Fix this
by (1) consistently substituting out extension contexts with the
contexts of the extended types, and (2) using the most nested context
to decide which parameters are key, instead of the context a parameter
was originally introduced in.

Note that (1) may have problems if/when extensions start introducing
their /own/ generic parameters. For now I tried to be consistent with
what was there.

rdar://problem/52364601
2019-07-08 17:46:14 -07:00
Slava Pestov
61f21a7195 IRGen: Emit field reflection descriptors for types with custom alignment
The code to decide if field descriptors were going to be emitted was
confusing, so I've refactored it a bit.
2019-04-12 01:46:23 -04:00
Saleem Abdulrasool
7ca074bd07 test: port most of the stdlib tests to Windows
This adjusts the standard library test suite to mostly pass on Windows.
The remaining failures are due to various cases:

- memory corruption (`_swift_stdlib_free` in swiftDemangle)
- heap corruption (canGrowUsingRealloc)
- withVAList failure (unresolved)
- unicode handling on the command line
2019-01-15 09:19:06 -08:00
Doug Gregor
d73a2e0d39 [Runtime] Properly form generic arguments for metadata-to-demangle-tree.
When mapping from type metadata to a demangle tree, fill in the complete
set of generic arguments. Most of the effort here is in dealing with
extensions that involve same-type constraints on a generic parameter, e.g.,

  extension Array where String == Element { }
  extension Dictionary where Key == Value { }

In such cases, the metadata won’t contain generic arguments for every
generic parameter. Rather, the generic arguments for non-key generic
parameters will need to be computed based on the same-type requirements
of the context. Do so, and eliminate the old hacks that put the generic
arguments on the innermost type. We don’t need them any more.

Part of rdar://problem/37170296.
2018-09-25 23:10:08 -07:00
Doug Gregor
3ea48770fe [Runtime] Handle non-key arguments when substituting from metadata.
Reimplement SubstGenericParametersFromMetadata to cope with non-key
generic parameters, which are counted when referring to generic parameters
from metadata but do not have corresponding generic arguments.
2018-09-22 23:32:49 -07:00
Karoy Lorentey
b0471b575e [test] Update Mirror tests for new Set/Dictionary internals 2018-08-16 20:05:32 +01:00
Arnold Schwaighofer
2d8a1dbbfe Codesign test/stdlib 2018-08-10 06:58:40 -07:00
Doug Gregor
d755b38ee5 [Runtime] Teach BridgeObjectBox::retain() not to drop the "not native" bit.
The "not native" bit in a BridgeObject is important, because it tells
us when we need to go through the Objective-C -retain method
vs. swift_retain. Losing the bit means that swift_retain() will stomp
on some memory within an Objective-C object, thinking its the inline
reference count.

Co-debugged with Arnold, who then found where this bit was getting dropped.
Fixes rdar://problem/39629937.
2018-04-23 14:04:22 -07:00
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05:00
Slava Pestov
c86d797c85 stdlib: Move Mirrors tests from Runtime.swift.gyb to Mirror.swift 2018-04-20 21:55:45 -07:00
Slava Pestov
902c0d3586 Runtime: Handle symbolic references inside other mangling nodes
Previously we could only handle symbolic references at the
top level, but this is insufficient; for example, you can
have a nested type X.Y where X is defined in the current
translation unit and Y is defined in an extension of X in
a different translation unit. In this case, X.Y mangles as
a tree where the child contains a symbolic reference to X.

Handle this by adding a new form of Demangle::mangleNode()
which takes a callback for resolving symbolic references.

Fixes <rdar://problem/39613190>.
2018-04-20 21:55:45 -07:00
Joe Groff
b51d43377e Runtime: Properly handle demangling nested generic typerefs with symbolic manglings.
The demangling tree for a symbolic reference doesn't indicate the generic context depth of the referenced type, so we have to form the type metadata from whole cloth without incrementally building up nested types as we do for concrete mangled types. Notice when DecodedMetadataBuilder is passed a context descriptor ref without a parent and directly form the entire type in this case. Fixes rdar://problem/38891999.
2018-04-05 16:23:16 -07:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Ben Cohen
dcab9493ae Removed some warnings (#12753) 2017-11-30 15:12:56 -08:00
Joe Shajrawi
66d0df6bae Revert "Temporary disable failing armv7 tests"
This reverts commit 78e5e25215.
2017-08-15 13:43:57 -07:00
Joe Shajrawi
78e5e25215 Temporary disable failing armv7 tests 2017-08-08 15:22:14 -07:00
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Greg Parker
d7c5b31f32 Revert "[test] Temporarily disable test stdlib/Mirror.swift on armv7s."
This reverts commit 9681fbc59d.

This was a workaround for an LLVM bug that is now fixed.
2017-04-25 15:49:51 -07:00
Erik Eckstein
789646a15b Demangling: Make demangled names more readable and further reduce the size of the simplified demangled names
The goal here is to make the short demangling as short and readable as possible, also at the cost of omitting some information.
The assumption is that whenever the short demangling is displayed, there is a way for the user to also get the full demangled name if needed.

*) omit <where ...> because it does not give useful information anyway

Deserializer.deserialize<A where ...> () throws -> [A]
--> Deserializer.deserialize<A> () throws -> [A]

*) for multiple specialized functions only emit a single “specialized”

specialized specialized Constructible.create(A.Element) -> Constructible<A>
--> specialized Constructible.create(A.Element) -> Constructible<A>

*) Don’t print function argument types:

foo(Int, Double, named: Int)
--> foo(_:_:named:)

This is a trade-off, because it can lead to ambiguity if there are overloads with different types.

*) make contexts of closures, local functions, etc. more readable by using “<a> in <b>” syntax
This is also done for the full and not only for the simplified demangling.

Renderer.(renderInlines([Inline]) -> String).(closure #1)
--> closure #1 in Renderer.renderInlines

*) change spacing, so that it matches our coding style:

foo <A> (x : A)
--> foo<A>(x: A)
2017-04-13 08:43:28 -07:00
Greg Parker
9681fbc59d [test] Temporarily disable test stdlib/Mirror.swift on armv7s. 2017-02-02 16:14:46 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +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
Doug Gregor
fcacd089d6 [Mirrors] Use tuple labels when forming a mirror for a tuple type.
Fixes rdar://problem/22191852.
2016-09-21 09:00:22 -07:00
Dmitri Gribenko
c9041beea3 Migrate callsites from 'expectNotEmpty()' to 'expectNotNil()' 2016-09-10 20:05:43 -07:00
Dmitri Gribenko
243a35cd65 Migrate callsites from 'expectEmpty()' to 'expectNil()' 2016-09-10 20:05:42 -07:00
Max Moiseev
9fc37efee4 [test] renaming test/1_stdlib to just test/stdlib 2016-09-01 16:51:43 -07:00