Skip to content

SILGen: Remove obsolete hack preventing emission of allocating init for unavailable initializer #31800

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
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
7 changes: 0 additions & 7 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,6 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
if (isa<ProtocolDecl>(decl->getDeclContext()))
return;

// Always-unavailable imported constructors are factory methods
// that have been imported as constructors and then hidden by an
// imported init method.
if (decl->hasClangNode() &&
decl->getAttrs().isUnavailable(decl->getASTContext()))
return;

SILDeclRef constant(decl);
DeclContext *declCtx = decl->getDeclContext();

Expand Down
6 changes: 6 additions & 0 deletions test/SILGen/Inputs/objc_init_unavailable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import Foundation;

@interface ClassWithUnavailableInit : NSObject

- (instancetype)initWithBundleID:(NSString *)bundleID __attribute__((availability(macos, unavailable)));
@end
19 changes: 19 additions & 0 deletions test/SILGen/objc_init_unavailable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) -enable-objc-interop -import-objc-header %S/Inputs/objc_init_unavailable.h %s | %FileCheck %s
// REQUIRES: objc_interop

@available(macOS, unavailable)
public func callUnavailableInit(name: String) -> ClassWithUnavailableInit {
return ClassWithUnavailableInit(bundleID: name)
}

// CHECK-LABEL: sil [ossa] @$s21objc_init_unavailable19callUnavailableInit4nameSo09ClassWitheF0CSS_tF : $@convention(thin) (@guaranteed String) -> @owned ClassWithUnavailableInit {
// CHECK: function_ref @$sSo24ClassWithUnavailableInitC8bundleIDABSgSSSg_tcfC : $@convention(method) (@owned Optional<String>, @thick ClassWithUnavailableInit.Type) -> @owned Optional<ClassWithUnavailableInit>
// CHECK: return

// CHECK-LABEL: sil shared [serializable] [ossa] @$sSo24ClassWithUnavailableInitC8bundleIDABSgSSSg_tcfC : $@convention(method) (@owned Optional<String>, @thick ClassWithUnavailableInit.Type) -> @owned Optional<ClassWithUnavailableInit> {
// CHECK: function_ref @$sSo24ClassWithUnavailableInitC8bundleIDABSgSSSg_tcfcTO : $@convention(method) (@owned Optional<String>, @owned ClassWithUnavailableInit) -> @owned Optional<ClassWithUnavailableInit>
// CHECK: return

// CHECK-LABEL: sil shared [serializable] [thunk] [ossa] @$sSo24ClassWithUnavailableInitC8bundleIDABSgSSSg_tcfcTO : $@convention(method) (@owned Optional<String>, @owned ClassWithUnavailableInit) -> @owned Optional<ClassWithUnavailableInit> {
// CHECK: objc_method %1 : $ClassWithUnavailableInit, #ClassWithUnavailableInit.init!initializer.foreign : (ClassWithUnavailableInit.Type) -> (String?) -> ClassWithUnavailableInit?, $@convention(objc_method) (Optional<NSString>, @owned ClassWithUnavailableInit) -> @owned Optional<ClassWithUnavailableInit>
// CHECK: return