Skip to content

Commit 5c45f85

Browse files
authored
Merge pull request #12614 from slavapestov/imported-materialize-for-set-override-bugs
Sema: Fix some issues with overrides of materializeForSet
2 parents e423640 + 0f2da21 commit 5c45f85

File tree

43 files changed

+125
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+125
-83
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,10 +2097,17 @@ class Verifier : public ASTWalker {
20972097
"Storage overrides but setter does not");
20982098
if (ASD->getMaterializeForSetFunc() &&
20992099
baseASD->getMaterializeForSetFunc() &&
2100-
baseASD->isSetterAccessibleFrom(ASD->getDeclContext()))
2101-
assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() ==
2102-
baseASD->getMaterializeForSetFunc() &&
2103-
"Storage override but materializeForSet does not");
2100+
baseASD->isSetterAccessibleFrom(ASD->getDeclContext())) {
2101+
if (baseASD->getMaterializeForSetFunc()->hasForcedStaticDispatch()) {
2102+
assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() == nullptr
2103+
&& "Forced static dispatch materializeForSet should not be "
2104+
"overridden");
2105+
} else {
2106+
assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() ==
2107+
baseASD->getMaterializeForSetFunc() &&
2108+
"Storage override but materializeForSet does not");
2109+
}
2110+
}
21042111
} else {
21052112
if (ASD->getGetter())
21062113
assert(!ASD->getGetter()->getOverriddenDecl() &&

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ static FuncDecl *addMaterializeForSet(AbstractStorageDecl *storage,
857857
// materializeForSet either.
858858
auto *baseMFS = baseASD->getMaterializeForSetFunc();
859859
if (baseMFS != nullptr &&
860+
!baseMFS->hasForcedStaticDispatch() &&
860861
baseASD->isSetterAccessibleFrom(storage->getDeclContext())) {
861862
materializeForSet->setOverriddenDecl(baseMFS);
862863
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6711,6 +6711,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
67116711
!baseASD->isSetterAccessibleFrom(overridingASD->getDeclContext()))
67126712
return;
67136713

6714+
// A materializeForSet for an override of storage with a
6715+
// forced static dispatch materializeForSet is not itself an
6716+
// override.
6717+
if (kind == AccessorKind::IsMaterializeForSet &&
6718+
baseAccessor->hasForcedStaticDispatch())
6719+
return;
6720+
67146721
// FIXME: Egregious hack to set an 'override' attribute.
67156722
if (!overridingAccessor->getAttrs().hasAttribute<OverrideAttr>()) {
67166723
auto loc = overridingASD->getOverrideLoc();

test/multifile/class-layout/final-stored-property/library.swift renamed to test/multifile/class-layout/final-stored-property/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
final class Burger {
42
let onions: Bool = true
53
let cheeseSlices: Int = 0

test/multifile/class-layout/final-stored-property/main.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// RUN: %target-build-swift %S/library.swift %S/main.swift
2-
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
3-
4-
// REQUIRES: executable_test
1+
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
2+
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
53

64
func meltCheese(_ burger: Burger) -> Int {
75
return burger.cheeseSlices

test/multifile/constant-struct-with-padding/Other.swift renamed to test/multifile/constant-struct-with-padding/Inputs/other.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
struct t {
42
var a = false // (or e.g. var a: Int32 = 0)
53
var b = 0.0 // (or e.g. var b: Int64 = 0)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Other.swift
3+
// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Inputs/other.swift
44

55
print( g.a )
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
// RUN: true
2-
31
var g = (false, 0.0)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Other.swift
3+
// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Inputs/other.swift
44

55
print( g.0 )
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
public func go() throws {
42
throw AXError(0)
53
}

test/multifile/error-type/imported/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-build-swift -module-name objc_enum_errortype -emit-library %S/main.swift %S/library.swift -import-objc-header %S/objc_enum_errortype.h
1+
// RUN: %target-build-swift -module-name objc_enum_errortype -emit-library %S/main.swift %S/Inputs/library.swift -import-objc-header %S/Inputs/objc_enum_errortype.h
22

33
// REQUIRES: objc_interop
44

test/multifile/error-type/one-module/library.swift renamed to test/multifile/error-type/one-module/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
enum NuclearMeltdown {
42
case Critical
53
case Mild
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Try with and without whole module optimization
22

3-
// RUN: %target-build-swift %S/library.swift %S/main.swift
4-
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
5-
6-
// REQUIRES: executable_test
3+
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
4+
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
75

86
extension NuclearMeltdown : Error {}

test/multifile/error-type/two-modules/library.swift renamed to test/multifile/error-type/two-modules/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
public enum NuclearMeltdown {
42
case Critical
53
case Mild

test/multifile/error-type/two-modules/main.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// RUN: %empty-directory(%t)
22

33
// RUN: %empty-directory(%t/linker)
4-
// RUN: %target-build-swift -emit-module -c %S/library.swift -o %t/linker/library.o
5-
// RUN: %target-build-swift -emit-library -c %S/library.swift -o %t/linker/library.o
4+
// RUN: %target-build-swift -emit-module -c %S/Inputs/library.swift -o %t/linker/library.o
5+
// RUN: %target-build-swift -emit-library -c %S/Inputs/library.swift -o %t/linker/library.o
66
// RUN: %target-build-swift %S/main.swift %t/linker/library.o -I %t/linker/ -L %t/linker/ -o %t/linker/main
77

8-
// REQUIRES: executable_test
9-
108
import library
119

1210
extension NuclearMeltdown : Error {}

test/multifile/extensions/two-modules/library.swift renamed to test/multifile/extensions/two-modules/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
public struct Point {
42
public let x: Int
53
public let y: Int

test/multifile/extensions/two-modules/main.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// RUN: %empty-directory(%t)
22

33
// RUN: mkdir -p %t/onone %t/wmo
4-
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/library.swift -o %t/onone/library.%target-dylib-extension
4+
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/Inputs/library.swift -o %t/onone/library.%target-dylib-extension
55
// RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main
66

7-
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/library.swift -o %t/wmo/library.%target-dylib-extension
7+
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/Inputs/library.swift -o %t/wmo/library.%target-dylib-extension
88
// RUN: %target-build-swift %S/main.swift %t/wmo/library.%target-dylib-extension -I %t/wmo/ -o %t/wmo/main
99

10-
// REQUIRES: executable_test
11-
1210
import library
1311

1412
extension Point {

test/multifile/imported-conformance/option-set/library.swift renamed to test/multifile/imported-conformance/option-set/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
import Foundation
42

53
@inline(__always)

test/multifile/imported-conformance/option-set/main.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// RUN: %empty-directory(%t)
22

33
// RUN: %empty-directory(%t/linker)
4-
// RUN: %target-build-swift -emit-module -emit-library %S/library.swift -o %t/linker/liblibrary.%target-dylib-extension -emit-module-path %t/linker/library.swiftmodule -module-name library
4+
// RUN: %target-build-swift -emit-module -emit-library %S/Inputs/library.swift -o %t/linker/liblibrary.%target-dylib-extension -emit-module-path %t/linker/library.swiftmodule -module-name library
55
// RUN: %target-build-swift %S/main.swift -I %t/linker/ -L %t/linker/ -llibrary -o %t/linker/main
66

7-
// REQUIRES: executable_test
87
// REQUIRES: objc_interop
98

109
import Foundation
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface Counter : NSObject
4+
@property(readwrite) int value;
5+
@end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Foundation
2+
import CounterFramework
3+
4+
public protocol CounterProtocol {
5+
var value: Int32 { get set }
6+
}
7+
8+
extension Counter : CounterProtocol {}
9+
10+
open class MyCounter : Counter {
11+
open override var value: Int32 { didSet { } }
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CounterFramework {
2+
header "counter.h"
3+
export *
4+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: mkdir -p %t/onone %t/wmo
4+
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -I %S/Inputs/ -module-name=library %S/Inputs/library.swift
5+
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/onone/ -emit-ir > /dev/null
6+
7+
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -I %S/Inputs/ -module-name=library -wmo %S/Inputs/library.swift
8+
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/wmo/ -emit-ir > /dev/null
9+
10+
// REQUIRES: objc_interop
11+
12+
import Foundation
13+
import library
14+
15+
class CustomCounter : MyCounter {
16+
override var value: Int32 { didSet { } }
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface Counter : NSObject
4+
@property(readwrite) int value;
5+
@end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Foundation
2+
import CounterFramework
3+
4+
public protocol CounterProtocol {
5+
var value: Int32 { get set }
6+
}
7+
8+
extension Counter : CounterProtocol {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Foundation
2+
import CounterFramework
3+
4+
open class MyCounter : Counter {
5+
open override var value: Int32 { didSet { } }
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CounterFramework {
2+
header "counter.h"
3+
export *
4+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: mkdir -p %t/onone %t/wmo
4+
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -I %S/Inputs/ -module-name=library %S/Inputs/library1.swift %S/Inputs/library2.swift
5+
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/onone/ -emit-ir > /dev/null
6+
7+
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -I %S/Inputs/ -module-name=library -wmo %S/Inputs/library1.swift %S/Inputs/library2.swift
8+
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/wmo/ -emit-ir > /dev/null
9+
10+
// REQUIRES: objc_interop
11+
12+
import Foundation
13+
import library
14+
15+
class CustomCounter : MyCounter {
16+
override var value: Int32 { didSet { } }
17+
}

test/multifile/synthesized-accessors/one-module-imported/library.swift renamed to test/multifile/synthesized-accessors/one-module-imported/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
import CoreGraphics
42

53
// Case 1 - witness is imported accessor

test/multifile/synthesized-accessors/one-module-imported/main.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Try with and without whole module optimization
22

3-
// RUN: %target-build-swift %S/library.swift %S/main.swift
4-
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
3+
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
4+
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
55

6-
// REQUIRES: executable_test
76
// REQUIRES: objc_interop
87

98
import CoreGraphics

test/multifile/synthesized-accessors/one-module-internal/library.swift renamed to test/multifile/synthesized-accessors/one-module-internal/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
struct FishAndChips {
42
var costPounds: Float
53
var costEuros: Float {

test/multifile/synthesized-accessors/one-module-internal/main.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Try with and without whole module optimization
22

3-
// RUN: %target-build-swift %S/library.swift %S/main.swift
4-
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
5-
6-
// REQUIRES: executable_test
3+
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
4+
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
75

86
protocol Takeaway {
97
var costPounds: Float { get set }

test/multifile/synthesized-accessors/one-module-public/library.swift renamed to test/multifile/synthesized-accessors/one-module-public/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
public struct FishAndChips {
42
public var costPounds: Float
53
public var costEuros: Float {

test/multifile/synthesized-accessors/one-module-public/main.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Try with and without whole module optimization
22

3-
// RUN: %target-build-swift %S/library.swift %S/main.swift
4-
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
5-
6-
// REQUIRES: executable_test
3+
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
4+
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
75

86
protocol Takeaway {
97
var costPounds: Float { get set }

test/multifile/synthesized-accessors/two-modules-imported/library.swift renamed to test/multifile/synthesized-accessors/two-modules-imported/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
import CoreGraphics
42

53
public protocol OtherPoint {

test/multifile/synthesized-accessors/two-modules-imported/main.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Try with and without whole module optimization
22

3-
// RUN: %target-build-swift %S/library.swift %S/main.swift
4-
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
3+
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
4+
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
55

6-
// REQUIRES: executable_test
76
// REQUIRES: objc_interop
87

98
import CoreGraphics

test/multifile/synthesized-accessors/two-modules/library.swift renamed to test/multifile/synthesized-accessors/two-modules/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
#if _runtime(_ObjC)
42
import Foundation
53
#endif

test/multifile/synthesized-accessors/two-modules/main.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// RUN: %empty-directory(%t)
22

33
// RUN: mkdir -p %t/onone %t/wmo
4-
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/library.swift -o %t/onone/library.%target-dylib-extension
4+
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/Inputs/library.swift -o %t/onone/library.%target-dylib-extension
55
// RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main
66

7-
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/library.swift -o %t/wmo/library.%target-dylib-extension
7+
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/Inputs/library.swift -o %t/wmo/library.%target-dylib-extension
88
// RUN: %target-build-swift %S/main.swift %t/wmo/library.%target-dylib-extension -I %t/wmo/ -o %t/wmo/main
99

10-
// REQUIRES: executable_test
11-
1210
import library
1311

1412
protocol Takeaway {

test/multifile/typealias/one-module/library.swift renamed to test/multifile/typealias/one-module/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
public enum Result<T, U>
42
{
53
case success(T)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-build-swift %S/main.swift %S/library.swift
4-
// RUN: %target-build-swift -g %S/main.swift %S/library.swift
5-
6-
// REQUIRES: executable_test
3+
// RUN: %target-build-swift %S/main.swift %S/Inputs/library.swift
4+
// RUN: %target-build-swift -g %S/main.swift %S/Inputs/library.swift
75

86
func testFunction<T>(withCompletion completion: (Result<T, Error>) -> Void) { }
97
testFunction { (result: GenericResult<Int>) in }

test/multifile/typealias/two-modules/library.swift renamed to test/multifile/typealias/two-modules/Inputs/library.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// RUN: true
2-
31
public enum Result<T, U>
42
{
53
case success(T)

0 commit comments

Comments
 (0)