Skip to content
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

[SR-7613] Missed constant propagation #50155

Open
swift-ci opened this issue May 5, 2018 · 6 comments
Open

[SR-7613] Missed constant propagation #50155

swift-ci opened this issue May 5, 2018 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented May 5, 2018

Previous ID SR-7613
Radar None
Original Reporter nuclearace (JIRA User)
Type Bug
Environment

swift 4.1 macOS

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: bacab61987ce077c0e5aca37f8eecfca

Issue Description:

It seems in the following example, Constants.a isn't being identified as a constant, and properly propagated to use sites.

struct Constants {
  static let a = MemoryLayout<Int>.size * 8
  static let b = Int.bitWidth
}

dump(Constants.a)
dump(Constants.b)

Godbolt link: https://godbolt.org/g/d7ti3U

@davezarzycki
Copy link
Collaborator

I looked into this briefly and I could be wrong, but it seems like SIL analysis is almost completely oblivious to `Builtin.sizeof()` and the fact that the result is constant.

@belkadan
Copy link
Contributor

belkadan commented May 7, 2018

cc @eeckstein

@belkadan
Copy link
Contributor

belkadan commented May 7, 2018

Note that Builtin.sizeof isn't always a constant, because of resilient structs and enums. But the compiler also knows which types are resilient and which aren't.

@eeckstein
Copy link
Member

By design SIL does not know anything about datatype sizes.

@davezarzycki
Copy link
Collaborator

Having SIL not knowing anything about datatype sizes (by default) is reasonable and good. That being said, what would go wrong if SIL special cased `Builtin.sizeof` and inlining it when the datatype is known to be fixed sized and fragile?

@eeckstein
Copy link
Member

Definitely doable (I just wanted to give an explanation why it is not done currently).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

4 participants