Skip to content

[pull] swiftwasm from main #5501

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 189 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
d4ffe40
Use dispatch barriers for open/edit/close on the message handling queue
ahoppen Jun 1, 2023
2dcaa6f
[Backtracing][Linux] Add Linux crash handler to the runtime.
al45tair Jun 5, 2023
deb06c8
[Backtracing][Linux] Add missing CrashInfo.h header.
al45tair Jun 5, 2023
e5f4c20
[Backtracing][Linux] Disable backtrace-on-crash until enabling PR.
al45tair Jun 5, 2023
14fcdbd
[Backtracing][Linux] Tidy a few things up after review.
al45tair Jun 6, 2023
979b749
[Backtracing][Linux] Move doc comment to header.
al45tair Jun 6, 2023
e0d9649
[Backtracing][IRGen] Add a semantic attribute to force frame pointer.
al45tair Jun 5, 2023
43ed01f
[Backtracing][Linux] Reorganise modules for _Backtracing.
al45tair Jun 5, 2023
438ab7f
[Backtracing][Linux] Add Linux support to the _Backtracing module.
al45tair Jun 5, 2023
6ad9720
[Backtracing][Linux] Temporarily add a default addressWidth.
al45tair Jun 5, 2023
8d91384
[Backtracing][Linux] Work correctly in the presence of partial reads.
al45tair Jun 6, 2023
7dcebb2
[CMake] Allow install_name_tool to edit pure swift library load paths
bnbarham Jun 6, 2023
0caa453
[Macros] Teach SILGen to visit declartions produced by freestanding m…
DougGregor Jun 6, 2023
de10b41
[interop][SwiftToCxx] support copy-assignment operation for Swift val…
hyp Jun 6, 2023
f3b16fd
[CS] Fix a couple of constraints in `getTypeForPattern`
hamishknight Jun 2, 2023
23dbf6f
[CS] Reverse the type order in a couple of pattern equality constraints
hamishknight Jun 2, 2023
8d2f2ba
[CS] Remove external type logic from `getTypeForPattern`
hamishknight Jun 2, 2023
7c514fc
[CS] Remove null pattern handling from `getTypeForPattern`
hamishknight Jun 2, 2023
2a3b15c
[CS] Remove null Type handling from `getTypeForPattern`
hamishknight Jun 2, 2023
21e787b
[Sema] Walk SyntacticElementTarget for completion
hamishknight Jun 2, 2023
7a137d6
[CS] Allow ExprPatterns to be type-checked in the solver
hamishknight Jun 2, 2023
0695917
[CS] Don't form conversion between switch subject and pattern
hamishknight Jun 2, 2023
b43d351
[CS] Improve diagnostics a bit for pattern mismatch
hamishknight Jun 2, 2023
da86703
[CS] Fix `coercePatternToType` enum cast handling
hamishknight Jun 2, 2023
eaa61a0
[test] Add test case that exercises lots of `~=` overloads
hamishknight Jun 6, 2023
954a0db
Parameterize visitAuxiliaryDecls to account for separate traversal
DougGregor Jun 6, 2023
5a7ba23
Add flags to toolchain Info.plist to allow using macros from Apple's …
owenv Jun 6, 2023
007ac9a
[Runtime] Don't cache malloc_default_zone.
mikeash Jun 2, 2023
3dc470f
[Features] Add an experimental feature flag for init accessors.
hborla May 8, 2023
684ef9c
[AST] Add a new accessor kind for init accessors.
hborla May 10, 2023
d065d82
[Demangler] Demangle init accessors.
hborla May 11, 2023
429f190
[Parser] Parse init accessors when the experimental feature is enabled.
hborla May 12, 2023
ac66a06
[SIL] Add a new AssignOrInit instruction for init accessors.
hborla May 17, 2023
d35da62
[AST] Add a 'newValue' parameter to init accessors.
hborla May 17, 2023
eb3ed2b
[SILGen] Emit AssignOrInitInst for assignment to a computed property …
hborla May 17, 2023
9039d8b
[Sema] Add a request for gathering all computed properties in a nominal
hborla May 22, 2023
0028bdf
[DefiniteInitialization] Rename DIUseKind::AssignWrappedValue to DIUs…
hborla May 22, 2023
7512f6e
[SIL] Add an assignment mode to AssignOrInitInst that will be set by DI.
hborla May 22, 2023
df69020
[DefiniteInitialization] Lower AssignOrInit instructions to either ca…
hborla May 22, 2023
e5f7502
[AST] Add 'initializes' and 'accesses' attributes for init accessor
hborla May 23, 2023
404a523
[Parser] Parse 'initializes' and 'accesses' attributes on init access…
hborla May 24, 2023
c1a0000
[AST] InitAccessors: Add a way to retrieve referenced property declar…
xedin May 24, 2023
f96e1d7
[Parse] InitAccessors: Validate that init accessor declaration context
xedin May 25, 2023
d7f5419
[AST] InitAccessors: Add initializes/accesses attribute location vali…
xedin May 25, 2023
4a4bf3b
[Sema] InitAccessors/NFC: Add tests for invalid references in initial…
xedin May 25, 2023
fe90ddc
[DI] InitAccessors: Implement handling of initializes/accesses attrib…
xedin May 25, 2023
a090eb4
[Parse] InitAccessor: Reject init accessor declarations on subscripts
xedin May 26, 2023
dc9420e
[SILGen] InitAccessors: Add a way to check whether SILDeclRef points …
xedin May 27, 2023
2a64f28
[SIL] InitAccessors: Implement lowering of init accessor types
xedin May 27, 2023
003e460
[DI] Memory collector shouldn't assume that decls always have names
xedin May 29, 2023
d670067
[SILGen] InitAccessors: Add a way to check whether property is redire…
xedin May 29, 2023
00a9ccf
[SILGen] InitAccessors: Remap property references into argument refer…
xedin May 29, 2023
5bac6e8
[SILGen] NFC: Generalize `isCurrentFunction{{ReadAccess, InitAccessor…
xedin May 30, 2023
6c0e391
[SILGen] InitAccessor: Emit init accessor function
xedin May 30, 2023
7b140f8
[SILGen] InitAccessors: AssignOrInit instruction should reference ini…
xedin May 30, 2023
3b85840
[SIL/DI] InitAccessors: Get all required info from AssignOrInit inste…
xedin May 30, 2023
68866d7
[DI] InitAccessors: Handle `assign_or_init` without initializations
xedin May 30, 2023
2e8b0e7
[RawSILLowering] InitAccessors: Implement lowering of `assign_or_init…
xedin May 31, 2023
4dbaaf3
[AST] InitAccessors: Allow assignments to `let` properties
xedin May 31, 2023
69269e6
[Sema] InitAccessors: Mark init accesor as mutating "self" only for v…
xedin May 31, 2023
63e7561
[SIL] InitAccessors: Introduce a new `Out` kind to `MarkUninitialized…
xedin May 31, 2023
112d0d4
[DI] InitAccessors: Start marking `initializes(...)` properties as "out"
xedin Jun 1, 2023
73765c8
[SIL] InitAccessors: Fix reference type handling by DI and RawSIL low…
xedin Jun 1, 2023
78aee95
[SILVerifier] InitAccessors: Adjust verifier to map init accessor ref…
xedin Jun 1, 2023
fb15b6f
[Sema] InitAccessors: Mark properties with init accessor as computed
xedin Jun 1, 2023
22061e6
[Sema] InitAccessors: Verify that a property never appears both in in…
xedin Jun 2, 2023
ad95e91
[Sema/SIL] InitAccessors: Incorporate init accessors into memberwise …
xedin Jun 3, 2023
0e61a75
[Parser] InitAccessors: Properties in `initializes/accesses` should b…
xedin Jun 5, 2023
b22e8e6
[SIL] InitAccessors: Add tracking of properties that require assign i…
xedin Jun 5, 2023
c82559e
[DI/Lowering] InitAccessors: Implement lowering of property assignments
xedin Jun 5, 2023
85a8a05
[SILParse] InitAccessors: Print/parse "mode" of `assign_or_init` inst…
xedin Jun 5, 2023
d191ef8
[SIL/Parse] InitAccessors: Implement printing and parsing of previous…
xedin Jun 6, 2023
0d921e3
[Test] InitAccessors/NFC: Fix SIL test not to expecte %18 as a result
xedin Jun 6, 2023
a71b9c2
[Tests] InitAccessors/NFC: All init accessor tests require "asserts"
xedin Jun 6, 2023
5b19c0c
[Tests] InitAccessors/NFC: Switch test to validate output directly af…
xedin Jun 6, 2023
aaa7261
[Tests] InitAccessors/NFC: add interpreter tests for different config…
xedin Jun 6, 2023
291fe21
Merge pull request #66385 from bnbarham/pad-install-name
bnbarham Jun 7, 2023
c74fd07
Merge pull request #64280 from hamishknight/platypus
swift-ci Jun 7, 2023
0d36738
Enable sil-verify-all on noimplicitcopy_consuming_parameters and noim…
gottesmm Jun 7, 2023
9d95514
[borrowing/consuming] Be sure to visit boxes with trivial @moveonly t…
gottesmm Jun 7, 2023
e4debda
Merge pull request #66305 from mikeash/dont-cache-malloc-default-zone
swift-ci Jun 7, 2023
7082074
Update mangled names in test case
DougGregor Jun 7, 2023
feb5c09
Remove OptionSet macro from the standard library.
DougGregor Jun 7, 2023
fe6f8f5
[IRGen] Implement support for multi payload enums in layout strings (…
drexin Jun 7, 2023
582946b
[Backtracing][Linux] Remove status argument.
al45tair Jun 7, 2023
1262518
[Backtracing][Linux] Add a comment about __cxa_demangle.
al45tair Jun 7, 2023
ae9a0c1
Merge pull request #66334 from al45tair/eng/PR-110261430
al45tair Jun 7, 2023
d4b8828
[Backtracing][Linux] Also remove the status argument from Runtime mod…
al45tair Jun 7, 2023
a890ec2
[Backtracing][Linux][Tests] Fix verify_all_overlays test.
al45tair Jun 6, 2023
a9ce1cd
[Backtracing][Linux] Add Linux support to swift-backtrace.
al45tair Jun 5, 2023
8cf570c
Revert "[Backtracing][Linux] Temporarily add a default addressWidth."
al45tair Jun 5, 2023
df8e698
[Backtracing][Linux] Remove some stray "public" annotations.
al45tair Jun 6, 2023
ee55964
[Backtracing][Linux] Enable Linux backtracing, add tests.
al45tair Jun 5, 2023
3042cd7
[Backtracing][Linux] Enable backtrace-on-crash for Linux.
al45tair Jun 5, 2023
5325a4f
Swift SIL: add some instruction classes and APIs
eeckstein Jun 6, 2023
50c23a1
Optimizer: implement the SILCombine peephole optimizations for retain…
eeckstein Jun 6, 2023
d673544
Merge pull request #66335 from al45tair/eng/PR-110261712
al45tair Jun 7, 2023
9e008fa
Merge pull request #66337 from al45tair/eng/PR-110262673
al45tair Jun 7, 2023
5d03a72
Merge pull request #66338 from al45tair/eng/PR-101623265
al45tair Jun 7, 2023
2f0e42b
[Backtracing] Use stderr by default unless interactive.
al45tair Jun 7, 2023
210ca2a
[Backtracing][Tests] Fix tests to redirect output from stderr.
al45tair Jun 7, 2023
0b9747e
[Backtracing] Also update the Linux crash handler, now it's merged.
al45tair Jun 7, 2023
646c221
[Backtracing][Tests] Fix a test I missed.
al45tair Jun 7, 2023
5ea5594
Merge pull request #66387 from DougGregor/silgen-freestanding-local-vars
DougGregor Jun 7, 2023
1ddecc0
Merge pull request #66403 from DougGregor/remove-option-set
DougGregor Jun 7, 2023
39a5000
Merge pull request #66394 from hyp/eng/copy-assign-reverse-interop
hyp Jun 7, 2023
274a43b
Merge pull request #66283 from xedin/init-accessors
xedin Jun 7, 2023
861fd2f
Merge pull request #66406 from al45tair/eng/PR-110371557
al45tair Jun 7, 2023
d51bbef
[Macros] Test case for opt-out from automatic attrs propagation
rintaro Jun 7, 2023
b2a04aa
[cxx-interop][driver] make '-emit-clang-header-path' a fully supporte…
hyp Jun 7, 2023
97e6b56
Merge pull request #66402 from gottesmm/main-rdar110364874
gottesmm Jun 7, 2023
60c91aa
[cxx-interop] Declare CxxStdlib dependency on Darwin when building both
egorzhdan Jun 7, 2023
36b3d3a
AST: Handle PackConformance in SubstitutionMap::lookupConformance()
slavapestov Jun 7, 2023
7cc8063
SIL: Forgot to pass SubstFlags::PreservePackExpansionLevel in one place
slavapestov Jun 7, 2023
d5b354f
AST: Spot fix for AbstractStorageDecl::isResilient()
slavapestov Jun 7, 2023
208eaac
Merge pull request #66365 from owenv/pr/ovoorhees/macro-settings
owenv Jun 7, 2023
65e37f7
Merge pull request #66013 from ahoppen/ahoppen/sourcekitd-barriers
ahoppen Jun 7, 2023
2f03c95
[Serialization] ModularizationError keeps full objects
xymus May 18, 2023
77de53b
[Backtracing][Linux] Use syscall() to call gettid().
al45tair Jun 7, 2023
fe0c14f
[Backtracing] Make StackOverflow test less sensitive.
al45tair Jun 7, 2023
a9d0df2
[Test] Fix FileCheck lines for 32bit in test.
nate-chandler Jun 7, 2023
174b110
[LSan] Disable backtracing for the lsan builds.
al45tair Jun 7, 2023
c3d1304
[SourceKit] Add request to expand macros syntactically
rintaro May 24, 2023
b5062bd
Merge pull request #66417 from rintaro/macros-attrpropagation-rdar110…
rintaro Jun 7, 2023
2488f19
[move-only] Make test 32 bit friendly.
gottesmm Jun 7, 2023
1cd4f4a
[Serialization] Intro ModularizationError::getSourceLoc
xymus May 22, 2023
b1e0b89
[Serialization] Invert order of diagnostics in forced recovery mode
xymus May 30, 2023
f0ad258
[SourceKit] Jump to a background queue before executing `SKDUIDFromUI…
ahoppen Jun 7, 2023
6f78bf6
Merge pull request #66434 from nate-chandler/test/20230607/1/pack_met…
swift-ci Jun 8, 2023
8b7ace9
Merge pull request #66424 from slavapestov/zip-collect-attempt-fixes
slavapestov Jun 8, 2023
b3af130
[IDE] Visit auxiliary declarations if walking expansions
bnbarham Jun 7, 2023
63e5472
Merge pull request #66429 from al45tair/eng/PR-110417355
al45tair Jun 8, 2023
1210e77
Merge pull request #66432 from al45tair/eng/PR-110418951
al45tair Jun 8, 2023
b948a30
Merge pull request #66436 from al45tair/eng/PR-110420951
al45tair Jun 8, 2023
46e98c1
Merge pull request #66295 from rintaro/sourcekit-syntactic-macroexpan…
rintaro Jun 8, 2023
c994500
[Driver] Use WebAssembly toolchain for WASI target
kateinoigakukun Jun 7, 2023
1e2553e
Merge pull request #66414 from swiftwasm/katei/upstream-use-wasm-tool…
swift-ci Jun 8, 2023
d396656
[Backtracing][Linux] Replace regex with ProcMapsScanner.
al45tair Jun 8, 2023
57bf922
Merge pull request #66425 from apple/egorzhdan/cxxstdlib-darwin-depen…
egorzhdan Jun 8, 2023
7b74f72
Merge pull request #66421 from bnbarham/index-macro-conformances
bnbarham Jun 8, 2023
f066219
SILGen: Don't copy a borrowed noncopyable address-only base of a comp…
jckarter Jun 8, 2023
23e2f34
Merge pull request #66441 from ahoppen/ahoppen/deadlock
ahoppen Jun 8, 2023
3ba40af
[NFC] TypeCheckDeclPrimary.cpp: remove unused `isGenericType`
MaxDesiatov Jun 8, 2023
9804075
[Serialization] Show contextual notes on deserialization errors
xymus May 25, 2023
4bacb7f
Merge pull request #66376 from eeckstein/simplify-retain-release-value
eeckstein Jun 8, 2023
4ce0bd0
NFC: Disable clang-format for inline bitfields
hamishknight Jun 8, 2023
2ff585d
[SourceKit] Highlight `consuming` and `borrowing` as keywords
ahoppen Jun 8, 2023
b0dab0b
[cxx-interop] evaluate default constructor's unevaluated exception sp…
hyp May 15, 2023
fc662b1
[SourceKit] Add barrier-related functions to sourcekitdInProc-darwin.…
ahoppen Jun 8, 2023
8c54d3d
[Sema] InitAccessors: Don't synthesize default memberwise arg for ini…
xedin Jun 8, 2023
af88a65
[Serialization] Be more specific irt which clang settings may cause a…
xymus Jun 8, 2023
bb7af04
Merge pull request #66460 from ahoppen/ahoppen/sourcekitd-exports
DougGregor Jun 8, 2023
019152c
Add REQUIRES: swift_in_compiler to discard.swift and outliner.swift
atrick Jun 8, 2023
3f45c17
[cxx-interop] Correctly import fields with type `NS_Option`.
zoecarver Jun 8, 2023
37b8be9
Merge pull request #66455 from hamishknight/bit-format
swift-ci Jun 8, 2023
ca7b8e2
Merge pull request #66445 from jckarter/noncopyable-computed-property…
jckarter Jun 8, 2023
f3cabc5
Merge pull request #66453 from apple/maxd/fix-typecheck-warning
swift-ci Jun 8, 2023
2ab1707
Add link to Swift.org documentation in UserGuide-CallingSwiftFromC++.md
zoecarver Jun 8, 2023
7543ad4
Add link to Swift.org documentation in UserManual.md
zoecarver Jun 8, 2023
67afcbd
Add link to Swift.org documentation in InteropOddities.md
zoecarver Jun 8, 2023
1317c92
Add link to Swift.org documentation in GettingStartedWithC++Interop.md
zoecarver Jun 8, 2023
250d7d2
Add link to Swift.org status page in CppInteroperabilityStatus.md
zoecarver Jun 8, 2023
c2361ba
Add link to Swift.org documentation in CppInteroperabilityManifesto.m…
zoecarver Jun 8, 2023
bfad6af
Merge pull request #66418 from hyp/eng/emit-clang-header-path-driver
hyp Jun 8, 2023
138def7
Merge pull request #65922 from hyp/eng/excp-cons-spec
hyp Jun 8, 2023
df29fc3
[cxx-interop] Make a test work properly with optimizations
egorzhdan Jun 8, 2023
3a97766
Avoid emitting variable debug info for closure captures.
adrian-prantl Jun 8, 2023
78d6822
Merge pull request #66458 from ahoppen/ahoppen/consume-borrow-highlig…
ahoppen Jun 8, 2023
8878679
Merge pull request #66471 from apple/zoecarver-patch-6
zoecarver Jun 9, 2023
9d418b4
Merge pull request #66463 from xedin/init-accessor-memberwise-default
xedin Jun 9, 2023
a4f7600
Merge pull request #66470 from apple/zoecarver-patch-5
zoecarver Jun 9, 2023
912e1ef
Merge pull request #66469 from apple/zoecarver-patch-4
zoecarver Jun 9, 2023
292e288
Merge pull request #66468 from apple/zoecarver-patch-3
zoecarver Jun 9, 2023
3c819c3
Merge pull request #66467 from apple/zoecarver-patch-1
zoecarver Jun 9, 2023
63ee747
Merge pull request #66438 from gottesmm/pr-9dd89bbe721d2dbc04c56d9589…
gottesmm Jun 9, 2023
f9bd1a5
Merge pull request #66452 from zoecarver/ns-option-as-field-take-two
zoecarver Jun 9, 2023
b0b9705
[CMake] Prevent rebuilds of pure swift libraries and executables
bnbarham Jun 9, 2023
4fe20a8
Merge pull request #66472 from apple/zoecarver-patch-2
zoecarver Jun 9, 2023
7026f65
Merge pull request #66465 from atrick/fix-test-requires-swift-source
atrick Jun 9, 2023
e6ca3f0
Merge pull request #66449 from al45tair/eng/PR-110452324
al45tair Jun 9, 2023
be7725f
[Backtracing][Linux] Include declarations for gettid() and tgkill().
al45tair Jun 9, 2023
9991468
Merge pull request #66478 from apple/egorzhdan/copy-test-fix
egorzhdan Jun 9, 2023
7092e50
Merge pull request #66479 from adrian-prantl/110329894
adrian-prantl Jun 9, 2023
759f520
[Macros] Only freestanding expression macros can have a non-Void resu…
DougGregor Jun 9, 2023
008b1ca
Merge pull request #66486 from al45tair/eng/PR-110417355-take2
al45tair Jun 9, 2023
b18e7f1
Merge pull request #66227 from xymus/recovery-notes
xymus Jun 9, 2023
14282f1
Merge pull request #66484 from bnbarham/remove-rebuilds
bnbarham Jun 9, 2023
4f8f262
Merge pull request #66504 from DougGregor/bad-macros-with-result-types
swift-ci Jun 9, 2023
2e484a1
Merge pull request #66494 from slavapestov/storage-decl-is-resilient-…
slavapestov Jun 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ swift_compiler_sources(Optimizer
SimplifyInitEnumDataAddr.swift
SimplifyLoad.swift
SimplifyPartialApply.swift
SimplifyRetainReleaseValue.swift
SimplifyStrongRetainRelease.swift
SimplifyStructExtract.swift
SimplifyTupleExtract.swift
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
//===--- SimplifyRetainReleaseValue.swift ---------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import SIL

extension RetainValueInst : Simplifyable, SILCombineSimplifyable {
func simplify(_ context: SimplifyContext) {

// Remove pairs of
// ```
// release_value %0 // the release is before the retain!
// retain_value %0
// ```
// which sometimes the ARC optimizations cannot do.
//
if optimizeReleaseRetainPair(context) {
return
}

// Replace
// ```
// %1 = enum #E.A, %0
// retain_value %1
// ```
// with
// ```
// %1 = enum #E.A, %0 // maybe dead
// retain_value %0
// ```
replaceOperandWithPayloadOfEnum(context)

// Remove if the operand is trivial (but not necessarily its type), e.g.
// ```
// %1 = value_to_bridge_object %0 : $UInt64
// retain_value %1 : $Builtin.BridgeObject
// ```
if removeIfOperandIsTrivial(context) {
return
}

// Replace e.g.
// ```
// retain_value %1 : $SomeClass
// ```
// with
// ```
// strong_retain %1 : $SomeClass
// ```
replaceWithStrongOrUnownedRetain(context)
}
}

extension ReleaseValueInst : Simplifyable, SILCombineSimplifyable {
func simplify(_ context: SimplifyContext) {

// Replace
// ```
// %1 = enum #E.A, %0
// release_value %1
// ```
// with
// ```
// %1 = enum #E.A, %0 // maybe dead
// release_value %0
// ```
replaceOperandWithPayloadOfEnum(context)

// Remove if the operand is trivial (but not necessarily its type), e.g.
// ```
// %1 = value_to_bridge_object %0 : $UInt64
// release_value %1 : $Builtin.BridgeObject
// ```
if removeIfOperandIsTrivial(context) {
return
}

// Replace e.g.
// ```
// release_value %1 : $SomeClass
// ```
// with
// ```
// release_value %1 : $SomeClass
// ```
replaceWithStrongOrUnownedRelease(context)
}
}

private extension RetainValueInst {
func optimizeReleaseRetainPair(_ context: SimplifyContext) -> Bool {
if let prevInst = self.previous,
let release = prevInst as? ReleaseValueInst,
release.value == self.value {
context.erase(instruction: release)
context.erase(instruction: self)
return true
}
return false
}

func replaceWithStrongOrUnownedRetain(_ context: SimplifyContext) {
if value.type.isReferenceCounted(in: parentFunction) {
let builder = Builder(before: self, context)
if value.type.isUnownedStorageType {
builder.createUnownedRetain(operand: value)
} else {
builder.createStrongRetain(operand: value)
}
context.erase(instruction: self)
}
}
}

private extension ReleaseValueInst {
func replaceWithStrongOrUnownedRelease(_ context: SimplifyContext) {
if value.type.isReferenceCounted(in: parentFunction) {
let builder = Builder(before: self, context)
if value.type.isUnownedStorageType {
builder.createUnownedRelease(operand: value)
} else {
builder.createStrongRelease(operand: value)
}
context.erase(instruction: self)
}
}
}

private extension UnaryInstruction {
func replaceOperandWithPayloadOfEnum(_ context: SimplifyContext) {
if let e = operand.value as? EnumInst,
!e.type.isValueTypeWithDeinit,
let payload = e.payload {
operand.set(to: payload, context)
}
}

func removeIfOperandIsTrivial(_ context: SimplifyContext) -> Bool {
if operand.value.isTrivial(context) {
context.erase(instruction: self)
return true
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ private func registerSwiftPasses() {
registerForSILCombine(GlobalValueInst.self, { run(GlobalValueInst.self, $0) })
registerForSILCombine(StrongRetainInst.self, { run(StrongRetainInst.self, $0) })
registerForSILCombine(StrongReleaseInst.self, { run(StrongReleaseInst.self, $0) })
registerForSILCombine(RetainValueInst.self, { run(RetainValueInst.self, $0) })
registerForSILCombine(ReleaseValueInst.self, { run(ReleaseValueInst.self, $0) })
registerForSILCombine(LoadInst.self, { run(LoadInst.self, $0) })

// Test passes
Expand Down
37 changes: 37 additions & 0 deletions SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@ extension Value {
var nonDebugUses: LazyFilterSequence<UseList> {
uses.lazy.filter { !($0.instruction is DebugValueInst) }
}

/// Walks over all fields of an aggregate and checks if a reference count
/// operation for this value is required. This differs from a simple `Type.isTrivial`
/// check, because it treats a value_to_bridge_object instruction as "trivial".
/// It can also handle non-trivial enums with trivial cases.
func isTrivial(_ context: some Context) -> Bool {
if self is Undef {
return true
}
var worklist = ValueWorklist(context)
defer { worklist.deinitialize() }

worklist.pushIfNotVisited(self)
while let v = worklist.pop() {
if v.type.isTrivial(in: parentFunction) {
continue
}
if v.type.isValueTypeWithDeinit {
return false
}
switch v {
case is ValueToBridgeObjectInst:
break
case is StructInst, is TupleInst:
let inst = (v as! SingleValueInstruction)
worklist.pushIfNotVisited(contentsOf: inst.operands.values.filter { !($0 is Undef) })
case let en as EnumInst:
if let payload = en.payload,
!(payload is Undef) {
worklist.pushIfNotVisited(payload)
}
default:
return false
}
}
return true
}
}

extension Builder {
Expand Down
2 changes: 1 addition & 1 deletion SwiftCompilerSources/Sources/SIL/ApplySite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension ApplySite {
///
/// This does not include the callee function operand.
public var arguments: LazyMapSequence<OperandArray, Value> {
argumentOperands.lazy.map { $0.value }
argumentOperands.values
}

public var substitutionMap: SubstitutionMap {
Expand Down
12 changes: 12 additions & 0 deletions SwiftCompilerSources/Sources/SIL/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ public struct Builder {
return notifyNew(release.getAs(StrongReleaseInst.self))
}

@discardableResult
public func createUnownedRetain(operand: Value) -> UnownedRetainInst {
let retain = bridged.createUnownedRetain(operand.bridged)
return notifyNew(retain.getAs(UnownedRetainInst.self))
}

@discardableResult
public func createUnownedRelease(operand: Value) -> UnownedReleaseInst {
let release = bridged.createUnownedRelease(operand.bridged)
return notifyNew(release.getAs(UnownedReleaseInst.self))
}

public func createFunctionRef(_ function: Function) -> FunctionRefInst {
let functionRef = bridged.createFunctionRef(function.bridged)
return notifyNew(functionRef.getAs(FunctionRefInst.self))
Expand Down
12 changes: 11 additions & 1 deletion SwiftCompilerSources/Sources/SIL/Instruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public class MultipleValueInstruction : Instruction {
}

/// Instructions, which have a single operand.
public protocol UnaryInstruction : AnyObject {
public protocol UnaryInstruction : Instruction {
var operands: OperandArray { get }
var operand: Operand { get }
}
Expand Down Expand Up @@ -306,14 +306,24 @@ final public class StrongRetainInst : RefCountingInst {
public var instance: Value { operand.value }
}

final public class UnownedRetainInst : RefCountingInst {
public var instance: Value { operand.value }
}

final public class RetainValueInst : RefCountingInst {
public var value: Value { return operand.value }
}

final public class StrongReleaseInst : RefCountingInst {
public var instance: Value { operand.value }
}

final public class UnownedReleaseInst : RefCountingInst {
public var instance: Value { operand.value }
}

final public class ReleaseValueInst : RefCountingInst {
public var value: Value { return operand.value }
}

final public class DestroyValueInst : Instruction, UnaryInstruction {
Expand Down
4 changes: 4 additions & 0 deletions SwiftCompilerSources/Sources/SIL/Operand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
base: OptionalBridgedOperand(op: base.advancedBy(bounds.lowerBound).op),
count: bounds.upperBound - bounds.lowerBound)
}

public var values: LazyMapSequence<LazySequence<OperandArray>.Elements, Value> {
self.lazy.map { $0.value }
}
}

public struct UseList : CollectionLikeSequence {
Expand Down
2 changes: 2 additions & 0 deletions SwiftCompilerSources/Sources/SIL/Registration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ public func registerSILClasses() {
register(EndApplyInst.self)
register(AbortApplyInst.self)
register(StrongRetainInst.self)
register(UnownedRetainInst.self)
register(RetainValueInst.self)
register(StrongReleaseInst.self)
register(UnownedReleaseInst.self)
register(ReleaseValueInst.self)
register(DestroyValueInst.self)
register(DestroyAddrInst.self)
Expand Down
8 changes: 8 additions & 0 deletions SwiftCompilerSources/Sources/SIL/Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
return !bridged.isNonTrivialOrContainsRawPointer(function.bridged.getFunction())
}

/// True if this type is a value type (struct/enum) that requires deinitialization beyond
/// destruction of its members.
public var isValueTypeWithDeinit: Bool { bridged.isValueTypeWithDeinit() }

public func isLoadable(in function: Function) -> Bool {
return bridged.isLoadable(function.bridged.getFunction())
}
Expand All @@ -39,6 +43,10 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
return bridged.isReferenceCounted(function.bridged.getFunction())
}

public var isUnownedStorageType: Bool {
return bridged.isUnownedStorageType()
}

public var hasArchetype: Bool { bridged.hasArchetype() }

public var isNominal: Bool { bridged.getNominalOrBoundGenericNominal() != nil }
Expand Down
26 changes: 25 additions & 1 deletion cmake/modules/AddPureSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ function(add_pure_swift_host_library name)
set_property(TARGET ${name}
PROPERTY BUILD_WITH_INSTALL_RPATH YES)

if(APSHL_SHARED AND CMAKE_SYSTEM_NAME STREQUAL Darwin)
# Allow install_name_tool to update paths (for rdar://109473564)
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Xlinker -headerpad_max_install_names")
endif()

# Respect LLVM_COMMON_DEPENDS if it is set.
#
# LLVM_COMMON_DEPENDS if a global variable set in ./lib that provides targets
Expand All @@ -157,7 +163,7 @@ function(add_pure_swift_host_library name)
add_custom_command(
TARGET ${name}
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}>
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}> "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${name}.swiftmodule" "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule"
COMMAND_EXPAND_LISTS
COMMENT "Update mtime of library outputs workaround")

Expand Down Expand Up @@ -298,6 +304,24 @@ function(add_pure_swift_host_tool name)
target_include_directories(${name} PUBLIC
${SWIFT_HOST_LIBRARIES_DEST_DIR})

# Workaround to touch the library and its objects so that we don't
# continually rebuild (again, see corresponding change in swift-syntax).
add_custom_command(
TARGET ${name}
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}>
COMMAND_EXPAND_LISTS
COMMENT "Update mtime of executable outputs workaround")

# Even worse hack - ${name}.swiftmodule is added as an output, even though
# this is an executable target. Just touch it all the time to avoid having
# to rebuild it every time.
add_custom_command(
TARGET ${name}
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule"
COMMAND_EXPAND_LISTS
COMMENT "Update mtime of executable outputs workaround")
# Export this target.
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
endfunction()
4 changes: 3 additions & 1 deletion docs/CppInteroperability/CppInteroperabilityManifesto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

# ⚠️ Warning: document is out of date. ⚠️

**This document has not had significant updates in the last three years. The goals and design outlined here do not necessarily reflect those established by the C++ Interop Work Group. For an up-to-date document, please see [the Forward Vision which is being developed here](https://github.com/zoecarver/swift/blob/docs/interop-roadmap/docs/CppInteroperability/ForwardVision.md).**
**This document has not had significant updates in the last three years. The goals and design outlined here do not necessarily reflect those established by the C++ Interop Work Group. For an up-to-date document, please see [the Forward Vision document](https://github.com/apple/swift-evolution/blob/main/visions/using-swift-from-c%2B%2B.md).**

[** ‼️ Additionally, the official C++ interoperability documentation is live at Swift.org and provides an up-to-date guide for mixing Swift and C++ ‼️ **](https://www.swift.org/documentation/cxx-interop/)

This document discusses the design and tradeoffs for bidirectional API-level
interoperability between Swift and C++.
Expand Down
2 changes: 2 additions & 0 deletions docs/CppInteroperability/CppInteroperabilityStatus.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[** ‼️ The official C++ interoperability documentation and status page is live at Swift.org and provides an up-to-date guide for mixing Swift and C++ ‼️ **](https://www.swift.org/documentation/cxx-interop/status)

# C++ Interoperability Status

Swift has some experimental ability to interoperate with C++.
Expand Down
2 changes: 2 additions & 0 deletions docs/CppInteroperability/GettingStartedWithC++Interop.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[** ‼️ The official C++ interoperability documentation is live at Swift.org and provides an up-to-date guide for mixing Swift and C++ ‼️ **](https://www.swift.org/documentation/cxx-interop/)

# Getting started with C++ Interoperability

This document is designed to get you started with bidirectional API-level interoperability between Swift and C++.
Expand Down
2 changes: 2 additions & 0 deletions docs/CppInteroperability/InteropOddities.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[** ‼️ The official C++ interoperability documentation is live at Swift.org and provides an up-to-date guide for mixing Swift and C++ ‼️ **](https://www.swift.org/documentation/cxx-interop/)

# C++ Interoperability Oddities

C++ APIs may have slightly different behavior than other C++ APIs. This is a general catch-all document where these
Expand Down
Loading