Skip to content

AST: address code review comments on isEquivalentToExtendedContext() #32667

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
Jul 2, 2020
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
12 changes: 8 additions & 4 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,16 @@ bool ExtensionDecl::isConstrainedExtension() const {

bool ExtensionDecl::isEquivalentToExtendedContext() const {
auto decl = getExtendedNominal();
auto extendDeclfromSameModule =
getParentModule() == decl->getParentModule() ||
bool extendDeclFromSameModule = false;
if (!decl->getAlternateModuleName().empty()) {
// if the extended type was defined in the same module with the extension,
// we should consider them as the same module to preserve ABI stability.
decl->getAlternateModuleName() == getParentModule()->getNameStr();
return extendDeclfromSameModule
extendDeclFromSameModule = decl->getAlternateModuleName() ==
getParentModule()->getNameStr();
} else {
extendDeclFromSameModule = decl->getParentModule() == getParentModule();
}
return extendDeclFromSameModule
&& !isConstrainedExtension()
&& !getDeclaredInterfaceType()->isExistentialType();
}
Expand Down
15 changes: 11 additions & 4 deletions test/TBD/move_to_extension.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
// REQUIRES: OS=macosx
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -typecheck %s -emit-tbd -emit-tbd-path %t/before_move.tbd -D BEFORE_MOVE -module-name Foo -enable-library-evolution
// RUN: %target-swift-frontend -typecheck %s -emit-tbd -emit-tbd-path %t/before_move.tbd -D BEFORE_MOVE -module-name Foo -enable-library-evolution -emit-sil -o %t/before_move.sil
// RUN: %FileCheck %s < %t/before_move.tbd
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/before_move.sil

// RUN: %target-swift-frontend %s -emit-module -emit-module-path %t/FooCore.swiftmodule -D AFTER_MOVE_FOO_CORE -module-name FooCore -enable-library-evolution
// RUN: %target-swift-frontend -typecheck %s -emit-tbd -emit-tbd-path %t/after_move.tbd -D AFTER_MOVE_FOO -module-name Foo -I %t -enable-library-evolution
// RUN: %target-swift-frontend -typecheck %s -emit-tbd -emit-tbd-path %t/after_move.tbd -D AFTER_MOVE_FOO -module-name Foo -I %t -enable-library-evolution -emit-sil -o %t/after_move.sil
// RUN: %FileCheck %s < %t/after_move.tbd
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/after_move.sil

// CHECK: '_$s3Foo4DateC14getCurrentYearSiyFZ'
// CHECK: '_$s3Foo9DateValueV4yearACSi_tcfC'
// CHECK: '_$s3Foo9DateValueV4yearSivg'
// CHECK: '_$s3Foo9DateValueV4yearSivpMV'

// CHECK-SIL: sil [available 10.7] @$s3Foo4DateC14getCurrentYearSiyFZ : $@convention(method) (@thick Date.Type) -> Int
// CHECK-SIL: sil [available 10.7] @$s3Foo9DateValueV4yearACSi_tcfC : $@convention(method) (Int, @thin DateValue.Type) -> @out DateValue
// CHECK-SIL: sil [available 10.7] @$s3Foo9DateValueV4yearSivg : $@convention(method) (@in_guaranteed DateValue) -> Int

#if BEFORE_MOVE

@available(OSX 10.7, *)
public class Date {
public static func getCurrentYear() -> Int { return 2020 }
}

@available(OSX 10.7, *)
public struct DateValue {
public init(year: Int) {}
public var year: Int { return 2020 }
Expand Down Expand Up @@ -47,7 +54,7 @@ public extension Date {
}

public extension DateValue {
public init(year: Int) {}
public init(year: Int) { self.init(year: 2020) }
public var year: Int { return 2020 }
}

Expand Down