2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
package com .digitalasset .daml .lf
5
+ package speedy
5
6
6
- import com .digitalasset .daml .lf .speedy .SValue
7
7
import com .digitalasset .daml .lf .speedy .SValue ._
8
- import value .Value
9
- import data .Ref
10
- import sttp .tapir .SchemaType .SOption
8
+ import data .{FrontStack , Ref }
11
9
12
10
abstract class CostModel {
13
11
14
12
import CostModel ._
15
13
16
- val AddNumeric : Function2 [Numeric , Numeric ]
17
- val SubNumeric : Function2 [Numeric , Numeric ]
18
- val MulNumeric : Function3 [Numeric , Numeric , Numeric ]
19
- val DivNumeric : Function3 [Numeric , Numeric , Numeric ]
20
- val BRoundNumeric : Function2 [Int , Numeric ]
21
- val BCastNumeric : Function3 [Numeric , Numeric , Numeric ]
22
- val BShiftNumeric : Function3 [ Numeric , Numeric , Numeric ]
23
- val BAddInt64 : Function2 [Int64 , Int64 ]
24
- val BSubInt64 : Function2 [Int64 , Int64 ]
25
- val BMulInt64 : Function2 [Int64 , Int64 ]
26
- val BDivInt64 : Function2 [Int64 , Int64 ]
27
- val BModInt64 : Function2 [Int64 , Int64 ]
28
- val BExpInt64 : Function2 [Int64 , Int64 ]
29
- val BInt64ToNumeric : Function2 [Numeric , Int64 ]
30
- val BNumericToInt64 : Function1 [Numeric ]
14
+ val AddNumeric : CostFunction2 [Numeric , Numeric ]
15
+ val SubNumeric : CostFunction2 [Numeric , Numeric ]
16
+ val MulNumeric : CostFunction3 [Numeric , Numeric , Numeric ]
17
+ val DivNumeric : CostFunction3 [Numeric , Numeric , Numeric ]
18
+ val BRoundNumeric : CostFunction2 [Int , Numeric ]
19
+ val BCastNumeric : CostFunction3 [Numeric , Numeric , Numeric ]
20
+ val BShiftNumeric : CostFunction2 [ Int , Numeric ]
21
+ val BAddInt64 : CostFunction2 [Int64 , Int64 ]
22
+ val BSubInt64 : CostFunction2 [Int64 , Int64 ]
23
+ val BMulInt64 : CostFunction2 [Int64 , Int64 ]
24
+ val BDivInt64 : CostFunction2 [Int64 , Int64 ]
25
+ val BModInt64 : CostFunction2 [Int64 , Int64 ]
26
+ val BExpInt64 : CostFunction2 [Int64 , Int64 ]
27
+ val BInt64ToNumeric : CostFunction2 [Numeric , Int64 ]
28
+ val BNumericToInt64 : CostFunction1 [Numeric ]
31
29
val BFoldl = NotDefined
32
30
val BFoldr = NotDefined
33
31
lazy val BTextMapEmpty = BGenMapEmpty
34
- lazy val BTextMapInsert : Function3 [Value , Value , TextMap ] = BGenMapInsert
35
- lazy val BTextMapLookup : Function2 [Value , TextMap ] = BGenMapLookup
36
- lazy val BTextMapDelete : Function2 [Value , TextMap ] = BGenMapDelete
37
- val BTextMapToList : Function1 [TextMap ]
32
+ lazy val BTextMapInsert : CostFunction3 [Value , Value , TextMap ] = BGenMapInsert
33
+ lazy val BTextMapLookup : CostFunction2 [Value , TextMap ] = BGenMapLookup
34
+ lazy val BTextMapDelete : CostFunction2 [Value , TextMap ] = BGenMapDelete
35
+ val BTextMapToList : CostFunction1 [TextMap ]
38
36
lazy val BTextMapSize = BGenMapSize
39
37
val BGenMapEmpty = NotDefined
40
- val BGenMapInsert : Function3 [Value , Value , GenMap ]
41
- val BGenMapLookup : Function2 [Value , GenMap ]
42
- val BGenMapDelete : Function2 [Value , GenMap ]
43
- val BGenMapKeys : Function1 [GenMap ]
44
- val BGenMapValues : Function1 [GenMap ]
45
- val BGenMapSize : Function1 [GenMap ]
46
- val BAppendText : Function2 [Text , Text ]
38
+ val BGenMapInsert : CostFunction3 [Value , Value , GenMap ]
39
+ val BGenMapLookup : CostFunction2 [Value , GenMap ]
40
+ val BGenMapDelete : CostFunction2 [Value , GenMap ]
41
+ val BGenMapToList : CostFunction1 [GenMap ]
42
+ val BGenMapKeys : CostFunction1 [GenMap ]
43
+ val BGenMapValues : CostFunction1 [GenMap ]
44
+ val BGenMapSize : CostFunction1 [GenMap ]
45
+ val BAppendText : CostFunction2 [Text , Text ]
47
46
val BError = NotDefined
48
- val BInt64ToText : Function1 [Int64 ]
49
- val BNumericToText : Function1 [Numeric ]
50
- val BTimestampToText : Function1 [Timestamp ]
51
- val BPartyToText : Function1 [Party ]
52
- val BContractIdToText : Function1 [ContractId ]
53
- val BCodePointsToText : Function1 [ List ]
54
- val BTextToParty : Function1 [Text ]
55
- val BTextToInt64 : Function1 [Text ]
56
- val BTextToNumeric : Function1 [ Text ]
57
- val BTextToCodePoints : Function1 [Text ]
58
- val BSHA256Text : Function1 [Text ]
59
- val BKECCAK256Text : Function1 [Text ]
60
- val BSECP256K1Bool : Function1 [Text ]
61
- val BDecodeHex : Function1 [Text ]
62
- val BEncodeHex : Function1 [Text ]
63
- val BTextToContractId : Function1 [Text ]
64
- val BDateToUnixDays : Function1 [Date ]
65
- val BExplodeText : Function1 [Text ]
47
+ val BInt64ToText : CostFunction1 [Int64 ]
48
+ val BNumericToText : CostFunction1 [Numeric ]
49
+ val BTimestampToText : CostFunction1 [Timestamp ]
50
+ val BPartyToText : CostFunction1 [Party ]
51
+ val BContractIdToText : CostFunction1 [ContractId ]
52
+ val BCodePointsToText : CostFunction1 [ FrontStack [ Long ] ]
53
+ val BTextToParty : CostFunction1 [Text ]
54
+ val BTextToInt64 : CostFunction1 [Text ]
55
+ val BTextToNumeric : CostFunction2 [ Int , Text ]
56
+ val BTextToCodePoints : CostFunction1 [Text ]
57
+ val BSHA256Text : CostFunction1 [Text ]
58
+ val BKECCAK256Text : CostFunction1 [Text ]
59
+ val BSECP256K1Bool : CostFunction1 [Text ]
60
+ val BDecodeHex : CostFunction1 [Text ]
61
+ val BEncodeHex : CostFunction1 [Text ]
62
+ val BTextToContractId : CostFunction1 [Text ]
63
+ val BDateToUnixDays : CostFunction1 [Date ]
64
+ val BExplodeText : CostFunction1 [Text ]
66
65
val BImplodeText = CostAware
67
- val BTimestampToUnixMicroseconds : Function1 [Timestamp ]
68
- val BDateToText : Function1 [Date ]
69
- val BUnixDaysToDate : Function1 [Int64 ]
70
- val BUnixMicrosecondsToTimestamp : Function1 [Int64 ]
71
- val BEqual : Function2 [Value , Value ]
72
- val BLess : Function2 [Value , Value ]
73
- val BLessEq : Function2 [Value , Value ]
74
- val BGreater : Function2 [Value , Value ]
75
- val BGreaterEq : Function2 [Value , Value ]
66
+ val BTimestampToUnixMicroseconds : CostFunction1 [Timestamp ]
67
+ val BDateToText : CostFunction1 [Date ]
68
+ val BUnixDaysToDate : CostFunction1 [Int64 ]
69
+ val BUnixMicrosecondsToTimestamp : CostFunction1 [Int64 ]
70
+ val BEqual : CostFunction2 [Value , Value ]
71
+ val BLess : CostFunction2 [Value , Value ]
72
+ val BLessEq : CostFunction2 [Value , Value ]
73
+ val BGreater : CostFunction2 [Value , Value ]
74
+ val BGreaterEq : CostFunction2 [Value , Value ]
76
75
val BEqualList = NotDefined
77
76
val BTrace = NotDefined
78
- val BCoerceContractId : Function1 [ContractId ]
77
+ val BCoerceContractId : CostFunction1 [ContractId ]
79
78
val BScaleBigNumeric = NotDefined // Available in 2.dev
80
79
val BPrecisionBigNumeric = NotDefined // Available in 2.dev
81
80
val BAddBigNumeric = NotDefined // Available in 2.dev
@@ -90,6 +89,13 @@ abstract class CostModel {
90
89
val BTypeRepTyConName = NotDefined
91
90
val BFailWithStatus = NotDefined
92
91
92
+ def update (cost : Cost ): Unit
93
+
94
+ def undefined (cost : NotDefined .type ): Unit
95
+
96
+ def costAware (cost : CostAware .type ): Unit
97
+
98
+ def getCost : Cost
93
99
}
94
100
95
101
object CostModel {
@@ -99,95 +105,105 @@ object CostModel {
99
105
type Int64 = Long
100
106
type Numeric = data.Numeric
101
107
type Text = String
102
- type Date = Int
108
+ type Date = Long
103
109
type Timestamp = Long
104
110
type TextMap = SMap
105
111
type GenMap = SMap
106
112
type List = SList
107
113
type ContractId = value.Value .ContractId
108
- type Value = _
114
+ type Value = SValue
109
115
type Party = Ref .Party
110
116
111
117
object NotDefined
112
118
113
119
object CostAware
114
120
115
- sealed abstract class Function1 [X ] {
121
+ sealed abstract class CostFunction1 [X ] {
116
122
def cost (x : X ): Cost
117
123
}
118
124
119
- case class Constant1 [X ](c : Cost ) extends Function1 [X ] {
125
+ final case class ConstantCost1 [X ](c : Cost ) extends CostFunction1 [X ] {
120
126
override def cost (x : X ): Cost = c
121
127
}
122
128
123
- sealed abstract class Function2 [X , Y ] {
129
+ sealed abstract class CostFunction2 [X , Y ] {
124
130
def cost (x : X , y : Y ): Cost
125
131
}
126
132
127
- case class Constant2 [X , Y ](c : Cost ) extends Function2 [X , Y ] {
133
+ final case class ConstantCost2 [X , Y ](c : Cost ) extends CostFunction2 [X , Y ] {
128
134
override def cost (x : X , y : Y ): Cost = c
129
135
}
130
136
131
- sealed abstract class Function3 [X , Y , Z ] {
137
+ sealed abstract class CostFunction3 [X , Y , Z ] {
132
138
def cost (x : Y , y : Y , z : Z ): Cost
133
139
}
134
140
135
- case class Constant3 [X , Y , Z ](c : Cost ) extends Function3 [X , Y , Z ] {
141
+ final case class ConstantCost3 [X , Y , Z ](c : Cost ) extends CostFunction3 [X , Y , Z ] {
136
142
override def cost (x : Y , y : Y , z : Z ): Cost = c
137
143
}
138
144
139
- object Empty extends CostModel {
140
- override val AddNumeric : Function2 [Numeric , Numeric ] = Constant2 (0 )
141
- override val SubNumeric : Function2 [Numeric , Numeric ] = Constant2 (0 )
142
- override val MulNumeric : Function3 [Numeric , Numeric , Numeric ] = Constant3 (0 )
143
- override val DivNumeric : Function3 [Numeric , Numeric , Numeric ] = Constant3 (0 )
144
- override val BRoundNumeric : Function2 [Cost , Numeric ] = Constant2 (0 )
145
- override val BCastNumeric : Function3 [Numeric , Numeric , Numeric ] = Constant3 (0 )
146
- override val BShiftNumeric : Function3 [Numeric , Numeric , Numeric ] = Constant3 (0 )
147
- override val BAddInt64 : Function2 [Int64 , Int64 ] = Constant2 (0 )
148
- override val BSubInt64 : Function2 [Int64 , Int64 ] = Constant2 (0 )
149
- override val BMulInt64 : Function2 [Int64 , Int64 ] = Constant2 (0 )
150
- override val BDivInt64 : Function2 [Int64 , Int64 ] = Constant2 (0 )
151
- override val BModInt64 : Function2 [Int64 , Int64 ] = Constant2 (0 )
152
- override val BExpInt64 : Function2 [Int64 , Int64 ] = Constant2 (0 )
153
- override val BInt64ToNumeric : Function2 [Numeric , Int64 ] = Constant2 (0 )
154
- override val BNumericToInt64 : Function1 [Numeric ] = Constant1 (0 )
155
- override val BTextMapToList : Function1 [TextMap ] = Constant1 (0 )
156
- override val BGenMapInsert : Function3 [Any , Any , GenMap ] = Constant3 (0 )
157
- override val BGenMapLookup : Function2 [Any , GenMap ] = Constant2 (0 )
158
- override val BGenMapDelete : Function2 [Any , GenMap ] = Constant2 (0 )
159
- override val BGenMapKeys : Function1 [GenMap ] = Constant1 (0 )
160
- override val BGenMapValues : Function1 [GenMap ] = Constant1 (0 )
161
- override val BGenMapSize : Function1 [GenMap ] = Constant1 (0 )
162
- override val BAppendText : Function2 [Text , Text ] = Constant2 (0 )
163
- override val BInt64ToText : Function1 [Int64 ] = Constant1 (0 )
164
- override val BNumericToText : Function1 [Numeric ] = Constant1 (0 )
165
- override val BTimestampToText : Function1 [Timestamp ] = Constant1 (0 )
166
- override val BPartyToText : Function1 [Party ] = Constant1 (0 )
167
- override val BContractIdToText : Function1 [ContractId ] = Constant1 (0 )
168
- override val BCodePointsToText : Function1 [List ] = Constant1 (0 )
169
- override val BTextToParty : Function1 [Text ] = Constant1 (0 )
170
- override val BTextToInt64 : Function1 [Text ] = Constant1 (0 )
171
- override val BTextToNumeric : Function1 [Text ] = Constant1 (0 )
172
- override val BTextToCodePoints : Function1 [Text ] = Constant1 (0 )
173
- override val BSHA256Text : Function1 [Text ] = Constant1 (0 )
174
- override val BKECCAK256Text : Function1 [Text ] = Constant1 (0 )
175
- override val BSECP256K1Bool : Function1 [Text ] = Constant1 (0 )
176
- override val BDecodeHex : Function1 [Text ] = Constant1 (0 )
177
- override val BEncodeHex : Function1 [Text ] = Constant1 (0 )
178
- override val BTextToContractId : Function1 [Text ] = Constant1 (0 )
179
- override val BDateToUnixDays : Function1 [Date ] = Constant1 (0 )
180
- override val BExplodeText : Function1 [Text ] = Constant1 (0 )
181
- override val BTimestampToUnixMicroseconds : Function1 [Timestamp ] = Constant1 (0 )
182
- override val BDateToText : Function1 [Date ] = Constant1 (0 )
183
- override val BUnixDaysToDate : Function1 [Int64 ] = Constant1 (0 )
184
- override val BUnixMicrosecondsToTimestamp : Function1 [Int64 ] = Constant1 (0 )
185
- override val BEqual : Function2 [Any , Any ] = Constant2 (0 )
186
- override val BLess : Function2 [Any , Any ] = Constant2 (0 )
187
- override val BLessEq : Function2 [Any , Any ] = Constant2 (0 )
188
- override val BGreater : Function2 [Any , Any ] = Constant2 (0 )
189
- override val BGreaterEq : Function2 [Any , Any ] = Constant2 (0 )
190
- override val BCoerceContractId : Function1 [ContractId ] = Constant1 (0 )
145
+ object EmptyModel extends CostModel {
146
+ override val AddNumeric : CostFunction2 [Numeric , Numeric ] = ConstantCost2 (0 )
147
+ override val SubNumeric : CostFunction2 [Numeric , Numeric ] = ConstantCost2 (0 )
148
+ override val MulNumeric : CostFunction3 [Numeric , Numeric , Numeric ] = ConstantCost3 (0 )
149
+ override val DivNumeric : CostFunction3 [Numeric , Numeric , Numeric ] = ConstantCost3 (0 )
150
+ override val BRoundNumeric : CostFunction2 [Cost , Numeric ] = ConstantCost2 (0 )
151
+ override val BCastNumeric : CostFunction3 [Numeric , Numeric , Numeric ] = ConstantCost3 (0 )
152
+ override val BShiftNumeric : CostFunction2 [Int , Numeric ] = ConstantCost2 (0 )
153
+ override val BAddInt64 : CostFunction2 [Int64 , Int64 ] = ConstantCost2 (0 )
154
+ override val BSubInt64 : CostFunction2 [Int64 , Int64 ] = ConstantCost2 (0 )
155
+ override val BMulInt64 : CostFunction2 [Int64 , Int64 ] = ConstantCost2 (0 )
156
+ override val BDivInt64 : CostFunction2 [Int64 , Int64 ] = ConstantCost2 (0 )
157
+ override val BModInt64 : CostFunction2 [Int64 , Int64 ] = ConstantCost2 (0 )
158
+ override val BExpInt64 : CostFunction2 [Int64 , Int64 ] = ConstantCost2 (0 )
159
+ override val BInt64ToNumeric : CostFunction2 [Numeric , Int64 ] = ConstantCost2 (0 )
160
+ override val BNumericToInt64 : CostFunction1 [Numeric ] = ConstantCost1 (0 )
161
+ override val BTextMapToList : CostFunction1 [TextMap ] = ConstantCost1 (0 )
162
+ override val BGenMapInsert : CostFunction3 [Value , Value , GenMap ] = ConstantCost3 (0 )
163
+ override val BGenMapLookup : CostFunction2 [Value , GenMap ] = ConstantCost2 (0 )
164
+ override val BGenMapDelete : CostFunction2 [Value , GenMap ] = ConstantCost2 (0 )
165
+ override val BGenMapToList : CostFunction1 [GenMap ] = ConstantCost1 (0 )
166
+ override val BGenMapKeys : CostFunction1 [GenMap ] = ConstantCost1 (0 )
167
+ override val BGenMapValues : CostFunction1 [GenMap ] = ConstantCost1 (0 )
168
+ override val BGenMapSize : CostFunction1 [GenMap ] = ConstantCost1 (0 )
169
+ override val BAppendText : CostFunction2 [Text , Text ] = ConstantCost2 (0 )
170
+ override val BInt64ToText : CostFunction1 [Int64 ] = ConstantCost1 (0 )
171
+ override val BNumericToText : CostFunction1 [Numeric ] = ConstantCost1 (0 )
172
+ override val BTimestampToText : CostFunction1 [Timestamp ] = ConstantCost1 (0 )
173
+ override val BPartyToText : CostFunction1 [Party ] = ConstantCost1 (0 )
174
+ override val BContractIdToText : CostFunction1 [ContractId ] = ConstantCost1 (0 )
175
+ override val BCodePointsToText : CostFunction1 [FrontStack [Long ]] = ConstantCost1 (0 )
176
+ override val BTextToParty : CostFunction1 [Text ] = ConstantCost1 (0 )
177
+ override val BTextToInt64 : CostFunction1 [Text ] = ConstantCost1 (0 )
178
+ override val BTextToNumeric : CostFunction2 [Int , Text ] = ConstantCost2 (0 )
179
+ override val BTextToCodePoints : CostFunction1 [Text ] = ConstantCost1 (0 )
180
+ override val BSHA256Text : CostFunction1 [Text ] = ConstantCost1 (0 )
181
+ override val BKECCAK256Text : CostFunction1 [Text ] = ConstantCost1 (0 )
182
+ override val BSECP256K1Bool : CostFunction1 [Text ] = ConstantCost1 (0 )
183
+ override val BDecodeHex : CostFunction1 [Text ] = ConstantCost1 (0 )
184
+ override val BEncodeHex : CostFunction1 [Text ] = ConstantCost1 (0 )
185
+ override val BTextToContractId : CostFunction1 [Text ] = ConstantCost1 (0 )
186
+ override val BDateToUnixDays : CostFunction1 [Date ] = ConstantCost1 (0 )
187
+ override val BExplodeText : CostFunction1 [Text ] = ConstantCost1 (0 )
188
+ override val BTimestampToUnixMicroseconds : CostFunction1 [Timestamp ] = ConstantCost1 (0 )
189
+ override val BDateToText : CostFunction1 [Date ] = ConstantCost1 (0 )
190
+ override val BUnixDaysToDate : CostFunction1 [Int64 ] = ConstantCost1 (0 )
191
+ override val BUnixMicrosecondsToTimestamp : CostFunction1 [Int64 ] = ConstantCost1 (0 )
192
+ override val BEqual : CostFunction2 [Value , Value ] = ConstantCost2 (0 )
193
+ override val BLess : CostFunction2 [Value , Value ] = ConstantCost2 (0 )
194
+ override val BLessEq : CostFunction2 [Value , Value ] = ConstantCost2 (0 )
195
+ override val BGreater : CostFunction2 [Value , Value ] = ConstantCost2 (0 )
196
+ override val BGreaterEq : CostFunction2 [Value , Value ] = ConstantCost2 (0 )
197
+ override val BCoerceContractId : CostFunction1 [ContractId ] = ConstantCost1 (0 )
198
+
199
+ override def update (cost : Cost ): Unit = {}
200
+
201
+ override def undefined (cost : NotDefined .type ): Unit = {}
202
+
203
+ override def costAware (cost : CostAware .type ): Unit = {}
204
+
205
+ override def getCost : Cost = {
206
+ 0
207
+ }
191
208
}
192
-
193
209
}
0 commit comments