Skip to content

Serialization: Serialize FuncDecl::hasForcedStaticDispatch() #12594

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

Closed
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
3 changes: 2 additions & 1 deletion include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
/// in source control, you should also update the comment to briefly
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
const uint16_t VERSION_MINOR = 372; // Last change: VTable serialized
const uint16_t VERSION_MINOR = 373; // Last change: has forced static dispatch

using DeclID = PointerEmbeddedInt<unsigned, 31>;
using DeclIDField = BCFixed<31>;
Expand Down Expand Up @@ -955,6 +955,7 @@ namespace decls_block {
BCFixed<1>, // explicitly objc?
SelfAccessKindField, // self access kind
BCFixed<1>, // has dynamic self?
BCFixed<1>, // has forced static dispatch?
BCFixed<1>, // throws?
BCVBR<5>, // number of parameter patterns
GenericEnvironmentIDField, // generic environment
Expand Down
6 changes: 4 additions & 2 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
bool isImplicit;
bool isStatic;
uint8_t rawStaticSpelling, rawAccessLevel, rawAddressorKind, rawMutModifier;
bool isObjC, hasDynamicSelf, throws;
bool isObjC, hasDynamicSelf, hasForcedStaticDispatch, throws;
unsigned numParamPatterns, numNameComponentsBiased;
GenericEnvironmentID genericEnvID;
TypeID interfaceTypeID;
Expand All @@ -2885,7 +2885,8 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {

decls_block::FuncLayout::readRecord(scratch, contextID, isImplicit,
isStatic, rawStaticSpelling, isObjC,
rawMutModifier, hasDynamicSelf, throws,
rawMutModifier, hasDynamicSelf,
hasForcedStaticDispatch, throws,
numParamPatterns, genericEnvID,
interfaceTypeID,
associatedDeclID, overriddenID,
Expand Down Expand Up @@ -3030,6 +3031,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
if (isImplicit)
fn->setImplicit();
fn->setDynamicSelf(hasDynamicSelf);
fn->setForcedStaticDispatch(hasForcedStaticDispatch);
fn->setNeedsNewVTableEntry(needsNewVTableEntry);

if (auto defaultArgumentResilienceExpansion = getActualResilienceExpansion(
Expand Down
1 change: 1 addition & 0 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,7 @@ void Serializer::writeDecl(const Decl *D) {
uint8_t(
getStableSelfAccessKind(fn->getSelfAccessKind())),
fn->hasDynamicSelf(),
fn->hasForcedStaticDispatch(),
fn->hasThrows(),
fn->getParameterLists().size(),
addGenericEnvironmentRef(
Expand Down
5 changes: 5 additions & 0 deletions test/SILGen/Inputs/dynamic_witness_other_module_other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public class ExtremeLateBindingCounter {
@objc public dynamic var counter: Int = 0
}
20 changes: 20 additions & 0 deletions test/SILGen/dynamic_witness_other_module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-module %S/Inputs/dynamic_witness_other_module_other.swift -emit-module-path %t

// RUN: %target-swift-frontend -emit-silgen %s -I %t | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir %s -I %t > /dev/null

import dynamic_witness_other_module_other

protocol EvenMoreExtremeLateBindingCounter {
var counter: Int { get set }
}

extension ExtremeLateBindingCounter : EvenMoreExtremeLateBindingCounter {}

// Make sure we emit a direct reference to the witness's materializeForSet
// instead of dispatching via class_method.

// CHECK-LABEL: sil private [transparent] [thunk] @_T0029dynamic_witness_other_module_C025ExtremeLateBindingCounterC0a1_b1_c1_D008EvenMoreefgH0A2dEP7counterSivmTW : $@convention(witness_method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout ExtremeLateBindingCounter) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>)
// CHECK: function_ref @_T0029dynamic_witness_other_module_C025ExtremeLateBindingCounterC7counterSivm : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @guaranteed ExtremeLateBindingCounter) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>)
// CHECK: return