Skip to content

Eliminate Builtin.UnknownObject as an AST type #27378

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

Merged
merged 1 commit into from
Sep 27, 2019

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Sep 26, 2019

New version of #12325 that doesn't attempt to change the runtime and reflection bits. Still needs better comments, more docs, etc.

@jrose-apple
Copy link
Contributor Author

apple/swift-lldb#2017
@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 696bb78ca978ecbdd39d21fded37ab5903a4b93a

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 696bb78ca978ecbdd39d21fded37ab5903a4b93a

@jrose-apple
Copy link
Contributor Author

apple/swift-lldb#2017
@swift-ci Please test

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Yay!

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 696bb78ca978ecbdd39d21fded37ab5903a4b93a


bb1(%8 : $@convention(objc_method) (Builtin.UnknownObject) -> ()):
bb1(%8 : $@convention(objc_method) (@opened("01234567-89ab-cdef-0123-000000000000") AnyObject) -> ()):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These updates match how dynamic_method_br is emitted these days.

@@ -76,7 +76,7 @@ enum MultiPayloadGeneric<T> {
enum MultiPayloadNontrivialSpareBits {
case payload1(Builtin.NativeObject)
case payload2(Builtin.Int64)
case payload3(Builtin.Int64, Builtin.UnknownObject)
case payload3(Builtin.Int64, Builtin.NativeObject)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests relied on having spare bits in UnknownObject, which was a questionable assumption. (Good thing we weren't actually using it!)

// CHECK: br label %9

// CHECK: ; <label>:9:
// CHECK: ret void
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests also relied on having spare bits in UnknownObject. They don't seem to offer any additional coverage now.

%6 = open_existential_ref %4 : $AnyObject to $@opened("01234567-89ab-cdef-0123-000000000000") AnyObject
%7 = unchecked_ref_cast %6 : $@opened("01234567-89ab-cdef-0123-000000000000") AnyObject to $Builtin.UnknownObject
dynamic_method_br %7 : $Builtin.UnknownObject, #X.f!1.foreign, bb1, bb2
dynamic_method_br %4 : $AnyObject, #X.f!1.foreign, bb1, bb2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one doesn't quite match what we emit today but I figured the test relied on the two branches having the same type.

@@ -142,17 +142,16 @@ bb0:
// Now check that a native object address may:
//
// 1. May alias raw pointer addresses.
// 2. Not alias an unknown object. Objective-C objects are allocated differently
// than Swift objects and may not alias.
// 2. May alias an unknown object.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

OOPS GOOD THING WE WEREN'T USING THIS

This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- 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

That honestly went better than expected, this should be ready now. I hope it doesn't muck up Instruments or anything though.

(Don't worry, watchers, it'll be tested additionally before it ships in an Xcode.)

apple/swift-lldb#2017
@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 696bb78ca978ecbdd39d21fded37ab5903a4b93a

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 696bb78ca978ecbdd39d21fded37ab5903a4b93a

@jrose-apple jrose-apple changed the title [WIP] Eliminate Builtin.UnknownObject as an AST type Eliminate Builtin.UnknownObject as an AST type Sep 26, 2019
@jrose-apple
Copy link
Contributor Author

Credit to @varungandhi-apple for getting me to try this again by running into a problem with Builtin.UnknownObject (even if he's already unblocked himself).

@jrose-apple
Copy link
Contributor Author

@atrick or @aschwaighofer, can you check that the test changes I called out above are reasonable?

@atrick
Copy link
Contributor

atrick commented Sep 26, 2019

The test case cleanup all looks good.

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.

4 participants