What's happened to CGPoint?

This little program:

import CoreGraphics

let p = CGPoint(x: 1, y: 2)
print(p)

compiles and runs as expected without any compiler flags:

$ swiftc --version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.2.0
$ swiftc test.swift && ./test
(1.0, 2.0)

But doing a release build, or as here compiling with -O, it will run in this unexpected way:

$ swiftc -O test.swift && ./test
warning: the Swift runtime was unable to demangle the type of field 'x'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
warning: the Swift runtime was unable to demangle the type of field 'y'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
CGPoint(x: (), y: ())

I'm surprised that I couldn't find anything when searching for this, or that I haven't noticed it earlier.

This is the default toolchain of Xcode 11.3.1 (11C504), which I've been using for some time. It doesn't seem to happen in larger programs (still command line programs, using CGPoint, compiled with -O).

Can anyone reproduce this or is it only me / my system?

I don't see this warning on master:

suyashsrijan bin % cat ~/Desktop/test.swift
import CoreGraphics

let p = CGPoint(x: 1, y: 2)
print(p)
suyashsrijan bin % ./swiftc -version
Swift version 5.2-dev (LLVM 6aa0c814b5, Swift 7fd0ca6cb2)
Target: x86_64-apple-darwin19.3.0
suyashsrijan bin % ./swiftc -O ~/Desktop/test.swift -sdk $(xcrun --show-sdk-path) && ./test
(1.0, 2.0)

Do you see it with some earlier toolchain (assuming you have access to one)?

I only have access to master and Xcode 11.3.1 (on which I get the same warning as above).

Ah, so you could reproduce it, OK, thanks.

Note that apart from getting the warning, all CGPoint values will be printed like this (as the warning correctly says):

CGPoint(x: (), y: ())

Yeah, only on 11.3.1. I think it's probably fixed on 5.2, but I don't have access to Xcode 11.4 at the moment. Anyway, you can do p.debugDescription which should print (1.0, 2.0) for you.

1 Like

Yes, it's fixed in Xcode 11.4 beta:

tim@sequoia /tmp % sudo xcode-select -s /Applications/Xcode-beta.app 
tim@sequoia /tmp % swiftc --version
Apple Swift version 5.2 (swiftlang-1103.0.25.1 clang-1103.2.32.5)
Target: x86_64-apple-darwin19.4.0
tim@sequoia /tmp % swiftc -O test.swift && ./test                   
(1.0, 2.0)

vs Xcode 11.3.1:

tim@sequoia /tmp % sudo xcode-select -s /Applications/Xcode.app
tim@sequoia /tmp % swiftc --version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.4.0
tim@sequoia /tmp % swiftc -O test.swift && ./test              
warning: the Swift runtime was unable to demangle the type of field 'x'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
warning: the Swift runtime was unable to demangle the type of field 'y'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
CGPoint(x: (), y: ())
3 Likes