Skip to content

[pull] swiftwasm from main #5525

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 31 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3c51106
Fix tests on Windows CI with vs2022
tristanlabelle Jun 9, 2023
50ef384
Fix the swift-inspect dump-generic-metadata operation.
hjyamauchi Jun 8, 2023
f940906
[Test] Use SyntaxRewriter.rewrite not visit
bnbarham Jun 12, 2023
6308cd0
Migrate test to touch.py
tristanlabelle Jun 12, 2023
0d5aa7f
Fix non-glob paths in touch.py
tristanlabelle Jun 12, 2023
ee3a47b
[Frontend] Ignore adjacent swiftmodule in compiler host modules
bnbarham Jun 8, 2023
11f34b7
Fix linting error
tristanlabelle Jun 13, 2023
5613006
[Sema] PreCheck: Diagnose standalone self within init accessors
xedin Jun 7, 2023
935142f
[ConstraintSystem] InitAccessors: Detect invalid references to member…
xedin Jun 7, 2023
3c924be
[CSFix] InitAccessors: Add a fix that tracks invalid member reference…
xedin Jun 7, 2023
db024d9
[CSDiagnostics] InitAccessors: Implement invalid member reference dia…
xedin Jun 7, 2023
f6fd0bc
[DI] InitAccessors: Enforce that @out parameters are fully initialize…
xedin Jun 8, 2023
ddcfe01
[Sema/SILGen] InitAccessors: Emit intersecting init accessor calls in…
xedin Jun 9, 2023
4f59538
[Sema] InitAccessors: Diagnose situations when memberwise init cannot…
xedin Jun 9, 2023
cffc3fd
[Sema/SILGen] InitAccessors: Don't synthesize memberwise init if `ini…
xedin Jun 13, 2023
6ca9728
[AST] InitAccessors: Mark properties that init other properties as me…
xedin Jun 13, 2023
34c8cf6
[Sema/SILGen] InitAccessors: Memberwise initializers with init access…
xedin Jun 13, 2023
6758fdb
Diagnose conformances on @objcImpl extensions
beccadax Jun 13, 2023
dd7acb1
[Backtracing][Linux] Properly align the stacks.
al45tair Jun 14, 2023
545334c
Merge pull request #66510 from tristanlabelle/fix-tests-windows-vs2022
compnerd Jun 14, 2023
d06e8c9
Merge pull request #66626 from al45tair/eng/PR-110743884
al45tair Jun 14, 2023
110f428
[Runtime] Add tracing for section scans.
mikeash Jun 6, 2023
8b48a0d
[Runtime+IRGen] Instantiate layout strings for generic multi payload …
drexin Jun 14, 2023
0c4a59b
Merge pull request #66569 from bnbarham/use-rewrite
bnbarham Jun 14, 2023
183902d
Merge pull request #66576 from bnbarham/ignore-host-modules
bnbarham Jun 14, 2023
2b8a397
Merge pull request #66513 from xedin/init-accessor-diagnostics
xedin Jun 14, 2023
68e22e1
AST: Fix logic error in TypeMatcher::visitParameterizedProtocolType()
slavapestov Jun 14, 2023
12b1843
Merge pull request #66377 from mikeash/section-scan-signposts
swift-ci Jun 14, 2023
1532fb1
Merge pull request #66609 from beccadax/just-empty-protocol
beccadax Jun 14, 2023
df71ee0
Merge pull request #66524 from hjyamauchi/dump-generic-metadata
compnerd Jun 14, 2023
056ac83
Merge pull request #66635 from slavapestov/type-matcher-parameterized…
slavapestov Jun 14, 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
13 changes: 13 additions & 0 deletions include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace swift {
class SerializedDefaultArgumentInitializer;
class SerializedTopLevelCodeDecl;
class StructDecl;
class AccessorDecl;

namespace serialization {
using DeclID = llvm::PointerEmbeddedInt<unsigned, 31>;
Expand Down Expand Up @@ -457,6 +458,18 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
return const_cast<DeclContext*>(this)->getInnermostMethodContext();
}

/// Returns the innermost accessor context that belongs to a property.
///
/// This routine looks through closure, initializer, and local function
/// contexts to find the innermost accessor declaration.
///
/// \returns the innermost accessor, or null if there is no such context.
LLVM_READONLY
AccessorDecl *getInnermostPropertyAccessorContext();
const AccessorDecl *getInnermostPropertyAccessorContext() const {
return const_cast<DeclContext*>(this)->getInnermostPropertyAccessorContext();
}

/// Returns the innermost type context.
///
/// This routine looks through closure, initializer, and local function
Expand Down
3 changes: 2 additions & 1 deletion include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ NOTE(sdk_version_pbm_version,none,
NOTE(compiled_module_ignored_reason,none,
"compiled module '%0' was ignored because %select{%error"
"|it belongs to a framework in the SDK"
"|loading from module interfaces is preferred}1",
"|loading from module interfaces is preferred"
"|it's a compiler host module}1",
(StringRef, unsigned))
NOTE(out_of_date_module_here,none,
"%select{compiled|cached|forwarding|prebuilt}0 module is out of date: '%1'",
Expand Down
22 changes: 21 additions & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,11 @@ ERROR(attr_objc_implementation_category_not_found,none,
NOTE(attr_objc_implementation_fixit_remove_category_name,none,
"remove arguments to implement the main '@interface' for this class",
())
ERROR(attr_objc_implementation_no_conformance,none,
"'@_objcImplementation' extension cannot add conformance to %0; "
"add this conformance %select{with an ordinary extension|"
"in the Objective-C header}1",
(Type, bool))

ERROR(member_of_objc_implementation_not_objc_or_final,none,
"%0 %1 does not match any %0 declared in the headers for %2; did you use "
Expand Down Expand Up @@ -7364,7 +7369,22 @@ ERROR(init_accessor_accesses_attribute_on_other_declaration,none,
ERROR(init_accessor_property_both_init_and_accessed,none,
"property %0 cannot be both initialized and accessed",
(DeclName))

ERROR(invalid_use_of_self_in_init_accessor,none,
"'self' within init accessors can only be used to reference "
"properties listed in 'initializes' and 'accesses'; "
"init accessors are run before 'self' is fully available", ())
ERROR(init_accessor_invalid_member_ref,none,
"cannot reference instance member %0; init accessors can only "
"refer to instance properties listed in 'initializes' and "
"'accesses' attributes",
(DeclNameRef))
ERROR(cannot_synthesize_memberwise_due_to_property_init_order,none,
"cannot synthesize memberwise initializer",
())
NOTE(out_of_order_access_in_init_accessor,none,
"init accessor for %0 cannot access stored property %1 because it "
"is called before %1 is initialized",
(Identifier, Identifier))

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
10 changes: 6 additions & 4 deletions include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,12 @@ class TypeMatcher {

if (firstArgs.size() == secondArgs.size()) {
for (unsigned i : indices(firstArgs)) {
return this->visit(CanType(firstArgs[i]),
secondArgs[i],
sugaredFirstType->castTo<ParameterizedProtocolType>()
->getArgs()[i]);
if (!this->visit(CanType(firstArgs[i]),
secondArgs[i],
sugaredFirstType->castTo<ParameterizedProtocolType>()
->getArgs()[i])) {
return false;
}
}

return true;
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Basic/StringExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ class NullTerminatedStringRef {
/// where escaped Unicode characters lead to malformed/invalid JSON.
void writeEscaped(llvm::StringRef Str, llvm::raw_ostream &OS);

/// Whether the path components of `path` begin with those from `prefix`.
bool pathStartsWith(StringRef prefix, StringRef path);

} // end namespace swift

#endif // SWIFT_BASIC_STRINGEXTRAS_H
40 changes: 40 additions & 0 deletions include/swift/RemoteInspection/GenericMetadataCacheEntry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===--- GenericMetadataCacheEntry.h ----------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Declares a struct that mirrors the layout of GenericCacheEntry in
// Metadata.cpp and use a static assert to check that the offset of
// the member Value match between the two.
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_REFLECTION_GENERICMETADATACACHEENTRY_H
#define SWIFT_REFLECTION_GENERICMETADATACACHEENTRY_H

#include <cstdint>

namespace swift {

template<typename StoredPointer>
struct GenericMetadataCacheEntry {
StoredPointer TrackingInfo;
uint16_t NumKeyParameters;
uint16_t NumWitnessTables;
uint16_t NumPacks;
uint16_t NumShapeClasses;
StoredPointer PackShapeDescriptors;
uint32_t Hash;
StoredPointer Value;
};

} // namespace swift

#endif // SWIFT_REFLECTION_GENERICMETADATACACHEENTRY_H
15 changes: 4 additions & 11 deletions include/swift/RemoteInspection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "swift/Concurrency/Actor.h"
#include "swift/Remote/MemoryReader.h"
#include "swift/Remote/MetadataReader.h"
#include "swift/RemoteInspection/GenericMetadataCacheEntry.h"
#include "swift/RemoteInspection/Records.h"
#include "swift/RemoteInspection/RuntimeInternals.h"
#include "swift/RemoteInspection/TypeLowering.h"
Expand Down Expand Up @@ -1289,22 +1290,14 @@ class ReflectionContext
StoredPointer allocationMetadataPointer(
MetadataAllocation<Runtime> Allocation) {
if (Allocation.Tag == GenericMetadataCacheTag) {
struct GenericMetadataCacheEntry {
StoredPointer LockedStorage;
uint8_t LockedStorageKind;
uint8_t TrackingInfo;
uint16_t NumKeyParameters;
uint16_t NumWitnessTables;
uint32_t Hash;
StoredPointer Value;
};
auto AllocationBytes =
getReader().readBytes(RemoteAddress(Allocation.Ptr),
Allocation.Size);
if (!AllocationBytes)
return 0;
auto Entry = reinterpret_cast<const GenericMetadataCacheEntry *>(
AllocationBytes.get());
auto Entry =
reinterpret_cast<const GenericMetadataCacheEntry<StoredPointer> *>(
AllocationBytes.get());
return Entry->Value;
}
return 0;
Expand Down
6 changes: 6 additions & 0 deletions include/swift/Runtime/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ void swift_initEnumMetadataMultiPayload(EnumMetadata *enumType,
unsigned numPayloads,
const TypeLayout * const *payloadTypes);

SWIFT_RUNTIME_EXPORT
void swift_initEnumMetadataMultiPayloadWithLayoutString(EnumMetadata *enumType,
EnumLayoutFlags flags,
unsigned numPayloads,
const Metadata * const *payloadTypes);

/// Return an integer value representing which case of a multi-payload
/// enum is inhabited.
///
Expand Down
17 changes: 16 additions & 1 deletion include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,8 @@ FUNCTION(InitStructMetadata,
// void swift_initStructMetadataWithLayoutString(Metadata *structType,
// StructLayoutFlags flags,
// size_t numFields,
// Metadata * const *fieldTypes,
// uint8_t * const *fieldTypes,
// const uint8_t *fieldTags
// uint32_t *fieldOffsets);
FUNCTION(InitStructMetadataWithLayoutString,
swift_initStructMetadataWithLayoutString, C_CC, AlwaysAvailable,
Expand Down Expand Up @@ -1312,6 +1313,7 @@ FUNCTION(InitEnumMetadataSinglePayload,
EFFECT(MetaData))

// void swift_initEnumMetadataMultiPayload(Metadata *enumType,
// EnumLayoutFlags layoutFlags,
// size_t numPayloads,
// TypeLayout * const *payloadTypes);
FUNCTION(InitEnumMetadataMultiPayload,
Expand All @@ -1322,6 +1324,19 @@ FUNCTION(InitEnumMetadataMultiPayload,
ATTRS(NoUnwind, WillReturn),
EFFECT(MetaData))

// void
// swift_initEnumMetadataMultiPayloadWithLayoutString(Metadata *enumType,
// EnumLayoutFlags layoutFlags,
// size_t numPayloads,
// Metadata * const *payloadTypes);
FUNCTION(InitEnumMetadataMultiPayloadWithLayoutString,
swift_initEnumMetadataMultiPayloadWithLayoutString,
C_CC, AlwaysAvailable,
RETURNS(VoidTy),
ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, TypeMetadataPtrPtrTy),
ATTRS(NoUnwind, WillReturn),
EFFECT(MetaData))

// int swift_getEnumCaseMultiPayload(opaque_t *obj, Metadata *enumTy);
FUNCTION(GetEnumCaseMultiPayload,
swift_getEnumCaseMultiPayload,
Expand Down
37 changes: 37 additions & 0 deletions include/swift/Sema/CSFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ enum class FixKind : uint8_t {

/// Ignore missing 'each' keyword before value pack reference.
IgnoreMissingEachKeyword,

/// Ignore the fact that member couldn't be referenced within init accessor
/// because its name doesn't appear in 'initializes' or 'accesses' attributes.
AllowInvalidMemberReferenceInInitAccessor,
};

class ConstraintFix {
Expand Down Expand Up @@ -3536,6 +3540,39 @@ class IgnoreMissingEachKeyword final : public ConstraintFix {
}
};

class AllowInvalidMemberReferenceInInitAccessor final : public ConstraintFix {
DeclNameRef MemberName;

AllowInvalidMemberReferenceInInitAccessor(ConstraintSystem &cs,
DeclNameRef memberName,
ConstraintLocator *locator)
: ConstraintFix(cs, FixKind::AllowInvalidMemberReferenceInInitAccessor,
locator),
MemberName(memberName) {}

public:
std::string getName() const override {
llvm::SmallVector<char, 16> scratch;
auto memberName = MemberName.getString(scratch);
return "allow reference to member '" + memberName.str() +
"' in init accessor";
}

bool diagnose(const Solution &solution, bool asNote = false) const override;

bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
return diagnose(*commonFixes.front().first);
}

static AllowInvalidMemberReferenceInInitAccessor *
create(ConstraintSystem &cs, DeclNameRef memberName,
ConstraintLocator *locator);

static bool classof(const ConstraintFix *fix) {
return fix->getKind() == FixKind::AllowInvalidMemberReferenceInInitAccessor;
}
};

} // end namespace constraints
} // end namespace swift

Expand Down
5 changes: 5 additions & 0 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,11 @@ struct MemberLookupResult {
/// This is a static member being access through a protocol metatype
/// but its result type doesn't conform to this protocol.
UR_InvalidStaticMemberOnProtocolMetatype,

/// This is a member that doesn't appear in 'initializes' and/or
/// 'accesses' attributes of the init accessor and therefore canno
/// t be referenced in its body.
UR_UnavailableWithinInitAccessor,
};

/// This is a list of considered (but rejected) candidates, along with a
Expand Down
6 changes: 6 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7168,6 +7168,12 @@ bool VarDecl::isMemberwiseInitialized(bool preferDeclaredProperties) const {
isBackingStorageForDeclaredProperty(this))
return false;

// If this is a computed property with `init` accessor, it's
// memberwise initializable when it could be used to initialize
// other stored properties.
if (auto *init = getAccessor(AccessorKind::Init))
return init->getAttrs().hasAttribute<InitializesAttr>();

// If this is a computed property, it's not memberwise initialized unless
// the caller has asked for the declared properties and it is either a
// `lazy` property or a property with an attached wrapper.
Expand Down
18 changes: 18 additions & 0 deletions lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ AbstractFunctionDecl *DeclContext::getInnermostMethodContext() {
return nullptr;
}

AccessorDecl *DeclContext::getInnermostPropertyAccessorContext() {
auto dc = this;
do {
if (auto decl = dc->getAsDecl()) {
auto accessor = dyn_cast<AccessorDecl>(decl);
// If we found a non-accessor decl, we're done.
if (accessor == nullptr)
return nullptr;

auto *storage = accessor->getStorage();
if (isa<VarDecl>(storage) && storage->getDeclContext()->isTypeContext())
return accessor;
}
} while ((dc = dc->getParent()));

return nullptr;
}

bool DeclContext::isTypeContext() const {
if (auto decl = getAsDecl())
return isa<NominalTypeDecl>(decl) || isa<ExtensionDecl>(decl);
Expand Down
16 changes: 3 additions & 13 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "swift/Basic/Compiler.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Basic/Statistic.h"
#include "swift/Basic/StringExtras.h"
#include "swift/Demangling/ManglingMacros.h"
#include "swift/Parse/Token.h"
#include "swift/Strings.h"
Expand Down Expand Up @@ -4235,18 +4236,6 @@ FrontendStatsTracer::getTraceFormatter<const SourceFile *>() {
return &TF;
}

static bool prefixMatches(StringRef prefix, StringRef path) {
auto prefixIt = llvm::sys::path::begin(prefix),
prefixEnd = llvm::sys::path::end(prefix);
for (auto pathIt = llvm::sys::path::begin(path),
pathEnd = llvm::sys::path::end(path);
prefixIt != prefixEnd && pathIt != pathEnd; ++prefixIt, ++pathIt) {
if (*prefixIt != *pathIt)
return false;
}
return prefixIt == prefixEnd;
}

bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) const {
// stdlib is non-user by definition
if (mod->isStdlibModule())
Expand Down Expand Up @@ -4274,5 +4263,6 @@ bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) con
return false;

StringRef runtimePath = searchPathOpts.RuntimeResourcePath;
return (!runtimePath.empty() && prefixMatches(runtimePath, modulePath)) || (!sdkPath.empty() && prefixMatches(sdkPath, modulePath));
return (!runtimePath.empty() && pathStartsWith(runtimePath, modulePath)) ||
(!sdkPath.empty() && pathStartsWith(sdkPath, modulePath));
}
13 changes: 13 additions & 0 deletions lib/Basic/StringExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>

Expand Down Expand Up @@ -1417,3 +1418,15 @@ void swift::writeEscaped(llvm::StringRef Str, llvm::raw_ostream &OS) {
}
}
}

bool swift::pathStartsWith(StringRef prefix, StringRef path) {
auto prefixIt = llvm::sys::path::begin(prefix),
prefixEnd = llvm::sys::path::end(prefix);
for (auto pathIt = llvm::sys::path::begin(path),
pathEnd = llvm::sys::path::end(path);
prefixIt != prefixEnd && pathIt != pathEnd; ++prefixIt, ++pathIt) {
if (*prefixIt != *pathIt)
return false;
}
return prefixIt == prefixEnd;
}
Loading