Skip to content

Commit 95214b0

Browse files
committed
remove feature flags, enable all new fixes
1 parent 1ee093a commit 95214b0

9 files changed

+234
-464
lines changed

interpreter/config.go

-7
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,4 @@ type Config struct {
7676
ValidateAccountCapabilitiesGetHandler ValidateAccountCapabilitiesGetHandlerFunc
7777
// ValidateAccountCapabilitiesPublishHandler is used to handle when a capability of an account is got.
7878
ValidateAccountCapabilitiesPublishHandler ValidateAccountCapabilitiesPublishHandlerFunc
79-
// ExportFixesEnabled specifies whether to export fixes are enabled
80-
ExportFixesEnabled bool
81-
// FunctionScopingFixEnabled specifies whether to enable the function scoping fix
82-
FunctionScopingFixEnabled bool
83-
// FunctionConditionsDeduplicationEnabled determines whether to skip running function conditions explicitly
84-
// if they are already included as part of the inherited default function.
85-
FunctionConditionsDeduplicationEnabled bool
8679
}

interpreter/interface_test.go

+56-82
Original file line numberDiff line numberDiff line change
@@ -1111,44 +1111,42 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) {
11111111

11121112
t.Parallel()
11131113

1114-
testWithConditionsDeduplication := func(t *testing.T, conditionsDeduplicationEnabled bool) []string {
1115-
1116-
var logs []string
1117-
1118-
logFunction := stdlib.NewStandardLibraryStaticFunction(
1119-
"log",
1120-
&sema.FunctionType{
1121-
Parameters: []sema.Parameter{
1122-
{
1123-
Label: sema.ArgumentLabelNotRequired,
1124-
Identifier: "value",
1125-
TypeAnnotation: sema.NewTypeAnnotation(sema.AnyStructType),
1126-
},
1114+
var logs []string
1115+
1116+
logFunction := stdlib.NewStandardLibraryStaticFunction(
1117+
"log",
1118+
&sema.FunctionType{
1119+
Parameters: []sema.Parameter{
1120+
{
1121+
Label: sema.ArgumentLabelNotRequired,
1122+
Identifier: "value",
1123+
TypeAnnotation: sema.NewTypeAnnotation(sema.AnyStructType),
11271124
},
1128-
ReturnTypeAnnotation: sema.NewTypeAnnotation(
1129-
sema.VoidType,
1130-
),
1131-
Purity: sema.FunctionPurityView,
1132-
},
1133-
``,
1134-
func(invocation interpreter.Invocation) interpreter.Value {
1135-
message := invocation.Arguments[0].MeteredString(
1136-
invocation.Interpreter,
1137-
interpreter.SeenReferences{},
1138-
invocation.LocationRange,
1139-
)
1140-
logs = append(logs, message)
1141-
return interpreter.Void
11421125
},
1143-
)
1126+
ReturnTypeAnnotation: sema.NewTypeAnnotation(
1127+
sema.VoidType,
1128+
),
1129+
Purity: sema.FunctionPurityView,
1130+
},
1131+
``,
1132+
func(invocation interpreter.Invocation) interpreter.Value {
1133+
message := invocation.Arguments[0].MeteredString(
1134+
invocation.Interpreter,
1135+
interpreter.SeenReferences{},
1136+
invocation.LocationRange,
1137+
)
1138+
logs = append(logs, message)
1139+
return interpreter.Void
1140+
},
1141+
)
11441142

1145-
baseValueActivation := sema.NewVariableActivation(sema.BaseValueActivation)
1146-
baseValueActivation.DeclareValue(logFunction)
1143+
baseValueActivation := sema.NewVariableActivation(sema.BaseValueActivation)
1144+
baseValueActivation.DeclareValue(logFunction)
11471145

1148-
baseActivation := activations.NewActivation(nil, interpreter.BaseActivation)
1149-
interpreter.Declare(baseActivation, logFunction)
1146+
baseActivation := activations.NewActivation(nil, interpreter.BaseActivation)
1147+
interpreter.Declare(baseActivation, logFunction)
11501148

1151-
code := `
1149+
code := `
11521150
struct interface Foo {
11531151
fun test() {
11541152
pre {
@@ -1174,60 +1172,36 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) {
11741172
}
11751173
`
11761174

1177-
inter, err := parseCheckAndInterpretWithOptions(
1178-
t,
1179-
code,
1180-
ParseCheckAndInterpretOptions{
1181-
Config: &interpreter.Config{
1182-
BaseActivationHandler: func(_ common.Location) *interpreter.VariableActivation {
1183-
return baseActivation
1184-
},
1185-
FunctionConditionsDeduplicationEnabled: conditionsDeduplicationEnabled,
1175+
inter, err := parseCheckAndInterpretWithOptions(
1176+
t,
1177+
code,
1178+
ParseCheckAndInterpretOptions{
1179+
Config: &interpreter.Config{
1180+
BaseActivationHandler: func(_ common.Location) *interpreter.VariableActivation {
1181+
return baseActivation
11861182
},
1187-
CheckerConfig: &sema.Config{
1188-
BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation {
1189-
return baseValueActivation
1190-
},
1183+
},
1184+
CheckerConfig: &sema.Config{
1185+
BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation {
1186+
return baseValueActivation
11911187
},
1192-
HandleCheckerError: nil,
11931188
},
1194-
)
1195-
require.NoError(t, err)
1189+
HandleCheckerError: nil,
1190+
},
1191+
)
1192+
require.NoError(t, err)
11961193

1197-
_, err = inter.Invoke("main")
1198-
require.NoError(t, err)
1199-
return logs
1200-
}
1194+
_, err = inter.Invoke("main")
1195+
require.NoError(t, err)
12011196

1202-
t.Run("enabled", func(t *testing.T) {
1203-
t.Parallel()
1204-
1205-
logs := testWithConditionsDeduplication(t, true)
1206-
require.Equal(
1207-
t,
1208-
[]string{
1209-
`"invoked Foo.test() pre-condition"`,
1210-
`"invoked Foo.test()"`,
1211-
`"invoked Foo.test() post-condition"`,
1212-
}, logs,
1213-
)
1214-
})
1215-
1216-
t.Run("disabled", func(t *testing.T) {
1217-
t.Parallel()
1218-
1219-
logs := testWithConditionsDeduplication(t, false)
1220-
require.Equal(
1221-
t,
1222-
[]string{
1223-
`"invoked Foo.test() pre-condition"`,
1224-
`"invoked Foo.test() pre-condition"`,
1225-
`"invoked Foo.test()"`,
1226-
`"invoked Foo.test() post-condition"`,
1227-
`"invoked Foo.test() post-condition"`,
1228-
}, logs,
1229-
)
1230-
})
1197+
require.Equal(
1198+
t,
1199+
[]string{
1200+
`"invoked Foo.test() pre-condition"`,
1201+
`"invoked Foo.test()"`,
1202+
`"invoked Foo.test() post-condition"`,
1203+
}, logs,
1204+
)
12311205
})
12321206
}
12331207

interpreter/interpreter.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,7 @@ func (interpreter *Interpreter) VisitFunctionDeclaration(declaration *ast.Functi
718718
// lexical scope: variables in functions are bound to what is visible at declaration time
719719
lexicalScope := interpreter.activations.CurrentOrNew()
720720

721-
config := interpreter.SharedState.Config
722-
723-
if isStatement && config.FunctionScopingFixEnabled {
721+
if isStatement {
724722

725723
// This function declaration is an inner function.
726724
//
@@ -1352,7 +1350,7 @@ func (declarationInterpreter *Interpreter) declareNonEnumCompositeValue(
13521350
// This works because:
13531351
// - `code.Functions` only contains default implementations.
13541352
// - There is always only one default implementation (cannot override by other interfaces).
1355-
if config.FunctionConditionsDeduplicationEnabled && code.Functions.Contains(name) {
1353+
if code.Functions.Contains(name) {
13561354
continue
13571355
}
13581356

@@ -2496,10 +2494,8 @@ func (interpreter *Interpreter) functionConditionsWrapper(
24962494
lexicalScope *VariableActivation,
24972495
) FunctionWrapper {
24982496

2499-
config := interpreter.SharedState.Config
2500-
25012497
if declaration.FunctionBlock == nil ||
2502-
(config.FunctionConditionsDeduplicationEnabled && declaration.FunctionBlock.HasStatements()) {
2498+
declaration.FunctionBlock.HasStatements() {
25032499
// If there's a default implementation (i.e: has statements),
25042500
// then skip explicitly/separately running the conditions of that functions.
25052501
// Because the conditions also get executed when the default implementation is executed.

interpreter/interpreter_expression.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -1338,11 +1338,7 @@ func (interpreter *Interpreter) VisitFunctionExpression(expression *ast.Function
13381338
// push a new activation, so that the mutations are not performed
13391339
// on the captured activation.
13401340

1341-
config := interpreter.SharedState.Config
1342-
1343-
if config.FunctionScopingFixEnabled {
1344-
interpreter.activations.PushNewWithCurrent()
1345-
}
1341+
interpreter.activations.PushNewWithCurrent()
13461342

13471343
functionType := interpreter.Program.Elaboration.FunctionExpressionFunctionType(expression)
13481344

interpreter/misc_test.go

+36-82
Original file line numberDiff line numberDiff line change
@@ -6867,99 +6867,53 @@ func TestInterpretClosure(t *testing.T) {
68676867
func TestInterpretClosureScopingFunctionExpression(t *testing.T) {
68686868
t.Parallel()
68696869

6870-
test := func(t *testing.T, fixEnabled bool, expected interpreter.Value) {
6871-
6872-
inter := parseCheckAndInterpret(t, `
6873-
fun test(a: Int): Int {
6874-
let bar = fun(): Int {
6875-
return a
6876-
}
6877-
let a = 2
6878-
return bar()
6870+
inter := parseCheckAndInterpret(t, `
6871+
fun test(a: Int): Int {
6872+
let bar = fun(): Int {
6873+
return a
68796874
}
6880-
`)
6881-
6882-
inter.SharedState.Config.FunctionScopingFixEnabled = fixEnabled
6883-
6884-
actual, err := inter.Invoke("test",
6885-
interpreter.NewUnmeteredIntValueFromInt64(1),
6886-
)
6887-
require.NoError(t, err)
6888-
6889-
AssertValuesEqual(
6890-
t,
6891-
inter,
6892-
expected,
6893-
actual,
6894-
)
6895-
}
6896-
6897-
t.Run("fix enabled", func(t *testing.T) {
6898-
t.Parallel()
6899-
6900-
test(t,
6901-
true,
6902-
interpreter.NewUnmeteredIntValueFromInt64(1),
6903-
)
6904-
})
6875+
let a = 2
6876+
return bar()
6877+
}
6878+
`)
69056879

6906-
t.Run("fix disabled", func(t *testing.T) {
6907-
t.Parallel()
6880+
actual, err := inter.Invoke("test",
6881+
interpreter.NewUnmeteredIntValueFromInt64(1),
6882+
)
6883+
require.NoError(t, err)
69086884

6909-
test(t,
6910-
false,
6911-
interpreter.NewUnmeteredIntValueFromInt64(2),
6912-
)
6913-
})
6885+
AssertValuesEqual(
6886+
t,
6887+
inter,
6888+
interpreter.NewUnmeteredIntValueFromInt64(1),
6889+
actual,
6890+
)
69146891
}
69156892

69166893
func TestInterpretClosureScopingInnerFunction(t *testing.T) {
69176894
t.Parallel()
69186895

6919-
test := func(t *testing.T, fixEnabled bool, expected interpreter.Value) {
6920-
6921-
inter := parseCheckAndInterpret(t, `
6922-
fun test(a: Int): Int {
6923-
fun bar(): Int {
6924-
return a
6925-
}
6926-
let a = 2
6927-
return bar()
6896+
inter := parseCheckAndInterpret(t, `
6897+
fun test(a: Int): Int {
6898+
fun bar(): Int {
6899+
return a
69286900
}
6929-
`)
6930-
6931-
inter.SharedState.Config.FunctionScopingFixEnabled = fixEnabled
6932-
6933-
value, err := inter.Invoke("test",
6934-
interpreter.NewUnmeteredIntValueFromInt64(1),
6935-
)
6936-
require.NoError(t, err)
6937-
6938-
AssertValuesEqual(
6939-
t,
6940-
inter,
6941-
expected,
6942-
value,
6943-
)
6944-
}
6945-
6946-
t.Run("fix enabled", func(t *testing.T) {
6947-
t.Parallel()
6948-
6949-
test(t,
6950-
true,
6951-
interpreter.NewUnmeteredIntValueFromInt64(1),
6952-
)
6953-
})
6901+
let a = 2
6902+
return bar()
6903+
}
6904+
`)
69546905

6955-
t.Run("fix disabled", func(t *testing.T) {
6956-
t.Parallel()
6906+
value, err := inter.Invoke("test",
6907+
interpreter.NewUnmeteredIntValueFromInt64(1),
6908+
)
6909+
require.NoError(t, err)
69576910

6958-
test(t,
6959-
false,
6960-
interpreter.NewUnmeteredIntValueFromInt64(2),
6961-
)
6962-
})
6911+
AssertValuesEqual(
6912+
t,
6913+
inter,
6914+
interpreter.NewUnmeteredIntValueFromInt64(1),
6915+
value,
6916+
)
69636917
}
69646918

69656919
func TestInterpretAssignmentAfterClosureFunctionExpression(t *testing.T) {

runtime/convertValues.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ func exportValueWithInterpreter(
237237
case *interpreter.PathCapabilityValue: //nolint:staticcheck
238238
return exportPathCapabilityValue(v, inter)
239239
case *interpreter.EphemeralReferenceValue:
240-
config := inter.SharedState.Config
241-
if config.ExportFixesEnabled &&
242-
v.Value == nil {
243-
240+
if v.Value == nil {
244241
return nil, nil
245242
}
246243

@@ -279,10 +276,7 @@ func exportValueWithInterpreter(
279276
case interpreter.FunctionValue:
280277
return exportFunctionValue(v, inter), nil
281278
case nil:
282-
config := inter.SharedState.Config
283-
if config.ExportFixesEnabled {
284-
return nil, nil
285-
}
279+
return nil, nil
286280
}
287281
return nil, &ValueNotExportableError{
288282
Type: value.StaticType(inter),

0 commit comments

Comments
 (0)