Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.
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
29 changes: 16 additions & 13 deletions lib/APINotes/APINotesReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,27 +1487,30 @@ APINotesReader::VersionedInfo<T>::VersionedInfo(
SmallVector<std::pair<VersionTuple, T>, 1> results)
: Results(std::move(results)) {

// Look for an exact version match.
Optional<unsigned> unversioned;
Selected = Results.size();
assert(!Results.empty());
assert(std::is_sorted(Results.begin(), Results.end(),
[](const std::pair<VersionTuple, T> &left,
const std::pair<VersionTuple, T> &right) -> bool {
assert(left.first != right.first && "two entries for the same version");
return left.first < right.first;
}));

Selected = Results.size();
for (unsigned i = 0, n = Results.size(); i != n; ++i) {
if (Results[i].first == version) {
if (version && Results[i].first >= version) {
// If the current version is "4", then entries for 4 are better than
// entries for 5, but both are valid. Because entries are sorted, we get
// that behavior by picking the first match.
Selected = i;
break;
}

if (!Results[i].first) {
assert(!unversioned && "Two unversioned entries?");
unversioned = i;
}
}

// If we didn't find a match but we have an unversioned result, use the
// unversioned result.
if (Selected == Results.size() && unversioned) {
Selected = *unversioned;
}
// unversioned result. This will always be the first entry because we encode
// it as version 0.
if (Selected == Results.size() && Results[0].first.empty())
Selected = 0;
}

auto APINotesReader::lookupObjCClassID(StringRef name) -> Optional<ContextID> {
Expand Down
10 changes: 8 additions & 2 deletions lib/APINotes/APINotesWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,16 @@ namespace {
template<typename T>
void emitVersionedInfo(
raw_ostream &out,
const SmallVectorImpl<std::pair<VersionTuple, T>> &infoArray,
SmallVectorImpl<std::pair<VersionTuple, T>> &infoArray,
llvm::function_ref<void(raw_ostream &out,
const typename MakeDependent<T>::Type& info)>
emitInfo) {
std::sort(infoArray.begin(), infoArray.end(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No array_pod_sort, eh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessarily POD, is it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. Maybe not by the language definition., but it'd work. std::sort() is not exactly a small thing to instantiate.

[](const std::pair<VersionTuple, T> &left,
const std::pair<VersionTuple, T> &right) -> bool {
assert(left.first != right.first && "two entries for the same version");
return left.first < right.first;
});
endian::Writer<little> writer(out);
writer.write<uint16_t>(infoArray.size());
for (const auto &element : infoArray) {
Expand Down Expand Up @@ -528,7 +534,7 @@ namespace {
using key_type_ref = key_type;
using data_type =
SmallVector<std::pair<VersionTuple, UnversionedDataType>, 1>;
using data_type_ref = const data_type &;
using data_type_ref = data_type &;
using hash_value_type = size_t;
using offset_type = unsigned;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Tags:
EnumKind: NSClosedEnum
- Name: UndoAllThatHasBeenDoneToMe
EnumKind: none
Typedefs:
- Name: MultiVersionedTypedef34Notes
SwiftName: MultiVersionedTypedef34Notes_NEW
- Name: MultiVersionedTypedef345Notes
SwiftName: MultiVersionedTypedef345Notes_NEW
- Name: MultiVersionedTypedef4Notes
SwiftName: MultiVersionedTypedef4Notes_NEW
- Name: MultiVersionedTypedef45Notes
SwiftName: MultiVersionedTypedef45Notes_NEW
SwiftVersions:
- Version: 3.0
Classes:
Expand Down Expand Up @@ -87,6 +96,55 @@ SwiftVersions:
Typedefs:
- Name: MyDoubleWrapper
SwiftWrapper: none



- Name: MultiVersionedTypedef34
SwiftName: MultiVersionedTypedef34_3
- Name: MultiVersionedTypedef34Header
SwiftName: MultiVersionedTypedef34Header_3
- Name: MultiVersionedTypedef34Notes
SwiftName: MultiVersionedTypedef34Notes_3
- Name: MultiVersionedTypedef345
SwiftName: MultiVersionedTypedef345_3
- Name: MultiVersionedTypedef345Header
SwiftName: MultiVersionedTypedef345Header_3
- Name: MultiVersionedTypedef345Notes
SwiftName: MultiVersionedTypedef345Notes_3
- Version: 5
Typedefs:
- Name: MultiVersionedTypedef345
SwiftName: MultiVersionedTypedef345_5
- Name: MultiVersionedTypedef345Header
SwiftName: MultiVersionedTypedef345Header_5
- Name: MultiVersionedTypedef345Notes
SwiftName: MultiVersionedTypedef345Notes_5
- Name: MultiVersionedTypedef45
SwiftName: MultiVersionedTypedef45_5
- Name: MultiVersionedTypedef45Header
SwiftName: MultiVersionedTypedef45Header_5
- Name: MultiVersionedTypedef45Notes
SwiftName: MultiVersionedTypedef45Notes_5
- Version: 4 # Versions are deliberately ordered as "3, 5, 4" to catch bugs.
Typedefs:
- Name: MultiVersionedTypedef34
SwiftName: MultiVersionedTypedef34_4
- Name: MultiVersionedTypedef34Header
SwiftName: MultiVersionedTypedef34Header_4
- Name: MultiVersionedTypedef34Notes
SwiftName: MultiVersionedTypedef34Notes_4
- Name: MultiVersionedTypedef345
SwiftName: MultiVersionedTypedef345_4
- Name: MultiVersionedTypedef345Header
SwiftName: MultiVersionedTypedef345Header_4
- Name: MultiVersionedTypedef345Notes
SwiftName: MultiVersionedTypedef345Notes_4
- Name: MultiVersionedTypedef4
SwiftName: MultiVersionedTypedef4_4
- Name: MultiVersionedTypedef4Header
SwiftName: MultiVersionedTypedef4Header_4
- Name: MultiVersionedTypedef4Notes
SwiftName: MultiVersionedTypedef4Notes_4
- Name: MultiVersionedTypedef45
SwiftName: MultiVersionedTypedef45_4
- Name: MultiVersionedTypedef45Header
SwiftName: MultiVersionedTypedef45Header_4
- Name: MultiVersionedTypedef45Notes
SwiftName: MultiVersionedTypedef45Notes_4
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ void moveToPointDUMP(double x, double y) __attribute__((swift_name("moveTo(x:y:)

void acceptClosure(void (^ __attribute__((noescape)) block)(void));

void privateFunc(void) __attribute__((swift_private));

typedef double MyDoubleWrapper __attribute__((swift_wrapper(struct)));

#if __OBJC__
@class NSString;

extern NSString *MyErrorDomain;
Expand All @@ -14,10 +19,6 @@ __attribute__((swift_bridge("MyValueType")))
@interface MyReferenceType
@end

void privateFunc(void) __attribute__((swift_private));

typedef double MyDoubleWrapper __attribute__((swift_wrapper(struct)));

@interface TestProperties
@property (nonatomic, readwrite, retain) id accessorsOnly;
@property (nonatomic, readwrite, retain, class) id accessorsOnlyForClass;
Expand All @@ -42,6 +43,7 @@ typedef double MyDoubleWrapper __attribute__((swift_wrapper(struct)));
__attribute__((swift_name("Swift4Name")))
@interface Swift3RenamedAlsoDUMP
@end
#endif


enum __attribute__((flag_enum)) FlagEnum {
Expand Down Expand Up @@ -110,3 +112,20 @@ enum SoonToBeNSClosedEnum {
enum UndoAllThatHasBeenDoneToMe {
UndoAllThatHasBeenDoneToMeA = 1
} __attribute__((flag_enum)) __attribute__((enum_extensibility(closed)));


typedef int MultiVersionedTypedef4;
typedef int MultiVersionedTypedef4Notes;
typedef int MultiVersionedTypedef4Header __attribute__((swift_name("MultiVersionedTypedef4Header_NEW")));

typedef int MultiVersionedTypedef34;
typedef int MultiVersionedTypedef34Notes;
typedef int MultiVersionedTypedef34Header __attribute__((swift_name("MultiVersionedTypedef34Header_NEW")));

typedef int MultiVersionedTypedef45;
typedef int MultiVersionedTypedef45Notes;
typedef int MultiVersionedTypedef45Header __attribute__((swift_name("MultiVersionedTypedef45Header_NEW")));

typedef int MultiVersionedTypedef345;
typedef int MultiVersionedTypedef345Notes;
typedef int MultiVersionedTypedef345Header __attribute__((swift_name("MultiVersionedTypedef345Header_NEW")));
69 changes: 69 additions & 0 deletions test/APINotes/versioned-multi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// RUN: rm -rf %t && mkdir -p %t

// Build and check the unversioned module file.
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Unversioned -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
// RUN: %clang_cc1 -ast-print %t/ModulesCache/Unversioned/VersionedKit.pcm | FileCheck -check-prefix=CHECK-UNVERSIONED %s

// Build and check the various versions.
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Versioned3 -fdisable-module-hash -fapinotes-modules -fapinotes-swift-version=3 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
// RUN: %clang_cc1 -ast-print %t/ModulesCache/Versioned3/VersionedKit.pcm | FileCheck -check-prefix=CHECK-VERSIONED-3 %s

// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Versioned4 -fdisable-module-hash -fapinotes-modules -fapinotes-swift-version=4 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
// RUN: %clang_cc1 -ast-print %t/ModulesCache/Versioned4/VersionedKit.pcm | FileCheck -check-prefix=CHECK-VERSIONED-4 %s

// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Versioned5 -fdisable-module-hash -fapinotes-modules -fapinotes-swift-version=5 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
// RUN: %clang_cc1 -ast-print %t/ModulesCache/Versioned5/VersionedKit.pcm | FileCheck -check-prefix=CHECK-VERSIONED-5 %s

#import <VersionedKit/VersionedKit.h>

// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef4;
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef4Notes __attribute__((swift_name("MultiVersionedTypedef4Notes_NEW")));
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef4Header __attribute__((swift_name("MultiVersionedTypedef4Header_NEW")));
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef34;
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef34Notes __attribute__((swift_name("MultiVersionedTypedef34Notes_NEW")));
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef34Header __attribute__((swift_name("MultiVersionedTypedef34Header_NEW")));
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef45;
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef45Notes __attribute__((swift_name("MultiVersionedTypedef45Notes_NEW")));
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef45Header __attribute__((swift_name("MultiVersionedTypedef45Header_NEW")));
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef345;
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef345Notes __attribute__((swift_name("MultiVersionedTypedef345Notes_NEW")));
// CHECK-UNVERSIONED: typedef int MultiVersionedTypedef345Header __attribute__((swift_name("MultiVersionedTypedef345Header_NEW")));

// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef4 __attribute__((swift_name("MultiVersionedTypedef4_4")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef4Notes __attribute__((swift_name("MultiVersionedTypedef4Notes_4")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef4Header __attribute__((swift_name("MultiVersionedTypedef4Header_4")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef34 __attribute__((swift_name("MultiVersionedTypedef34_3")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef34Notes __attribute__((swift_name("MultiVersionedTypedef34Notes_3")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef34Header __attribute__((swift_name("MultiVersionedTypedef34Header_3")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef45 __attribute__((swift_name("MultiVersionedTypedef45_4")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef45Notes __attribute__((swift_name("MultiVersionedTypedef45Notes_4")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef45Header __attribute__((swift_name("MultiVersionedTypedef45Header_4")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef345 __attribute__((swift_name("MultiVersionedTypedef345_3")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef345Notes __attribute__((swift_name("MultiVersionedTypedef345Notes_3")));
// CHECK-VERSIONED-3: typedef int MultiVersionedTypedef345Header __attribute__((swift_name("MultiVersionedTypedef345Header_3")));

// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef4 __attribute__((swift_name("MultiVersionedTypedef4_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef4Notes __attribute__((swift_name("MultiVersionedTypedef4Notes_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef4Header __attribute__((swift_name("MultiVersionedTypedef4Header_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef34 __attribute__((swift_name("MultiVersionedTypedef34_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef34Notes __attribute__((swift_name("MultiVersionedTypedef34Notes_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef34Header __attribute__((swift_name("MultiVersionedTypedef34Header_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef45 __attribute__((swift_name("MultiVersionedTypedef45_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef45Notes __attribute__((swift_name("MultiVersionedTypedef45Notes_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef45Header __attribute__((swift_name("MultiVersionedTypedef45Header_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef345 __attribute__((swift_name("MultiVersionedTypedef345_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef345Notes __attribute__((swift_name("MultiVersionedTypedef345Notes_4")));
// CHECK-VERSIONED-4: typedef int MultiVersionedTypedef345Header __attribute__((swift_name("MultiVersionedTypedef345Header_4")));

// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef4;
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef4Notes __attribute__((swift_name("MultiVersionedTypedef4Notes_NEW")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef4Header __attribute__((swift_name("MultiVersionedTypedef4Header_NEW")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef34;
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef34Notes __attribute__((swift_name("MultiVersionedTypedef34Notes_NEW")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef34Header __attribute__((swift_name("MultiVersionedTypedef34Header_NEW")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef45 __attribute__((swift_name("MultiVersionedTypedef45_5")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef45Notes __attribute__((swift_name("MultiVersionedTypedef45Notes_5")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef45Header __attribute__((swift_name("MultiVersionedTypedef45Header_5")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef345 __attribute__((swift_name("MultiVersionedTypedef345_5")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef345Notes __attribute__((swift_name("MultiVersionedTypedef345Notes_5")));
// CHECK-VERSIONED-5: typedef int MultiVersionedTypedef345Header __attribute__((swift_name("MultiVersionedTypedef345Header_5")));
12 changes: 6 additions & 6 deletions test/APINotes/versioned.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@
// CHECK-UNVERSIONED: void acceptClosure(void (^block)(void) __attribute__((noescape)));
// CHECK-VERSIONED: void acceptClosure(void (^block)(void));

// CHECK-UNVERSIONED: void privateFunc() __attribute__((swift_private));

// CHECK-UNVERSIONED: typedef double MyDoubleWrapper __attribute__((swift_wrapper("struct")));

// CHECK-UNVERSIONED: enum MyErrorCode {
// CHECK-UNVERSIONED-NEXT: MyErrorCodeFailed = 1
// CHECK-UNVERSIONED-NEXT: } __attribute__((ns_error_domain(MyErrorDomain)));

// CHECK-UNVERSIONED: __attribute__((swift_bridge("MyValueType")))
// CHECK-UNVERSIONED: @interface MyReferenceType

// CHECK-UNVERSIONED: void privateFunc() __attribute__((swift_private));
// CHECK-VERSIONED: void privateFunc();

// CHECK-UNVERSIONED: typedef double MyDoubleWrapper __attribute__((swift_wrapper("struct")));
// CHECK-VERSIONED: typedef double MyDoubleWrapper;

// CHECK-VERSIONED: enum MyErrorCode {
// CHECK-VERSIONED-NEXT: MyErrorCodeFailed = 1
Expand All @@ -71,10 +75,6 @@
// CHECK-VERSIONED-NOT: __attribute__((swift_bridge("MyValueType")))
// CHECK-VERSIONED: @interface MyReferenceType

// CHECK-VERSIONED: void privateFunc();

// CHECK-VERSIONED: typedef double MyDoubleWrapper;

// CHECK-UNVERSIONED: __attribute__((swift_objc_members)
// CHECK-UNVERSIONED-NEXT: @interface TestProperties
// CHECK-VERSIONED-NOT: __attribute__((swift_objc_members)
Expand Down