Commit Graph

112 Commits

Author SHA1 Message Date
Augusto Noronha
e2c8b761cd [NFC][RemoteInspection] Add an opaque AddressSpace field to RemoteAddress
Add an extra opaque field to AddressSpace, which can be used by clients
of RemoteInspection to distinguish between different address spaces.

LLDB employs an optimization where it reads memory from files instead of
the running process whenever it can to speed up memory reads (these can
be slow when debugging something over a network). To do this, it needs
to keep track whether an address originated from a process or a file. It
currently distinguishes addresses by setting an unused high bit on the
address, but because of pointer authentication this is not a reliable
solution. In order to keep this optimization working, this patch adds an
extra opaque AddressSpace field to RemoteAddress, which LLDB can use on
its own implementation of MemoryReader to distinguish between addresses.

This patch is NFC for the other RemoteInspection clients, as it adds
extra information to RemoteAddress, which is entirely optional and if
unused should not change the behavior of the library.

Although this patch is quite big the changes are largely mechanical,
replacing threading StoredPointer with RemoteAddress.

rdar://148361743
(cherry picked from commit 58df5534d2)
(cherry picked from commit 8f3862b5e7)
2025-07-11 16:36:40 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Slava Pestov
4855621b0a ASTDemangler: Pass down a generic signature so that we can reconstruct pack generic parameters 2023-02-21 15:33:19 -05:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Adrian Prantl
fede775269 Make Objective-C interoperability configurable in the runtime
In order to be able to debug, for example, a Linux process from a macOS host, we
need to be able to initialize a ReflectionContext without Objective-C
interoperability. This patch turns ObjCInterOp into another template trait, so
it's possible to instantiate a non-ObjC MetadataReader on a system built with
ObjC-interop (but not vice versa).

This patch changes the class hierarchy to

                          TargetMetadata<Runtime>
                                    |
                          TargetHeapMetadata<Runtime>
                                    |
                          TargetAnyClassMetadata<Runtime>
                                   /                \
                                  /               TargetAnyClassMetadataObjCInterop<Runtime>
                                 /                              \
TargetClassMetadata<Runtime, TargetAnyClassMetadata<Runtime>>    \
                                                                  \
                    TargetClassMetadata<Runtime, TargetAnyClassMetadataObjCInterop<Runtime>>

TargetAnyClassMetadataObjCInterop inherits from TargetAnyClassMetadata because
most of the implementation is the same. This choice makes TargetClassMetadata a
bit tricky. In this patch I went with templating the parent class.

rdar://87179578
2022-01-20 18:28:18 -08:00
Mike Ash
fd6922f92d Add error reporting when looking up types by demangled name. 2020-08-28 14:43:51 -04:00
David Ungar
9dcd2b52b2 Allocate LLVMContext in IRGenModule. 2020-04-16 11:57:44 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Robert Widmann
bd57f14661 [NFC] Push const IRGenOptions and SILOptions everywhere 2020-01-13 22:01:41 -08:00
Joe Groff
40e40103a8 Merge pull request #27418 from jckarter/reflection-symbolic-absolute-pointer
MetadataReader: Add an API for reading absolute pointers.
2019-09-30 08:48:32 -07:00
Joe Groff
4012a207c8 MetadataReader: Add an API for reading absolute pointers.
Pointer data in some remote reflection targets may required relocation, or may not be
fully resolvable, such as when we're dumping info from a single image on disk that
references other dynamic libraries. Add a `RemoteAbsolutePointer` type that can hold a
symbol, offset, or combination of both, and add APIs to `MemoryReader` and `MetadataReader`
for reading pointers that can get unresolved relocation info from an image, or apply
relocations to pointer information. MetadataReader can use the symbol name information to
fill in demanglings of symbolic-reference-bearing mangled names by using the information
from the symbol name to fill in the name even though the context descriptors are not
available.

