Exported generators under -shared: print boxed objects and quote internal field names - #315
Merged
Merged
Conversation
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.
Closes #314.
Problem
A generator exported from a shared library returned garbage (or the importer failed to compile) when used from a program built with
-shared. Generator methods on exported classes (*items()) failed the same way. Static multi-file builds were not affected because they don't go through the embedded declaration text (__decls).Cause
Two bugs in the declaration text a library embeds for importers:
ObjectTypeover a tuple), but it was printed as a plain{...}, which the importer reads back as a value tuple. Library and importer disagreed on the layout..stepfield was printed as.step:s32, which is a syntax error. The importer dropped the whole declaration, and compilation then failed infor...ofwith "Element access with a non-constant index".Fix
BoxedObject<T>(MLIRGenTypes.cpp) that resolves toObjectTypeoverT. The declaration printer now writes objects held by reference asBoxedObject<{...}>.BoxedObjectrather thanBoxed: user generic types resolve before built-in ones, and an existing test already declaresclass Boxed.".step": s32), which parses back to the exact name.MLIRPrinter(printBoxedObjectTypes,quoteNonIdentifierFieldNames), set only byMLIRDeclarationPrinter, so type printing in diagnostics is unchanged.@boxedvariable still prints its bare storage shape;@boxedalready adds the extra dereference, soBoxedObject<>there would dereference twice.Declaration text before and after:
Tests
export_generators.ts/import_generators.ts:function*,constgenerator, class generator method, namespaced generator, directnext()calls. Registered as static,-sharedand-jit -sharedtests; all pass.unittests/MLIRGen/DeclarationPrinter.cpp: boxed return type, bare shape for@boxedvariables, quoted non-identifier field names.🤖 Generated with Claude Code