@@ -1967,6 +1967,22 @@ static NodePointer getParameterList(NodePointer funcType) {
1967
1967
return parameterContainer;
1968
1968
}
1969
1969
1970
+ static const Metadata *decodeType (TypeDecoder<DecodedMetadataBuilder> &decoder,
1971
+ NodePointer type) {
1972
+ assert (type->getKind () == Node::Kind::Type);
1973
+
1974
+ auto builtTypeOrError = decoder.decodeMangledType (type);
1975
+
1976
+ if (builtTypeOrError.isError ()) {
1977
+ auto err = builtTypeOrError.getError ();
1978
+ char *errStr = err->copyErrorString ();
1979
+ err->freeErrorString (errStr);
1980
+ return nullptr ;
1981
+ }
1982
+
1983
+ return builtTypeOrError.getType ();
1984
+ }
1985
+
1970
1986
SWIFT_CC (swift)
1971
1987
SWIFT_RUNTIME_STDLIB_SPI
1972
1988
unsigned swift_func_getParameterCount(const char *typeNameStart,
@@ -1985,7 +2001,8 @@ unsigned swift_func_getParameterCount(const char *typeNameStart,
1985
2001
SWIFT_CC (swift) SWIFT_RUNTIME_STDLIB_SPI
1986
2002
const Metadata *_Nullable
1987
2003
swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength,
1988
- GenericEnvironmentDescriptor *genericEnv) {
2004
+ GenericEnvironmentDescriptor *genericEnv,
2005
+ const void * const *genericArguments) {
1989
2006
StackAllocatedDemangler<1024 > demangler;
1990
2007
1991
2008
auto *funcType =
@@ -1999,31 +2016,30 @@ swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength,
1999
2016
2000
2017
assert (resultType->getKind () == Node::Kind::ReturnType);
2001
2018
2019
+ SubstGenericParametersFromMetadata substFn (genericEnv, genericArguments);
2020
+
2002
2021
DecodedMetadataBuilder builder (
2003
2022
demangler,
2004
2023
/* substGenericParam=*/
2005
- [](unsigned , unsigned ) { return nullptr ; },
2024
+ [&substFn](unsigned depth, unsigned index) {
2025
+ return substFn.getMetadata (depth, index);
2026
+ },
2006
2027
/* SubstDependentWitnessTableFn=*/
2007
- [](const Metadata *, unsigned ) { return nullptr ; });
2028
+ [&substFn](const Metadata *type, unsigned index) {
2029
+ return substFn.getWitnessTable (type, index);
2030
+ });
2008
2031
2009
2032
TypeDecoder<DecodedMetadataBuilder> decoder (builder);
2010
- auto builtTypeOrError =
2011
- decoder.decodeMangledType (resultType->getFirstChild ());
2012
- if (builtTypeOrError.isError ()) {
2013
- auto err = builtTypeOrError.getError ();
2014
- char *errStr = err->copyErrorString ();
2015
- err->freeErrorString (errStr);
2016
- return nullptr ;
2017
- }
2018
2033
2019
- return builtTypeOrError. getType ( );
2034
+ return decodeType (decoder, resultType-> getFirstChild () );
2020
2035
}
2021
2036
2022
2037
SWIFT_CC (swift) SWIFT_RUNTIME_STDLIB_SPI
2023
2038
unsigned
2024
2039
swift_func_getParameterTypeInfo(
2025
2040
const char *typeNameStart, size_t typeNameLength,
2026
2041
GenericEnvironmentDescriptor *genericEnv,
2042
+ const void * const *genericArguments,
2027
2043
Metadata const **types, unsigned typesLength) {
2028
2044
if (typesLength < 0 ) return -1 ;
2029
2045
@@ -2041,35 +2057,36 @@ swift_func_getParameterTypeInfo(
2041
2057
if (!(parameterList && parameterList->getNumChildren () == typesLength))
2042
2058
return -2 ;
2043
2059
2060
+ SubstGenericParametersFromMetadata substFn (genericEnv, genericArguments);
2061
+
2044
2062
DecodedMetadataBuilder builder (
2045
2063
demangler,
2046
2064
/* substGenericParam=*/
2047
- [](unsigned , unsigned ) { return nullptr ; },
2065
+ [&substFn](unsigned depth, unsigned index) {
2066
+ return substFn.getMetadata (depth, index);
2067
+ },
2048
2068
/* SubstDependentWitnessTableFn=*/
2049
- [](const Metadata *, unsigned ) { return nullptr ; });
2069
+ [&substFn](const Metadata *type, unsigned index) {
2070
+ return substFn.getWitnessTable (type, index);
2071
+ });
2050
2072
TypeDecoder<DecodedMetadataBuilder> decoder (builder);
2051
2073
2052
- auto typeIdx = 0 ;
2053
2074
// for each parameter (TupleElement), store it into the provided buffer
2054
- for (auto *parameter : *parameterList) {
2075
+ for (unsigned index = 0 ; index != typesLength; ++index) {
2076
+ auto *parameter = parameterList->getChild (index);
2077
+
2055
2078
if (parameter->getKind () == Node::Kind::TupleElement) {
2056
2079
assert (parameter->getNumChildren () == 1 );
2057
2080
parameter = parameter->getFirstChild ();
2058
2081
}
2059
2082
2060
2083
assert (parameter->getKind () == Node::Kind::Type);
2061
2084
2062
- auto builtTypeOrError = decoder.decodeMangledType (parameter);
2063
- if (builtTypeOrError.isError ()) {
2064
- auto err = builtTypeOrError.getError ();
2065
- char *errStr = err->copyErrorString ();
2066
- err->freeErrorString (errStr);
2067
- typeIdx += 1 ;
2068
- continue ;
2069
- }
2085
+ auto type = decodeType (decoder, parameter);
2086
+ if (!type)
2087
+ return -3 ; // Failed to decode a type.
2070
2088
2071
- types[typeIdx] = builtTypeOrError.getType ();
2072
- ++typeIdx;
2089
+ types[index] = type;
2073
2090
} // end foreach parameter
2074
2091
2075
2092
return typesLength;
0 commit comments