Skip to content

[pull] swiftwasm from main #5528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
00495ec
Disable downstream project tests in smoke test trigger
shahmishal Jul 6, 2022
02603e3
[Build] Read all shell output as UTF-8
bnbarham Jun 7, 2023
71a42d4
[Test] Remove 64-bit specific FileCheck line.
nate-chandler Jun 14, 2023
e42667b
[Diagnostics] Suppress printing explicit pack types in the ASTPrinter…
hborla Jun 14, 2023
2dc5da0
swift_build_support: support FreeBSD on arm64 in `targets.py`
MaxDesiatov Jun 14, 2023
f374fa0
[nfc][cxx-interop] Remove `NS(U)Integer` typedefs from a test.
zoecarver Jun 14, 2023
c5d6e3c
swift_build_support cmake.py: allow bootstrapping CMake on FreeBSD
MaxDesiatov Jun 14, 2023
35bd509
Merge pull request #66632 from hborla/pack-diagnostics
hborla Jun 14, 2023
38050cd
Merge pull request #66641 from apple/maxd/bsd-arm64
swift-ci Jun 14, 2023
3f0885d
Merge pull request #66637 from nate-chandler/test/20230614/1/pack_met…
nate-chandler Jun 15, 2023
c435405
build-script-impl: add support for `freebsd-arm64`
MaxDesiatov Jun 15, 2023
8499aa0
SwiftConfigureSDK.cmake: support `freebsd-arm64`
MaxDesiatov Jun 15, 2023
e0c9aa1
Merge pull request #66440 from bnbarham/sprinkle-utf8
bnbarham Jun 15, 2023
adaa892
Merge pull request #66646 from zoecarver/remove-nsint-typedefs
zoecarver Jun 15, 2023
d74c085
[Runtime+IRGen] Add layout string support for generic singleton enums…
drexin Jun 15, 2023
dc0a3c9
Merge pull request #66652 from apple/maxd/bootstrap-bsd-cmake
swift-ci Jun 15, 2023
5e3ba59
Merge pull request #66655 from apple/maxd/bsi-bsd-arm64
swift-ci Jun 15, 2023
fde2cf5
Merge pull request #59934 from apple/disable-downstream-project-test-…
swift-ci Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ macro(configure_sdk_unix name architectures)
message(FATAL_ERROR "unknown arch for ${prefix}: ${arch}")
endif()
elseif("${prefix}" STREQUAL "FREEBSD")
if(NOT arch STREQUAL x86_64)
if(NOT arch MATCHES "(arm64|x86_64)")
message(FATAL_ERROR "unsupported arch for FreeBSD: ${arch}")
endif()

Expand All @@ -389,7 +389,7 @@ macro(configure_sdk_unix name architectures)
string(REGEX REPLACE "[-].*" "" freebsd_system_version ${CMAKE_SYSTEM_VERSION})
message(STATUS "FreeBSD Version: ${freebsd_system_version}")

