Skip to content

Sema: Fix some issues with overrides of materializeForSet #12614

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
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
15 changes: 11 additions & 4 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,10 +2097,17 @@ class Verifier : public ASTWalker {
"Storage overrides but setter does not");
if (ASD->getMaterializeForSetFunc() &&
baseASD->getMaterializeForSetFunc() &&
baseASD->isSetterAccessibleFrom(ASD->getDeclContext()))
assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() ==
baseASD->getMaterializeForSetFunc() &&
"Storage override but materializeForSet does not");
baseASD->isSetterAccessibleFrom(ASD->getDeclContext())) {
if (baseASD->getMaterializeForSetFunc()->hasForcedStaticDispatch()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For later: should this just be final?

assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() == nullptr
&& "Forced static dispatch materializeForSet should not be "
"overridden");
} else {
assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() ==
baseASD->getMaterializeForSetFunc() &&
"Storage override but materializeForSet does not");
}
}
} else {
if (ASD->getGetter())
assert(!ASD->getGetter()->getOverriddenDecl() &&
Expand Down
1 change: 1 addition & 0 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ static FuncDecl *addMaterializeForSet(AbstractStorageDecl *storage,
// materializeForSet either.
auto *baseMFS = baseASD->getMaterializeForSetFunc();
if (baseMFS != nullptr &&
!baseMFS->hasForcedStaticDispatch() &&
baseASD->isSetterAccessibleFrom(storage->getDeclContext())) {
materializeForSet->setOverriddenDecl(baseMFS);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6705,6 +6705,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
!baseASD->isSetterAccessibleFrom(overridingASD->getDeclContext()))
return;

// A materializeForSet for an override of storage with a
// forced static dispatch materializeForSet is not itself an
// override.
if (kind == AccessorKind::IsMaterializeForSet &&
baseAccessor->hasForcedStaticDispatch())
return;

// FIXME: Egregious hack to set an 'override' attribute.
if (!overridingAccessor->getAttrs().hasAttribute<OverrideAttr>()) {
auto loc = overridingASD->getOverrideLoc();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

final class Burger {
let onions: Bool = true
let cheeseSlices: Int = 0
Expand Down
6 changes: 2 additions & 4 deletions test/multifile/class-layout/final-stored-property/main.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// RUN: %target-build-swift %S/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift

// REQUIRES: executable_test
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift

func meltCheese(_ burger: Burger) -> Int {
return burger.cheeseSlices
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

struct t {
var a = false // (or e.g. var a: Int32 = 0)
var b = 0.0 // (or e.g. var b: Int64 = 0)
Expand Down
2 changes: 1 addition & 1 deletion test/multifile/constant-struct-with-padding/main.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)

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

print( g.a )
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
// RUN: true

var g = (false, 0.0)
2 changes: 1 addition & 1 deletion test/multifile/constant-tuple-with-padding/main.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)

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

print( g.0 )
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

public func go() throws {
throw AXError(0)
}
2 changes: 1 addition & 1 deletion test/multifile/error-type/imported/main.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// 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

// REQUIRES: objc_interop

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

enum NuclearMeltdown {
case Critical
case Mild
Expand Down
6 changes: 2 additions & 4 deletions test/multifile/error-type/one-module/main.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Try with and without whole module optimization

// RUN: %target-build-swift %S/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift

// REQUIRES: executable_test
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift

extension NuclearMeltdown : Error {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

public enum NuclearMeltdown {
case Critical
case Mild
Expand Down
6 changes: 2 additions & 4 deletions test/multifile/error-type/two-modules/main.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// RUN: %empty-directory(%t)

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

// REQUIRES: executable_test

import library

extension NuclearMeltdown : Error {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

public struct Point {
public let x: Int
public let y: Int
Expand Down
6 changes: 2 additions & 4 deletions test/multifile/extensions/two-modules/main.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// RUN: %empty-directory(%t)

// RUN: mkdir -p %t/onone %t/wmo
// 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
// 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
// RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main

// 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
// 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
// RUN: %target-build-swift %S/main.swift %t/wmo/library.%target-dylib-extension -I %t/wmo/ -o %t/wmo/main

// REQUIRES: executable_test

import library

extension Point {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

import Foundation

@inline(__always)
Expand Down
3 changes: 1 addition & 2 deletions test/multifile/imported-conformance/option-set/main.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// RUN: %empty-directory(%t)

// RUN: %empty-directory(%t/linker)
// 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
// 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
// RUN: %target-build-swift %S/main.swift -I %t/linker/ -L %t/linker/ -llibrary -o %t/linker/main

// REQUIRES: executable_test
// REQUIRES: objc_interop

import Foundation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>

@interface Counter : NSObject
@property(readwrite) int value;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation
import CounterFramework

public protocol CounterProtocol {
var value: Int32 { get set }
}

extension Counter : CounterProtocol {}

open class MyCounter : Counter {
open override var value: Int32 { didSet { } }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CounterFramework {
header "counter.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)

// RUN: mkdir -p %t/onone %t/wmo
// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -I %S/Inputs/ -module-name=library %S/Inputs/library.swift
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/onone/ -emit-ir > /dev/null

// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -I %S/Inputs/ -module-name=library -wmo %S/Inputs/library.swift
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/wmo/ -emit-ir > /dev/null

// REQUIRES: objc_interop

import Foundation
import library

class CustomCounter : MyCounter {
override var value: Int32 { didSet { } }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>

@interface Counter : NSObject
@property(readwrite) int value;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation
import CounterFramework

public protocol CounterProtocol {
var value: Int32 { get set }
}

extension Counter : CounterProtocol {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation
import CounterFramework

open class MyCounter : Counter {
open override var value: Int32 { didSet { } }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CounterFramework {
header "counter.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)

// RUN: mkdir -p %t/onone %t/wmo
// 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
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/onone/ -emit-ir > /dev/null

// 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
// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/wmo/ -emit-ir > /dev/null

// REQUIRES: objc_interop

import Foundation
import library

class CustomCounter : MyCounter {
override var value: Int32 { didSet { } }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

import CoreGraphics

// Case 1 - witness is imported accessor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Try with and without whole module optimization

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

// REQUIRES: executable_test
// REQUIRES: objc_interop

import CoreGraphics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

struct FishAndChips {
var costPounds: Float
var costEuros: Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Try with and without whole module optimization

// RUN: %target-build-swift %S/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift

// REQUIRES: executable_test
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift

protocol Takeaway {
var costPounds: Float { get set }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

public struct FishAndChips {
public var costPounds: Float
public var costEuros: Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Try with and without whole module optimization

// RUN: %target-build-swift %S/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift

// REQUIRES: executable_test
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift

protocol Takeaway {
var costPounds: Float { get set }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

import CoreGraphics

public protocol OtherPoint {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Try with and without whole module optimization

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

// REQUIRES: executable_test
// REQUIRES: objc_interop

import CoreGraphics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

#if _runtime(_ObjC)
import Foundation
#endif
Expand Down
6 changes: 2 additions & 4 deletions test/multifile/synthesized-accessors/two-modules/main.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// RUN: %empty-directory(%t)

// RUN: mkdir -p %t/onone %t/wmo
// 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
// 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
// RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main

// 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
// 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
// RUN: %target-build-swift %S/main.swift %t/wmo/library.%target-dylib-extension -I %t/wmo/ -o %t/wmo/main

// REQUIRES: executable_test

import library

protocol Takeaway {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

public enum Result<T, U>
{
case success(T)
Expand Down
6 changes: 2 additions & 4 deletions test/multifile/typealias/one-module/main.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// RUN: %empty-directory(%t)

// RUN: %target-build-swift %S/main.swift %S/library.swift
// RUN: %target-build-swift -g %S/main.swift %S/library.swift

// REQUIRES: executable_test
// RUN: %target-build-swift %S/main.swift %S/Inputs/library.swift
// RUN: %target-build-swift -g %S/main.swift %S/Inputs/library.swift

func testFunction<T>(withCompletion completion: (Result<T, Error>) -> Void) { }
testFunction { (result: GenericResult<Int>) in }
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// RUN: true

public enum Result<T, U>
{
case success(T)
Expand Down
Loading