mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report. Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected. This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
68 lines
2.6 KiB
C++
68 lines
2.6 KiB
C++
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-swift-frontend %S/setter-in-cxx.swift -module-name Properties -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/properties.h
|
|
|
|
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-props-execution.o
|
|
// RUN: %target-interop-build-swift %S/setter-in-cxx.swift -o %t/swift-props-execution -Xlinker %t/swift-props-execution.o -module-name Properties -Xfrontend -entry-point-function-name -Xfrontend swiftMain
|
|
|
|
// RUN: %target-codesign %t/swift-props-execution
|
|
// RUN: %target-run %t/swift-props-execution | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
#include <assert.h>
|
|
#include "properties.h"
|
|
|
|
int main() {
|
|
using namespace Properties;
|
|
|
|
auto smallStructWithProps = createSmallStructWithProps();
|
|
smallStructWithProps.setStoredInt(12);
|
|
assert(smallStructWithProps.getStoredInt() == 12);
|
|
assert(smallStructWithProps.getComputedInt() == 14);
|
|
smallStructWithProps.setComputedInt(45);
|
|
assert(smallStructWithProps.getStoredInt() == 43);
|
|
assert(smallStructWithProps.getComputedInt() == 45);
|
|
|
|
auto largeStructWithProps = smallStructWithProps.getLargeStructWithProps();
|
|
assert(largeStructWithProps.getStoredSmallStruct().getX() == 0xFAE);
|
|
largeStructWithProps.setStoredSmallStruct(createFirstSmallStruct(999));
|
|
assert(largeStructWithProps.getStoredSmallStruct().getX() == 999);
|
|
|
|
auto firstSmallStruct = largeStructWithProps.getStoredSmallStruct();
|
|
assert(firstSmallStruct.getX() == 999);
|
|
firstSmallStruct.setX(42);
|
|
assert(firstSmallStruct.getX() == 42);
|
|
|
|
largeStructWithProps.setStoredLargeStruct(largeStructWithProps.getStoredLargeStruct());
|
|
|
|
smallStructWithProps.setLargeStructWithProps(largeStructWithProps);
|
|
// CHECK: SET: LargeStruct(x1: 90, x2: 1, x3: 2, x4: 3, x5: 4, x6: 5), FirstSmallStruct(x: 999)
|
|
|
|
auto largeStruct = largeStructWithProps.getStoredLargeStruct();
|
|
largeStruct.setX1(0);
|
|
largeStruct.setX2(largeStruct.getX2() * 2);
|
|
largeStruct.setX3(-72);
|
|
largeStructWithProps.setStoredLargeStruct(largeStruct);
|
|
|
|
smallStructWithProps.setLargeStructWithProps(largeStructWithProps);
|
|
// CHECK-NEXT: SET: LargeStruct(x1: 0, x2: 2, x3: -72, x4: 3, x5: 4, x6: 5), FirstSmallStruct(x: 999)
|
|
|
|
auto propsInClass = createPropsInClass(-1234);
|
|
assert(propsInClass.getStoredInt() == -1234);
|
|
propsInClass.setStoredInt(45);
|
|
assert(propsInClass.getStoredInt() == 45);
|
|
propsInClass.setComputedInt(-11);
|
|
assert(propsInClass.getComputedInt() == -11);
|
|
assert(propsInClass.getStoredInt() == -13);
|
|
|
|
{
|
|
auto x = LargeStruct::getStaticX();
|
|
assert(x == 0);
|
|
LargeStruct::setStaticX(13);
|
|
x = LargeStruct::getStaticX();
|
|
assert(x == 13);
|
|
}
|
|
return 0;
|
|
}
|