Class CopyGenerator
The generated code follows this pattern:
Void _copy(T source): [check the source is the same class - an open owner, or an override] super._copy(source) // when the super has a :=:, declared or inherited // For each field: fieldValue = LOAD source.field STORE this.field, fieldValue return
Key semantic requirements:
- Copies ALL fields from source to this
- This is a mutating operation (modifies this)
- Returns Void (no return value)
- Both SET and UNSET field values are copied
- Super's _copy is called if super is not Any
This is a SHALLOW copy, by design - the copy principle (Steve, 2026-10-07; stated once in
docs/language-design/EK9_FORMAL_SPECIFICATION.md, "The Copy Principle"): each target field refers to
the SAME object as the source's, as b <- a and passing a parameter do. A built-in collection copies at
its own level; a deeper or SELECTIVE copy is user code (a hand-written operator :=: or a domain
method), because only the domain knows which fields to duplicate, share or drop. So this generator never
recurses and needs no cycle guard (a field-wise variant, fca82f857, was reverted).
The copy is POLYMORPHIC (Q5b, PolymorphicCopy, Contract 20): the owner's own :=:(Owner) and
the override of each inherited :=:(Super) copy in full only when the source is an instance of the owner
and the source's _copyAccepts(this) agrees - both objects have the same copy owner - and otherwise THROW
an EK9 Exception. A closed owner's own copy needs no check (no other class can reach it). This generator also
emits _copyAccepts itself (generateCopyAccepts(MethodSymbol, AggregateSymbol)).
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractSyntheticGenerator
AbstractSyntheticGenerator.CycleGuardEntry, AbstractSyntheticGenerator.ScopeSetup -
Field Summary
Fields inherited from class AbstractSyntheticGenerator
stackContext, synthesisedCallMetaData -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerate(MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol) Generate the _copy operator IR for the given aggregate - its own:=:(Owner), or the override of an inherited:=:(Super)signature (PolymorphicCopy, Q5b; told apart by the parameter type).generateCopyAccepts(MethodSymbol methodSymbol, AggregateSymbol aggregateSymbol) Generate the owner's_copyAccepts(target as Any) <- Boolean: istargetan instance of this owner (a SUBTYPE test - the owner or any class below it)? Asked of the SOURCE of a copy with the copy's target, so a copy runs in full only between objects whose nearest copy owner is the same class.Methods inherited from class AbstractSyntheticGenerator
aggregateHasOperator, constructorCall, createDebugInfo, createSynthesisScope, fieldTypeHasRealOperator, generateBinaryOperatorGuards, generateBooleanBranch, generateCycleGuardedRegion, generateCycleGuardEnter, generateFieldLoad, generateFieldLoad, generateFieldSetStatusCheck, generateIsSetGuard, generateIsSetGuard, generateLabelName, generatePoisonableCycleGuardedRegion, generateResultReturnBlock, generateResultReturnBlock, generateStringLiteralLoad, generateTempName, generateThisIsSetGuard, generateThisIsSetGuard, generateUnsetReturnBlockWithLabel, generateUnsetReturnBlockWithLabel, getAnyType, getAnyTypeName, getBitsType, getBitsTypeName, getBooleanType, getBooleanTypeName, getIntegerType, getIntegerTypeName, getReturnBlockHelper, getStringType, getStringTypeName, getSuperTypeName, getSyntheticFields, getType, getTypeName, getVoidTypeName, initializeScope, initializeScopeNoReturn, isAnyType, isTraitType, methodCall, nearestSuperOperator, needsCycleGuard, rendersNothing, servingOperatorParameterTypeName, superCallOwner, superContributesRepresentation, superHasOperator
-
Constructor Details
-
CopyGenerator
CopyGenerator(IRGenerationContext stackContext)
-
-
Method Details
-
generate
Generate the _copy operator IR for the given aggregate - its own:=:(Owner), or the override of an inherited:=:(Super)signature (PolymorphicCopy, Q5b; told apart by the parameter type).- Parameters:
operatorSymbol- The _copy operator method symbolaggregateSymbol- The aggregate containing the operator- Returns:
- List of IR instructions implementing the operator
-
generateCopyAccepts
Generate the owner's_copyAccepts(target as Any) <- Boolean: istargetan instance of this owner (a SUBTYPE test - the owner or any class below it)? Asked of the SOURCE of a copy with the copy's target, so a copy runs in full only between objects whose nearest copy owner is the same class.accepted = INSTANCEOF target, Owner [SUBTYPE] BRANCH_FALSE accepted, not_accepted rtn = Boolean._ofTrue() ; RETURN rtn not_accepted: rtn = Boolean._ofFalse() ; RETURN rtn
-