|
19 | 19 | package interpreter
|
20 | 20 |
|
21 | 21 | import (
|
| 22 | + "time" |
| 23 | + |
22 | 24 | "github.com/onflow/atree"
|
23 | 25 |
|
24 | 26 | "github.com/onflow/cadence/common"
|
| 27 | + "github.com/onflow/cadence/errors" |
25 | 28 | "github.com/onflow/cadence/sema"
|
26 | 29 | )
|
27 | 30 |
|
@@ -118,3 +121,120 @@ type ValueRemoveContext = ValueTransferContext
|
118 | 121 | type ComputationReporter interface {
|
119 | 122 | ReportComputation(compKind common.ComputationKind, intensity uint)
|
120 | 123 | }
|
| 124 | + |
| 125 | +type ValueIterationContext interface { |
| 126 | + ValueTransferContext |
| 127 | + WithMutationPrevention(valueID atree.ValueID, f func()) |
| 128 | +} |
| 129 | + |
| 130 | +type ValueStringContext interface { |
| 131 | + ValueIterationContext |
| 132 | +} |
| 133 | + |
| 134 | +// NoOpStringContext is the ValueStringContext implementation used in Value.RecursiveString method. |
| 135 | +// Since Value.RecursiveString is a non-mutating operation, it should only need the no-op memory metering |
| 136 | +// and a WithMutationPrevention implementation. |
| 137 | +// All other methods should not be reachable, hence is safe to panic in them. |
| 138 | +// |
| 139 | +// TODO: Ideally, Value.RecursiveString shouldn't need the full ValueTransferContext. |
| 140 | +// But that would require refactoring the iterator methods for arrays and dictionaries. |
| 141 | +type NoOpStringContext struct{} |
| 142 | + |
| 143 | +var _ ValueStringContext = NoOpStringContext{} |
| 144 | + |
| 145 | +func (n NoOpStringContext) MeterMemory(_ common.MemoryUsage) error { |
| 146 | + return nil |
| 147 | +} |
| 148 | + |
| 149 | +func (n NoOpStringContext) WithMutationPrevention(_ atree.ValueID, f func()) { |
| 150 | + f() |
| 151 | + return |
| 152 | +} |
| 153 | + |
| 154 | +func (n NoOpStringContext) ReadStored(_ common.Address, _ common.StorageDomain, _ StorageMapKey) Value { |
| 155 | + panic(errors.NewUnreachableError()) |
| 156 | +} |
| 157 | + |
| 158 | +func (n NoOpStringContext) ConvertStaticToSemaType(_ StaticType) (sema.Type, error) { |
| 159 | + panic(errors.NewUnreachableError()) |
| 160 | +} |
| 161 | + |
| 162 | +func (n NoOpStringContext) IsSubType(_ StaticType, _ StaticType) bool { |
| 163 | + panic(errors.NewUnreachableError()) |
| 164 | +} |
| 165 | + |
| 166 | +func (n NoOpStringContext) IsSubTypeOfSemaType(_ StaticType, _ sema.Type) bool { |
| 167 | + panic(errors.NewUnreachableError()) |
| 168 | +} |
| 169 | + |
| 170 | +func (n NoOpStringContext) WriteStored(_ common.Address, _ common.StorageDomain, _ StorageMapKey, _ Value) (existed bool) { |
| 171 | + panic(errors.NewUnreachableError()) |
| 172 | +} |
| 173 | + |
| 174 | +func (n NoOpStringContext) Storage() Storage { |
| 175 | + panic(errors.NewUnreachableError()) |
| 176 | +} |
| 177 | + |
| 178 | +func (n NoOpStringContext) RemoveReferencedSlab(_ atree.Storable) { |
| 179 | + panic(errors.NewUnreachableError()) |
| 180 | +} |
| 181 | + |
| 182 | +func (n NoOpStringContext) MaybeValidateAtreeValue(_ atree.Value) { |
| 183 | + panic(errors.NewUnreachableError()) |
| 184 | +} |
| 185 | + |
| 186 | +func (n NoOpStringContext) MaybeValidateAtreeStorage() { |
| 187 | + panic(errors.NewUnreachableError()) |
| 188 | +} |
| 189 | + |
| 190 | +func (n NoOpStringContext) InvalidateReferencedResources(_ Value, _ LocationRange) { |
| 191 | + panic(errors.NewUnreachableError()) |
| 192 | +} |
| 193 | + |
| 194 | +func (n NoOpStringContext) CheckInvalidatedResourceOrResourceReference(_ Value, _ LocationRange) { |
| 195 | + panic(errors.NewUnreachableError()) |
| 196 | +} |
| 197 | + |
| 198 | +func (n NoOpStringContext) MaybeTrackReferencedResourceKindedValue(_ *EphemeralReferenceValue) { |
| 199 | + panic(errors.NewUnreachableError()) |
| 200 | +} |
| 201 | + |
| 202 | +func (n NoOpStringContext) ReportComputation(_ common.ComputationKind, _ uint) { |
| 203 | + panic(errors.NewUnreachableError()) |
| 204 | +} |
| 205 | + |
| 206 | +func (n NoOpStringContext) TracingEnabled() bool { |
| 207 | + panic(errors.NewUnreachableError()) |
| 208 | +} |
| 209 | + |
| 210 | +func (n NoOpStringContext) reportArrayValueDeepRemoveTrace(_ string, _ int, _ time.Duration) { |
| 211 | + panic(errors.NewUnreachableError()) |
| 212 | +} |
| 213 | + |
| 214 | +func (n NoOpStringContext) reportArrayValueTransferTrace(_ string, _ int, _ time.Duration) { |
| 215 | + panic(errors.NewUnreachableError()) |
| 216 | +} |
| 217 | + |
| 218 | +func (n NoOpStringContext) reportDictionaryValueTransferTrace(_ string, _ int, _ time.Duration) { |
| 219 | + panic(errors.NewUnreachableError()) |
| 220 | +} |
| 221 | + |
| 222 | +func (n NoOpStringContext) reportDictionaryValueDeepRemoveTrace(_ string, _ int, _ time.Duration) { |
| 223 | + panic(errors.NewUnreachableError()) |
| 224 | +} |
| 225 | + |
| 226 | +func (n NoOpStringContext) reportCompositeValueDeepRemoveTrace(_ string, _ string, _ string, _ time.Duration) { |
| 227 | + panic(errors.NewUnreachableError()) |
| 228 | +} |
| 229 | + |
| 230 | +func (n NoOpStringContext) reportCompositeValueTransferTrace(_ string, _ string, _ string, _ time.Duration) { |
| 231 | + panic(errors.NewUnreachableError()) |
| 232 | +} |
| 233 | + |
| 234 | +func (n NoOpStringContext) reportDomainStorageMapDeepRemoveTrace(_ string, _ int, _ time.Duration) { |
| 235 | + panic(errors.NewUnreachableError()) |
| 236 | +} |
| 237 | + |
| 238 | +func (n NoOpStringContext) OnResourceOwnerChange(_ *CompositeValue, _ common.Address, _ common.Address) { |
| 239 | + panic(errors.NewUnreachableError()) |
| 240 | +} |
0 commit comments