Skip to content

Fix @effects of finalizeUninitializedArray when assertions are enabled #34101

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 1 commit into from
Sep 28, 2020
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: 15 additions & 0 deletions stdlib/public/core/ArrayShared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func _deallocateUninitializedArray<Element>(
array._deallocateUninitialized()
}

#if !INTERNAL_CHECKS_ENABLED
@_alwaysEmitIntoClient
@_semantics("array.finalize_intrinsic")
@_effects(readnone)
Expand All @@ -75,6 +76,20 @@ func _finalizeUninitializedArray<Element>(
mutableArray._endMutation()
return mutableArray
}
#else
// When asserts are enabled, _endCOWMutation writes to _native.isImmutable
// So we cannot have @_effects(readnone)
@_alwaysEmitIntoClient
@_semantics("array.finalize_intrinsic")
public // COMPILER_INTRINSIC
func _finalizeUninitializedArray<Element>(
_ array: __owned Array<Element>
) -> Array<Element> {
var mutableArray = array
mutableArray._endMutation()
return mutableArray
}
#endif

extension Collection {
// Utility method for collections that wish to implement
Expand Down
2 changes: 2 additions & 0 deletions test/SILOptimizer/opt-remark-generator-yaml.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// RUN: %empty-directory(%t)
// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s

// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts

// This file is testing out the basic YAML functionality to make sure that it
// works without burdening opt-remark-generator-yaml.swift with having to update all
// of the yaml test cases everytime new code is added.
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/opt-remark-generator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-opt-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil %s -o /dev/null -Xfrontend -verify
// REQUIRES: optimized_stdlib
// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts

// XFAIL: OS=linux-androideabi && CPU=armv7

Expand Down