Skip to content

Commit 6ce2e1d

Browse files
authored
Merge pull request #4342 from swiftwasm/maxd/main-merge
Resolve build issues with upstream `main`
2 parents 656a56c + d8c05a6 commit 6ce2e1d

17 files changed

+378
-168
lines changed

include/swift/Runtime/Concurrent.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,14 @@ template <class ElemTy> struct ConcurrentReadableArray {
520520
// These are marked as ref-qualified (the &) to make sure they can't be
521521
// called on temporaries, since the temporary would be destroyed before the
522522
// return value can be used, making it invalid.
523-
const ElemTy *begin() & { return Start; }
524-
const ElemTy *end() & { return Start + Count; }
523+
const ElemTy *begin() const& { return Start; }
524+
const ElemTy *end() const& { return Start + Count; }
525+
const ElemTy& operator [](size_t index) const& {
526+
assert(index < count() && "out-of-bounds access to snapshot element");
527+
return Start[index];
528+
}
525529

526-
size_t count() { return Count; }
530+
size_t count() const { return Count; }
527531
};
528532

529533
// This type cannot be safely copied or moved.

lib/IRGen/GenStruct.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,52 @@ namespace {
734734
isOutlined);
735735
}
736736

737+
void assignWithCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
738+
SILType T, bool isOutlined) const override {
739+
if (auto copyConstructor = findCopyConstructor()) {
740+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
741+
srcAddr.getAddress(),
742+
destAddr.getAddress());
743+
return;
744+
}
745+
StructTypeInfoBase<AddressOnlyClangRecordTypeInfo, FixedTypeInfo,
746+
ClangFieldInfo>::assignWithCopy(IGF, destAddr,
747+
srcAddr, T,
748+
isOutlined);
749+
}
750+
751+
void initializeWithTake(IRGenFunction &IGF, Address dest, Address src,
752+
SILType T, bool isOutlined) const override {
753+
if (auto copyConstructor = findCopyConstructor()) {
754+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
755+
src.getAddress(),
756+
dest.getAddress());
757+
destroy(IGF, src, T, isOutlined);
758+
return;
759+
}
760+
761+
StructTypeInfoBase<AddressOnlyClangRecordTypeInfo, FixedTypeInfo,
762+
ClangFieldInfo>::initializeWithTake(IGF, dest,
763+
src, T,
764+
isOutlined);
765+
}
766+
767+
void assignWithTake(IRGenFunction &IGF, Address dest, Address src, SILType T,
768+
bool isOutlined) const override {
769+
if (auto copyConstructor = findCopyConstructor()) {
770+
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
771+
src.getAddress(),
772+
dest.getAddress());
773+
destroy(IGF, src, T, isOutlined);
774+
return;
775+
}
776+
777+
StructTypeInfoBase<AddressOnlyClangRecordTypeInfo, FixedTypeInfo,
778+
ClangFieldInfo>::assignWithTake(IGF, dest,
779+
src, T,
780+
isOutlined);
781+
}
782+
737783
llvm::NoneType getNonFixedOffsets(IRGenFunction &IGF) const { return None; }
738784
llvm::NoneType getNonFixedOffsets(IRGenFunction &IGF, SILType T) const {
739785
return None;

stdlib/public/SwiftShims/MetadataSections.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#ifndef SWIFT_STDLIB_SHIMS_METADATASECTIONS_H
2222
#define SWIFT_STDLIB_SHIMS_METADATASECTIONS_H
2323

24+
#if defined(__cplusplus) && !defined(__swift__)
25+
#include <atomic>
26+
#endif
27+
2428
#include "SwiftStddef.h"
2529
#include "SwiftStdint.h"
2630

@@ -36,7 +40,12 @@ typedef struct MetadataSectionRange {
3640
} MetadataSectionRange;
3741

3842

39-
/// Identifies the address space ranges for the Swift metadata required by the Swift runtime.
43+
/// Identifies the address space ranges for the Swift metadata required by the
44+
/// Swift runtime.
45+
///
46+
/// \warning If you change the size of this structure by adding fields, it is an
47+
/// ABI-breaking change on platforms that use it. Make sure to increment
48+
/// \c CurrentSectionMetadataVersion if you do.
4049
struct MetadataSections {
4150
__swift_uintptr_t version;
4251

@@ -56,20 +65,23 @@ struct MetadataSections {
5665
/// loader (i.e. no equivalent of \c __dso_handle or \c __ImageBase), this
5766
/// field is ignored and should be set to \c nullptr.
5867
///
68+
/// \bug When imported into Swift, this field is not atomic.
69+
///
5970
/// \sa swift_addNewDSOImage()
71+
#if defined(__swift__) || defined(__STDC_NO_ATOMICS__)
6072
const void *baseAddress;
73+
#elif defined(__cplusplus)
74+
std::atomic<const void *> baseAddress;
75+
#else
76+
_Atomic(const void *) baseAddress;
77+
#endif
6178

62-
/// `next` and `prev` are used by the runtime to construct a
63-
/// circularly doubly linked list to quickly iterate over the metadata
64-
/// from each image loaded into the address space. These are invasive
65-
/// to enable the runtime registration, which occurs at image load time, to
66-
/// be allocation-free as it is invoked from an image constructor function
67-
/// context where the system may not yet be ready to perform allocations.
68-
/// Additionally, avoiding the allocation enables a fast load operation, which
69-
/// directly impacts application load time.
70-
struct MetadataSections *next;
71-
struct MetadataSections *prev;
72-
79+
/// Unused.
80+
///
81+
/// These pointers (or the space they occupy) can be repurposed without
82+
/// causing ABI breakage. Set them to \c nullptr.
83+
void *unused0;
84+
void *unused1;
7385

7486
MetadataSectionRange swift5_protocols;
7587
MetadataSectionRange swift5_protocol_conformances;

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -476,33 +476,33 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
476476
}
477477
}
478478

479-
/// Explicit construction from an UnsafeMutablePointer.
480-
///
481-
/// This is inherently unsafe; UnsafeMutablePointer assumes the
482-
/// referenced memory has +1 strong ownership semantics, whereas
483-
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
484-
///
485-
/// - Warning: Accessing `pointee` as a type that is unrelated to
486-
/// the underlying memory's bound type is undefined.
487-
@_transparent
488-
public init<U>(@_nonEphemeral _ from: UnsafeMutablePointer<U>) {
489-
self._rawValue = from._rawValue
490-
}
491-
492-
/// Explicit construction from an UnsafeMutablePointer.
493-
///
494-
/// Returns nil if `from` is nil.
495-
///
496-
/// This is inherently unsafe; UnsafeMutablePointer assumes the
497-
/// referenced memory has +1 strong ownership semantics, whereas
498-
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
499-
///
500-
/// - Warning: Accessing `pointee` as a type that is unrelated to
501-
/// the underlying memory's bound type is undefined.
502-
@_transparent
479+
/// Explicit construction from an UnsafeMutablePointer.
480+
///
481+
/// This is inherently unsafe; UnsafeMutablePointer assumes the
482+
/// referenced memory has +1 strong ownership semantics, whereas
483+
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
484+
///
485+
/// - Warning: Accessing `pointee` as a type that is unrelated to
486+
/// the underlying memory's bound type is undefined.
487+
@_transparent
488+
public init<U>(@_nonEphemeral _ from: UnsafeMutablePointer<U>) {
489+
self._rawValue = from._rawValue
490+
}
491+
492+
/// Explicit construction from an UnsafeMutablePointer.
493+
///
494+
/// Returns nil if `from` is nil.
495+
///
496+
/// This is inherently unsafe; UnsafeMutablePointer assumes the
497+
/// referenced memory has +1 strong ownership semantics, whereas
498+
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
499+
///
500+
/// - Warning: Accessing `pointee` as a type that is unrelated to
501+
/// the underlying memory's bound type is undefined.
502+
@_transparent
503503
public init?<U>(@_nonEphemeral _ from: UnsafeMutablePointer<U>?) {
504-
guard let unwrapped = from else { return nil }
505-
self.init(unwrapped)
504+
guard let unwrapped = from else { return nil }
505+
self.init(unwrapped)
506506
}
507507

508508
/// Explicit construction from a UnsafePointer.

stdlib/public/core/LazyCollection.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
public protocol LazyCollectionProtocol: Collection, LazySequenceProtocol
1414
where Elements: Collection { }
1515

16-
extension LazyCollectionProtocol {
17-
// Lazy things are already lazy
18-
@inlinable // protocol-only
19-
public var lazy: LazyCollection<Elements> {
20-
return elements.lazy
21-
}
22-
}
23-
24-
extension LazyCollectionProtocol where Elements: LazyCollectionProtocol {
25-
// Lazy things are already lazy
26-
@inlinable // protocol-only
27-
public var lazy: Elements {
28-
return elements
29-
}
16+
extension LazyCollectionProtocol {
17+
// Lazy things are already lazy
18+
@inlinable // protocol-only
19+
public var lazy: LazyCollection<Elements> {
20+
return elements.lazy
21+
}
22+
}
23+
24+
extension LazyCollectionProtocol where Elements: LazyCollectionProtocol {
25+
// Lazy things are already lazy
26+
@inlinable // protocol-only
27+
public var lazy: Elements {
28+
return elements
29+
}
3030
}
3131

3232
/// A collection containing the same elements as a `Base` collection,

stdlib/public/core/UnsafePointer.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -600,25 +600,25 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
600600
self.init(mutating: unwrapped)
601601
}
602602

603-
/// Creates an immutable typed pointer referencing the same memory as the
604-
/// given mutable pointer.
605-
///
606-
/// - Parameter other: The pointer to convert.
607-
@_transparent
603+
/// Creates an immutable typed pointer referencing the same memory as the
604+
/// given mutable pointer.
605+
///
606+
/// - Parameter other: The pointer to convert.
607+
@_transparent
608608
public init(@_nonEphemeral _ other: UnsafeMutablePointer<Pointee>) {
609-
self._rawValue = other._rawValue
610-
}
609+
self._rawValue = other._rawValue
610+
}
611611

