swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

Compilation with enums is about 40x slower compared to compilation while cxx-interop is disabled #75617

Open machineko opened 1 month ago

machineko commented 1 month ago

Description

While trying to compile enum with cxx-interop turned on compiler is at least 30-40x times slower compared to version without cxx-interop. It is happening on both macOS and linux (debian) with swift 6.0-snapshot.

Reproduction

Minimal swift-package example

public enum CXXDataType: Int {
  case TYPE_R_16F = 2
  case TYPE_C_16F = 6
  case TYPE_R_16BF = 14
  case TYPE_C_16BF = 15
  case TYPE_R_32F = 0
  case TYPE_C_32F = 4
  case TYPE_R_64F = 1
  case TYPE_C_64F = 5
  case TYPE_R_4I = 16
  case TYPE_C_4I = 17
  case TYPE_R_4U = 18
  case TYPE_C_4U = 19
  case TYPE_R_8I = 3
  case TYPE_C_8I = 7
  case TYPE_R_8U = 8
  case TYPE_C_8U = 9
  case TYPE_R_16I = 20
  case TYPE_C_16I = 21
  case TYPE_R_16U = 22
  case TYPE_C_16U = 23
  case TYPE_R_32I = 10
  case TYPE_C_32I = 11
  case TYPE_R_32U = 12
  case TYPE_C_32U = 13
  case TYPE_R_64I = 24
  case TYPE_C_64I = 25
  case TYPE_R_64U = 26
  case TYPE_C_64U = 27
  case TYPE_R_8F_E4M3 = 28
  case TYPE_R_8F_E5M2 = 29
}
import Testing
@testable import cxxtest

@Test func example() async throws {
    let cxxtype = CXXDataType(rawValue: 0)
    #expect(cxxtype!.rawValue == 0)
}
 swiftSettings: [
    .interoperabilityMode(.Cxx),
] // for both .testTarget and .target
 cxxLanguageStandard: .cxx17

With cxx interop

swift test -c release
Building for production...
Build complete! (53.91s)
swift test
Building for debugging...
Build complete! (53.40s)

Without cxx interop

swift test -c release
Building for production...
Build complete!  (1.45s)
swift test
Building for debugging...
Build complete! (1.83s)

Expected behavior

compiling with cxx-interop turned on should be only a bit slower

Environment

1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)

Additional information

No response

tbkka commented 1 month ago

CC: @ravikandhadai

machineko commented 1 month ago

It seems to be also happening on Windows with 6.0 version