Emitter
struct Emitter : Sendable
Hylo’s IR emitter.
The emitter transforms well-formed, typed ASTs to a representation suitable for flow-sensitive analysis. IR generated from the emitter may be incomplete and must go through mandatory passes before it can be fed to code generation.
You create an instance by calling Emitter.withInstance, providing the module in which IR
should be incorporated and a diagnostic log. Then, the two main entry points are:
incorporateTopLevelDeclarations: incorporates the top-level declarations of a module’s AST into its corresponding IR form.incorporateSyntheticDeclarations: generates the implementations of the synthesized declarations that are notionally part of a module. This method is called after definite deinitialization.
Other entry points may be used during IR passes (e.g., emitDeinit).
Note
Unless documented otherwise, the methods ofEmitter type insert IR in self.module
at self.insertionPoint, anchoring new instructions at the given source range, named site
in their parameter lists.
-
The diagnostics of lowering errors.
Declaration
Swift
private var diagnostics: DiagnosticSet -
The module into which new IR is inserted.
Declaration
Swift
private var module: Module! -
A stack of frames describing the variables and allocations of each traversed lexical scope.
Declaration
Swift
private var frames: Emitter.Stack -
The loops in which control flow has currently entered.
Declaration
Swift
private var loops: Emitter.LoopIDs -
For each block, the state of
frameswhere the block was first entered. -
Where new instructions are inserted.
Declaration
Swift
var insertionPoint: InsertionPoint? -
The source code associated with instructions to be inserted.
Declaration
Swift
var currentSource: SourceRange -
The program being lowered.
Declaration
Swift
private var program: TypedProgram { get } -
The AST of the program being lowered.
Declaration
Swift
private var ast: AST { get } -
The basic block in which new instructions are currently inserted.
Declaration
Swift
private var insertionBlock: Block.ID? { get } -
The function containing the current insertion block.
Declaration
Swift
private var insertionFunction: Function.ID? { get } -
The scope corresponding to the current insertion block.
Declaration
Swift
private var insertionScope: AnyScopeID? { get } -
The address of the return value in the current function, if any.
Declaration
Swift
private var returnValue: Operand? { get } -
Reports the given diagnostic.
Declaration
Swift
private mutating func report(_ d: Diagnostic) -
Appends a new basic block at the end of
self.insertionFunction, defined in s.Declaration
Swift
private mutating func appendBlock<T>(in s: T) -> Block.ID where T : ScopeID -
Appends a new basic block at the end of
self.insertionFunction, defined in the same scope asself.insertionBlock.Declaration
Swift
private mutating func appendBlock() -> Block.ID -
Inserts
newInstructionintoself.moduleat the end ofself.insertionPoint.Requires
self.insertionPointrefers to the end of a block.Declaration
Swift
@discardableResult private mutating func insert<I>(_ newInstruction: I) -> Operand? where I : Instruction
-
Inserts the IR for the top-level declarations of
self.module.Declaration
Swift
mutating func incorporateTopLevelDeclarations() -
Inserts the IR for the synthesized declarations of
self.module.Declaration
Swift
mutating func incorporateSyntheticDeclarations()
-
Inserts the IR for the top-level declaration
d.Requires
dis at module scope.Declaration
Swift
private mutating func lower(topLevel d: AnyDeclID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(conformance d: ConformanceDecl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(extension d: ExtensionDecl.ID) -
Inserts the IR for
d, returning the ID of the lowered function.Declaration
Swift
@discardableResult private mutating func lower(function d: FunctionDecl.ID) -> Function.ID -
Inserts the IR for
d, returning the ID of the lowered function.Requires
selfhas a clear lowering context.Declaration
Swift
private mutating func lowerInClearContext(function d: FunctionDecl.ID) -> Function.ID -
Returns the frame enclosing the body of
d, whose entry block isentry.Declaration
-
Inserts the IR for the statements of
b, which is the body of a function returning instances ofreturnType, and returns the site of the return statement.Declaration
Swift
@discardableResult private mutating func siteOfReturn( lowering b: BraceStmt.ID, whichReturns returnType: AnyType ) -> SourceRange -
Inserts the IR for calling
d, which is a foreign function interface.Declaration
Swift
private mutating func lower(ffi d: FunctionDecl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(initializer d: InitializerDecl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(method d: MethodDecl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(methodImpl d: MethodImpl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(subscript d: SubscriptDecl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(subscriptImpl d: SubscriptImpl.ID) -
Inserts the IR for
b, which is the body ofdand is enclosed inbodyFrame.Declaration
Swift
private mutating func lower(body b: BraceStmt.ID, of d: SubscriptImpl.ID, in f: Frame) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(namespace d: NamespaceDecl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(product d: ProductTypeDecl.ID) -
Inserts the IR for
d.Declaration
Swift
private mutating func lower(trait d: TraitDecl.ID) -
Inserts the IR for given declaration
members.Declaration
Swift
private mutating func lower(members: [AnyDeclID]) -
Inserts the IR for
d.Requires
dis a global binding.Declaration
Swift
private mutating func lower(globalBinding d: BindingDecl.ID) -
Inserts the IR for the local binding
d.Requires
dis a local binding.Declaration
Swift
private mutating func lower(localBinding d: BindingDecl.ID) -
Inserts the IR for stored local binding
d.Requires
dis a localvarorsink letbinding.Declaration
Swift
private mutating func lower(storedLocalBinding d: BindingDecl.ID) -
Inserts the IR to declare and initialize the names in
lhs, which refer to subobjects ofsubfieldrelative tostorage, by consuming the value ofinitializer.Declaration
Swift
private mutating func emitInitStoredLocalBindings( in lhs: AnyPatternID, referringTo subfield: RecordPath, relativeTo storage: Operand, consuming initializer: AnyExprID ) -
Inserts the IR to declare and initialize
name, which refers to the givensubfieldrelative tostorage, by consuming the value ofinitializer.Declaration
Swift
private mutating func emitInitStoredLocalBinding( _ name: NamePattern.ID, referringTo subfield: RecordPath, relativeTo storage: Operand, consuming initializer: AnyExprID ) -
Inserts the IR to declare and initialize the names in
lhs, which refer to subobjects ofsubfieldrelative tostorage, by consuming the value ofinitializer.Declaration
Swift
private mutating func emitInitStoredLocalBindings( in lhs: TuplePattern.ID, referringTo subfield: RecordPath, relativeTo storage: Operand, consuming initializer: AnyExprID ) -
Inserts the IR to declare the names in
pattern, which refer to parts ofsubfieldrelative tostorage.Declaration
Swift
private mutating func emitLocalDeclarations<T: PatternID>( introducedBy pattern: T, referringTo subfield: RecordPath, relativeTo storage: Operand ) -
Inserts the IR to declare
name, which refers tosubfieldrelative tostorage, returning that sub-location.Declaration
-
Inserts the IR for projected local binding
d.Requires
dis a localletorinoutbinding.Declaration
Swift
private mutating func lower(projectedLocalBinding d: BindingDecl.ID) -
Assigns the bindings declared in
dto their corresponding projection ofrhs.Declaration
Swift
private mutating func assignProjections(of rhs: Operand, to d: BindingPattern.ID)
-
Synthesizes the implementation of
d.Declaration
Swift
mutating func lower(synthetic d: SynthesizedFunctionDecl) -
Inserts the IR for
d, which is a synthetic deinitializer.Declaration
Swift
private mutating func lower(syntheticDeinit d: SynthesizedFunctionDecl) -
Inserts the IR for
d, which is a synthetic move initialization method.Declaration
Swift
private mutating func lower(syntheticMoveInit d: SynthesizedFunctionDecl) -
Inserts the IR for initializing the stored parts of
receiver, which stores a record, consumingargument.Declaration
-
Inserts the IR for initializing the payload of
receiver, which stores a union container, consumingargument.Declaration
-
Inserts the IR for initializing the payload of
receiver, which stores a union containing apayload, consumingargument.Requires
the type ofstorageis a union containing apayload.Declaration
-
Inserts the IR for
d, which is a synthetic move initialization method.Declaration
Swift
private mutating func lower(syntheticMoveAssign d: SynthesizedFunctionDecl) -
Inserts the IR for
d, which is a synthetic copy method.Declaration
Swift
private mutating func lower(syntheticCopy d: SynthesizedFunctionDecl) -
Inserts the ID for
d, which is an equality operator.Declaration
Swift
private mutating func lower(syntheticEqual d: SynthesizedFunctionDecl) -
Declares
din the current module and returns its corresponding identifier, callingactionto generate its implementation if it should be emitted the current module.Declaration
-
Inserts the IR for copying the stored parts of
source, which stores a record, totarget.Declaration
-
Inserts the IR for copying
source, which stores a union container, totarget.Declaration
-
Inserts the IR for copying
source, which stores a union containing apayload, totarget.Declaration
-
Inserts the IR for lowering
d, which is a global binding initializer, returning the ID of the lowered function.Declaration
Swift
@discardableResult private mutating func lower(globalBindingInitializer d: SynthesizedFunctionDecl) -> Function.ID -
Undocumented
Declaration
Swift
private mutating func lower(syntheticAutoclosure d: SynthesizedFunctionDecl) -> Function.ID -
Returns
trueif the body ofd, which has been lowered tofinself, has yet to be generated inself.Declaration
Swift
private func shouldEmitBody(of d: SynthesizedFunctionDecl, loweredTo f: Function.ID) -> Bool
-
The description of the next action a program should execute.
See moreDeclaration
Swift
private enum ControlFlow : Equatable -
Inserts IR for handling the given control flow, applying
handleNextto generate the IR corresponding to.next.Declaration
Swift
private mutating func emitControlFlow( _ f: ControlFlow, handlingNextWith handleNext: (inout Self) -> Void ) -
Inserts IR for returning from current function, anchoring instructions at
s.Declaration
Swift
private mutating func emitControlFlow(return s: ReturnStmt.ID) -
Inserts IR for breaking from innermost loop, anchoring instructions at
s.Declaration
Swift
private mutating func emitControlFlow(break s: BreakStmt.ID) -
Inserts the IR for
s, returning its effect on control flow.Declaration
Swift
private mutating func emit<T>(stmt s: T) -> ControlFlow where T : StmtID -
Undocumented
Declaration
Swift
private mutating func _emit(assignStmt s: AssignStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(braceStmt s: BraceStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(stmtList stmts: [AnyStmtID]) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(breakStmt s: BreakStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(condCompilationStmt s: ConditionalCompilationStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(conditionalBindingStmt s: ConditionalBindingStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(conditionalStmt s: ConditionalStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(declStmt s: DeclStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(discardStmt s: DiscardStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func _emit(doWhileStmt s: DoWhileStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func _emit(exprStmt s: ExprStmt.ID) -> ControlFlow -
Inserts the IR for loop
s, returning its effect on control flow.Declaration
Swift
private mutating func emit(forStmt s: ForStmt.ID) -> ControlFlow -
Inserts the IR for consuming loop
s, returning its effect on control flow.Declaration
Swift
private mutating func emit(consumingForStmt s: ForStmt.ID) -> ControlFlow -
Inserts the IR for non-consuming loop
s, returning its effect on control flow.Declaration
Swift
private mutating func emit(nonConsumingForStmt s: ForStmt.ID) -> ControlFlow -
Inserts the IR for initializing the start and end positions of
domain, whose conformance to the collection trait is witnessed bywitness, returning these positions.Declaration
Swift
private mutating func _emitPositions( forIteratingOver domain: Operand, usingWitness witness: CollectionWitness ) -> (startIndex: Operand, endIndex: Operand) -
Inserts the IR for
s, returning its effect on control flow.Declaration
Swift
private mutating func _emit(returnStmt s: ReturnStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(whileStmt s: WhileStmt.ID) -> ControlFlow -
Undocumented
Declaration
Swift
private mutating func emit(yieldStmt s: YieldStmt.ID) -> ControlFlow
-
Inserts the IR for initializing
storageby storingvalueto it. -
Inserts the IR for storing the value of
eto a fresh stack allocation, returning the address of this allocation.Declaration
Swift
@discardableResult private mutating func emitStore<T>(value e: T) -> Operand where T : ExprID -
Inserts the IR for storing the value of
etostorage.Requires
storageis the address of some uninitialized memory block capable of storing the value ofe.Declaration
Swift
private mutating func emitStore<T>(value e: T, to storage: Operand) where T : ExprID -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: BufferLiteralExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: CaptureExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func emitStore(_ e: CastExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(upcast e: CastExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func emitStore(downcast e: CastExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(pointerConversion e: CastExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: ConditionalExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func emitStore(_ e: FloatLiteralExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: FunctionCallExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func emitStore(_ e: IntegerLiteralExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: LambdaExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: NameExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore( _ e: PragmaLiteralExpr.ID, to storage: Operand ) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: RemoteTypeExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func emitStore(_ e: SequenceExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func emitStore(_ e: FoldedSequenceExpr, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func emitStore(_ e: SubscriptCallExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: StringLiteralExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: TupleExpr.ID, to storage: Operand) -
Inserts the IR for storing the value of
etostorage.Declaration
Swift
private mutating func _emitStore(_ e: TupleMemberExpr.ID, to storage: Operand) -
Inserts the IR to store the value of
etostorage, converting it to the type ofstorageif necessary.The type comparison is performed in the scope of
e.Declaration
Swift
private mutating func emitStore<T: ExprID>( convertingIfNecessary e: T, to storage: Operand ) -
Writes the value of
literaltostorage.Declaration
Swift
private mutating func emitStore<T: NumericLiteralExpr>( numericLiteral literal: T.ID, to storage: Operand ) -
Writes the value of
literaltostorage, knowing it is a core floating-point instance evaluated byevaluate.Declaration
Swift
private mutating func _emitStore<T: NumericLiteralExpr>( floatingPoint literal: T.ID, to storage: Operand, evaluatedBy evaluate: (String) -> FloatingPointConstant ) -
Writes the value of
literaltostorage, knowing it is a core integer instance with given sign and width.Declaration
Swift
private mutating func _emitStore<T: NumericLiteralExpr>( integer literal: T.ID, signed: Bool, bitWidth: Int, to storage: Operand ) -
Writes an instance of
Hylo.Boolwith valuevtostorage.Requires
storageis the address of uninitialized memory of typeHylo.Int.Declaration
Swift
private mutating func _emitStore(boolean v: Bool, to storage: Operand) -
Writes an instance of
Hylo.Intwith valuevtostorage.Requires
storageis the address of uninitialized memory of typeHylo.Int.Declaration
Swift
mutating func _emitStore(int v: Int, to storage: Operand) -
Writes an instance of
Hylo.Stringwith valuevtostorage.Requires
storageis the address of uninitialized memory of typeHylo.String.Declaration
Swift
private mutating func _emitStore(utf8 v: String.UTF8View, to storage: Operand) -
Inserts the IR for storing
a, which is anaccess, tostorage.Parameters
storagean address derived from an
alloc_stackthat is outlived by the provenances ofa. -
Inserts the IR for calling
calleeonarguments, storing the result tostorage.Declaration
-
Inserts the IR for calling
calleeonarguments, storing the result tostorage.Declaration
-
Inserts the IR for calling
calleeonarguments, storing the result tostorage.Declaration
Swift
private mutating func _emitApply( _ callee: BundleReference<MethodDecl>, to arguments: [Operand], writingResultTo storage: Operand ) -
Inserts the IR for given constructor
call, which initializes storagerby applying initializerdparameterized bya.Declaration
Swift
private mutating func _emit(constructorCall call: FunctionCallExpr.ID, initializing s: Operand)Parameters
callThe syntax of the call.
sThe address of uninitialized storage typed by the receiver of
call. This storage is borrowed for initialization after evaluatingcall‘s arguments and before the call. -
Inserts the IR for given memberwise constructor
call, which initializesreceiver.Declaration
Swift
private mutating func _emit( memberwiseInitializerCall call: FunctionCallExpr.ID, initializing receiver: Operand )Parameters
callThe syntax of the call.
receiverThe address of uninitialized storage typed by the receiver of
d. This storage is borrowed for initialization after evaluatingcall‘s arguments. -
Inserts the IR preparing the run-time arguments passed to
calleeincall, loweringargumentsand synthesizing default values atsyntheticSite.Information about argument resolution is read from
program.callOperands. Arguments passed explicitly have a corresponding expression inarguments. If default arguments are used,calleeis a name expression referring to a callable declaration.Declaration
Swift
private mutating func _emitArguments( to callee: AnyExprID, in call: CallID, usingExplicit arguments: [LabeledArgument] ) -> [Operand] -
Inserts the IR for the argument
epassed to a parameter of typepDeclaration
Swift
private mutating func _emitArgument( _ e: AnyExprID, to p: ParameterType ) -> Operand -
Inserts the IR for argument
epassed to an autoclosure parameter of typep.Declaration
Swift
private mutating func _emitAutoclosureArgument(_ e: AnyExprID, to p: ParameterType) -> Operand -
Inserts the IR for argument
epassed to a parameter of typepDeclaration
Swift
private mutating func _emitPragmaLiteralArgument( _ e: PragmaLiteralExpr.ID, to p: ParameterType ) -> Operand -
Inserts the IR generating the operands of the subscript call
e.Declaration
Swift
private mutating func emitOperands( _ e: SubscriptCallExpr.ID ) -> (callee: BundleReference<SubscriptDecl>, arguments: [Operand]) -
Inserts the IR for infix operand
epassed to a parameter of typep.Declaration
Swift
private mutating func emit( infixOperand e: FoldedSequenceExpr, passedTo p: ParameterType ) -> Operand -
Emits the IR of a call to
fwith givenarguments.Declaration
Swift
private mutating func _emit(apply f: BuiltinFunction, to arguments: [LabeledArgument]) -> Operand -
Inserts the IR for given
callee, which is marked for mutation iffisMutatingistrue, and returns the callee’s value along with its lifted arguments.Lifted arguments correspond to the captures of the
callee, which are additional parameters of the lowered function. Bound member functions have a single lifted argument denoting their receiver. Local functions with non-empty environments may have many. Lifted arguments are returned in the same order as the additional parameters in the lowered function.Requires
calleehas a lambda type.Declaration
-
Inserts the IR for given
callee, which is marked for mutation iffisMutatingistrue, and returns the callee’s value along with its lifted arguments.Declaration
-
Inserts the IR evaluating
callee, which refers to a member function, returning the callee’s value along with the call receiver.The callee is marked for mutation iff
isMutatingistrue, in which case the receiver is accessed with asetorinoutcapability.Declaration
-
Inserts the IR constructing the callee of a call referring to
d, which is a member function ofr, returning the callee’s value along with the call receiver.The callee is marked for mutation iff
isMutatingistrue, in which case the receiver is accessed with asetorinoutcapability.Declaration
-
Returns the value of a reference to
b, which is bound toreceiver.If
brequests only one capability, the returned callee is a direct function reference to the corresponding variant. Otherwise, it isbunchanged. The returned capture is an access onreceivertaking the weakest capability thatbrequests. This access may be modified later to take a stronger capability if last use analysis allows it.Declaration
Swift
private mutating func _emitMethodBundleCallee( referringTo b: BundleReference<MethodDecl>, on receiver: Operand ) -> (callee: Callee, captures: [Operand]) -
Inserts the IR for given
calleeand returns its value.Requires
calleehas a lambda type.Declaration
Swift
private mutating func emitLambdaCallee(_ callee: AnyExprID) -> Operand -
Inserts the IR for given
calleeand returns its value along with its lifted arguments.Declaration
Swift
private mutating func emitSubscriptCallee( _ callee: AnyExprID ) -> (callee: BundleReference<SubscriptDecl>, captures: [Operand]) -
Inserts the IR for given
calleeand returns its value along with its lifted arguments.Declaration
Swift
private mutating func emitNamedSubscriptCallee( _ callee: NameExpr.ID ) -> (callee: BundleReference<SubscriptDecl>, captures: [Operand]) -
Inserts the IR evaluating
callee, which refers to a member subscript, returning the callee’s value along with the call receiver.Declaration
Swift
private mutating func emitMemberSubscriptCallee( _ callee: NameExpr.ID ) -> (callee: BundleReference<SubscriptDecl>, captures: [Operand]) -
Returns
(success: a, failure: b)whereais the basic block reached if all items inconditionhold andbis the basic block reached otherwise, creating new basic blocks inscope.Declaration
-
If
ddeclares stored bindings, inserts the IR for allocating their storage and returns a the address of that storage. Otherwise, returnsnil.Declaration
Swift
private mutating func emitAllocation(binding d: BindingDecl.ID) -> Operand? -
Returns a basic block in which the names in
dhave been declared and initialized.This method emits IR to:
- evaluate the
d‘s initializer as value v, - check whether the value in v is an instance of
d’s type; - if it isn’t, jump to
failure; - if it is, jump to a new basic block and define and initialize the bindings declared in
d.
If
dhas a consuming introducer (e.g.,var), the value ofd’s initializer is moved tostorage, which denotes a memory location withd’s type. Otherwise,storageisniland the bindings indare defined as new projections. In either case, the emitter’s context is is updated to associate each binding to its value.The return value of the method is a basic block, defined in
scope. If v has the same type asd, the narrowing is irrefutable andfailureis unreachable in the generated IR.Declaration
- evaluate the
-
Returns a basic block in which the names in
lhshave been declared and initialized.Declaration
Parameters
rhsA union container of a type that includes
lhsType.storageFor a consuming narrowing, the storage of the bindings declared in
lhs.failureThe basic block to which control flow jumps if the narrowing fails.
scopeThe scope in which the new basic block is introducked.
-
Inserts the IR for branch condition
e.Requires
e.typeisHylo.BoolDeclaration
Swift
private mutating func emit(branchCondition e: AnyExprID) -> Operand -
Inserts the IR for extracting the built-in value stored in an instance of
Hylo.Bool. -
If
shas a remote type, returns the result of an instruction exposing the captured access; otherwise, returnss. -
Inserts the IR for coercing
sourceto an address of typetarget.sourceis returned unchanged if it stores an instance oftarget. Otherwise, the IR producing an address of typetargetis inserted, consumingsourceif necessary.Declaration
-
Inserts the IR for coercing
sourceto an address of typetarget.Requires
targetis canonical.Declaration
-
Inserts the IR for coercing
sourceto an address of typetarget.Requires
targetis canonical.Declaration
-
Inserts the IR for coercing
sourceto an address of typetarget.Requires
targetis canonical.Declaration
-
Traps on this execution path because of un unexpected coercion from
lhstorhs.Declaration
Swift
private func unexpectedCoercion( from lhs: AnyType, to rhs: AnyType, file: StaticString = #filePath, line: UInt = #line ) -> Never -
Inserts the IR for converting
foreignto a value of typeir. -
Appends the IR to convert
oto a FFI argument.The returned operand is the result of a
loadinstruction. -
Returns an existential container of type
twrappringwitness.Declaration
-
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(_ e: AnyExprID) -> Operand -
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(_ e: CastExpr.ID) -> Operand -
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(upcast e: CastExpr.ID) -> Operand -
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(pointerConversion e: CastExpr.ID) -> Operand -
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(_ e: InoutExpr.ID) -> Operand -
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(_ e: NameExpr.ID) -> Operand -
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(_ e: SubscriptCallExpr.ID) -> Operand -
Inserts the IR for lvalue
e.Declaration
Swift
private mutating func emitLValue(_ e: TupleMemberExpr.ID) -> Operand -
Inserts the IR for
rused a lvalue.Declaration
Swift
private mutating func _emitLValue(reference r: DeclReference) -> Operand -
Returns the address of the
operation‘s receiver, which refers to a member declaration.Declaration
Swift
private mutating func _emitLValue(receiver r: DeclReference.Receiver) -> Operand -
Inserts the IR denoting a direct reference to
d.Declaration
Swift
private mutating func _emitLValue( directReferenceTo d: AnyDeclID ) -> Operand -
Inserts the IR to return the address of the member declared by
d, bound tor, and specialized byz.Declaration
-
Returns the projection the property declared by
d, bound tor, and specialized byz.Declaration
-
Returns the projection of the property declared by
d, bound tor, and specialized byz.Declaration
-
Replaces
i, which is amoveinstruction with move-assignment ofsemantics == .inoutor move-initialization ifsemantics == .set, returning the identity of the first instruction taking the place ofi.After the call,
insertionPointset tonil.Declaration
Swift
mutating func replaceMove(_ i: InstructionID, with semantics: AccessEffect) -> InstructionID -
Inserts IR for move-initializing/assigning
storagewithvalue.The value of
semanticsdefines the type of move to emit:.setemits move-initialization..inoutemits move-assignment.[.inout, .set]emits amoveinstruction that will is later replaced during definite initialization analysis by either move-assignment ifstorageis found initialized or by move-initialization otherwise.
Declaration
-
Inserts IR for move-initializing/assigning
storagewith built-invalue. -
Inserts IR for move-initializing/assigning
storagewithvalueusingmovableto locate the implementations of these operations.The value of
semanticsdefines the type of move to emit:.setemits move-initialization..inoutemits move-assignment.
Requires
storagedoes not have a built-in type.Declaration
Swift
private mutating func _emitMove( _ semantics: AccessEffect, _ value: Operand, to storage: Operand, withMovableConformance movable: FrontEnd.Conformance )
-
Inserts IR for copying
sourcetotarget. -
Inserts IR for copying
sourcetotargetusingcopyableto locate the implementation of the copy operation.Declaration
Swift
private mutating func _emitCopy( _ source: Operand, to target: Operand, withCopyableConformance copyable: FrontEnd.Conformance )
-
If
storageis deinitializable inself.insertionScope, inserts the IR for deinitializing it, or reports a diagnostic otherwise.Let
Tbe the type ofstorage,storageis deinitializable iffThas a deinitializer exposed toself.insertionScope.Declaration
Swift
mutating func _emitDeinit(_ storage: Operand) -
Inserts the IR for deinitializing
storageusing theDeinitializableconformancec.Declaration
Swift
private mutating func _emitDeinit( _ storage: Operand, via c: FrontEnd.Conformance ) -
If
storageis deinitializable inself.insertionScope, inserts the IR for deinitializing it; reports a diagnostic for each part that isn’t deinitializable otherwise.Declaration
Swift
mutating func _emitDeinitParts(of storage: Operand) -
If
storage, which stores a record, is deinitializable inself.insertionScope, inserts the IR for deinitializing it; reports a diagnostic for each part that isn’t deinitializable otherwise.Requires
the type ofstoragehas a record layout.Declaration
Swift
private mutating func _emitDeinitRecordParts(of storage: Operand) -
If
storage, which stores a union, is deinitializable inself.insertionScope, inserts the IR for deinitializing it; reports a diagnostic for each part that isn’t deinitializable otherwise.Requires
the type ofstorageis a union.Declaration
Swift
private mutating func _emitDeinitUnionPayload(of storage: Operand) -
If
storage, which stores a union container holding apayload, is deinitializable inself.insertionScope, inserts the IR for deinitializing it; reports a diagnostic for each part that isn’t deinitializable otherwise.Declaration
Swift
private mutating func _emitDeinitUnionPayload(of storage: Operand, containing payload: AnyType)
-
Undocumented
Declaration
-
Inserts the IR writing in
targetwhether the parts oflhsandrhsare pairwise equal.Declaration
-
Inserts the IR writing in
targetwhether the payloads oflhsandrhsare equal.Declaration
-
Returns the canonical form of
tin the current insertion scope.Declaration
Swift
private func canonical(_ t: AnyType) -> AnyType -
Returns the type of
dspecialized withspecializationin the current insertion scope.Declaration
Swift
private func canonicalType<T: Decl>( of d: T.ID, specializedBy specialization: GenericArguments ) -> AnyType -
Returns the capabilities required by the receiver of
callee, which is the type of a member function or method bundle.Declaration
Swift
private func receiverCapabilities(_ callee: AnyType) -> AccessEffectSet -
Inserts a stack allocation for an object of type
t.Declaration
Swift
private mutating func _alloc_stack(_ t: AnyType) -> Operand -
Inserts the IR for deallocating each allocation in the top frame of
self.frames.Declaration
Swift
private mutating func _emitDeallocTopFrame() -
Undocumented
Declaration
Swift
private mutating func _dealloc_stack(_ source: Operand) -
Appends the IR for computing the address of the given
subfieldof the record atrecordAddressand returns the resulting address.Declaration
-
Emits the IR for copying the union discriminator of
container, which is the address of a union container. -
Appends the IR for jumping to the block assigned to the type of
scrutinee‘s payload intargets.Declaration
Swift
private mutating func _emitUnionSwitch( on scrutinee: Operand, toOneOf targets: UnionSwitch.Targets ) -
Returns the result of calling
actiononselfwithinnewFrame.newFrameis pushed onself.framesbeforeactionis called. Whenactionreturns, outstanding stack allocations are deallocated andnewFrameis popped. References to stack memory allocated byactionare invalidated when this method returns.Declaration
Swift
private mutating func within<T>(_ newFrame: Frame, _ action: (inout `Self`) -> T) -> T -
Returns the result of calling
actionon a copy ofselfwhose insertion block and frames are clear.Declaration
Swift
private mutating func withClearContext<T>(_ action: (inout `Self`) throws -> T) rethrows -> T -
Inserts a
cond_branchinstruction that jumps totargetIfTrueifconditionis true ortargetIfFalseotherwise.Declaration
-
The local variables and allocations of a lexical scope.
See moreDeclaration
Swift
fileprivate struct Frame : Sendable -
A stack of frames.
See moreDeclaration
Swift
fileprivate struct Stack : Sendable -
The identifier of a loop lexically enclosing newly generated IR.
See moreDeclaration
Swift
fileprivate struct LoopID : Sendable -
A stack of loop identifiers.
Declaration
Swift
fileprivate typealias LoopIDs = [LoopID] -
If the state of the stack upon entering
bis not known, records it asframes; otherwise asserts that it has the same allocations asframes.This test is used to ensure that all points branching to a block have consistent stack allocations.
Declaration
Swift
fileprivate mutating func checkEntryStack(_ b: Block.ID) -
Calls
body(&self)withcurrentSourceset to the lexical location ofx, returning the result.Declaration
Swift
mutating func lowering<ASTNode, R>(_ x: ASTNode, _ body: (inout Emitter) -> R) -> R where ASTNode : NodeIDProtocol -
Calls
body(&self)withcurrentSourceset to the lexical location ofx, returning the result.Declaration
Swift
mutating func lowering<T, R>(_ x: SourceRepresentable<T>, _ body: (inout Emitter) -> R) -> R -
Calls
body(&self)withcurrentSourceset to the lexical beginning ofx, returning the result.Declaration
Swift
mutating func lowering<ID, R>(before x: ID, _ body: (inout Emitter) -> R) -> R where ID : NodeIDProtocol -
Calls
body(&self)withcurrentSourceset to the lexical end ofx, returning the result.Declaration
Swift
mutating func lowering<ID, R>(after x: ID, _ body: (inout Emitter) -> R) -> R where ID : NodeIDProtocol -
Calls
body(&self)withcurrentSourceset tox, returning the result.Declaration
Swift
mutating func lowering<R>(at x: SourceRange, _ body: (inout Emitter) -> R) -> R -
The conditions described by the
See moremark_stateinstruction.Declaration
Swift
fileprivate enum InitializationState -
The ways of opening described by the
See moreopen_unioninstruction.Declaration
Swift
fileprivate enum OpenUnionOption -
Undocumented
Declaration
Swift
fileprivate mutating func _mark_state(_ x: InitializationState, _ op: Operand?) -
Undocumented
Declaration
-
Undocumented
Declaration
Swift
fileprivate mutating func _unreachable() -
Undocumented
Declaration
Swift
fileprivate mutating func _return() -
Undocumented
Declaration
-
Undocumented
Declaration
Swift
fileprivate mutating func _end_access(_ x: Operand) -
Undocumented
Declaration
Swift
fileprivate mutating func _yield(_ c: AccessEffect, _ a: Operand) -
Undocumented
Declaration
Swift
fileprivate mutating func _branch(to x: Block.ID) -
Undocumented
Declaration
Swift
fileprivate mutating func _open_union( _ container: Operand, as payload: AnyType, _ option: OpenUnionOption = .notForInitialization ) -> Operand -
Undocumented
Declaration
Swift
fileprivate mutating func _close_union(_ x: Operand) -
Undocumented
Declaration
-
Undocumented
-
Inserts a
loadinstruction reading fromsource. -
Undocumented
-
Undocumented
Declaration
-
Undocumented
Declaration
Swift
fileprivate mutating func _project_bundle( applying b: BundleReference<SubscriptDecl>, to arguments: [Operand] ) -> Operand -
Undocumented
-
Undocumented
Declaration
Swift
fileprivate mutating func _release_capture(_ source: Operand) -
Undocumented
Declaration
-
Undocumented
Declaration
Swift
fileprivate mutating func _constant_string(utf8 value: Data) -> Operand -
Undocumented
-
Undocumented
Declaration
-
Undocumented
Declaration
Swift
fileprivate mutating func _call_bundle( _ m: BundleReference<MethodDecl>, _ a: [Operand], to o: Operand, scopeOfUse: AnyScopeID ) -
Undocumented
Declaration
-
Undocumented
Declaration
-
Undocumented
Declaration
Swift
fileprivate mutating func _generic_parameter(at x: GenericParameterDecl.ID) -> Operand -
Undocumented
Declaration
Swift
fileprivate mutating func _global_addr(at x: BindingDecl.ID) -> Operand -
Undocumented
-
Undocumented
Declaration
Swift
fileprivate mutating func _move(_ source: Operand, _ target: Operand, via movability: FrontEnd.Conformance) -
Undocumented
-
Undocumented
Declaration
Swift
fileprivate mutating func _union_switch(case discriminator: Operand, of u: UnionType, _ targets: UnionSwitch.Targets)
View on GitHub