Skip to content

Unnecessary retain/release pair around closure #82155

Open
@eeckstein

Description

@eeckstein

Description

The retain/release pair around the execute call should be eliminated.

Discussion: https://forums.swift.org/t/why-does-swift-decide-to-insert-a-retain-release-pair-here

Reproduction

public class Object { var count = 0 }

@inline(never)
func execute<T>(closure: () -> T) -> T {
    closure()
}

func compare(reference: Object, count: Int) -> Bool {
    // retain Object
    execute { reference.count == count }
    // release Object
}

Expected behavior

no ARC traffic in this function

Environment

reproducible with top of main

Additional information

No response

Metadata

Metadata

Assignees

Labels

ARCFeature: automatic reference countingSILOptimizerArea → compiler: SIL optimization passesclosuresFeature: closurescompilerThe Swift compiler itselfexpressionsFeature: expressionsperformanceswift 6.2

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions