Skip to content

Fix serialization format for the @_nonSendable attribute #41349

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 2 commits into from
Feb 12, 2022
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
4 changes: 2 additions & 2 deletions lib/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// 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.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 667; // @_backDeploy
const uint16_t SWIFTMODULE_VERSION_MINOR = 668; // @_nonSendable fix

/// A standard hash seed used for all string hashes in a serialized module.
///
Expand Down Expand Up @@ -1923,7 +1923,7 @@ namespace decls_block {

using NonSendableDeclAttrLayout = BCRecordLayout<
NonSendable_DECL_ATTR,
BCFixed<1> // assumed flag
BCFixed<1> // non-sendable kind
>;

using OptimizeDeclAttrLayout = BCRecordLayout<
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
auto *theAttr = cast<NonSendableAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[NonSendableDeclAttrLayout::Code];
NonSendableDeclAttrLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
(unsigned)theAttr->getKind());
(unsigned)theAttr->Specificity);
return;
}

Expand Down
5 changes: 5 additions & 0 deletions test/Serialization/Inputs/def_nonsendable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@_nonSendable
public struct A { }

@_nonSendable(_assumed)
public struct B { }
16 changes: 16 additions & 0 deletions test/Serialization/nonsendable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -module-name def_nonsendable -o %t %S/Inputs/def_nonsendable.swift
// RUN: llvm-bcanalyzer %t/def_nonsendable.swiftmodule | %FileCheck %s
// RUN: %target-swift-frontend -typecheck -I %t %s -o /dev/null
// RUN: %target-swift-frontend -emit-sil -I %t %s -o /dev/null

// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -module-to-print=def_nonsendable -I %t -source-filename=%s | %FileCheck -check-prefix=CHECK-PRINT %s

// CHECK-NOT: UnknownCode

// CHECK-PRINT-DAG: @_nonSendable struct A
// CHECK-PRINT-DAG: @_nonSendable(_assumed) struct B

import def_nonsendable

func test(a: A, b: B) { }