Skip to content

Commit 3d4401c

Browse files
Merge pull request #4364 from swiftwasm/main
[pull] swiftwasm from main
2 parents b0d9b9d + 965f32d commit 3d4401c

37 files changed

+710
-642
lines changed

include/swift/Remote/MemoryReader.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,32 @@ class MemoryReader {
149149
return RemoteAbsolutePointer("", readValue);
150150
}
151151

152-
/// Atempt to resolve the pointer to a symbol for the given remote address.
153152
virtual llvm::Optional<RemoteAbsolutePointer>
154153
resolvePointerAsSymbol(RemoteAddress address) {
155154
return llvm::None;
156155
}
157156

157+
/// Lookup a symbol for the given remote address.
158+
virtual RemoteAbsolutePointer getSymbol(RemoteAddress address) {
159+
if (auto symbol = resolvePointerAsSymbol(address))
160+
return *symbol;
161+
return RemoteAbsolutePointer("", address.getAddressData());
162+
}
163+
164+
/// Lookup a dynamic symbol name (ie dynamic loader binding) for the given
165+
/// remote address. Note: An address can be referenced by both dynamic and
166+
/// regular symbols, this function must return a dynamic symbol only.
167+
virtual RemoteAbsolutePointer getDynamicSymbol(RemoteAddress address) {
168+
return nullptr;
169+
}
170+
158171
/// Attempt to read and resolve a pointer value at the given remote address.
159172
llvm::Optional<RemoteAbsolutePointer> readPointer(RemoteAddress address,
160173
unsigned pointerSize) {
161-
// Try to resolve the pointer as a symbol first, as reading memory
162-
// may potentially be expensive.
163-
if (auto symbolPointer = resolvePointerAsSymbol(address))
164-
return symbolPointer;
174+
// First, try to lookup the pointer as a dynamic symbol (binding), as
175+
// reading memory may potentially be expensive.
176+
if (auto dynamicSymbol = getDynamicSymbol(address))
177+
return dynamicSymbol;
165178

166179
auto result = readBytes(address, pointerSize);
167180
if (!result)

include/swift/Remote/MetadataReader.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ class MetadataReader {
420420
return nullptr;
421421
}
422422
} else {
423-
resolved = Reader->resolvePointer(RemoteAddress(remoteAddress), 0);
424-
if (resolved.getSymbol().empty()) {
425-
// No symbol found, use the already calculated address.
426-
resolved = RemoteAbsolutePointer("", remoteAddress);
427-
}
423+
resolved = Reader->getSymbol(RemoteAddress(remoteAddress));
428424
}
429425

430426
switch (kind) {

include/swift/SIL/TypeLowering.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,39 @@ CanSILFunctionType getNativeSILFunctionType(
12041204
Optional<SubstitutionMap> reqtSubs = None,
12051205
ProtocolConformanceRef witnessMethodConformance = ProtocolConformanceRef());
12061206

1207+
/// The thunk kinds used in the differentiation transform.
1208+
enum class DifferentiationThunkKind {
1209+
/// A reabstraction thunk.
1210+
///
1211+
/// Reabstraction thunks transform a function-typed value to another one with
1212+
/// different parameter/result abstraction patterns. This is identical to the
1213+
/// thunks generated by SILGen.
1214+
Reabstraction,
1215+
1216+
/// An index subset thunk.
1217+
///
1218+
/// An index subset thunk is used transform JVP/VJPs into a version that is
1219+
/// "wrt" fewer differentiation parameters.
1220+
/// - Differentials of thunked JVPs use zero for non-requested differentiation
1221+
/// parameters.
1222+
/// - Pullbacks of thunked VJPs discard results for non-requested
1223+
/// differentiation parameters.
1224+
IndexSubset
1225+
};
1226+
1227+
/// Build the type of a function transformation thunk.
1228+
CanSILFunctionType buildSILFunctionThunkType(
1229+
SILFunction *fn,
1230+
CanSILFunctionType &sourceType,
1231+
CanSILFunctionType &expectedType,
1232+
CanType &inputSubstType,
1233+
CanType &outputSubstType,
1234+
GenericEnvironment *&genericEnv,
1235+
SubstitutionMap &interfaceSubs,
1236+
CanType &dynamicSelfType,
1237+
bool withoutActuallyEscaping,
1238+
Optional<DifferentiationThunkKind> differentiationThunkKind = None);
1239+
12071240
} // namespace swift
12081241

