Repository navigation
Generator: emit the template text from raw string literals, and tidy the specs - #283
Merged
Merged
Conversation
…d tidy the specs The emitter wrote the header, the counters, the interceptors, the model's slot table, Bind, Resolve and the trusted reader one AppendLine at a time. They are now raw string literals with the generated text laid out as it is emitted; only the parts computed per slot (EmitRead, Statement) stay code. The generated output is byte-identical. Also: - SlotSpec.Parameter was written and never read: removed. - The model list and its ids are built with Distinct and OrderBy instead of a dictionary used as a set plus a sort. - The partial model's settable names are joined with string.Join. - A redundant local in ModelReader is folded into its test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AppendLine writes the host's line ending and a raw string literal keeps the line endings of the file the generator was built from, so a generator built on Windows and run on Linux or macOS emitted a mix. The finished text is now normalized to LF once before it is added to the compilation, and a test asserts the generated file has no carriage return. Also renames two locals in Emitter.EmitModel that read like the generated names beside them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es, and cover two more shapes Bind and the Layout class were each split into a template, a conditional AppendLine and a second template. The partial model's check and the ordinal fields are now holes at the start of a line, so each is one template. Generator.Tests gains a partial model with nothing settable (the list of settable names the built type is checked against is empty) and a model with no member to map (a layout with no ordinal field), so those paths of the emitter are generated and read in the test project. The generated output for every model in the test project, and for the benchmark project, is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hat opens it The closing quotes of the raw string literals in the emitter were at column 0, so the template text sat at column 0 inside indented methods. Each literal now closes at the indent of the line where it opens (an expression body, a statement, a ternary arm), and its content is that indent plus the generated indent, so the compiler strips the code's indent and the generated text is unchanged. The generated file is byte-identical to before for the test project (counters on and off) and the benchmark project. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… of the emitter's strings The comments in the generated file are broken at the sentence and the colon, one clause to a line, so none runs past about 80 columns. The XML documentation stays on the one public generated type (the test-only counters class) and is now a multi-line summary on the class and on every member; the types and members that are file-local keep plain comments, as nothing outside the generated file can see them. Every fixed text in the emitter that spelled a tab as an escape (the interceptor constraint, the slot table entries, the layout's ordinal fields, the partial model's check, the trusted Bind, the reader methods and the guarded read's loop and cases) is now a raw string literal. The row readers take their indent as a depth, and one helper spells it. The generated code is identical to before once comments are left out (the test project with counters on and off, and the benchmark project); only the comment lines differ. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
What
Emitter.cswrote the generated file oneAppendLineat a time. The text that is the same for every model is now written as raw string literals, laid out the way it is emitted, with holes for the model type, the ids and the counters switch. The header, the counters class, the interceptors, the model's slot table,Bind,Resolve, the trustedBind, the literal reader and the layout class are done this way.EmitRead,Statementand the per-slot lines stay code, since they are computed per slot.The file is a little longer (755 to 808 lines): the gain is that each emitted block can be read as the text it produces, not a count of lines.
Small tidy items, in the same change:
SlotSpec.Parameterwas filled in and never read; removed (it only changes record equality for the incremental cache).DistinctandOrderByinstead of a dictionary used as a set plus a sort.string.Joininstead of concatenating thenSubstring(2).ModelReaderis folded into its test.The
Receiverenum is not removed: #280 made it live (the interceptor shape depends on it), so that item of the plan no longer applies.Comments in the generated file
file-scoped, so nobody outside the generated file sees them: they keep plain comments.absentexplanation inResolvemoved from the generated code to a comment in the emitter.Tabs in the emitter
Every fixed text that spelled a tab as an escape is a raw string literal. The row readers take their indent as a depth, and one helper spells it.
Line endings
AppendLinewrites the host's line ending, while a raw string literal keeps the line endings of the file the generator was built from (Windows checkouts have CRLF, the repository stores LF). A generator built on one platform and run on another would therefore have written a mix. The finished text is now normalized to LF once, before it is added to the compilation (sb.Replace("\r\n", "\n")), and a new test asserts the generated file contains no carriage return. This is compile time only.Generated output is unchanged
The generated
OdxMaps.g.cswas captured on master and on this branch, for three builds (the generator test models with the counters on and off, and the generated benchmark project), both with the same models. Master's output has CRLF on Windows; the branch's is LF only, so the gate is: the branch's output equals master's with CRLF turned into LF.The last commit changes the comments the generator writes (see Comments in the generated file), so for that commit the same comparison is made with comment-only lines and trailing comments deleted from both sides: identical for all three builds (516145, 464368 and 81333 bytes with the comments, no CR). The generator tests pass (189) and the solution builds without warnings.
Two emitter paths were in no model, so two models were added to the generator tests (in the test project, as a model has to be declared
partialin the compilation to count as partial), and master's generator was run over them too:PartialConstructorPost, built through its constructor): the list of settable names is empty;MemberlessPost): the generator accepts it, and its layout has no ordinal field.A partial model with every member's ordinal declared and the counters on (the check inside the trusted
Bind) was already in the models (TrustedPartialPost,TrustedToolkitPost).Checks
MSBuild Open.Database.Extensions.sln -restore -p:Configuration=Debug: no warnings, no errors.Review
Reviewers read the diff (three read-only lenses, then two further adversaries and two lenses from the PM); each finding was checked against the code. No blocking or major finding.
Kept and done:
EmitModelnamed like the generatedknownandl: renamed.Bindand theLayoutclass were a template, a conditionalAppendLineand a template: the partial model's check and the ordinal fields are now holes at the start of a line, so each is one template.Dropped, with the reason:
Bindas one template for all three shapes: the layout one (a cache loop andResolve), the counted trusted one (counters, one return) and the plain trusted one (an expression body) share only the signature, so one template would need holes for whole bodies, which is the code in strings it replaced. The partial check is the one line they share, and it is now a hole.l.O{k} = -1;line and theabsenthole inResolve: a template for the not-mapped slot would be one line, and one for the absent case would repeat the nine-line shape to change one statement and a comment.AppendLinelines with\t: per-slot rows, or one line.Emitter.csnames a spec file that does not exist: older than this change, untouched.🤖 Generated with Claude Code