swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-161] Stack promotion fails to promote nested elements

Open rudkx opened this issue 10 years ago • 4 comments

Previous ID SR-161
Radar None
Original Reporter @rudkx
Type Bug

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, SILOptimizer
Assignee @eeckstein
Priority Medium

md5: 31dd23fe56d493abedff68a7378655a3

Issue Description:

In an example like the one below we manage to promote 'c' in foo() to the stack, but not the 'd' within 'c', despite it being legal.

class D {
  var y: Int = 0
}

class C {
  var x: Int = 0
  var d: D = D()
}

@inline(never)
func bar(c: C) {
  c.x = 1
}

@inline(never)
func foo() -> Int {
  let c = C()
  bar(c)
  return c.x
}

print(foo())

rudkx avatar Dec 09 '15 18:12 rudkx

Note that you need to use -whole-module-optimization with this example to get 'c' promoted.

rudkx avatar Dec 09 '15 18:12 rudkx

We are not promoting the inner element because of potential deinit side-effects, which we don't analyze yet.

eeckstein avatar Feb 13 '16 00:02 eeckstein

Is this resolved, or no longer valid? If either, this should be closed.

Dante-Broggi avatar Sep 21 '18 21:09 Dante-Broggi

Nothing has changed with respect to deinit side-effects. So I imagine it is still valid.

gottesmm avatar Sep 24 '18 20:09 gottesmm