For now, this is NFC (MemoryReader::resolvePointer just forwards the pointer data), but
lays the groundwork for implementation of relocation in ObjectMemoryReader.
2019-09-28 16:53:34 -07:00
Jordan Rose
8ff1dac381 [AST] Break some header dependencies for faster rebuilds (#27374)
DiagnosticEngine.h no longer depends on Attr.h.
Expr.h no longer depends on TypeRepr.h.

No functionality change.
2019-09-26 09:17:10 -07:00
Slava Pestov
01e65e18c4 SIL: Share TypeConverter between SILModules in batch mode 2019-09-06 21:50:15 -04:00
Joe Groff
fc8be62895 RemoteAST: Add a request to get the underlying type from an opaque type descriptor. 2019-05-01 15:42:57 -07:00
Adrian Prantl
0b8fc3d405 Remove Resilience workarounds and describe fixed-size global resilient
variables in DWARF.

rdar://problem/48409386
2019-03-27 10:51:16 -07:00
Slava Pestov
efa0b36ec8 RemoteAST: More concision 2019-03-04 20:33:30 -05:00
Slava Pestov
905a6def79 RemoteAST: Clean up use of std::pair and std::tuple for opened existentials with named structs 2019-02-12 15:18:03 -05:00
Slava Pestov
56a74c4cd3 RemoteAST: Add new entry point to unwrap an Error existential container
The getDynamicTypeAndAddressForExistential() function takes the
address of an existential value; so when looking at an Error,
this is the address of the reference, not the address of the
instance.

lldb needs to look at Error instances too, so add a new entry
point named getDynamicTypeAndAddressForError() which avoids the
extra dereference.

This will be tested on the lldb side.
2019-02-12 14:59:57 -05:00
Slava Pestov
bd3b45138f RemoteAST: More consistent behavior of existentials inside classes
LLDB calls getDynamicTypeAndAddressForExistential() on an existential
value without knowing if its a class existential or opaque existential.

Class existentials return the address of the instance itself here,
whereas opaque existentials always returned the address of the
payload value.

This meant the caller could not usefully operate on the payload value
if it was of class type, because there was no way of knowing if the
extra dereference had occurred or not.

Now, always load the reference if the wrapped type is a class, even
if the existential is opaque.

Will be tested on the lldb side with another change I'm working on.
2019-02-12 14:59:57 -05:00
Slava Pestov
76ebaee078 MetadataReader: Add support for NSError toll-free bridging
An Error existential value can directly store a
reference to an NSError instance without wrapping
it in an Error container.

When "projecting" such an existential, the dynamic type
is the NSError's isa pointer, and the payload is the
address of the instance itself.
2019-02-12 14:59:57 -05:00
Slava Pestov
b6951932b4 ASTDemangler: Implement type alias types
Debug info uses a special mangling where type aliases can be
represented without being desugared; attempt to reconstruct
the TypeAliasType in this case.
2019-01-25 21:59:48 -05:00
Davide Italiano
4f45622803 [RemoteAST] Stop bypassing resilience when doing queries.
Avoid going to IRGen with a resilient type to avoid crashing.
This is tested in lldb.

<rdar://problem/45049259>
2018-11-06 12:43:43 -08:00
Slava Pestov
4fb5ccf40e AST: Rename RemoteASTTypeBuilder to ASTBuilder 2018-11-02 18:19:40 -04:00
Slava Pestov
9c50867370 Move RemoteAST's RemoteASTTypeBuilder to lib/AST/ASTDemangler.cpp 2018-11-02 18:19:40 -04:00
Slava Pestov
9074136a09 RemoteAST: Add experimental swift::remoteAST::getTypeForMangling() entry point
This will eventually replace swift::ide::getTypeFromMangledSymbolname().
2018-11-02 00:47:11 -04:00
Slava Pestov
d093fcb4a4 Reflection: Decode imported Objective-C classes and protocols as their own TypeRef
Right now we expect that every class and protocol has a field
descriptor that tells us if the entity is @objc or not.

For imported types, the descriptor will not exist if we did not
directly emit a field whose concrete type contains the imported
type. For example, in lldb, we might have a generic type whose
runtime substituted type includes an imported type.

In this case, TypeLowering would fail to produce a layout because
it did not find a field descriptor for the imported type.

A better approach is to have the TypeDecoder call a different
factory method for imported types, and handle them specially in
TypeLowering, bypassing the field type metadata altogether.
2018-11-02 00:47:11 -04:00
Pavel Yaskevich
621b970b53 [ABI/Metadata] Add @autoclosure to function parameter flags
Add `@autoclosure` to parameter flags associated with
function type metadata, which makes it possible to correctly
round-trip mangled name <-> metadata of function types which
have parameters marked as `@autoclosure`.

Resolves: rdar://problem/45489901
2018-10-24 15:29:30 -07:00
Davide Italiano
b25953e0ea [RemoteAST] Fix typo in existential payload calculation.
This only shows up in lldb, so I'm adding a test there and
test the two commits together.
2018-10-20 16:31:15 -07:00
John McCall
1784875819 Store value ownership generically in ParameterTypeFlags; NFC. 2018-10-20 00:24:38 -04:00
Slava Pestov
ce770cdf4e AST: Introduce GenericSignature::forEachParam()
This replaces the inefficient pattern:

  for (auto param : sig->getGenericParams()) {
    if (sig->isCanonicalTypeInContext(param)) {
      ...
    } else {
      ...
    }
  }
2018-09-27 21:28:36 -07:00
Graydon Hoare
14db5d2285 [AST] Add and use NominalTypeDecl::LookupDirectFlags rather than booleans. 2018-09-21 14:34:26 -07:00
Davide Italiano
8d25db681b [MetadataReader] Rename pointed to pointer for consistency.
Pointed out by John McCall in a previous review (I just procrastinated
to do it, until today).
2018-09-05 16:27:49 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Davide Italiano
242338c8c0 [RemoteAST] Implement support for existential metatypes.
<rdar://problem/43059340>
2018-08-08 12:48:10 -07:00
Davide Italiano
a7f36075ff Merge pull request #17571 from dcci/existentialremoteast
[RemoteAST] Initial support for projecting the type out of an existen…
2018-07-31 14:27:50 -07:00
Slava Pestov
bb59562192 IRGen: Create a new IRGenModule constructor for dummy instances 2018-07-30 18:37:09 -07:00
Davide Italiano
4b5c2295d1 [RemoteAST] Support for extracting the type/valuea out of an existential.
This will be used in lldb.
<rdar://problem/41546568>
2018-07-30 17:00:23 -07:00
David Zarzycki
da506fc0f5 [Reflection] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Joe Groff
e2dd2ff11f Runtime: Handle synthesized decl "related entity" tags.
Clang-importer-synthesized declarations get an extra tag character included in their mangling, which was not being preserved in type context descriptors. This caused runtime lookup for these synthesized types to fail. Fix this by adding the tag information to type context descriptors and teaching the runtime to match it up when fetching metadata by mangled name. Fixes rdar://problem/40878715.
2018-06-28 12:11:12 -07:00
Adrian Prantl
9bc39498e8 Revert "Restrict RemoteASTTypeBuilder::findModule() to the list of loaded modules."
This reverts commit 30ea6ec66c.

LLDB is smarter than I expected it to be.  One of the failing tests
"metatype" is very short and does not import any modules
whatsoever. It turns out that swift_runtime->GetMetadataPromise()
creates a RemoteAST with the Scratch AST context. LLDB does not
pre-import any modules for the scratch AST context.

Using the scratch context is actually the behavior we'd want for all
kinds of dynamic type resolution, since we need to handle the
worst-case dynamic type (a tuple of existentials that each originate
from different modules that don't import each other) gracefully.

So what I'm going to try next is revert the RemoteAST change and try
to get the dynamic type resolution in this case to use the scratch AST
context instead of the per-module AST context.

I'm still going to add a flag to RemoteAST to indicate wether
importing other modules should be allowed or not and set that
according to whether this is a module context or the scratch context.
2018-06-20 19:03:40 -07:00
Adrian Prantl
30ea6ec66c Restrict RemoteASTTypeBuilder::findModule() to the list of loaded modules.
LLDB uses RemoteAST for its per-module SwiftASTContext. Importing
external modules here could permanently damage this context, for
example when a Clang import fails because of missing header search
options. To avoid this situation, restrict RemoteAST's access to only
the module's transitive closure of imports.

Triggering this situation needs two independent Swift compilation
units. An accompanying testcase (Swift/RemoteASTImport.test) has been
added to LLDB.

rdar://problem/40950542
2018-06-19 17:21:21 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Slava Pestov
55633e8d06 IRGen: New way of bypassing resilience for LLDB
When running Swift from within LLDB, we need to bypass resilience since LLDB
does not support resilience yet. However, the bypass was done too early as
part of the module loader, which had the effect of disabling resilience
altogether.

We still want resilience at the SIL level so that function types lower the
same with debugger support turned on and off. Only IRGen needs to bypass
resilience, so that LLDB can calculate fragile layouts of types. Also, the
DebuggerSupport flag is not always set in the ASTContexts created by LLDB.

So replace it with a new flag that only controls this behavior and nothing
else, and make it part of IRGenOptions to make it totally clear that it only
impacts IRGen.

Together with the paired LLDB change, fixes <rdar://problem/38719739>
and <rdar://problem/38483762>.
2018-04-18 21:06:49 -07:00
Huon Wilson
38029bab2a [ABI] Store a ValueOwnership directly, not a manual encoding of it. 2018-03-08 12:36:37 +11:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
David Ungar
026b850d0c Only pass output filename and main input file name for debugging into IRGenModule constructor. 2018-02-15 20:52:26 -07:00
David Ungar
fec411e9bc reformatted 2018-02-15 15:34:55 -07:00