Skip to content

[nfc] Add tests for witness table size optimizations. #34995

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 1 commit into from
Feb 1, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ module CustomDestructor {
header "custom-destructors.h"
requires cplusplus
}

module WitnessLayoutOpts {
header "witness-layout-opts.h"
requires cplusplus
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LAYOUT_H
#define TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LAYOUT_H

struct Empty { };

struct I8Size { char value; };

struct I32Size { char value[3]; char other; };

#endif // TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LAYOUT_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s

// This test checks that the compiler uses well-known witness tables for types
// that have the appropriate size/shape (for example, { i8 x 4 } -> i32).

// These witness tables look very differnt on Windows so it doesn't make sense
// to test them in the same file.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the comment says, the witness tables appear fairly different on Windows, so I don't think it's feasible to test both platforms in the same file. If anyone disagrees, let me know and I'll investigate further / update the test.

// XFAIL: OS=windows-msvc

import WitnessLayoutOpts

protocol Dummy { }

// CHECK-DAG: @"$sBi8_WV" = external global i8*, align 8
// CHECK-DAG: @"$sSo5EmptyVMf" = linkonce_odr hidden constant {{.*}}@"$sBi8_WV"

extension Empty : Dummy { }

// CHECK-DAG: @"$sSo6I8SizeVMf" = linkonce_odr hidden constant {{.*}}@"$sBi8_WV"
extension I8Size : Dummy { }

// CHECK-DAG: @"$sSo7I32SizeVWV" = linkonce_odr hidden constant %swift.vwtable { {{.*}} i8* bitcast (i32 (%swift.opaque*, i32, %swift.type*)* @"$sSo7I32SizeVwet" to i8*), i8* bitcast (void (%swift.opaque*, i32, i32, %swift.type*)* @"$sSo7I32SizeVwst" to i8*)
// CHECK-DAG: "$sSo7I32SizeVMf" = linkonce_odr hidden constant {{.*}}@"$sSo7I32SizeVWV"
extension I32Size : Dummy { }