[Sema] String representation of type information for derived conformances via macros#89463
Draft
Paul-Passeron wants to merge 1 commit into
Draft
[Sema] String representation of type information for derived conformances via macros#89463Paul-Passeron wants to merge 1 commit into
Paul-Passeron wants to merge 1 commit into
Conversation
This commit introduces the `getNominalTypeInfoString` function that returns a string describing the nominal type for which we derive conformances for, producing valid swift syntax.
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.
Overview:
This PR introduces a way to build a string representation of the type information needed for the derivation of conformances via macros (see #89419).
Motivation:
A case for deriving conformances via macros is made in the PR linked above.
As of today, macros are purely syntactical and carry no type information, nor can they query the compiler for it.
Conformance derivation requires some information on the type being conformed for (e.g. the names of the stored properties of a struct for which we are deriving
Equatable).This type information must be explicitly passed as an argument to the deriving macro, and therefore needs a string representation.
Changes:
Introduces a function that builds the string representation of type information needed by a deriving macro in Swift-like syntax. The representation is returned unquoted, quoting and escaping is the caller's responsibility. Quoting and escaping avoids requiring ABI-stable additions to the stdlib, keeping the representation opaque to the type-checker.
The format is Swift-like syntax of the form:
The exact contents are not yet stable and are expected to evolve as more conformance derivations are migrated to macro-based derivation. A follow-up PR will introduce a parser for this format on the macro side.