Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/protocol/protocol.x

Protocols from declaration to conform forms.

Functions

FunctionSummary
Compiler.conformance_rowsReturns the interface rows of the resolved conformances adoptions declare.
Compiler.discard_helperReturns (binding signature) for a generated helper that calls the function binding of type signature and then discards the unnamed argument temporaries which selects (bit n for argument n).
Compiler.dump_conformancePrints stable conformance rows for typedefs in globs.
Compiler.forward_parametersReturns (declarations arguments) for a helper that forwards its parameters of types: each declaration names a fresh parameter a0, a1, …, and each argument reads it.
Compiler.generate_protocol_adaptersInserts native aliases and presents other resolved conformances as conform forms.
Compiler.install_generated_protocol_symbolsPublishes external native alias and ordinary adapter signatures.
Compiler.native_protocol_aliasReports whether a generated member names a native protocol host function.
Compiler.parse_protocol_declarationParses a protocol body or concrete adoption at the current token.
Compiler.protocol_discard_helperThe discard_helper for participant’s protocol member.
Compiler.protocol_member_namesReturns unique member spellings from the participant’s visible adopted conformances.
Compiler.protocol_members_forReturns the resolved conformance for participant and base, if any.
Compiler.protocol_rejects_direct_memberReports whether conformance supersedes an ambient direct member: 0 when it does not, 1 when the participant’s own adoption does, and 2 when an ancestor’s adoption does.
Compiler.protocol_update_helperReturns a generated helper for a direct protocol-backed update.
Compiler.publish_protocol_nodeValidates and installs one normalized protocol or adoption node.
Compiler.rebuild_protocolsRebuilds the per-unit protocol and adoption registries from symbols.
Compiler.record_source_typedefRemembers a source typedef’s declaration and visibility, which native alias insertion reads for its participant.
Compiler.resolve_as_declaredResolves the adoptions visible in symbols as a declaring unit’s full parse resolves its own: before the parse, and again, after the generated members are published, where the parse publishes each one.
Compiler.resolve_protocol_memberResolves a protocol member for participant.
Compiler.resolve_protocolsResolves every visible adoption into the current conformance registry.
Compiler.reverse_converter_spellingReturns the conventional reverse converter spelling.
Compiler.wrapper_functionReturns the function result name(params) { body } bound in this unit.

Compiler

Compiler.conformance_rows

Map Compiler.conformance_rows(Compiler c, List adoptions)

Returns the interface rows of the resolved conformances adoptions declare.

Source: src/protocol/resolution.x:211

Compiler.discard_helper

List Compiler.discard_helper( Compiler c, List binding, Type signature, String stem, int which)

Returns (binding signature) for a generated helper that calls the function binding of type signature and then discards the unnamed argument temporaries which selects (bit n for argument n). A discarded argument is one the compiler produced for this call alone, so its discard member may release what it owns before the enclosing scope ends. Returns null when no selected argument type has a discard member, or an ordinary pointer or aggregate result may borrow an argument.

Source: src/protocol/call-helpers.x:131

Compiler.dump_conformance

void Compiler.dump_conformance(Compiler c, Map globs)

Prints stable conformance rows for typedefs in globs. Rows are ordered by participant and protocol and identify whether each adoption is owned by this unit, so prelude and live symbol modes can be compared.

Source: src/protocol/lookup.x:163

Compiler.forward_parameters

List Compiler.forward_parameters(Compiler c, List types)

Returns (declarations arguments) for a helper that forwards its parameters of types: each declaration names a fresh parameter a0, a1, …, and each argument reads it.

Source: src/protocol/call-helpers.x:29

Compiler.generate_protocol_adapters

List Compiler.generate_protocol_adapters(Compiler c, List ast)

Inserts native aliases and presents other resolved conformances as conform forms. A native alias is inserted at the participant’s inferred public or private boundary. Each other conformance whose forward converter the unit defines goes to the rule on the conform head, which src/components/protocol-adapters.x registers to write its adapters into the unit’s pending support. The external conformances the unit declares are first recorded in its interface. Returns ast with native insertions applied.

Source: src/protocol/adapters.x:111

Compiler.install_generated_protocol_symbols

void Compiler.install_generated_protocol_symbols(Compiler c)

Publishes external native alias and ordinary adapter signatures. Protocols must already be resolved in the active symbol table.

Source: src/protocol/adapters.x:150

Compiler.native_protocol_alias

int Compiler.native_protocol_alias(Compiler c, String name)

Reports whether a generated member names a native protocol host function. Its defining header supplies the alias instead of a C prototype.

Source: src/protocol/adapters.x:191

Compiler.parse_protocol_declaration

List Compiler.parse_protocol_declaration(Compiler c)

Parses a protocol body or concrete adoption at the current token. The method consumes through the closing brace or semicolon. Full parsing publishes the normalized row immediately. Macro-hole parsing returns syntax for later binding; shallow parsing publishes only when protocol collection is enabled and otherwise returns the uninstalled node. A leading meta makes an adoption’s witnesses available to compile-time code.

Source: src/protocol/declarations.x:122

