Skip to content

Commit ab049c7

Browse files
committed
chore: Rename abiSafe to runtimeOnly
1 parent 9ad24ae commit ab049c7

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

src/awst_build/arc4-util.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ export function isArc4EncodableType(ptype: PType): boolean {
161161
if (ptype.equals(accountPType)) return true
162162
if (ptype instanceof ReadonlyTuplePType) return ptype.items.every((i) => isArc4EncodableType(i))
163163
if (ptype instanceof MutableTuplePType) return ptype.items.every((i) => isArc4EncodableType(i))
164-
if (ptype instanceof ImmutableObjectPType) return ptype.abiSafe && ptype.orderedProperties().every(([, pt]) => isArc4EncodableType(pt))
165-
if (ptype instanceof MutableObjectPType) return ptype.abiSafe && ptype.orderedProperties().every(([, pt]) => isArc4EncodableType(pt))
164+
if (ptype instanceof ImmutableObjectPType)
165+
return !ptype.runtimeOnly && ptype.orderedProperties().every(([, pt]) => isArc4EncodableType(pt))
166+
if (ptype instanceof MutableObjectPType) return !ptype.runtimeOnly && ptype.orderedProperties().every(([, pt]) => isArc4EncodableType(pt))
166167
if (ptype instanceof ArrayPType || ptype instanceof FixedArrayPType || ptype instanceof ReadonlyArrayPType)
167168
return isArc4EncodableType(ptype.elementType)
168169
return false
@@ -216,15 +217,15 @@ export function ptypeToArc4EncodedType(ptype: PType, sourceLocation: SourceLocat
216217
if (ptype instanceof MutableTuplePType)
217218
return new ARC4TupleType({ types: ptype.items.map((i) => ptypeToArc4EncodedType(i, sourceLocation)) })
218219

219-
if (ptype instanceof ImmutableObjectPType && ptype.abiSafe)
220+
if (ptype instanceof ImmutableObjectPType && !ptype.runtimeOnly)
220221
return new ARC4StructType({
221222
name: ptype.alias?.name ?? ptype.name,
222223
module: ptype.module,
223224
description: ptype.description,
224225
fields: Object.fromEntries(ptype.orderedProperties().map(([p, pt]) => [p, ptypeToArc4EncodedType(pt, sourceLocation)])),
225226
frozen: true,
226227
})
227-
if (ptype instanceof MutableObjectPType && ptype.abiSafe)
228+
if (ptype instanceof MutableObjectPType && !ptype.runtimeOnly)
228229
return new ARC4StructType({
229230
name: ptype.alias?.name ?? ptype.name,
230231
module: ptype.module,

src/awst_build/eb/arc4/struct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class StructClassBuilder extends ClassBuilder {
3030
genericTypeArgs: 1,
3131
callLocation: sourceLocation,
3232
funcName: this.typeDescription,
33-
argSpec: (a) => [a.required(new ImmutableObjectPType({ properties: this.ptype.instanceType.fields, abiSafe: true }))],
33+
argSpec: (a) => [a.required(new ImmutableObjectPType({ properties: this.ptype.instanceType.fields, runtimeOnly: false }))],
3434
})
3535
const initialSingle = initialValues.singleEvaluation()
3636

src/awst_build/eb/storage/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function assertCanBeUsedForStorage(ptype: PType, sourceLocation?: SourceL
3737
if (ptype instanceof UnsupportedType || ptype instanceof TransientType) {
3838
throw new CodeError(`Type ${ptype} cannot be used for storage`, { sourceLocation })
3939
}
40-
if ((ptype instanceof MutableObjectPType || ptype instanceof ImmutableObjectPType) && !ptype.abiSafe) {
40+
if ((ptype instanceof MutableObjectPType || ptype instanceof ImmutableObjectPType) && ptype.runtimeOnly) {
4141
const ptypeName = ptype.alias?.fullName || ptype.toString()
4242
throw new CodeError(`Type ${ptypeName} cannot be used for storage`, { sourceLocation })
4343
}

src/awst_build/ptypes/arc4-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class ARC4StructType extends ARC4EncodedType {
194194
}
195195

196196
get nativeType(): MutableObjectPType {
197-
return new MutableObjectPType({ properties: this.fields, abiSafe: true })
197+
return new MutableObjectPType({ properties: this.fields, runtimeOnly: false })
198198
}
199199

200200
get wtype(): wtypes.ARC4Struct {
@@ -639,7 +639,7 @@ export class TypedApplicationCallResponseType extends ImmutableObjectPType {
639639
itxn: applicationItxnType,
640640
returnValue,
641641
},
642-
abiSafe: true,
642+
runtimeOnly: false,
643643
})
644644
this.name = `TypedApplicationCallResponseType<${returnValue.name}>`
645645
this.returnValue = returnValue

src/awst_build/ptypes/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -932,31 +932,31 @@ abstract class ObjectPType extends PType {
932932
readonly properties: Record<string, PType>
933933
readonly singleton = false
934934
readonly immutable: boolean
935-
readonly abiSafe: boolean
935+
readonly runtimeOnly: boolean
936936

937937
constructor(props: {
938938
alias?: SymbolName | null
939939
properties: Record<string, PType>
940940
description?: string
941941
namePrefix: string
942942
immutable: boolean
943-
abiSafe: boolean
943+
runtimeOnly: boolean
944944
}) {
945945
super()
946946
this.name = `${props.namePrefix}${generateObjectHash(props.properties)}`
947947
this.properties = props.properties
948948
this.description = props.description
949949
this.alias = props.alias ?? null
950950
this.immutable = props.immutable
951-
this.abiSafe = props.abiSafe
951+
this.runtimeOnly = props.runtimeOnly
952952
}
953953

954954
orderedProperties() {
955955
return Object.entries(this.properties)
956956
}
957957

958958
toString(): string {
959-
return `${this.abiSafe ? '' : '@runtimeOnly'}{${this.orderedProperties()
959+
return `${this.runtimeOnly ? '@runtimeOnly' : ''}{${this.orderedProperties()
960960
.map((p) => `${this.immutable ? 'readonly ' : ''}${p[0]}:${p[1].name}`)
961961
.join(',')}}`
962962
}
@@ -976,7 +976,7 @@ export class ObjectLiteralPType extends ObjectPType {
976976
...props,
977977
namePrefix: `ObjectLiteral`,
978978
immutable: false,
979-
abiSafe: true,
979+
runtimeOnly: false,
980980
})
981981
}
982982

@@ -989,15 +989,15 @@ export class ObjectLiteralPType extends ObjectPType {
989989
alias: this.alias,
990990
properties: this.properties,
991991
description: this.description,
992-
abiSafe: this.abiSafe,
992+
runtimeOnly: this.runtimeOnly,
993993
})
994994
}
995995
getMutable(): MutableObjectPType {
996996
return new MutableObjectPType({
997997
alias: this.alias,
998998
properties: this.properties,
999999
description: this.description,
1000-
abiSafe: this.abiSafe,
1000+
runtimeOnly: this.runtimeOnly,
10011001
})
10021002
}
10031003

@@ -1022,7 +1022,7 @@ export class ObjectLiteralPType extends ObjectPType {
10221022
export class ImmutableObjectPType extends ObjectPType {
10231023
readonly [PType.IdSymbol] = 'ImmutableObjectPType'
10241024

1025-
constructor(props: { alias?: SymbolName | null; properties: Record<string, PType>; description?: string; abiSafe: boolean }) {
1025+
constructor(props: { alias?: SymbolName | null; properties: Record<string, PType>; description?: string; runtimeOnly: boolean }) {
10261026
super({
10271027
...props,
10281028
namePrefix: `ReadonlyObject`,
@@ -1055,7 +1055,7 @@ export class ImmutableObjectPType extends ObjectPType {
10551055
export class MutableObjectPType extends ObjectPType {
10561056
readonly [PType.IdSymbol] = 'MutableObjectPType'
10571057

1058-
constructor(props: { alias?: SymbolName | null; properties: Record<string, PType>; description?: string; abiSafe: boolean }) {
1058+
constructor(props: { alias?: SymbolName | null; properties: Record<string, PType>; description?: string; runtimeOnly: boolean }) {
10591059
super({
10601060
...props,
10611061
namePrefix: `Object`,
@@ -1077,7 +1077,7 @@ export class MutableObjectPType extends ObjectPType {
10771077
alias: this.alias,
10781078
properties: this.properties,
10791079
description: this.description,
1080-
abiSafe: this.abiSafe,
1080+
runtimeOnly: this.runtimeOnly,
10811081
})
10821082
}
10831083

@@ -1866,7 +1866,7 @@ export const compiledContractType = new ImmutableObjectPType({
18661866
localUints: uint64PType,
18671867
localBytes: uint64PType,
18681868
},
1869-
abiSafe: true,
1869+
runtimeOnly: false,
18701870
})
18711871
export const compiledLogicSigType = new ImmutableObjectPType({
18721872
alias: new SymbolName({
@@ -1877,7 +1877,7 @@ export const compiledLogicSigType = new ImmutableObjectPType({
18771877
properties: {
18781878
account: accountPType,
18791879
},
1880-
abiSafe: true,
1880+
runtimeOnly: false,
18811881
})
18821882

18831883
export const arc28EmitFunction = new LibFunctionType({

src/awst_build/type-resolver.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class TypeResolver {
254254
if (parts.some((p) => p.equals(arc4StructBaseType))) {
255255
return arc4StructBaseType
256256
} else if (parts.every((p) => instanceOfAny(p, ImmutableObjectPType, MutableObjectPType))) {
257-
return this.reflectObjectType(tsType, false, sourceLocation)
257+
return this.reflectObjectType(tsType, true, sourceLocation)
258258
} else {
259259
return IntersectionPType.fromTypes(parts)
260260
}
@@ -301,7 +301,7 @@ export class TypeResolver {
301301
return this.reflectFunctionType(typeName, callSignatures, sourceLocation)
302302
}
303303
if (isObjectType(tsType)) {
304-
return this.reflectObjectType(tsType, true, sourceLocation)
304+
return this.reflectObjectType(tsType, false, sourceLocation)
305305
}
306306
throw new InternalError(`Cannot determine type of ${typeName}`, { sourceLocation })
307307
}
@@ -352,7 +352,11 @@ export class TypeResolver {
352352
}
353353
}
354354

355-
private reflectObjectType(tsType: ts.Type, abiSafe: boolean, sourceLocation: SourceLocation): ImmutableObjectPType | MutableObjectPType {
355+
private reflectObjectType(
356+
tsType: ts.Type,
357+
runtimeOnly: boolean,
358+
sourceLocation: SourceLocation,
359+
): ImmutableObjectPType | MutableObjectPType {
356360
const typeAlias = tsType.aliasSymbol ? this.getSymbolFullName(tsType.aliasSymbol, sourceLocation) : undefined
357361
const properties: Record<string, PType> = {}
358362

@@ -383,9 +387,9 @@ export class TypeResolver {
383387
}
384388
}
385389
if (expectReadonly) {
386-
return new ImmutableObjectPType({ alias: typeAlias, properties, description: tryGetTypeDescription(tsType), abiSafe })
390+
return new ImmutableObjectPType({ alias: typeAlias, properties, description: tryGetTypeDescription(tsType), runtimeOnly })
387391
} else {
388-
return new MutableObjectPType({ alias: typeAlias, properties, description: tryGetTypeDescription(tsType), abiSafe })
392+
return new MutableObjectPType({ alias: typeAlias, properties, description: tryGetTypeDescription(tsType), runtimeOnly })
389393
}
390394
}
391395

0 commit comments

Comments
 (0)