Skip to content

Remove Builtin.UnknownObject completely #12325

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

Closed

Conversation

jrose-apple
Copy link
Contributor

  • The runtime now provides prebuilt value witnesses for AnyObject (mangled name yXl).

  • The demangler and remangler continue to support "BO" because it's convenient to be able to demangle old symbols.

  • Reflection still uses the notion of "unknown object" to mean an object with unknown refcounting. That's different from AnyObject because AnyObject is still an existential, meaning it contains an object with unknown refcounting.

  • The reflection tests are broken at the moment.

  • Type-based alias analysis for Builtin.UnknownObject was incorrect, so it's a good thing we weren't using it.

  • Same with enum layout. (This one assumed UnknownObject never referred to an Objective-C tagged pointer. That certainly wasn't how we were using it!)

- The runtime now provides prebuilt value witnesses for AnyObject
  (mangled name yXl).

- The demangler and remangler continue to support "BO" because it's
  convenient to be able to demangle old symbols.

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. That's different from AnyObject
  because AnyObject is still an existential, meaning it /contains/
  an object with unknown refcounting.

- The reflection tests are broken at the moment.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor Author

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reflection tests are busted; I just get "invalid lowering" when I try to use yXl.

@@ -3,6 +3,8 @@
// RUN: %target-build-swift %S/Inputs/TypeLowering.swift -parse-as-library -emit-module -emit-library -module-name TypeLowering -o %t/libTypesToReflect.%target-dylib-extension
// RUN: %target-swift-reflection-dump -binary-filename %t/libTypesToReflect.%target-dylib-extension -binary-filename %platform-module-dir/libswiftCore.%target-dylib-extension -dump-type-lowering < %s | %FileCheck %s --check-prefix=CHECK-%target-ptrsize

// REQUIRES: UnknownObject_removal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help?

@@ -4,6 +4,7 @@

// REQUIRES: objc_interop
// REQUIRES: CPU=x86_64
// REQUIRES: UnknownObject_removal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help?

@swift-ci
Copy link
Contributor

swift-ci commented Oct 7, 2017

Build failed
Swift Test Linux Platform
Git Sha - 238215c

@@ -906,7 +906,6 @@ emitAssociatedTypeMetadataRecord(const ProtocolConformance *Conformance) {
void IRGenModule::emitBuiltinReflectionMetadata() {
if (getSwiftModule()->isStdlibModule()) {
BuiltinTypes.insert(Context.TheNativeObjectType);
BuiltinTypes.insert(Context.TheUnknownObjectType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try something like BuiltinTypes.insert(Context.getAnyObjectType()->getCanonicalType())?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... it would have to emit the descriptor under the old name "BO" too. Also see my comments in Reflection/TypeLowering.cpp

@slavapestov
Copy link
Contributor

@jrose-apple This is awesome, but I'm worried we're going to break reflection when binaries built with Swift 4.1 are used with an older version of the library.

The way it works is for "primitive" types, we emit "builtin type descriptors" which just state the size, alignment and extra inhabitants of the type.

You changed it to no longer emit this descriptor for UnknownObject, which makes sense, but I think it should now emit a descriptor for AnyObject, but probably under the old name so that the old library can find it.

@@ -607,7 +607,7 @@ const TypeRef *TypeConverter::getUnknownObjectTypeRef() {
if (UnknownObjectTR != nullptr)
return UnknownObjectTR;

UnknownObjectTR = BuiltinTypeRef::create(Builder, "BO");
UnknownObjectTR = BuiltinTypeRef::create(Builder, "yXl");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, keep this as "BO" -- the mangled name here doesn't 'mean' anything, it's just used to find the descriptor emitted in IRGen/GenReflection

@@ -1048,9 +1048,6 @@ class LowerType
if (B->getMangledName() == "Bo") {
return TC.getReferenceTypeInfo(ReferenceKind::Strong,
ReferenceCounting::Native);
} else if (B->getMangledName() == "BO") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And keep this too, maybe add a comment that "BO" is no longer a real type

@swift-ci
Copy link
Contributor

swift-ci commented Oct 7, 2017

Build failed
Swift Test OS X Platform
Git Sha - 238215c

@slavapestov
Copy link
Contributor

@jrose-apple Take a look at lldb too, thankfully most of the usages look trivially removable:

source/Symbol/SwiftASTContext.cpp:    case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:                       m_ast_context_ap->TheUnknownObjectType.getPointer());
source/Symbol/SwiftASTContext.cpp:            referent_type->is<swift::BuiltinUnknownObjectType>() ||
source/Symbol/SwiftASTContext.cpp:    if (can_type == GetASTContext()->TheUnknownObjectType.getPointer())
source/Symbol/SwiftASTContext.cpp:      type_kind == swift::TypeKind::BuiltinUnknownObject)
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:    case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:    case swift::TypeKind::BuiltinUnknownObject:
source/Symbol/SwiftASTContext.cpp:  case swift::TypeKind::BuiltinUnknownObject:

@jrose-apple
Copy link
Contributor Author

Oops, thanks for the LLDB reminder! I'll probably need to talk to you about yXl vs BO, but this isn't high-priority.

@jrose-apple
Copy link
Contributor Author

Closing in favor of #27378.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants