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

Constant members should not contribute to layout #68984

Open
saagarjha opened this issue Oct 5, 2023 · 1 comment
Open

Constant members should not contribute to layout #68984

saagarjha opened this issue Oct 5, 2023 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@saagarjha
Copy link
Contributor

Description
Members that are constant and can never be modified should get folded out and stored on a per-type basis.

Steps to reproduce

struct Foo1 {
	var foo: Int { 0 }
}

struct Foo2 {
	let foo = 0
}

print(MemoryLayout<Foo1>.size)
print(MemoryLayout<Foo2>.size)

Expected behavior

0
0

Environment

  • Swift compiler version info
    swift-driver version: 1.87.2 Apple Swift version 5.9 (swiftlang-5.9.2.1.6 clang-1500.1.0.1.1)
    Target: arm64-apple-macosx14.0
  • Xcode version info
    Xcode 15.1
    Build version 15C5028h
  • Deployment target: macOS 14.0
@saagarjha saagarjha added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 5, 2023
@grynspan
Copy link
Contributor

Presumably this would not apply to constant members with non-constant initializers such as let x = Int.random(...).

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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants