mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +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.
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
|
|
// RUN: %target-swift-frontend %t/use-array.swift -module-name UseArray -enable-experimental-cxx-interop -typecheck -verify -emit-clang-header-path %t/UseArray.h
|
|
|
|
// RUN: %target-interop-build-clangxx -fno-exceptions -std=gnu++20 -c %t/array-execution.cpp -I %t -o %t/swift-stdlib-execution.o
|
|
// RUN: %target-build-swift %t/use-array.swift -o %t/swift-stdlib-execution -Xlinker %t/swift-stdlib-execution.o -module-name UseArray -Xfrontend -entry-point-function-name -Xfrontend swiftMain
|
|
// RUN: %target-codesign %t/swift-stdlib-execution
|
|
// RUN: %target-run %t/swift-stdlib-execution | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
//--- use-array.swift
|
|
@_expose(Cxx)
|
|
public func createArray(_ val: CInt) -> [CInt] {
|
|
return [val, val]
|
|
}
|
|
|
|
@_expose(Cxx)
|
|
public func passthroughArray(_ val: [CInt]) -> Array<CInt> {
|
|
return val
|
|
}
|
|
|
|
@_expose(Cxx)
|
|
public func printArray(_ val: Array<CInt>) {
|
|
print(val)
|
|
}
|
|
|
|
public func printStrings(_ strings: [String]) {
|
|
for s in strings {
|
|
print("GOT STRING '\(s)'")
|
|
}
|
|
print("DONE PRINTING.")
|
|
}
|
|
|
|
//--- array-execution.cpp
|
|
|
|
#include <cassert>
|
|
#include "UseArray.h"
|
|
|
|
int main() {
|
|
using namespace swift;
|
|
{
|
|
Array<int> val = UseArray::createArray(2);
|
|
UseArray::printArray(UseArray::passthroughArray(val));
|
|
int count = 2;
|
|
for (int x: val) {
|
|
assert(x == 2);
|
|
--count;
|
|
}
|
|
assert(count == 0);
|
|
}
|
|
// CHECK: [2, 2]
|
|
{
|
|
auto val = Array<int>::init();
|
|
val.append(-11);
|
|
UseArray::printArray(val);
|
|
assert(val.getCount() == 1);
|
|
assert(val.getCapacity() >= 1);
|
|
auto zeroInt = val[0];
|
|
assert(zeroInt == -11);
|
|
auto firstInt = val.removeAt(0);
|
|
assert(firstInt == -11);
|
|
assert(val.getCount() == 0);
|
|
UseArray::printArray(val);
|
|
}
|
|
// CHECK-NEXT: [-11]
|
|
// CHECK-NEXT: []
|
|
{
|
|
auto array = swift::Array<swift::String>::init();
|
|
array.append("123456789ABCDEFG");
|
|
UseArray::printStrings(array);
|
|
}
|
|
// CHECK-NEXT: GOT STRING '123456789ABCDEFG'
|
|
// CHECK-NEXT: DONE PRINTING
|
|
return 0;
|
|
}
|