Skip to content

Commit 7e9b64e

Browse files
authored
Merge pull request #40957 from eeckstein/function-argument-effects
Infrastructure for function argument effects + two "escaping" effects
2 parents 3791207 + f09dfc9 commit 7e9b64e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1825
-136
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ swift_compiler_sources(Optimizer
1111
SILPrinter.swift
1212
MergeCondFails.swift
1313
ReleaseDevirtualizer.swift
14+
RunUnitTests.swift
1415
)

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ReleaseDevirtualizer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private extension StructExtractInst {
204204
let structType = operand.type
205205

206206
var nonTrivialFieldsCount = 0
207-
for field in structType.getStructFields(in: function) {
207+
for field in structType.getNominalFields(in: function) {
208208
if field.isTrivial(in: function) {
209209
nonTrivialFieldsCount += 1
210210
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===--- UnitTests.swift - A pseudo pass for running the unit tests -------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SIL
14+
15+
/// This pass should only be used by sil-opt to run all the unit tests.
16+
///
17+
let runUnitTests = FunctionPass(name: "run-unit-tests", {
18+
(function: Function, context: PassContext) in
19+
20+
print("--- Run unit tests ---")
21+
22+
print("test ProjectionPath")
23+
SmallProjectionPath.runUnitTests()
24+
})

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ private func registerSwiftPasses() {
5151
registerPass(simplifyStrongRetainPass, { simplifyStrongRetainPass.run($0) })
5252
registerPass(simplifyStrongReleasePass, { simplifyStrongReleasePass.run($0) })
5353
registerPass(assumeSingleThreadedPass, { assumeSingleThreadedPass.run($0) })
54+
registerPass(runUnitTests, { runUnitTests.run($0) })
5455
registerPass(releaseDevirtualizerPass, { releaseDevirtualizerPass.run($0) })
5556
}

SwiftCompilerSources/Sources/Optimizer/PassManager/PassUtils.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ struct PassContext {
123123
func getContextSubstitutionMap(for type: Type) -> SubstitutionMap {
124124
SubstitutionMap(PassContext_getContextSubstitutionMap(_bridged, type.bridged))
125125
}
126+
127+
func modifyEffects(in function: Function, _ body: (inout FunctionEffects) -> ()) {
128+
function._modifyEffects(body)
129+
// TODO: do we need to notify any changes?
130+
}
126131
}
127132

128133
struct FunctionPass {

SwiftCompilerSources/Sources/SIL/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ add_swift_compiler_module(SIL
1111
Argument.swift
1212
BasicBlock.swift
1313
Builder.swift
14+
Effects.swift
1415
Function.swift
1516
GlobalVariable.swift
1617
Instruction.swift
1718
Location.swift
1819
Operand.swift
1920
Registration.swift
21+
SmallProjectionPath.swift
2022
SubstitutionMap.swift
2123
Type.swift
2224
Utils.swift

0 commit comments

Comments
 (0)