Skip to content

[stdlib] ManagedBuffer independent of malloc_size. #31686

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 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions include/swift/AST/PlatformKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ AVAILABILITY_PLATFORM(watchOSApplicationExtension, "application extensions for w
AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS")
AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst")
AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst")
AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD")

#undef AVAILABILITY_PLATFORM
2 changes: 2 additions & 0 deletions lib/AST/PlatformKind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform,
case PlatformKind::watchOS:
case PlatformKind::watchOSApplicationExtension:
return Target.isWatchOS();
case PlatformKind::OpenBSD:
return Target.isOSOpenBSD();
case PlatformKind::none:
llvm_unreachable("handled above");
}
Expand Down
11 changes: 11 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
"APIs deprecated as of macOS 10.9 and earlier are unavailable in Swift";
break;

case PlatformKind::OpenBSD:
deprecatedAsUnavailableMessage = "";
break;

case PlatformKind::none:
break;
}
Expand Down Expand Up @@ -1962,6 +1966,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
case PlatformKind::watchOSApplicationExtension:
return name == "watchos" || name == "watchos_app_extension";

case PlatformKind::OpenBSD:
return name == "openbsd";

case PlatformKind::none:
return false;
}
Expand Down Expand Up @@ -2001,6 +2008,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
case PlatformKind::watchOSApplicationExtension:
// No deprecation filter on watchOS
return false;

case PlatformKind::OpenBSD:
// No deprecation filter on OpenBSD
return false;
}

llvm_unreachable("Unexpected platform");
Expand Down
3 changes: 3 additions & 0 deletions lib/PrintAsObjC/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,9 @@ class DeclAndTypePrinter::Implementation
case PlatformKind::watchOSApplicationExtension:
plat = "watchos_app_extension";
break;
case PlatformKind::OpenBSD:
plat = "openbsd";
break;
case PlatformKind::none:
llvm_unreachable("handled above");
}
Expand Down
2 changes: 2 additions & 0 deletions lib/SymbolGraphGen/AvailabilityMixin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ StringRef getDomain(const AvailableAttr &AvAttr) {
return { "tvOSAppExtension" };
case swift::PlatformKind::watchOSApplicationExtension:
return { "watchOSAppExtension" };
case swift::PlatformKind::OpenBSD:
return { "OpenBSD" };
case swift::PlatformKind::none:
return { "*" };
}
Expand Down
2 changes: 2 additions & 0 deletions lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
switch(Ver.Platform) {
case swift::PlatformKind::none:
llvm_unreachable("cannot find platform kind");
case swift::PlatformKind::OpenBSD:
llvm_unreachable("not used for this platform");
case swift::PlatformKind::iOS:
case swift::PlatformKind::iOSApplicationExtension:
return Ver.IsSimulator ? LinkerPlatformId::iOS_sim:
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/BridgingBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal final class __BridgingBufferStorage
internal typealias _BridgingBuffer
= ManagedBufferPointer<_BridgingBufferHeader, AnyObject>

@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
extension ManagedBufferPointer
where Header == _BridgingBufferHeader, Element == AnyObject {
internal init(_ count: Int) {
Expand Down
4 changes: 4 additions & 0 deletions stdlib/public/core/ManagedBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extension ManagedBuffer {
/// idea to store this information in the "header" area when
/// an instance is created.
@inlinable
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
public final var capacity: Int {
let storageAddr = UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(self))
let endAddr = storageAddr + _swift_stdlib_malloc_size(storageAddr)
Expand Down Expand Up @@ -197,6 +198,7 @@ public struct ManagedBufferPointer<Header, Element> {
/// properties. The `deinit` of `bufferClass` must destroy its
/// stored `Header` and any constructed `Element`s.
@inlinable
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
public init(
bufferClass: AnyClass,
minimumCapacity: Int,
Expand Down Expand Up @@ -329,6 +331,7 @@ extension ManagedBufferPointer {
/// idea to store this information in the "header" area when
/// an instance is created.
@inlinable
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
public var capacity: Int {
return (
_capacityInBytes &- ManagedBufferPointer._elementOffset
Expand Down Expand Up @@ -431,6 +434,7 @@ extension ManagedBufferPointer {

/// The actual number of bytes allocated for this object.
@inlinable
@available(OpenBSD, unavailable, message: "malloc_size is unavailable.")
internal var _capacityInBytes: Int {
return _swift_stdlib_malloc_size(_address)
}
Expand Down
1 change: 1 addition & 0 deletions test/IDE/complete_decl_attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct MyStruct {}
// AVAILABILITY1-NEXT: Keyword/None: macOSApplicationExtension[#Platform#]; name=macOSApplicationExtension{{$}}
// AVAILABILITY1-NEXT: Keyword/None: macCatalyst[#Platform#]; name=macCatalyst
// AVAILABILITY1-NEXT: Keyword/None: macCatalystApplicationExtension[#Platform#]; name=macCatalystApplicationExtension
// AVAILABILITY1-NEXT: Keyword/None: OpenBSD[#Platform#]; name=OpenBSD{{$}}
// AVAILABILITY1-NEXT: End completions

@available(*, #^AVAILABILITY2^#)
Expand Down
1 change: 1 addition & 0 deletions test/Interpreter/generic_ref_counts.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift | %FileCheck %s
// REQUIRES: executable_test
// XFAIL: OS=openbsd

import Swift

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/ManagedBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// XFAIL: OS=openbsd

import StdlibUnittest

Expand Down
3 changes: 3 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ static void reportAttributes(ASTContext &Ctx,
static UIdent PlatformOSXAppExt("source.availability.platform.osx_app_extension");
static UIdent PlatformtvOSAppExt("source.availability.platform.tvos_app_extension");
static UIdent PlatformWatchOSAppExt("source.availability.platform.watchos_app_extension");
static UIdent PlatformOpenBSD("source.availability.platform.openbsd");
std::vector<const DeclAttribute*> Scratch;

for (auto Attr : getDeclAttributes(D, Scratch)) {
Expand Down Expand Up @@ -702,6 +703,8 @@ static void reportAttributes(ASTContext &Ctx,
PlatformUID = PlatformtvOSAppExt; break;
case PlatformKind::watchOSApplicationExtension:
PlatformUID = PlatformWatchOSAppExt; break;
case PlatformKind::OpenBSD:
PlatformUID = PlatformOpenBSD; break;
}

AvailableAttrInfo Info;
Expand Down