Skip to content

Commit 610c545

Browse files
authored
Merge pull request swiftlang#12788 from xedin/revert-function-metadata-changes
Revert function metadata changes
2 parents 884f3db + 659c1bc commit 610c545

File tree

16 files changed

+256
-617
lines changed

16 files changed

+256
-617
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -550,21 +550,19 @@ enum class FunctionMetadataConvention: uint8_t {
550550
template <typename int_type>
551551
class TargetFunctionTypeFlags {
552552
enum : int_type {
553-
NumParametersMask = 0x00FFFFFFU,
554-
ConventionMask = 0x0F000000U,
555-
ConventionShift = 25U,
556-
ThrowsMask = 0x10000000U,
557-
ParamFlagsMask = 0x01000000U,
553+
NumArgumentsMask = 0x00FFFFFFU,
554+
ConventionMask = 0x0F000000U,
555+
ConventionShift = 24U,
556+
ThrowsMask = 0x10000000U,
558557
};
559558
int_type Data;
560559

561560
constexpr TargetFunctionTypeFlags(int_type Data) : Data(Data) {}
562561
public:
563562
constexpr TargetFunctionTypeFlags() : Data(0) {}
564563

565-
constexpr TargetFunctionTypeFlags
566-
withNumParameters(unsigned numParams) const {
567-
return TargetFunctionTypeFlags((Data & ~NumParametersMask) | numParams);
564+
constexpr TargetFunctionTypeFlags withNumArguments(unsigned numArguments) const {
565+
return TargetFunctionTypeFlags((Data & ~NumArgumentsMask) | numArguments);
568566
}
569567

570568
constexpr TargetFunctionTypeFlags<int_type>
@@ -578,25 +576,19 @@ class TargetFunctionTypeFlags {
578576
return TargetFunctionTypeFlags<int_type>((Data & ~ThrowsMask) |
579577
(throws ? ThrowsMask : 0));
580578
}
581-
582-
constexpr TargetFunctionTypeFlags<int_type>
583-
withParameterFlags(bool hasFlags) const {
584-
return TargetFunctionTypeFlags<int_type>((Data & ~ParamFlagsMask) |
585-
(hasFlags ? ParamFlagsMask : 0));
579+
580+
unsigned getNumArguments() const {
581+
return Data & NumArgumentsMask;
586582
}
587-
588-
unsigned getNumParameters() const { return Data & NumParametersMask; }
589-
583+
590584
FunctionMetadataConvention getConvention() const {
591585
return FunctionMetadataConvention((Data&ConventionMask) >> ConventionShift);
592586
}
593587

594588
bool throws() const {
595589
return bool(Data & ThrowsMask);
596590
}
597-
598-
bool hasParameterFlags() const { return bool(Data & ParamFlagsMask); }
599-
591+
600592
int_type getIntValue() const {
601593
return Data;
602594
}
@@ -614,56 +606,6 @@ class TargetFunctionTypeFlags {
614606
};
615607
using FunctionTypeFlags = TargetFunctionTypeFlags<size_t>;
616608

617-
template <typename int_type>
618-
class TargetParameterTypeFlags {
619-
enum : int_type {
620-
InOutMask = 1 << 0,
621-
SharedMask = 1 << 1,
622-
VariadicMask = 1 << 2,
623-
};
624-
int_type Data;
625-
626-
constexpr TargetParameterTypeFlags(int_type Data) : Data(Data) {}
627-
628-
public:
629-
constexpr TargetParameterTypeFlags() : Data(0) {}
630-
631-
constexpr TargetParameterTypeFlags<int_type> withInOut(bool isInOut) const {
632-
return TargetParameterTypeFlags<int_type>((Data & ~InOutMask) |
633-
(isInOut ? InOutMask : 0));
634-
}
635-
636-
constexpr TargetParameterTypeFlags<int_type> withShared(bool isShared) const {
637-
return TargetParameterTypeFlags<int_type>((Data & ~SharedMask) |
638-
(isShared ? SharedMask : 0));
639-
}
640-
641-
constexpr TargetParameterTypeFlags<int_type>
642-
withVariadic(bool isVariadic) const {
643-
return TargetParameterTypeFlags<int_type>((Data & ~VariadicMask) |
644-
(isVariadic ? VariadicMask : 0));
645-
}
646-
647-
bool isNone() const { return Data == 0; }
648-
bool isInOut() const { return Data & InOutMask; }
649-
bool isShared() const { return Data & SharedMask; }
650-
bool isVariadic() const { return Data & VariadicMask; }
651-
652-
int_type getIntValue() const { return Data; }
653-
654-
static TargetParameterTypeFlags<int_type> fromIntValue(int_type Data) {
655-
return TargetParameterTypeFlags(Data);
656-
}
657-
658-
bool operator==(TargetParameterTypeFlags<int_type> other) const {
659-
return Data == other.Data;
660-
}
661-
bool operator!=(TargetParameterTypeFlags<int_type> other) const {
662-
return Data != other.Data;
663-
}
664-
};
665-
using ParameterFlags = TargetParameterTypeFlags<uint32_t>;
666-
667609
/// Field types and flags as represented in a nominal type's field/case type
668610
/// vector.
669611
class FieldType {

include/swift/Reflection/TypeRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class FunctionTypeRef final : public TypeRef {
344344
for (const auto &Param : Parameters) {
345345
ID.addString(Param.getLabel().str());
346346
ID.addPointer(Param.getType());
347-
ID.addInteger(static_cast<uint32_t>(Param.getFlags().getIntValue()));
347+
ID.addInteger(static_cast<uint32_t>(Param.getFlags().toRaw()));
348348
}
349349
ID.addPointer(Result);
350350
ID.addInteger(static_cast<uint64_t>(Flags.getIntValue()));

include/swift/Remote/MetadataReader.h

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_REMOTE_METADATAREADER_H
1818
#define SWIFT_REMOTE_METADATAREADER_H
1919

20+
#include "swift/AST/Types.h"
2021
#include "swift/Runtime/Metadata.h"
2122
#include "swift/Remote/MemoryReader.h"
2223
#include "swift/Demangling/Demangler.h"
@@ -32,9 +33,9 @@ namespace remote {
3233
template <typename BuiltType> class FunctionParam {
3334
StringRef Label;
3435
BuiltType Type;
35-
ParameterFlags Flags;
36+
ParameterTypeFlags Flags;
3637

37-
FunctionParam(StringRef label, BuiltType type, ParameterFlags flags)
38+
FunctionParam(StringRef label, BuiltType type, ParameterTypeFlags flags)
3839
: Label(label), Type(type), Flags(flags) {}
3940

4041
public:
@@ -44,15 +45,14 @@ template <typename BuiltType> class FunctionParam {
4445

4546
StringRef getLabel() const { return Label; }
4647
BuiltType getType() const { return Type; }
47-
ParameterFlags getFlags() const { return Flags; }
48+
ParameterTypeFlags getFlags() const { return Flags; }
4849

4950
void setLabel(StringRef label) { Label = label; }
5051
void setType(BuiltType type) { Type = type; }
5152

5253
void setVariadic() { Flags = Flags.withVariadic(true); }
5354
void setShared() { Flags = Flags.withShared(true); }
5455
void setInOut() { Flags = Flags.withInOut(true); }
55-
void setFlags(ParameterFlags flags) { Flags = flags; };
5656

5757
FunctionParam withLabel(StringRef label) const {
5858
return FunctionParam(label, Type, Flags);
@@ -62,7 +62,7 @@ template <typename BuiltType> class FunctionParam {
6262
return FunctionParam(Label, type, Flags);
6363
}
6464

65-
FunctionParam withFlags(ParameterFlags flags) const {
65+
FunctionParam withFlags(ParameterTypeFlags flags) const {
6666
return FunctionParam(Label, Type, flags);
6767
}
6868
};
@@ -798,32 +798,40 @@ class MetadataReader {
798798
}
799799
case MetadataKind::Function: {
800800
auto Function = cast<TargetFunctionTypeMetadata<Runtime>>(Meta);
801-
auto *const parameters = Function->getParameters();
802801

803802
std::vector<FunctionParam<BuiltType>> Parameters;
804-
for (unsigned i = 0, n = Function->getNumParameters(); i != n; ++i) {
805-
StoredPointer ParamMetadata;
806-
if (!Reader->readInteger(RemoteAddress(parameters + i), &ParamMetadata))
807-
return BuiltType();
808-
809-
auto ParamTypeRef = readTypeFromMetadata(ParamMetadata);
810-
if (!ParamTypeRef)
803+
StoredPointer ArgumentAddress = MetadataAddress +
804+
sizeof(TargetFunctionTypeMetadata<Runtime>);
805+
for (StoredPointer i = 0; i < Function->getNumArguments(); ++i,
806+
ArgumentAddress += sizeof(StoredPointer)) {
807+
StoredPointer FlaggedArgumentAddress;
808+
if (!Reader->readInteger(RemoteAddress(ArgumentAddress),
809+
&FlaggedArgumentAddress))
811810
return BuiltType();
812811

813812
FunctionParam<BuiltType> Param;
814-
Param.setType(ParamTypeRef);
815-
Param.setFlags(Function->getParameterFlags(i));
816-
Parameters.push_back(std::move(Param));
813+
814+
// TODO: Use target-agnostic FlaggedPointer to mask this!
815+
const auto InOutMask = (StoredPointer) 1;
816+
// FIXME: Add import parameter related flags from metadata
817+
if ((FlaggedArgumentAddress & InOutMask) != 0)
818+
Param.setInOut();
819+
820+
FlaggedArgumentAddress &= ~InOutMask;
821+
if (auto ParamTypeRef = readTypeFromMetadata(FlaggedArgumentAddress)) {
822+
Param.setType(ParamTypeRef);
823+
Parameters.push_back(std::move(Param));
824+
} else {
825+
return BuiltType();
826+
}
817827
}
818828

819829
auto Result = readTypeFromMetadata(Function->ResultType);
820830
if (!Result)
821831
return BuiltType();
822832

823-
auto flags = FunctionTypeFlags()
824-
.withConvention(Function->getConvention())
825-
.withThrows(Function->throws())
826-
.withParameterFlags(Function->hasParameterFlags());
833+
auto flags = FunctionTypeFlags().withConvention(Function->getConvention())
834+
.withThrows(Function->throws());
827835
auto BuiltFunction =
828836
Builder.createFunctionType(Parameters, Result, flags);
829837
TypeCache[MetadataAddress] = BuiltFunction;
@@ -1187,24 +1195,8 @@ class MetadataReader {
11871195
return _readMetadata<TargetExistentialMetatypeMetadata>(address);
11881196
case MetadataKind::ForeignClass:
11891197
return _readMetadata<TargetForeignClassMetadata>(address);
1190-
case MetadataKind::Function: {
1191-
StoredSize flagsValue;
1192-
auto flagsAddr =
1193-
address + TargetFunctionTypeMetadata<Runtime>::OffsetToFlags;
1194-
if (!Reader->readInteger(RemoteAddress(flagsAddr), &flagsValue))
1195-
return nullptr;
1196-
1197-
auto flags =
1198-
TargetFunctionTypeFlags<StoredSize>::fromIntValue(flagsValue);
1199-
1200-
auto totalSize = sizeof(TargetFunctionTypeMetadata<Runtime>) +
1201-
flags.getNumParameters() * sizeof(StoredPointer);
1202-
1203-
if (flags.hasParameterFlags())
1204-
totalSize += flags.getNumParameters() * sizeof(uint32_t);
1205-
1206-
return _readMetadata(address, totalSize);
1207-
}
1198+
case MetadataKind::Function:
1199+
return _readMetadata<TargetFunctionTypeMetadata>(address);
12081200
case MetadataKind::HeapGenericLocalVariable:
12091201
return _readMetadata<TargetGenericBoxHeapMetadata>(address);
12101202
case MetadataKind::HeapLocalVariable:

include/swift/Runtime/Metadata.h

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,48 +1745,36 @@ using EnumMetadata = TargetEnumMetadata<InProcess>;
17451745
template <typename Runtime>
17461746
struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
17471747
using StoredSize = typename Runtime::StoredSize;
1748-
using Parameter = const TargetMetadata<Runtime> *;
1748+
1749+
// TODO: Make this target agnostic
1750+
using Argument = FlaggedPointer<const TargetMetadata<Runtime> *, 0>;
17491751

17501752
TargetFunctionTypeFlags<StoredSize> Flags;
17511753

17521754
/// The type metadata for the result type.
17531755
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> ResultType;
17541756

1755-
Parameter *getParameters() { return reinterpret_cast<Parameter *>(this + 1); }
1756-
1757-
const Parameter *getParameters() const {
1758-
return reinterpret_cast<const Parameter *>(this + 1);
1757+
TargetPointer<Runtime, Argument> getArguments() {
1758+
return reinterpret_cast<TargetPointer<Runtime, Argument>>(this + 1);
17591759
}
17601760

1761-
ParameterFlags getParameterFlags(unsigned index) const {
1762-
assert(index < getNumParameters());
1763-
auto flags = hasParameterFlags() ? getParameterFlags()[index] : 0;
1764-
return ParameterFlags::fromIntValue(flags);
1761+
TargetPointer<Runtime, const Argument> getArguments() const {
1762+
return reinterpret_cast<TargetPointer<Runtime, const Argument>>(this + 1);
17651763
}
1766-
1767-
StoredSize getNumParameters() const {
1768-
return Flags.getNumParameters();
1764+
1765+
StoredSize getNumArguments() const {
1766+
return Flags.getNumArguments();
17691767
}
17701768
FunctionMetadataConvention getConvention() const {
17711769
return Flags.getConvention();
17721770
}
17731771
bool throws() const { return Flags.throws(); }
1774-
bool hasParameterFlags() const { return Flags.hasParameterFlags(); }
17751772

17761773
static constexpr StoredSize OffsetToFlags = sizeof(TargetMetadata<Runtime>);
17771774

17781775
static bool classof(const TargetMetadata<Runtime> *metadata) {
17791776
return metadata->getKind() == MetadataKind::Function;
17801777
}
1781-
1782-
uint32_t *getParameterFlags() {
1783-
return reinterpret_cast<uint32_t *>(getParameters() + getNumParameters());
1784-
}
1785-
1786-
const uint32_t *getParameterFlags() const {
1787-
return reinterpret_cast<const uint32_t *>(getParameters() +
1788-
getNumParameters());
1789-
}
17901778
};
17911779
using FunctionTypeMetadata = TargetFunctionTypeMetadata<InProcess>;
17921780

@@ -2651,58 +2639,28 @@ swift_getGenericWitnessTable(GenericWitnessTable *genericTable,
26512639
/// \brief Fetch a uniqued metadata for a function type.
26522640
SWIFT_RUNTIME_EXPORT
26532641
const FunctionTypeMetadata *
2654-
swift_getFunctionTypeMetadata(FunctionTypeFlags flags,
2655-
const Metadata *const *parameters,
2656-
const uint32_t *parameterFlags,
2657-
const Metadata *result);
2642+
swift_getFunctionTypeMetadata(const void *flagsArgsAndResult[]);
26582643

26592644
SWIFT_RUNTIME_EXPORT
26602645
const FunctionTypeMetadata *
26612646
swift_getFunctionTypeMetadata1(FunctionTypeFlags flags,
2662-
const Metadata *arg0,
2663-
const Metadata *result);
2664-
2665-
SWIFT_RUNTIME_EXPORT
2666-
const FunctionTypeMetadata *
2667-
swift_getFunctionTypeMetadata1WithFlags(FunctionTypeFlags flags,
2668-
const Metadata *arg0,
2669-
ParameterFlags flags0,
2670-
const Metadata *result);
2647+
const void *arg0,
2648+
const Metadata *resultMetadata);
26712649

26722650
SWIFT_RUNTIME_EXPORT
26732651
const FunctionTypeMetadata *
26742652
swift_getFunctionTypeMetadata2(FunctionTypeFlags flags,
2675-
const Metadata *arg0,
2676-
const Metadata *arg1,
2677-
const Metadata *result);
2653+
const void *arg0,
2654+
const void *arg1,
2655+
const Metadata *resultMetadata);
26782656

26792657
SWIFT_RUNTIME_EXPORT
26802658
const FunctionTypeMetadata *
2681-
swift_getFunctionTypeMetadata2WithFlags(FunctionTypeFlags flags,
2682-
const Metadata *arg0,
2683-
ParameterFlags flags0,
2684-
const Metadata *arg1,
2685-
ParameterFlags flags1,
2686-
const Metadata *result);
2687-
2688-
SWIFT_RUNTIME_EXPORT
2689-
const FunctionTypeMetadata *swift_getFunctionTypeMetadata3(
2690-
FunctionTypeFlags flags,
2691-
const Metadata *arg0,
2692-
const Metadata *arg1,
2693-
const Metadata *arg2,
2694-
const Metadata *result);
2695-
2696-
SWIFT_RUNTIME_EXPORT
2697-
const FunctionTypeMetadata *swift_getFunctionTypeMetadata3WithFlags(
2698-
FunctionTypeFlags flags,
2699-
const Metadata *arg0,
2700-
ParameterFlags flags0,
2701-
const Metadata *arg1,
2702-
ParameterFlags flags1,
2703-
const Metadata *arg2,
2704-
ParameterFlags flags2,
2705-
const Metadata *result);
2659+
swift_getFunctionTypeMetadata3(FunctionTypeFlags flags,
2660+
const void *arg0,
2661+
const void *arg1,
2662+
const void *arg2,
2663+
const Metadata *resultMetadata);
27062664

27072665
/// \brief Fetch a uniqued metadata for a thin function type.
27082666
SWIFT_RUNTIME_EXPORT

0 commit comments

Comments
 (0)