12091242
namespace llvm {

include/swift/SILOptimizer/Differentiation/Thunk.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,6 @@ class ADContext;
4747
// moved to a shared location.
4848
//===----------------------------------------------------------------------===//
4949

50-
/// The thunk kinds used in the differentiation transform.
51-
enum class DifferentiationThunkKind {
52-
/// A reabstraction thunk.
53-
///
54-
/// Reabstraction thunks transform a function-typed value to another one with
55-
/// different parameter/result abstraction patterns. This is identical to the
56-
/// thunks generated by SILGen.
57-
Reabstraction,
58-
59-
/// An index subset thunk.
60-
///
61-
/// An index subset thunk is used transform JVP/VJPs into a version that is
62-
/// "wrt" fewer differentiation parameters.
63-
/// - Differentials of thunked JVPs use zero for non-requested differentiation
64-
/// parameters.
65-
/// - Pullbacks of thunked VJPs discard results for non-requested
66-
/// differentiation parameters.
67-
IndexSubset
68-
};
69-
70-
CanGenericSignature buildThunkSignature(SILFunction *fn, bool inheritGenericSig,
71-
OpenedArchetypeType *openedExistential,
72-
GenericEnvironment *&genericEnv,
73-
SubstitutionMap &contextSubs,
74-
SubstitutionMap &interfaceSubs,
75-
ArchetypeType *&newArchetype);
76-
77-
/// Build the type of a function transformation thunk.
78-
CanSILFunctionType buildThunkType(SILFunction *fn,
79-
CanSILFunctionType &sourceType,
80-
CanSILFunctionType &expectedType,
81-
GenericEnvironment *&genericEnv,
82-
SubstitutionMap &interfaceSubs,
83-
bool withoutActuallyEscaping,
84-
DifferentiationThunkKind thunkKind);
8550

8651
/// Get or create a reabstraction thunk from `fromType` to `toType`, to be
8752
/// called in `caller`.

include/swift/StaticMirror/ObjectFileContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class Image {
7070

7171
remote::RemoteAbsolutePointer resolvePointer(uint64_t Addr,
7272
uint64_t pointerValue) const;
73+
74+
remote::RemoteAbsolutePointer getDynamicSymbol(uint64_t Addr) const;
7375
};
7476

7577
/// MemoryReader that reads from the on-disk representation of an executable
@@ -118,6 +120,9 @@ class ObjectMemoryReader : public reflection::MemoryReader {
118120

119121
remote::RemoteAbsolutePointer resolvePointer(reflection::RemoteAddress Addr,
120122
uint64_t pointerValue) override;
123+
124+
remote::RemoteAbsolutePointer
125+
getDynamicSymbol(reflection::RemoteAddress Addr) override;
121126
};
122127

123128
using ReflectionContextOwner = std::unique_ptr<void, void (*)(void *)>;

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ RequirementMachine::getLongestValidPrefix(const MutableTerm &term) const {
239239
case Symbol::Kind::Superclass:
240240
case Symbol::Kind::ConcreteType:
241241
case Symbol::Kind::ConcreteConformance:
242-
llvm_unreachable("Property symbol cannot appear in a type term");
242+
llvm::errs() <<"Invalid symbol in a type term: " << term << "\n";
243+
abort();
243244
}
244245

245246
// This symbol is valid, add it to the longest prefix.
@@ -265,6 +266,9 @@ bool RequirementMachine::isCanonicalTypeInContext(Type type) const {
265266
explicit Walker(const RequirementMachine &self) : Self(self) {}
266267

267268
Action walkToTypePre(Type component) override {
269+
if (!component->hasTypeParameter())
270+
return Action::SkipChildren;
271+
268272
if (!component->isTypeParameter())
269273
return Action::Continue;
270274

@@ -305,6 +309,9 @@ Type RequirementMachine::getCanonicalTypeInContext(
305309
TypeArrayView<GenericTypeParamType> genericParams) const {
306310

307311
return type.transformRec([&](Type t) -> Optional<Type> {
312+
if (!t->hasTypeParameter())
313+
return t;
314+
308315
if (!t->isTypeParameter())
309316
return None;
310317

0 commit comments

Comments
 (0)