Skip to content

Conversation

bitjammer
Copy link
Contributor

Adds metadata emission for heap closures.

rdar://problem/24989531

@bitjammer
Copy link
Contributor Author

@swift-ci Please test

@bitjammer
Copy link
Contributor Author

Swift.IRGen.closure.swift looks like a simple update. I think I know what's going on with Swift.IRGen.protocol_resilience.sil.

@bitjammer
Copy link
Contributor Author

Yeah, looks like this function has witness method convention and the fulfillment isn't from a class pointer, metadata or l-value metadata. I'll fix it up in the morning. Maybe we'll want to add metadata sources for self and self's witness table for completeness.

Create a builder divorced from the ReflectionContext so that
MetadataSources can be created in other contexts, such as emitting
private heap metadata during IRGen, where we'll have to record the
layout of captures and how to get metadata for generic arguments in
order to construct typerefs of the captures, etc.

Add Parent, Metadata capture, and Impossible metadata sources.
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.

A closure capture descriptor has the following:

- The number of captures.
- The number of sources of metadata reachable from the closure.
  This is important for substituting generics at runtime since we
  can't know precisely what will get captured until we observe a
  closure.
- The number of types in the NecessaryBindings structure.
  This is a holding tank in a closure for sources of metadata that
  can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
  source of metadata for every generic argument needed to perform
  substitution at runtime.
  Key: The typeref for the generic parameter visible from the closure
  in the Swift source.
  Value: The metadata source, which describes how to crawl the heap from
  the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.

Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.

rdar://problem/24989531
These can show up in partial applications of functions with the
witness_method calling convention.
For convenience when reading looking at heap closure metadata.

Also move the capture typerefs above the metadata sources, since
they're more likely to be accessed than generic metadata sources.
MCJIT doesn't like offset relocations into the data sections, so the
capture descriptors and their typerefs/metadata source encoded strings
will need to be emitted as globals and not go into the reflection data
sections.
@bitjammer
Copy link
Contributor Author

@swift-ci Please test

@bitjammer
Copy link
Contributor Author

@egranata is that Linux failure real?

@bitjammer
Copy link
Contributor Author

Just rebuilt LLDB locally and the REPL commands that the test runs are working fine, so I think it's noise.

  1> [2,3,4]
$R0: [Int] = 3 values {
  [0] = 2
  [1] = 3
  [2] = 4
}
  2> $R0[0] 
$R1: Int = 2
  3> $R0[1] 
$R2: Int = 3
  4> $R0[2] 
$R3: Int = 4

@bitjammer
Copy link
Contributor Author

Ah, that Linux test has been failing for a while on that bot. I filed https://bugs.swift.org/browse/SR-1301 to track that.

@bitjammer bitjammer merged commit f24f445 into master Apr 23, 2016
@bitjammer bitjammer deleted the closure-metadata branch April 25, 2016 06:49
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.

1 participant