set(SWIFT_SDK_FREEBSD_ARCH_x86_64_TRIPLE "x86_64-unknown-freebsd${freebsd_system_version}")
set(SWIFT_SDK_FREEBSD_ARCH_${arch}_TRIPLE "${arch}-unknown-freebsd${freebsd_system_version}")
elseif("${prefix}" STREQUAL "OPENBSD")
if(NOT arch STREQUAL amd64)
message(FATAL_ERROR "unsupported arch for OpenBSD: ${arch}")
Expand Down
7 changes: 7 additions & 0 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ struct PrintOptions {
/// Whether to always desugar optional types from `base_type?` to `Optional<base_type>`
bool AlwaysDesugarOptionalTypes = false;

/// Whether to always print explicit `Pack{...}` around pack
/// types.
///
/// This is set to \c false for diagnostic arguments.
bool PrintExplicitPackTypes = true;

/// \see ShouldQualifyNestedDeclarations
enum class QualifyNestedDeclarations {
Never,
Expand Down Expand Up @@ -606,6 +612,7 @@ struct PrintOptions {
/// The print options used for formatting diagnostic arguments.
static PrintOptions forDiagnosticArguments() {
PrintOptions result;
result.PrintExplicitPackTypes = false;
return result;
}

Expand Down
5 changes: 5 additions & 0 deletions include/swift/Runtime/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ void swift_initEnumMetadataSingleCase(EnumMetadata *enumType,
EnumLayoutFlags flags,
const TypeLayout *payload);

SWIFT_RUNTIME_EXPORT
void swift_initEnumMetadataSingleCaseWithLayoutString(
EnumMetadata *self, EnumLayoutFlags layoutFlags,
const Metadata *payloadType);

/// Initialize the type metadata for a single-payload enum type.
///
/// \param enumType - pointer to the instantiated but uninitialized metadata
Expand Down
11 changes: 11 additions & 0 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,17 @@ FUNCTION(InitEnumMetadataSingleCase,
ATTRS(NoUnwind, WillReturn),
EFFECT(MetaData))

// void swift_initEnumMetadataSingleCaseWithLayoutString(Metadata *enumType,
// EnumLayoutFlags flags,
// Metadata *payload);
FUNCTION(InitEnumMetadataSingleCaseWithLayoutString,
swift_initEnumMetadataSingleCaseWithLayoutString,
C_CC, AlwaysAvailable,
RETURNS(VoidTy),
ARGS(TypeMetadataPtrTy, SizeTy, TypeMetadataPtrTy),
ATTRS(NoUnwind, WillReturn),
EFFECT(MetaData))

// void swift_initEnumMetadataSinglePayload(Metadata *enumType,
// EnumLayoutFlags flags,
// TypeLayout *payload,
Expand Down
7 changes: 5 additions & 2 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6051,7 +6051,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
}

void visitPackType(PackType *T) {
Printer << "Pack{";
if (Options.PrintExplicitPackTypes)
Printer << "Pack{";

auto Fields = T->getElementTypes();
for (unsigned i = 0, e = Fields.size(); i != e; ++i) {
Expand All @@ -6060,7 +6061,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
Type EltType = Fields[i];
visit(EltType);
}
Printer << "}";

if (Options.PrintExplicitPackTypes)
Printer << "}";
}

void visitSILPackType(SILPackType *T) {
Expand Down
75 changes: 48 additions & 27 deletions lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,42 @@ namespace {
metadata);
}

void initializeMetadataWithLayoutString(IRGenFunction &IGF,
llvm::Value *metadata,
bool isVWTMutable,
SILType T,
MetadataDependencyCollector *collector) const override {
// Not yet supported on this type, so forward to regular method
initializeMetadata(IGF, metadata, isVWTMutable, T, collector);
void initializeMetadataWithLayoutString(
IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
MetadataDependencyCollector *collector) const override {
if (TIK >= Fixed)
return;

assert(ElementsWithPayload.size() == 1 &&
"empty singleton enum should not be dynamic!");

auto payloadTy =
T.getEnumElementType(ElementsWithPayload[0].decl, IGM.getSILModule(),
IGM.getMaximalTypeExpansionContext());

auto request = DynamicMetadataRequest::getNonBlocking(
MetadataState::LayoutComplete, collector);
auto payloadMetadata =
IGF.emitTypeMetadataRefForLayout(payloadTy, request);

auto flags = emitEnumLayoutFlags(IGF.IGM, isVWTMutable);
IGF.Builder.CreateCall(
IGF.IGM
.getInitEnumMetadataSingleCaseWithLayoutStringFunctionPointer(),
{metadata, flags, payloadMetadata});

// Pre swift-5.1 runtimes were missing the initialization of the
// the extraInhabitantCount field. Do it here instead.
auto payloadLayout = emitTypeLayoutRef(IGF, payloadTy, collector);
auto payloadRef = IGF.Builder.CreateBitOrPointerCast(
payloadLayout, IGF.IGM.TypeLayoutTy->getPointerTo());
auto payloadExtraInhabitantCount =
IGF.Builder.CreateLoad(IGF.Builder.CreateStructGEP(
Address(payloadRef, IGF.IGM.TypeLayoutTy, Alignment(1)), 3,
Size(IGF.IGM.DataLayout.getTypeAllocSize(IGF.IGM.SizeTy) * 2 +
IGF.IGM.DataLayout.getTypeAllocSize(IGF.IGM.Int32Ty))));
emitStoreOfExtraInhabitantCount(IGF, payloadExtraInhabitantCount,
metadata);
}

bool mayHaveExtraInhabitants(IRGenModule &IGM) const override {
Expand Down Expand Up @@ -973,11 +1002,9 @@ namespace {
// witness table initialization.
}

void initializeMetadataWithLayoutString(IRGenFunction &IGF,
llvm::Value *metadata,
bool isVWTMutable,
SILType T,
MetadataDependencyCollector *collector) const override {
void initializeMetadataWithLayoutString(
IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
MetadataDependencyCollector *collector) const override {
// No-payload enums are always fixed-size so never need dynamic value
// witness table initialization.
}
Expand Down Expand Up @@ -3207,11 +3234,9 @@ namespace {
{metadata, flags, payloadLayout, emptyCasesVal});
}

void initializeMetadataWithLayoutString(IRGenFunction &IGF,
llvm::Value *metadata,
bool isVWTMutable,
SILType T,
MetadataDependencyCollector *collector) const override {
void initializeMetadataWithLayoutString(
IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
MetadataDependencyCollector *collector) const override {
// Not yet supported on this type, so forward to regular method
initializeMetadata(IGF, metadata, isVWTMutable, T, collector);
}
Expand Down Expand Up @@ -5335,11 +5360,9 @@ namespace {
{metadata, flags, numPayloadsVal, payloadLayoutArray});
}

void initializeMetadataWithLayoutString(IRGenFunction &IGF,
llvm::Value *metadata,
bool isVWTMutable,
SILType T,
MetadataDependencyCollector *collector) const override {
void initializeMetadataWithLayoutString(
IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
MetadataDependencyCollector *collector) const override {
// Fixed-size enums don't need dynamic metadata initialization.
if (TIK >= Fixed) return;

Expand Down Expand Up @@ -6035,11 +6058,9 @@ namespace {
llvm_unreachable("resilient enums cannot be defined");
}

void initializeMetadataWithLayoutString(IRGenFunction &IGF,
llvm::Value *metadata,
bool isVWTMutable,
SILType T,
MetadataDependencyCollector *collector) const override {
void initializeMetadataWithLayoutString(
IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
MetadataDependencyCollector *collector) const override {
llvm_unreachable("resilient enums cannot be defined");
}

Expand Down
11 changes: 7 additions & 4 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5737,14 +5737,17 @@ namespace {
}

auto &strategy = getEnumImplStrategy(IGM, getLoweredType());
bool isSupportedCase = strategy.getElementsWithPayload().size() > 1 ||
(strategy.getElementsWithPayload().size() == 1 &&
strategy.getElementsWithNoPayload().empty());

return !!getLayoutString() ||
(IGM.Context.LangOpts.hasFeature(
Feature::LayoutStringValueWitnessesInstantiation) &&
Feature::LayoutStringValueWitnessesInstantiation) &&
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation &&
(HasDependentVWT || HasDependentMetadata) &&
!isa<FixedTypeInfo>(IGM.getTypeInfo(getLoweredType())) &&
strategy.getElementsWithPayload().size() > 1);
(HasDependentVWT || HasDependentMetadata) &&
!isa<FixedTypeInfo>(IGM.getTypeInfo(getLoweredType())) &&
isSupportedCase);
}

llvm::Constant *emitNominalTypeDescriptor() {
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenValueWitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ bool isRuntimeInstatiatedLayoutString(IRGenModule &IGM,
Feature::LayoutStringValueWitnessesInstantiation) &&
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation) {
if (auto *enumEntry = typeLayoutEntry->getAsEnum()) {
return enumEntry->isMultiPayloadEnum();
return enumEntry->isMultiPayloadEnum() || enumEntry->isSingleton();
}
return (typeLayoutEntry->isAlignedGroup() &&
!typeLayoutEntry->isFixedSize(IGM));
Expand Down
8 changes: 0 additions & 8 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ Type FailureDiagnostic::resolveType(Type rawType, bool reconstituteSugar,
return env->mapElementTypeIntoPackContext(type);
}

if (auto *packType = type->getAs<PackType>()) {
if (packType->getNumElements() == 1) {
auto eltType = resolveType(packType->getElementType(0));
if (auto expansion = eltType->getAs<PackExpansionType>())
return expansion->getPatternType();
}
}

return type->isPlaceholder() ? Type(type->getASTContext().TheUnresolvedType)
: type;
});
Expand Down
15 changes: 2 additions & 13 deletions lib/Sema/TypeCheckGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ static std::string gatherGenericParamBindingsText(

SmallString<128> result;
llvm::raw_svector_ostream OS(result);
auto options = PrintOptions::forDiagnosticArguments();

for (auto gp : genericParams) {
auto canonGP = gp->getCanonicalType()->castTo<GenericTypeParamType>();
Expand All @@ -859,19 +860,7 @@ static std::string gatherGenericParamBindingsText(
if (!type)
return "";

if (auto *packType = type->getAs<PackType>()) {
bool first = true;
for (auto eltType : packType->getElementTypes()) {
if (first)
first = false;
else
OS << ", ";

OS << eltType;
}
} else {
OS << type.getString();
}
type->print(OS, options);
}

OS << "]";
Expand Down
57 changes: 57 additions & 0 deletions stdlib/public/runtime/Enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,61 @@ swift::swift_initEnumMetadataSingleCase(EnumMetadata *self,
vwtable->publishLayout(layout);
}

void swift::swift_initEnumMetadataSingleCaseWithLayoutString(
EnumMetadata *self, EnumLayoutFlags layoutFlags,
const Metadata *payloadType) {
assert(self->hasLayoutString());

auto payloadLayout = payloadType->getTypeLayout();
auto vwtable = getMutableVWTableForInit(self, layoutFlags);

TypeLayout layout;
layout.size = payloadLayout->size;
layout.stride = payloadLayout->stride;
layout.flags = payloadLayout->flags.withEnumWitnesses(true);
layout.extraInhabitantCount = payloadLayout->getNumExtraInhabitants();

auto refCountBytes = _swift_refCountBytesForMetatype(payloadType);
const size_t fixedLayoutStringSize =
layoutStringHeaderSize + sizeof(uint64_t) * 2;

uint8_t *layoutStr =
(uint8_t *)MetadataAllocator(LayoutStringTag)
.Allocate(fixedLayoutStringSize + refCountBytes, alignof(uint8_t));

size_t layoutStrOffset = sizeof(uint64_t);
writeBytes(layoutStr, layoutStrOffset, refCountBytes);
size_t fullOffset = 0;
size_t previousFieldOffset = 0;
LayoutStringFlags flags = LayoutStringFlags::Empty;

_swift_addRefCountStringForMetatype(layoutStr, layoutStrOffset, flags,
payloadType, fullOffset,
previousFieldOffset);

writeBytes(layoutStr, layoutStrOffset, (uint64_t)previousFieldOffset);
writeBytes(layoutStr, layoutStrOffset, (uint64_t)0);

// we mask out HasRelativePointers, because at this point they have all been
// resolved to metadata pointers
layoutStrOffset = 0;
writeBytes(layoutStr, layoutStrOffset,
((uint64_t)flags) &
~((uint64_t)LayoutStringFlags::HasRelativePointers));

vwtable->destroy = swift_generic_destroy;
vwtable->initializeWithCopy = swift_generic_initWithCopy;
vwtable->initializeWithTake = swift_generic_initWithTake;
vwtable->assignWithCopy = swift_generic_assignWithCopy;
vwtable->assignWithTake = swift_generic_assignWithTake;

installCommonValueWitnesses(layout, vwtable);

self->setLayoutString(layoutStr);

vwtable->publishLayout(layout);
}

void
swift::swift_initEnumMetadataSinglePayload(EnumMetadata *self,
EnumLayoutFlags layoutFlags,
Expand Down Expand Up @@ -221,6 +276,8 @@ void swift::swift_initEnumMetadataMultiPayloadWithLayoutString(
EnumLayoutFlags layoutFlags,
unsigned numPayloads,
const Metadata * const *payloadLayouts) {
assert(enumType->hasLayoutString());

// Accumulate the layout requirements of the payloads.
size_t payloadSize = 0, alignMask = 0;
bool isPOD = true, isBT = true;
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/runtime/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2750,8 +2750,8 @@ void swift::swift_initStructMetadataWithLayoutString(
previousFieldOffset);
}

writeBytes(layoutStr, layoutStrOffset, previousFieldOffset);
writeBytes(layoutStr, layoutStrOffset, 0);
writeBytes(layoutStr, layoutStrOffset, (uint64_t)previousFieldOffset);
writeBytes(layoutStr, layoutStrOffset, (uint64_t)0);

// we mask out HasRelativePointers, because at this point they have all been
// resolved to metadata pointers
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/pack-expansion-expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func tupleExpansion<each T, each U>(
_ = zip(repeat each tuple1, with: repeat each tuple1.element) // legacy syntax

_ = zip(repeat each tuple1, with: repeat each tuple2)
// expected-error@-1 {{global function 'zip(_:with:)' requires the type packs 'each T' and 'each U' have the same shape}}
// expected-error@-1 {{global function 'zip(_:with:)' requires the type packs 'repeat each T' and 'repeat each U' have the same shape}}

_ = forward(repeat each tuple3)
}
Expand Down
6 changes: 3 additions & 3 deletions test/Constraints/pack_expansion_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ func patternInstantiationConcreteValid() {

func patternInstantiationConcreteInvalid() {
let _: Set<Int> = patternInstantiationTupleTest1()
// expected-error@-1 {{cannot convert value of type '(repeat Array<Pack{_}>)' to specified type 'Set<Int>'}}
// expected-error@-1 {{cannot convert value of type '(repeat Array<_>)' to specified type 'Set<Int>'}}

let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<Pack{Int, _}>)' is not convertible to '(Array<Int>, Set<String>)', tuples have a different number of elements}}
let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<Int, _>)' is not convertible to '(Array<Int>, Set<String>)', tuples have a different number of elements}}
}

func patternInstantiationGenericValid<each T, each U>(t: repeat each T, u: repeat each U)
Expand Down Expand Up @@ -272,7 +272,7 @@ func patternInstantiationGenericInvalid<each T: Hashable>(t: repeat each T) {
let _: (repeat Set<each T>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array<each T>)' to specified type '(repeat Set<each T>)}}
// expected-error@-1 {{generic parameter 'each T' could not be inferred}}

let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<Pack{repeat each T, _}>)' is not convertible to '(repeat Array<each T>, Set<String>)', tuples have a different number of elements}}
let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<repeat each T, _>)' is not convertible to '(repeat Array<each T>, Set<String>)', tuples have a different number of elements}}
}

// rdar://107996926 - Vanishing metatype of tuple not supported
Expand Down
Loading