Skip to content

Commit

Permalink
fix: Make all tuples immutable for now to match puya
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmenzel committed Oct 16, 2024
1 parent f5e0a4c commit 441eb2d
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 67 deletions.
7 changes: 3 additions & 4 deletions scripts/generate-op-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as fs from 'fs'
import { camelCase } from 'change-case'
import * as fs from 'fs'
import { enumerate, hasFlags } from '../src/util'
import type { OpFunction, OpGrouping, OpOverloadedFunction } from './build-op-module'
import { AlgoTsType, buildOpModule } from './build-op-module'
import { enumerate, hasFlags } from '../src/util'
import { it } from 'vitest'

const opModule = buildOpModule()

Expand Down Expand Up @@ -120,7 +119,7 @@ function mapReturnType(returnTypes: AlgoTsType[]) {
if (ptypes.length === 1) {
return ptypes[0]
}
return `new ptypes.TuplePType({items: [${ptypes.join(', ')}], immutable: true})`
return `new ptypes.TuplePType({items: [${ptypes.join(', ')}]})`
}

function* emitTypes() {
Expand Down
2 changes: 1 addition & 1 deletion src/awst/node-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const explicitNodeFactory = {
tupleExpression(props: Omit<Props<TupleExpression>, 'wtype'>) {
return new TupleExpression({
...props,
wtype: new WTuple({ types: props.items.map((i) => i.wtype), immutable: false }),
wtype: new WTuple({ types: props.items.map((i) => i.wtype), immutable: true }),
})
},
methodDocumentation(props?: { description?: string | null; args?: Map<string, string>; returns?: string | null }) {
Expand Down
1 change: 0 additions & 1 deletion src/awst_build/base-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ export abstract class BaseVisitor implements Visitor<Expressions, NodeBuilder> {
items: sourceType.items.map((item, index) =>
index < targetType.items.length ? this.buildAssignmentExpressionType(targetType.items[index], item, sourceLocation) : item,
),
immutable: sourceType.immutable,
})
} else if (targetType instanceof ArrayPType) {
// Narrow array literal types to array type
Expand Down
4 changes: 1 addition & 3 deletions src/awst_build/eb/arc4/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ class EntriesFunctionBuilder extends FunctionBuilder {

call(args: ReadonlyArray<InstanceBuilder>, typeArgs: ReadonlyArray<PType>, sourceLocation: SourceLocation): NodeBuilder {
parseFunctionArgs({ args, typeArgs, callLocation: sourceLocation, argSpec: (_) => [], genericTypeArgs: 0, funcName: 'entries' })
const iteratorType = IterableIteratorType.parameterise([
new TuplePType({ items: [uint64PType, this.arrayBuilder.ptype.elementType], immutable: true }),
])
const iteratorType = IterableIteratorType.parameterise([new TuplePType({ items: [uint64PType, this.arrayBuilder.ptype.elementType] })])
return new IterableIteratorExpressionBuilder(
nodeFactory.enumeration({
expr: this.arrayBuilder.iterate(sourceLocation),
Expand Down
2 changes: 1 addition & 1 deletion src/awst_build/eb/assert-match-function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AssertMatchFunctionBuilder extends NodeBuilder {
)
} else if (testProperty.hasProperty('between')) {
const range = requireInstanceBuilder(testProperty.memberAccess('between', sourceLocation)).singleEvaluation()
const rangePType = new TuplePType({ items: [subjectType, subjectType], immutable: true })
const rangePType = new TuplePType({ items: [subjectType, subjectType] })
codeInvariant(range.resolvableToPType(rangePType), 'Between range must be of type $')
const zeroIndex = instanceEb(nodeFactory.uInt64Constant({ value: 0n, sourceLocation }), uint64PType)
const gte = subjectProperty
Expand Down
2 changes: 1 addition & 1 deletion src/awst_build/eb/storage/box/box-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class BoxMapMaybeFunctionBuilder extends BoxMapFunctionBuilderBase {
genericTypeArgs: 0,
argSpec: (a) => [a.required(this.keyType)],
})
const type = new TuplePType({ items: [this.contentType, boolPType], immutable: true })
const type = new TuplePType({ items: [this.contentType, boolPType] })

return instanceEb(
nodeFactory.stateGetEx({
Expand Down
2 changes: 1 addition & 1 deletion src/awst_build/eb/storage/box/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class BoxMaybeFunctionBuilder extends FunctionBuilder {
genericTypeArgs: 0,
argSpec: () => [],
})
const type = new TuplePType({ items: [this.contentType, boolPType], immutable: true })
const type = new TuplePType({ items: [this.contentType, boolPType] })

return instanceEb(
nodeFactory.stateGetEx({
Expand Down
99 changes: 48 additions & 51 deletions src/awst_build/op-metadata.ts

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/awst_build/ptypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ export class ArrayLiteralPType extends TransientType {

getTupleType(): TuplePType {
return new TuplePType({
immutable: false,
items: this.items,
})
}
Expand All @@ -486,10 +485,10 @@ export class TuplePType extends PType {
readonly items: PType[]
readonly singleton = false
readonly immutable: boolean
constructor(props: { items: PType[]; immutable?: boolean }) {
constructor(props: { items: PType[] }) {
super()
this.items = props.items
this.immutable = props.immutable ?? true
this.immutable = true
}

get wtype(): WTuple {
Expand Down
1 change: 0 additions & 1 deletion src/awst_build/type-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ export class TypeResolver {

return new TuplePType({
items: tsType.typeArguments.map((t) => this.resolveType(t, sourceLocation)),
immutable: tsType.target.readonly,
})
}

Expand Down

0 comments on commit 441eb2d

Please sign in to comment.