Skip to content

Commit bf44477

Browse files
authored
Merge pull request #4106 from swiftwasm/main
Merge upstream `main` into `swiftwasm`
2 parents eec58c3 + 847b6c0 commit bf44477

26 files changed

+141
-100
lines changed

include/swift/AST/Decl.h

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5463,7 +5463,16 @@ class ParamDecl : public VarDecl {
54635463
friend class DefaultArgumentInitContextRequest;
54645464
friend class DefaultArgumentExprRequest;
54655465

5466-
llvm::PointerIntPair<Identifier, 1, bool> ArgumentNameAndDestructured;
5466+
enum class ArgumentNameFlags : uint8_t {
5467+
/// Whether or not this parameter is destructed.
5468+
Destructured = 1 << 0,
5469+
5470+
/// Whether or not this parameter is '_const'.
5471+
IsCompileTimeConst = 1 << 1,
5472+
};
5473+
5474+
llvm::PointerIntPair<Identifier, 2, OptionSet<ArgumentNameFlags>>
5475+
ArgumentNameAndFlags;
54675476
SourceLoc ParameterNameLoc;
54685477
SourceLoc ArgumentNameLoc;
54695478
SourceLoc SpecifierLoc;
@@ -5494,13 +5503,10 @@ class ParamDecl : public VarDecl {
54945503

54955504
/// Whether or not this parameter is 'isolated'.
54965505
IsIsolated = 1 << 2,
5497-
5498-
/// Whether or not this parameter is '_const'.
5499-
IsCompileTimeConst = 1 << 3,
55005506
};
55015507

55025508
/// The default value, if any, along with flags.
5503-
llvm::PointerIntPair<StoredDefaultArgument *, 4, OptionSet<Flags>>
5509+
llvm::PointerIntPair<StoredDefaultArgument *, 3, OptionSet<Flags>>
55045510
DefaultValueAndFlags;
55055511

55065512
friend class ParamSpecifierRequest;
@@ -5518,7 +5524,7 @@ class ParamDecl : public VarDecl {
55185524

55195525
/// Retrieve the argument (API) name for this function parameter.
55205526
Identifier getArgumentName() const {
5521-
return ArgumentNameAndDestructured.getPointer();
5527+
return ArgumentNameAndFlags.getPointer();
55225528
}
55235529

55245530
/// Retrieve the parameter (local) name for this function parameter.
@@ -5538,8 +5544,17 @@ class ParamDecl : public VarDecl {
55385544
TypeRepr *getTypeRepr() const { return TyRepr; }
55395545
void setTypeRepr(TypeRepr *repr) { TyRepr = repr; }
55405546

5541-
bool isDestructured() const { return ArgumentNameAndDestructured.getInt(); }
5542-
void setDestructured(bool repr) { ArgumentNameAndDestructured.setInt(repr); }
5547+
bool isDestructured() const {
5548+
auto flags = ArgumentNameAndFlags.getInt();
5549+
return flags.contains(ArgumentNameFlags::Destructured);
5550+
}
5551+
5552+
void setDestructured(bool repr) {
5553+
auto flags = ArgumentNameAndFlags.getInt();
5554+
flags = repr ? flags | ArgumentNameFlags::Destructured
5555+
: flags - ArgumentNameFlags::Destructured;
5556+
ArgumentNameAndFlags.setInt(flags);
5557+
}
55435558

55445559
DefaultArgumentKind getDefaultArgumentKind() const {
55455560
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
@@ -5671,13 +5686,15 @@ class ParamDecl : public VarDecl {
56715686

56725687
/// Whether or not this parameter is marked with '_const'.
56735688
bool isCompileTimeConst() const {
5674-
return DefaultValueAndFlags.getInt().contains(Flags::IsCompileTimeConst);
5689+
return ArgumentNameAndFlags.getInt().contains(
5690+
ArgumentNameFlags::IsCompileTimeConst);
56755691
}
56765692

56775693
void setCompileTimeConst(bool value = true) {
5678-
auto flags = DefaultValueAndFlags.getInt();
5679-
DefaultValueAndFlags.setInt(value ? flags | Flags::IsCompileTimeConst
5680-
: flags - Flags::IsCompileTimeConst);
5694+
auto flags = ArgumentNameAndFlags.getInt();
5695+
flags = value ? flags | ArgumentNameFlags::IsCompileTimeConst
5696+
: flags - ArgumentNameFlags::IsCompileTimeConst;
5697+
ArgumentNameAndFlags.setInt(flags);
56815698
}
56825699

56835700
/// Does this parameter reject temporary pointer conversions?

include/swift/AST/TypeAlignments.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace swift {
7575
constexpr size_t SILFunctionAlignInBits = 2;
7676
constexpr size_t ASTContextAlignInBits = 2;
7777
constexpr size_t TypeVariableAlignInBits = 4;
78-
constexpr size_t StoredDefaultArgumentAlignInBits = 4;
78+
constexpr size_t StoredDefaultArgumentAlignInBits = 3;
7979

8080
// Well, this is the *minimum* pointer alignment; it's going to be 3 on
8181
// 64-bit targets, but that doesn't matter.

include/swift/Runtime/Concurrent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ struct ConcurrentReadableHashMap {
881881
auto *newElements = ElementStorage::allocate(newCapacity);
882882

883883
if (elements) {
884-
if constexpr (std::is_trivially_copyable<ElemTy>::value) {
884+
if (std::is_trivially_copyable<ElemTy>::value) {
885885
memcpy(newElements->data(), elements->data(),
886886
elementCount * sizeof(ElemTy));
887887
} else {

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6554,7 +6554,7 @@ ParamDecl::ParamDecl(SourceLoc specifierLoc,
65546554
/*IsStatic*/ false,
65556555
VarDecl::Introducer::Let, parameterNameLoc, parameterName, dc,
65566556
StorageIsNotMutable),
6557-
ArgumentNameAndDestructured(argumentName, false),
6557+
ArgumentNameAndFlags(argumentName, None),
65586558
ParameterNameLoc(parameterNameLoc),
65596559
ArgumentNameLoc(argumentNameLoc), SpecifierLoc(specifierLoc) {
65606560
Bits.ParamDecl.SpecifierComputed = false;

lib/IRGen/GenDistributed.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
107107
SILFunction *Target) {
108108
auto &Context = IGM.Context;
109109

110-
auto getRawPointerParmeter = [&]() {
110+
auto getRawPointerParameter = [&]() {
111111
auto ptrType = Context.getUnsafeRawPointerType();
112112
return SILParameterInfo(ptrType->getCanonicalType(),
113113
ParameterConvention::Direct_Guaranteed);
@@ -131,8 +131,8 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
131131
return SILFunctionType::get(
132132
/*genericSignature=*/nullptr, extInfo, SILCoroutineKind::None,
133133
ParameterConvention::Direct_Guaranteed,
134-
{/*argumentBuffer=*/getRawPointerParmeter(),
135-
/*resultBuffer=*/getRawPointerParmeter(),
134+
{/*argumentBuffer=*/getRawPointerParameter(),
135+
/*resultBuffer=*/getRawPointerParameter(),
136136
/*actor=*/targetTy->getParameters().back()},
137137
/*Yields=*/{},
138138
/*Results=*/{},

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,54 +1913,90 @@ cstrToStringRef(const char *typeNameStart, size_t typeNameLength) {
19131913
return typeName;
19141914
}
19151915

1916-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_SPI
1917-
unsigned
1918-
swift_func_getParameterCount(const char *typeNameStart, size_t typeNameLength) {
1916+
/// Given mangling for a method, extract its function type in demangled
1917+
/// representation.
1918+
static NodePointer extractFunctionTypeFromMethod(Demangler &demangler,
1919+
const char *typeNameStart,
1920+
size_t typeNameLength) {
19191921
llvm::Optional<llvm::StringRef> typeName =
19201922
cstrToStringRef(typeNameStart, typeNameLength);
19211923
if (!typeName)
1922-
return -1;
1923-
1924-
StackAllocatedDemangler<1024> demangler;
1924+
return nullptr;
19251925

19261926
auto node = demangler.demangleSymbol(*typeName);
1927-
if (!node) return -2;
1927+
if (!node)
1928+
return nullptr;
19281929

19291930
node = node->findByKind(Node::Kind::Function, /*maxDepth=*/2);
1930-
if (!node) return -3;
1931+
if (!node)
1932+
return nullptr;
19311933

19321934
node = node->findByKind(Node::Kind::Type, /*maxDepth=*/2);
1933-
if (!node) return -4;
1935+
if (!node)
1936+
return nullptr;
19341937

1935-
node = node->findByKind(Node::Kind::ArgumentTuple, /*maxDepth=*/3);
1936-
// Get the "deepest" Tuple from the ArgumentTuple, that's the arguments
1937-
while (node && node->getKind() != Node::Kind::Tuple) {
1938-
node = node->getFirstChild();
1938+
// If this is a generic function, it requires special handling.
1939+
if (auto genericType =
1940+
node->findByKind(Node::Kind::DependentGenericType, /*maxDepth=*/1)) {
1941+
node = genericType->findByKind(Node::Kind::Type, /*maxDepth=*/1);
1942+
return node->findByKind(Node::Kind::FunctionType, /*maxDepth=*/1);
19391943
}
19401944

1941-
if (node) {
1942-
return node->getNumChildren();
1943-
}
1945+
auto funcType = node->getFirstChild();
1946+
assert(funcType->getKind() == Node::Kind::FunctionType);
1947+
return funcType;
1948+
}
1949+
1950+
/// For a single unlabeled parameter this function returns whole
1951+
/// `ArgumentTuple`, for everything else a `Tuple` element inside it.
1952+
static NodePointer getParameterList(NodePointer funcType) {
1953+
assert(funcType->getKind() == Node::Kind::FunctionType);
1954+
1955+
auto parameterContainer =
1956+
funcType->findByKind(Node::Kind::ArgumentTuple, /*maxDepth=*/1);
1957+
assert(parameterContainer->getNumChildren() > 0);
1958+
1959+
// This is a type that convers entire parameter list.
1960+
auto parameterList = parameterContainer->getFirstChild();
1961+
assert(parameterList->getKind() == Node::Kind::Type);
1962+
1963+
auto parameters = parameterList->getFirstChild();
1964+
if (parameters->getKind() == Node::Kind::Tuple)
1965+
return parameters;
1966+
1967+
return parameterContainer;
1968+
}
1969+
1970+
SWIFT_CC(swift)
1971+
SWIFT_RUNTIME_STDLIB_SPI
1972+
unsigned swift_func_getParameterCount(const char *typeNameStart,
1973+
size_t typeNameLength) {
1974+
StackAllocatedDemangler<1024> demangler;
19441975

1945-
return -5;
1976+
auto funcType =
1977+
extractFunctionTypeFromMethod(demangler, typeNameStart, typeNameLength);
1978+
if (!funcType)
1979+
return -1;
1980+
1981+
auto parameterList = getParameterList(funcType);
1982+
return parameterList->getNumChildren();
19461983
}
19471984

19481985
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_SPI
19491986
const Metadata *_Nullable
19501987
swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength) {
1951-
llvm::Optional<llvm::StringRef> typeName =
1952-
cstrToStringRef(typeNameStart, typeNameLength);
1953-
if (!typeName) return nullptr;
1954-
19551988
StackAllocatedDemangler<1024> demangler;
1956-
auto node = demangler.demangleSymbol(*typeName);
1957-
if (!node) return nullptr;
19581989

1959-
node = node->findByKind(Node::Kind::Function, /*maxDepth=*/2);
1960-
if (!node) return nullptr;
1990+
auto *funcType =
1991+
extractFunctionTypeFromMethod(demangler, typeNameStart, typeNameLength);
1992+
if (!funcType)
1993+
return nullptr;
1994+
1995+
auto resultType = funcType->getLastChild();
1996+
if (!resultType)
1997+
return nullptr;
19611998

1962-
node = node->findByKind(Node::Kind::ReturnType, /*maxDepth=*/4);
1963-
if (!node) return nullptr;
1999+
assert(resultType->getKind() == Node::Kind::ReturnType);
19642000

19652001
DecodedMetadataBuilder builder(
19662002
demangler,
@@ -1970,7 +2006,8 @@ swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength) {
19702006
[](const Metadata *, unsigned) { return nullptr; });
19712007

19722008
TypeDecoder<DecodedMetadataBuilder> decoder(builder);
1973-
auto builtTypeOrError = decoder.decodeMangledType(node);
2009+
auto builtTypeOrError =
2010+
decoder.decodeMangledType(resultType->getFirstChild());
19742011
if (builtTypeOrError.isError()) {
19752012
auto err = builtTypeOrError.getError();
19762013
char *errStr = err->copyErrorString();
@@ -1988,31 +2025,19 @@ swift_func_getParameterTypeInfo(
19882025
Metadata const **types, unsigned typesLength) {
19892026
if (typesLength < 0) return -1;
19902027

1991-
llvm::Optional<llvm::StringRef> typeName =
1992-
cstrToStringRef(typeNameStart, typeNameLength);
1993-
if (!typeName) return -1;
1994-
19952028
StackAllocatedDemangler<1024> demangler;
1996-
auto node = demangler.demangleSymbol(*typeName);
1997-
if (!node) return -1;
19982029

1999-
node = node->findByKind(Node::Kind::Function, /*maxDepth=*/2);
2000-
if (!node) return -3;
2030+
auto *funcType =
2031+
extractFunctionTypeFromMethod(demangler, typeNameStart, typeNameLength);
2032+
if (!funcType)
2033+
return -1;
20012034

2002-
node = node->findByKind(Node::Kind::Type, /*maxDepth=*/2);
2003-
if (!node) return -4;
2004-
2005-
node = node->findByKind(Node::Kind::ArgumentTuple, /*maxDepth=*/3);
2006-
// Get the "deepest" Tuple from the ArgumentTuple, that's the arguments
2007-
while (node && node->getKind() != Node::Kind::Tuple) {
2008-
node = node->getFirstChild();
2009-
}
2035+
auto parameterList = getParameterList(funcType);
20102036

20112037
// Only successfully return if the expected parameter count is the same
20122038
// as space prepared for it in the buffer.
2013-
if (!node || (node && node->getNumChildren() != typesLength)) {
2014-
return -5;
2015-
}
2039+
if (!(parameterList && parameterList->getNumChildren() == typesLength))
2040+
return -2;
20162041

20172042
DecodedMetadataBuilder builder(
20182043
demangler,
@@ -2024,14 +2049,15 @@ swift_func_getParameterTypeInfo(
20242049

20252050
auto typeIdx = 0;
20262051
// for each parameter (TupleElement), store it into the provided buffer
2027-
for (auto tupleElement : *node) {
2028-
assert(tupleElement->getKind() == Node::Kind::TupleElement);
2029-
assert(tupleElement->getNumChildren() == 1);
2052+
for (auto *parameter : *parameterList) {
2053+
if (parameter->getKind() == Node::Kind::TupleElement) {
2054+
assert(parameter->getNumChildren() == 1);
2055+
parameter = parameter->getFirstChild();
2056+
}
20302057

2031-
auto typeNode = tupleElement->getFirstChild();
2032-
assert(typeNode->getKind() == Node::Kind::Type);
2058+
assert(parameter->getKind() == Node::Kind::Type);
20332059

2034-
auto builtTypeOrError = decoder.decodeMangledType(tupleElement);
2060+
auto builtTypeOrError = decoder.decodeMangledType(parameter);
20352061
if (builtTypeOrError.isError()) {
20362062
auto err = builtTypeOrError.getError();
20372063
char *errStr = err->copyErrorString();
@@ -2041,14 +2067,10 @@ swift_func_getParameterTypeInfo(
20412067
}
20422068

20432069
types[typeIdx] = builtTypeOrError.getType();
2044-
typeIdx += 1;
2070+
++typeIdx;
20452071
} // end foreach parameter
20462072

2047-
if (node) {
2048-
return node->getNumChildren();
2049-
}
2050-
2051-
return -9;
2073+
return typesLength;
20522074
}
20532075

20542076
// ==== End of Function metadata functions ---------------------------------------

stdlib/public/stubs/Assert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "swift/Runtime/Config.h"
1414
#include "swift/Runtime/Debug.h"
1515
#include "swift/Runtime/Portability.h"
16-
#include "../SwiftShims/AssertionReporting.h"
16+
#include "SwiftShims/AssertionReporting.h"
1717
#include <cstdarg>
1818
#include <cstdint>
1919
#include <stdio.h>

stdlib/public/stubs/Availability.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "swift/Basic/Lazy.h"
2121
#include "swift/Runtime/Debug.h"
2222
#include <TargetConditionals.h>
23-
#include "../SwiftShims/FoundationShims.h"
23+
#include "SwiftShims/FoundationShims.h"
2424

2525
struct os_system_version_s {
2626
unsigned int major;

stdlib/public/stubs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ set(LLVM_OPTIONAL_SOURCES
2626

2727
set(swift_stubs_c_compile_flags ${SWIFT_RUNTIME_CORE_CXX_FLAGS})
2828
list(APPEND swift_stubs_c_compile_flags -DswiftCore_EXPORTS)
29-
list(APPEND swift_stubs_c_compile_flags -I${SWIFT_SOURCE_DIR}/include)
29+
list(APPEND swift_stubs_c_compile_flags -I${SWIFT_SOURCE_DIR}/include -I${SWIFT_SOURCE_DIR}/stdlib/public)
3030

3131
add_swift_target_library(swiftStdlibStubs
3232
OBJECT_LIBRARY

stdlib/public/stubs/FoundationHelpers.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#if SWIFT_OBJC_INTEROP
2222
#import <CoreFoundation/CoreFoundation.h>
23-
#include "../SwiftShims/CoreFoundationShims.h"
23+
#include "SwiftShims/CoreFoundationShims.h"
2424
#import <objc/runtime.h>
2525
#include "swift/Runtime/Once.h"
2626
#include <dlfcn.h>

0 commit comments

Comments
 (0)