Skip to content

Add a field reflection function that constructs keypaths. #34815

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
Nov 30, 2020

Conversation

pschuh
Copy link
Contributor

@pschuh pschuh commented Nov 18, 2020

While the existing _forEachField in ReflectionMirror.swift
already gives the offsets and types for each field, this isn't
enough information to construct a keypath for that field in
order to modify it.

For reference, this should be sufficient to implement the features
described here: (https://forums.swift.org/t/storedpropertyiterable/19218/62)
purely at runtime without any derived conformances for many types.

Note: Since there isn't enough reflection information for constructing
.mutatingGetSet fields, this means that we're not able to support
reflecting certain types of fields (functions, non-final class fields,
etc). Whether this is an error or not is controlled by the .ignoreUnknown
option.

@pschuh pschuh requested review from jckarter and mikeash November 18, 2020 23:09
While the existing _forEachField in ReflectionMirror.swift
already gives the offsets and types for each field, this isn't
enough information to construct a keypath for that field in
order to modify it.

For reference, this should be sufficent to implement the features
described here: (https://forums.swift.org/t/storedpropertyiterable/19218/62)
purely at runtime without any derived conformances for many types.

Note: Since there isn't enough reflection information for
`.mutatingGetSet` fields, this means that we're not able to support
reflecting certain types of fields (functions, nonfinal class fields,
etc). Whether this is an error or not is controlled by the `.ignoreUnknown`
option.
Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

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

Nice!

@compnerd
Copy link
Member

@swift-ci please test

@pschuh pschuh merged commit 4e39e59 into swiftlang:main Nov 30, 2020
ainu-bot pushed a commit to google/swift that referenced this pull request Dec 1, 2020
* 'main' of github.com:apple/swift: (67 commits)
  [build-script] Allow to tune dsymutil parallelism (swiftlang#34795)
  [Testing] Add missing REQUIRES
  [concurrency] SILGen: emit @asyncHandler functions.
  [concurrency] SILGen: allow the Builtin.createAsyncTaskFuture to have a non-generic closure argument.
  [concurrency] stdlib: add a _runAsyncHandler compiler intrinsic.
  Mangling: add support for mangling the body-function of asyncHandlers
  Make sure ~AutoDiffLinearMapContext() is called.
  fix SourceLoc-related crasher and add tests
  [AutoDiff] Bump-pointer allocate pullback structs in loops. (swiftlang#34886)
  update differentiable programming manifesto
  [Async CC] Always add full type metadata to bindings.
  [cxx-interop] Fix assertion to allow variadic members.
  [ome] Remove bad pattern of having a global SILBuilder with a global SILBuilderWithContext and multiple local SILBuilderWithScope.
  [ome] Invoke simplifyInstruction after lowering ownership and use replaceAllSimplifiedUsesAndErase instead of a manual RAUW.
  Partially revert Float16 availability changes (swiftlang#34847)
  Add a field reflection function that constructs keypaths. (swiftlang#34815)
  Allow the creation of a shadow variable when the type is a refcounted pointer (swiftlang#34835)
  [CMake] Extend copy-legacy-layouts dependency to swiftmodules (swiftlang#34846)
  [sil] Remove usage from TypeLowering of SILBuilder::create*AndFold().
  [allocbox-to-stack] Fix an ossa bug in PromotedParamCloner.
  ...
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