Compiler.protocol_discard_helper

List Compiler.protocol_discard_helper( Compiler c, Type participant, String member, int which)

The discard_helper for participant’s protocol member.

Source: src/protocol/call-helpers.x:157

Compiler.protocol_member_names

List Compiler.protocol_member_names(Compiler c, Type participant)

Returns unique member spellings from the participant’s visible adopted conformances. Resolution remains responsible for selecting a binding.

Source: src/protocol/lookup.x:105

Compiler.protocol_members_for

List Compiler.protocol_members_for(Compiler c, Type participant, Type base)

Returns the resolved conformance for participant and base, if any. Lookup canonicalizes the participant and may use the nearest adopted typedef ancestor. Native conformances install their generated bindings before the cached conformance row is returned.

Source: src/protocol/lookup.x:21

Compiler.protocol_rejects_direct_member

int Compiler.protocol_rejects_direct_member( Compiler c, Type participant, String member)

Reports whether conformance supersedes an ambient direct member: 0 when it does not, 1 when the participant’s own adoption does, and 2 when an ancestor’s adoption does. The answer is cached for the canonical participant and uses the first visible adopted ancestor that declares the member.

Source: src/protocol/lookup.x:130

Compiler.protocol_update_helper

String Compiler.protocol_update_helper( Compiler c, Type participant, String member, int postfix)

Returns a generated helper for a direct protocol-backed update. The resolved member must have exactly (Participant, RHS) -> Participant. A matching helper is emitted once into the unit’s pending support; postfix selects whether it returns the old or stored value. Returns null when the member cannot implement this update shape.

Source: src/protocol/call-helpers.x:62

Compiler.publish_protocol_node

List Compiler.publish_protocol_node( Compiler c, List node, Token participant_token, Token representation_token)

Validates and installs one normalized protocol or adoption node. The node must carry a protocol record or supported adoption shape with its storage and source location. Installation invalidates cached protocol decisions and returns the canonical published node. Generated contexts may also retain that node in Sym for replay. A (meta-protocol ADOPTION) node publishes its adoption and marks it for compile-time code.

Source: src/protocol/registry.x:249

Compiler.rebuild_protocols

void Compiler.rebuild_protocols(Compiler c, Map symbols)

Rebuilds the per-unit protocol and adoption registries from symbols. Existing rows, helper decisions, and lookup caches are discarded; a null map leaves those registries empty. The conformance rows included interfaces recorded are kept for reuse. Conformance reset and resolution belong to resolve_protocols.

Source: src/protocol/registry.x:505

Compiler.record_source_typedef

void Compiler.record_source_typedef( Compiler c, String name, List declaration, int private)

Remembers a source typedef’s declaration and visibility, which native alias insertion reads for its participant.

Source: src/protocol/adapters.x:371

Compiler.resolve_as_declared

void Compiler.resolve_as_declared(Compiler c, Map symbols)

Resolves the adoptions visible in symbols as a declaring unit’s full parse resolves its own: before the parse, and again, after the generated members are published, where the parse publishes each one. Their declaring units report their failures, so nothing is reported.

Source: src/protocol/resolution.x:227

Compiler.resolve_protocol_member

List Compiler.resolve_protocol_member( Compiler c, Type participant, String member_name)

Resolves a protocol member for participant. Returns a (binding signature) pair for the selected implementation or null when no eligible resolved member exists; positive and negative results are cached. Inside the selected implementation itself the result is null, so the member’s own body keeps the native operation.

Source: src/protocol/lookup.x:216

Compiler.resolve_protocols

void Compiler.resolve_protocols(Compiler c)

Resolves every visible adoption into the current conformance registry. Resolution starts from an empty registry; diagnostics are located only for adoptions owned by the current translation unit. An adoption another unit declared and recorded keeps that conformance, which is installed when it is first used.

Source: src/protocol/resolution.x:145

Compiler.reverse_converter_spelling

String Compiler.reverse_converter_spelling( Compiler c, String base_name, String infix, String participant)

Returns the conventional reverse converter spelling. A Base.participant reverse converter is declared under the participant’s source spelling, and package mode rewrites that joined name as a whole, so the package prefix sits at the front of the derived binding instead of inside it. The split is keyed on a known package because a foreign header may spell __ in a type name.

Source: src/protocol/registry.x:225

Compiler.wrapper_function

List Compiler.wrapper_function( Compiler c, Type result, List binding, List params, List body)

Returns the function result name(params) { body } bound in this unit. result is the storage class and result type, so static, inline and external helpers share it; params are the parameter declarations, and body its lowered statements.

Source: src/protocol/call-helpers.x:19

Design notes

This module owns the protocol feature: it parses protocol and adoption declarations, keeps their rows in per-unit registries, resolves each adoption into a conformance, answers member and operator lookups, and presents each conformance as native aliases or a conform form, from which src/components/protocol-adapters.x writes the adapters. Registries are rebuilt per translation unit; a static row is visible only in the unit of its canonical source path. The unit that declares an external adoption resolves it and records the conformance in its interface, which an including unit reuses.