612-
/// Creates an immutable typed pointer referencing the same memory as the
613-
/// given mutable pointer.
614-
///
615-
/// - Parameter other: The pointer to convert. If `other` is `nil`, the
616-
/// result is `nil`.
617-
@_transparent
612+
/// Creates an immutable typed pointer referencing the same memory as the
613+
/// given mutable pointer.
614+
///
615+
/// - Parameter other: The pointer to convert. If `other` is `nil`, the
616+
/// result is `nil`.
617+
@_transparent
618618
public init?(@_nonEphemeral _ other: UnsafeMutablePointer<Pointee>?) {
619-
guard let unwrapped = other else { return nil }
620-
self.init(unwrapped)
621-
}
619+
guard let unwrapped = other else { return nil }
620+
self.init(unwrapped)
621+
}
622622

623623

624624
/// Allocates uninitialized memory for the specified number of instances of

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -235,31 +235,31 @@ public struct UnsafeRawPointer: _Pointer {
235235
_rawValue = unwrapped._rawValue
236236
}
237237

238-
/// Creates a new raw pointer from the given typed pointer.
239-
///
240-
/// Use this initializer to explicitly convert `other` to an `UnsafeRawPointer`
241-
/// instance. This initializer creates a new pointer to the same address as
242-
/// `other` and performs no allocation or copying.
243-
///
244-
/// - Parameter other: The typed pointer to convert.
245-
@_transparent
238+
/// Creates a new raw pointer from the given typed pointer.
239+
///
240+
/// Use this initializer to explicitly convert `other` to an `UnsafeRawPointer`
241+
/// instance. This initializer creates a new pointer to the same address as
242+
/// `other` and performs no allocation or copying.
243+
///
244+
/// - Parameter other: The typed pointer to convert.
245+
@_transparent
246246
public init<T>(@_nonEphemeral _ other: UnsafeMutablePointer<T>) {
247-
_rawValue = other._rawValue
248-
}
247+
_rawValue = other._rawValue
248+
}
249249

