Skip to content

[WIP][IRGen] Emit type field descriptors for imported structs #14185

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 2 commits into from
Feb 3, 2018

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jan 26, 2018

Having field descriptors for imported structs helps to implement new reflection
call to retrieve field names/types.

@xedin xedin changed the title [IRGen] Emit type field descriptors for imported structs [WIP][IRGen] Emit type field descriptors for imported structs Jan 26, 2018
@xedin
Copy link
Contributor Author

xedin commented Jan 26, 2018

Opaque metadata goes to reflection Builtins section, so I need to register that with swift_registerTypeMetadata call so it's discoverable by _typeByMangledName.

@xedin
Copy link
Contributor Author

xedin commented Jan 26, 2018

/cc @jckarter

@jckarter
Copy link
Contributor

Shouldn't the nominal type descriptor for an opaque-metadata type still end up in the RuntimeResolvableTypes array?

@xedin
Copy link
Contributor Author

xedin commented Jan 26, 2018

I realized that yes, it should but currently it doesn't, that's the only way to establish name -> metadata relationship...

@xedin
Copy link
Contributor Author

xedin commented Jan 27, 2018

@jckarter I'm kind of stuck here because I'm not sure if it's valid to look into properties of the nominal types which are being added for lazy metadata emission, it doesn't seem like the best approach. It looks like if we were to do that we'd actually pollute binary with unnecessary lazy callbacks. Another way maybe it to augment lazy metadata access function to emit lazy type metadata accessors for its fields when evaluated?

I'm leaning towards closing this and actually leaving lazy field types accessor for imported types, so runtime hook can use reflection for regular swift types and getFieldType lazy accessor for imported ones, but that would be ugly...

@xedin
Copy link
Contributor Author

xedin commented Jan 27, 2018

Thinking about that some more, we can't actually lazily emit metadata accessors for the fields because they require reserved global var space to hook initialization too, which means we have to actually look inside of the imported structs etc. :(

@jckarter
Copy link
Contributor

It seems to me that we would end up emitting the exact same set of type metadata as we do today, since we currently force all of the field type metadata indirectly by generating the get_field_types hook.

@xedin xedin force-pushed the field-desc-for-imported-structs branch from 35720d6 to 704f465 Compare February 1, 2018 08:27
@xedin
Copy link
Contributor Author

xedin commented Feb 1, 2018

@jckarter Finally finished this up I think, for every field it's going to invoke getAddrOfForeignTypeMetadataCandidate if there is a struct inside to make sure that type metadata is generated. Please take a look!

@xedin
Copy link
Contributor Author

xedin commented Feb 1, 2018

@swift-ci please test

@swiftlang swiftlang deleted a comment from swift-ci Feb 1, 2018
@swiftlang swiftlang deleted a comment from swift-ci Feb 1, 2018
@jckarter
Copy link
Contributor

jckarter commented Feb 1, 2018

Looks good! Maybe add some tests for Swift structs containing fields with imported types in structural positions, e.g.:

struct Foo {
  var a: (ImportedTypeX, ImportedTypeY)
  var b: ImportedTypeZ?
}

should force ImportedType[XYZ] metadata to get generated too.

@xedin
Copy link
Contributor Author

xedin commented Feb 1, 2018

@jckarter test/Reflection/typeref_decoding_imported.swift does exactly that, but I wonder how can I verify that metadata itself is generated?

@jckarter
Copy link
Contributor

jckarter commented Feb 2, 2018

I see. The fact that the types now show up in the dumper output (and you test for that) should be sufficient then.

@xedin
Copy link
Contributor Author

xedin commented Feb 2, 2018

@jckarter presence of such metadata is going to be extensively tested by #13926 because swift_getFieldAt is going to rely on it being always present, so I guess I'll hold up merging this until I make some more progress at #13926

@jckarter
Copy link
Contributor

jckarter commented Feb 2, 2018

It shouldn't harm anything to land this first.

@xedin
Copy link
Contributor Author

xedin commented Feb 2, 2018

Alright :)

@xedin
Copy link
Contributor Author

xedin commented Feb 2, 2018

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Feb 2, 2018

Aha! Good that I re-ran the tests, since this is impacted by changes made by @rudkx where "!" is going to generate "Optional", going to change the test and merge.

xedin added 2 commits February 2, 2018 15:38
Update IRGen to trigger generation of type metadata for foreign
struct types found in fields. And fix TypeRefBuilder to handle
the case where struct has fields but at the same time has opaque
metadata.
@xedin xedin force-pushed the field-desc-for-imported-structs branch from 704f465 to 9e08ea4 Compare February 2, 2018 23:54
@xedin
Copy link
Contributor Author

xedin commented Feb 2, 2018

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Feb 3, 2018

@swift-ci please test Linux platform

@xedin
Copy link
Contributor Author

xedin commented Feb 3, 2018

@swift-ci please smoke test Linux platform

@swift-ci
Copy link
Contributor

swift-ci commented Feb 3, 2018

Build failed
Swift Test Linux Platform
Git Sha - 704f465fd2f00b58cafbc170ee80d02324ca74e1

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