Files
swift-mirror/test/SILGen/conformance_requirement_order.swift
Slava Pestov 38c478f5ee AST: Look through module aliases in TypeDecl::compare()
The last step in building a generic signature is to sort the requirements.
Requirements are sorted by comparing their subject types. If two
requirements have the same subject type, which can only happen with
conformance requirements, we break the tie by comparing protocol
declarations.

We compare protocol declarations using TypeDecl::compare(), which is a
shortlex order on the components of the fully qualified name of a
protocol (eg, Swift.Sequence, etc.)

While this order is part of the ABI, it has not been updated over the
years for several important changes:

- It did not handle module aliases; if we import a module via an
  alias, we should use the real module name to compare protocols, and
  not the aliased name. This produced inconsistent results if the
  same module was imported under different names, which can happen
  with module interface files that use module aliases.

- It did not handle the -module-abi-name flag. Changing the ABI name
  of a module changes how we mangle protocol names, and the order
  should match the mangling.

This change fixes the first case only. The second requires more
careful staging, because of _Concurrency and CompilerSwiftSyntax.

Fixes rdar://147441890.
2025-03-27 16:38:47 -04:00

16 lines
765 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module %s -module-name Horse -D LIB -emit-module-path %t/Horse.swiftmodule
// RUN: %target-swift-emit-silgen %s -module-name main -I %t -module-alias SwiftHorse=Horse | %FileCheck %s
#if LIB
public protocol Equine {}
#else
import SwiftHorse
// Make sure we use the module's real name, and not its alias name, so that
// we always have Horse.Equine < Swift.Equatable. If this doesn't hold, the
// two requirements in the mangling will be flipped.
// CHECK-LABEL: sil hidden [ossa] @$s4main21requirementOrderHorseyyx0D06EquineRzSQRzlF : $@convention(thin) <T where T : Equine, T : Equatable> (@in_guaranteed T) -> () {
func requirementOrderHorse<T: Equine & Equatable>(_: T) {}
#endif