T02, your code is data - #40
Merged
Merged
Conversation
Reads the assembly built from L1 as what it is, a database. The table census, the five types, the eight methods, every name the file defines and the three local names that are not among them, the pdb next door that holds those three, the MemberRef table read as a transcript of the lowering, the ratio of names to definitions, the fourteen attributes nobody applied, and the scale gap against System.Private.CoreLib. Adds lessons/shared/l1, the canonical L1 program from the pedagogy notes. xray only builds a fixture inside a lesson directory, so the source lives here and each lesson's fixture project pulls it in with a Compile Include and builds its own copy. Adds docs/diagrams/rows-and-tokens.dg, which has no counts in it on purpose, since counts belong on the page where the build regenerates them. Verified against the committed expected output on osx-arm64 and on server3 on linux-x64. Both matched byte for byte.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The second lesson of the tour. T01 walked one line of C# through ten stages and went past the assembly on its way to somewhere else. This one stops and opens the assembly, and reads it as what it actually is, which is a database.
The shared L1 program
This is the part that affects every lesson from here on, so it is worth reading even if the lesson itself is not interesting to you.
lessons/shared/l1/Shapes.csis now in the repository. It is the canonical L1 program from the pedagogy notes, the ten line shapes program the book is meant to come back to at greater depth in every part. Until now each lesson invented its own fixture, which is fine for a smoke test and wrong for a book whose argument is that the same ordinary program looks different from ten different heights.xraybuilds<lesson>/fixture/*.csprojand has no notion of a fixture living anywhere else, and this did not seem worth changing the tool for. So the source sits inlessons/shared/l1and a lesson's own fixture project pulls it in.Each lesson gets its own build in its own output directory, so two lessons cannot tread on each other and a lesson that needs a different configuration can have one.
lessons/shared/l1/README.mdrecords that, plus why the program is shaped the way it is and what changing it would cost.The fixture project turns nothing off. A census of a program built with things muted for convenience would be tidier than a census of a normal build, and it would be worth less than nothing.
What is on the page
Thirteen blocks, eleven of which print, all reading the same
L1.dllwithSystem.Reflection.Metadata, which ships in the box. Nothing here needs a debugger, a runtime build or a privilege.foreachneeded.foreachturns up as GetEnumerator, MoveNext, get_Current and Dispose, and the interpolated string turns up as a handler struct. First sight of lowering, which T04 does properly.System.Private.CoreLib.Three prediction gates: how many types a three class program defines, whether an assembly containing no
usingstatement referencesIDisposable.Dispose, and whether the nametotalis in the assembly. Every option has a written reason, including the wrong ones.One new diagram,
docs/diagrams/rows-and-tokens.dg, showing the three reference tables chained together and a four byte token split into a table number and a row number. It has no counts in it on purpose. Counts belong on the page, where the build regenerates them, because a number in a diagram is a number nothing checks.How it is checked
Eight captured outputs are committed, and they include row counts and token values. That is deliberate, and it is the same call T01 made when it committed IL bytes: those are exactly the things that should turn red when a compiler changes what it emits.
Two blocks are dropped, because they print things that belong to the machine rather than to .NET, and both are covered by assertions instead. The scale block asserts three lines, the shape of the program's own row count, and that the library is more than a thousand times the program, a threshold set well under the real ratio of over two thousand so that a future library shedding rows does not turn a true statement red. The machine block asserts one of the four supported platforms and a three part release version. Every claim has a written reason.
Verified before opening this
Locally on osx-arm64, and on server3 on linux-x64, both against the committed expected output, and both matched byte for byte. A lesson with eight captured outputs full of row counts is the kind of thing that turns out to differ on the second platform, so it is worth finding that out before the CI legs rather than after.
Not in here
No
runtime:citations.pin.jsonstill holds a null commit, so none of them would resolve, and the page says so plainly. The portable pdb format is specified indotnet/runtimerather than in ECMA-335 and gets a proper citation once the pin lands.