@@ -35,7 +35,7 @@ use cedar_policy_core::validator::{
35
35
ValidatorActionId ,
36
36
} ;
37
37
use cedar_policy_core:: validator:: { ValidatorEntityType , ValidatorEntityTypeKind } ;
38
- use smol_str:: SmolStr ;
38
+ use smol_str:: { format_smolstr , SmolStr } ;
39
39
use std:: collections:: { BTreeMap , BTreeSet } ;
40
40
use std:: ops:: Deref ;
41
41
use std:: sync:: Arc ;
@@ -55,15 +55,15 @@ impl SymRequest {
55
55
pub fn empty_sym_req ( ) -> Self {
56
56
SymRequest {
57
57
principal : Term :: Var ( TermVar {
58
- id : "principal" . to_string ( ) ,
58
+ id : "principal" . into ( ) ,
59
59
ty : TermType :: Bool ,
60
60
} ) ,
61
61
action : Term :: Var ( TermVar {
62
- id : "action" . to_string ( ) ,
62
+ id : "action" . into ( ) ,
63
63
ty : TermType :: Bool ,
64
64
} ) ,
65
65
resource : Term :: Var ( TermVar {
66
- id : "resource" . to_string ( ) ,
66
+ id : "resource" . into ( ) ,
67
67
ty : TermType :: Bool ,
68
68
} ) ,
69
69
context : Term :: Record ( Arc :: new ( BTreeMap :: new ( ) ) ) ,
@@ -183,30 +183,30 @@ impl SymEntityData {
183
183
match EntitySchemaEntry :: of_schema ( ety, validator_ety, schema) {
184
184
// Corresponds to `SymEntityData.ofStandardEntityType` in Lean
185
185
EntitySchemaEntry :: Standard ( sch) => {
186
- let attrs_uuf = Uuf ( op:: Uuf {
187
- id : format ! ( "attrs[{ety}]" ) ,
186
+ let attrs_uuf = Uuf ( Arc :: new ( op:: Uuf {
187
+ id : format_smolstr ! ( "attrs[{ety}]" ) ,
188
188
arg : entity ( ety. clone ( ) ) , // more efficient than the Lean: avoids `TermType::of_type()` and constructs the `TermType` directly
189
189
out : TermType :: of_type ( & record ( sch. attrs ) ) ?,
190
- } ) ;
190
+ } ) ) ;
191
191
let ancs_uuf = |anc_ty : & EntityType | {
192
- Uuf ( op:: Uuf {
193
- id : format ! ( "ancs[{ety}, {anc_ty}]" ) ,
192
+ Uuf ( Arc :: new ( op:: Uuf {
193
+ id : format_smolstr ! ( "ancs[{ety}, {anc_ty}]" ) ,
194
194
arg : entity ( ety. clone ( ) ) , // more efficient than the Lean: avoids `TermType::of_type()` and constructs the `TermType` directly
195
195
out : TermType :: set_of ( entity ( anc_ty. clone ( ) ) ) , // more efficient than the Lean: avoids `TermType::of_type()` and constructs the `TermType` directly
196
- } )
196
+ } ) )
197
197
} ;
198
198
let sym_tags = |tag_ty : Type | -> Result < SymTags , CompileError > {
199
199
Ok ( SymTags {
200
- keys : Uuf ( op:: Uuf {
201
- id : format ! ( "tagKeys[{ety}]" ) ,
200
+ keys : Uuf ( Arc :: new ( op:: Uuf {
201
+ id : format_smolstr ! ( "tagKeys[{ety}]" ) ,
202
202
arg : entity ( ety. clone ( ) ) , // more efficient than the Lean: avoids `TermType::of_type()` and constructs the `TermType` directly
203
203
out : TermType :: set_of ( TermType :: String ) ,
204
- } ) ,
205
- vals : Uuf ( op:: Uuf {
206
- id : format ! ( "tagVals[{ety}]" ) ,
204
+ } ) ) ,
205
+ vals : Uuf ( Arc :: new ( op:: Uuf {
206
+ id : format_smolstr ! ( "tagVals[{ety}]" ) ,
207
207
arg : TermType :: tag_for ( ety. clone ( ) ) , // record representing the pair type (ety, .string)
208
208
out : TermType :: of_type ( & tag_ty) ?,
209
- } ) ,
209
+ } ) ) ,
210
210
} )
211
211
} ;
212
212
@@ -227,14 +227,14 @@ impl SymEntityData {
227
227
228
228
// Corresponds to `SymEntityData.ofEnumEntityType` in Lean
229
229
EntitySchemaEntry :: Enum ( eids) => {
230
- let attrs_udf = Udf ( function:: Udf {
230
+ let attrs_udf = Udf ( Arc :: new ( function:: Udf {
231
231
arg : entity ( ety. clone ( ) ) ,
232
232
out : TermType :: Record {
233
233
rty : Arc :: new ( BTreeMap :: new ( ) ) ,
234
234
} ,
235
- table : BTreeMap :: new ( ) ,
235
+ table : Arc :: new ( BTreeMap :: new ( ) ) ,
236
236
default : Term :: Record ( Arc :: new ( BTreeMap :: new ( ) ) ) ,
237
- } ) ;
237
+ } ) ) ;
238
238
Ok ( SymEntityData {
239
239
attrs : attrs_udf,
240
240
ancestors : BTreeMap :: new ( ) ,
@@ -251,14 +251,14 @@ impl SymEntityData {
251
251
schema : & ValidatorSchema ,
252
252
) -> Self {
253
253
let sch = ActionSchemaEntries :: of_schema ( schema) ;
254
- let attrs_udf = Udf ( function:: Udf {
254
+ let attrs_udf = Udf ( Arc :: new ( function:: Udf {
255
255
arg : entity ( act_ty. clone ( ) ) ,
256
256
out : TermType :: Record {
257
257
rty : Arc :: new ( BTreeMap :: new ( ) ) ,
258
258
} ,
259
- table : BTreeMap :: new ( ) ,
259
+ table : Arc :: new ( BTreeMap :: new ( ) ) ,
260
260
default : Term :: Record ( Arc :: new ( BTreeMap :: new ( ) ) ) ,
261
- } ) ;
261
+ } ) ) ;
262
262
let term_of_type = |ety : EntityType , uid : EntityUID | -> Option < Term > {
263
263
if uid. type_name ( ) == & ety {
264
264
Some ( Term :: Prim ( TermPrim :: Entity ( uid) ) )
@@ -277,23 +277,24 @@ impl SymEntityData {
277
277
}
278
278
} ;
279
279
let ancs_udf = |anc_ty : & EntityType | -> UnaryFunction {
280
- Udf ( function:: Udf {
280
+ Udf ( Arc :: new ( function:: Udf {
281
281
arg : entity ( act_ty. clone ( ) ) ,
282
282
out : TermType :: set_of ( entity ( anc_ty. clone ( ) ) ) ,
283
- table : sch
284
- . iter ( )
285
- . filter_map ( |( uid, entry) | {
286
- Some ( (
287
- term_of_type ( act_ty. clone ( ) , uid. clone ( ) ) ?,
288
- ancs_term ( anc_ty, & entry. ancestors ) ,
289
- ) )
290
- } )
291
- . collect ( ) ,
283
+ table : Arc :: new (
284
+ sch. iter ( )
285
+ . filter_map ( |( uid, entry) | {
286
+ Some ( (
287
+ term_of_type ( act_ty. clone ( ) , uid. clone ( ) ) ?,
288
+ ancs_term ( anc_ty, & entry. ancestors ) ,
289
+ ) )
290
+ } )
291
+ . collect ( ) ,
292
+ ) ,
292
293
default : Term :: Set {
293
294
elts : Arc :: new ( BTreeSet :: new ( ) ) ,
294
295
elts_ty : entity ( anc_ty. clone ( ) ) ,
295
296
} ,
296
- } )
297
+ } ) )
297
298
} ;
298
299
let acts = sch
299
300
. iter ( )
@@ -372,20 +373,20 @@ impl SymRequest {
372
373
fn of_request_type ( req_ty : & RequestType < ' _ > ) -> Result < Self , CompileError > {
373
374
Ok ( Self {
374
375
principal : Term :: Var ( TermVar {
375
- id : "principal" . to_string ( ) ,
376
+ id : "principal" . into ( ) ,
376
377
ty : TermType :: Entity {
377
378
ety : req_ty. principal . clone ( ) ,
378
379
} ,
379
380
} ) ,
380
381
action : Term :: Prim ( TermPrim :: Entity ( req_ty. action . clone ( ) ) ) ,
381
382
resource : Term :: Var ( TermVar {
382
- id : "resource" . to_string ( ) ,
383
+ id : "resource" . into ( ) ,
383
384
ty : TermType :: Entity {
384
385
ety : req_ty. resource . clone ( ) ,
385
386
} ,
386
387
} ) ,
387
388
context : Term :: Var ( TermVar {
388
- id : "context" . to_string ( ) ,
389
+ id : "context" . into ( ) ,
389
390
ty : TermType :: of_type ( & record ( req_ty. context . clone ( ) ) ) ?,
390
391
} ) ,
391
392
} )
0 commit comments