250-
/// Creates a new raw pointer from the given typed pointer.
251-
///
252-
/// Use this initializer to explicitly convert `other` to an `UnsafeRawPointer`
253-
/// instance. This initializer creates a new pointer to the same address as
254-
/// `other` and performs no allocation or copying.
255-
///
256-
/// - Parameter other: The typed pointer to convert. If `other` is `nil`, the
257-
/// result is `nil`.
258-
@_transparent
250+
/// Creates a new raw pointer from the given typed pointer.
251+
///
252+
/// Use this initializer to explicitly convert `other` to an `UnsafeRawPointer`
253+
/// instance. This initializer creates a new pointer to the same address as
254+
/// `other` and performs no allocation or copying.
255+
///
256+
/// - Parameter other: The typed pointer to convert. If `other` is `nil`, the
257+
/// result is `nil`.
258+
@_transparent
259259
public init?<T>(@_nonEphemeral _ other: UnsafeMutablePointer<T>?) {
260-
guard let unwrapped = other else { return nil }
261-
_rawValue = unwrapped._rawValue
262-
}
260+
guard let unwrapped = other else { return nil }
261+
_rawValue = unwrapped._rawValue
262+
}
263263

264264
/// Deallocates the previously allocated memory block referenced by this pointer.
265265
///

0 commit comments

Comments
 (0)