Skip to content

[Sema] String representation of type information for derived conformances via macros#89463

Draft
Paul-Passeron wants to merge 1 commit into
swiftlang:mainfrom
Paul-Passeron:type-info
Draft

[Sema] String representation of type information for derived conformances via macros#89463
Paul-Passeron wants to merge 1 commit into
swiftlang:mainfrom
Paul-Passeron:type-info

Conversation

@Paul-Passeron
Copy link
Copy Markdown

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:

NominalTypeInfo(name: "Foo", kind:
	structLike(StructTypeInfo(properties: [
		StoredProperty(name: "bar", 
					   typeName: "Bar", 
					   isVar: true, 
					   isStatic: false),
		...
	])))

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.

This commit introduces the `getNominalTypeInfoString` function that returns a
string describing the nominal type for which we derive conformances for,
producing valid swift syntax.
@Paul-Passeron Paul-Passeron changed the title String representation of type information for derived conformances via macros [Sema] String representation of type information for derived conformances via macros May 27, 2026
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