Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge destructor removal into stable cadence #2928

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8743fae
remove parsing support for destructors
dsainati1 Sep 13, 2023
b6476df
remove typechecking support for destructors
dsainati1 Sep 13, 2023
ac178d1
automatically delete nested resources on destroy
dsainati1 Sep 15, 2023
070e278
remove unused variables
dsainati1 Sep 15, 2023
85eacf5
add support for default arguments to AST
dsainati1 Sep 20, 2023
ef45306
parsing default event
dsainati1 Sep 20, 2023
34f4344
re-add removed test
dsainati1 Sep 20, 2023
d09b578
partial checking
dsainati1 Sep 21, 2023
6846737
support for declarations
dsainati1 Sep 21, 2023
60c1d1e
more progress on checking
dsainati1 Sep 22, 2023
2b1ef90
fix checking order so variables are properly in scope
dsainati1 Sep 22, 2023
26b5ade
check only certain expressions are allowed
dsainati1 Sep 22, 2023
ff166ec
amend error message
dsainati1 Sep 22, 2023
a986a76
permit paths
dsainati1 Sep 22, 2023
b365401
Merge branch 'feature/stable-cadence' of github.com:onflow/cadence in…
dsainati1 Sep 22, 2023
415bef4
Merge branch 'sainati/ban-custom-destructors' of github.com:onflow/ca…
dsainati1 Sep 22, 2023
01f5e1c
update error message on unexpected default arg
dsainati1 Sep 22, 2023
c4786ca
Merge branch 'sainati/default-event-parsing' of github.com:onflow/cad…
dsainati1 Sep 22, 2023
3295bbb
emit default event
dsainati1 Sep 26, 2023
59210c1
emit events on destroy
dsainati1 Sep 26, 2023
b8954d4
fix attachment base values
dsainati1 Sep 26, 2023
e40c490
fix scoping across interpreters
dsainati1 Sep 26, 2023
24e6164
lint
dsainati1 Sep 26, 2023
8d2169f
fix lint
dsainati1 Sep 26, 2023
85c12ac
Merge branch 'sainati/default-event-checking' of github.com:onflow/ca…
dsainati1 Sep 27, 2023
0d9bf8c
emit interface events as well
dsainati1 Sep 27, 2023
339767b
Update runtime/ast/composite.go
dsainati1 Sep 27, 2023
1e83b48
add test for same name interfaces
dsainati1 Sep 27, 2023
6e42dee
Merge branch 'feature/stable-cadence' of github.com:onflow/cadence in…
dsainati1 Sep 27, 2023
a3b43ad
Merge branch 'sainati/ban-custom-destructors' of github.com:onflow/ca…
dsainati1 Sep 27, 2023
9f23589
fix test
dsainati1 Sep 27, 2023
dbf0770
Merge branch 'sainati/default-event-parsing' of github.com:onflow/cad…
dsainati1 Sep 27, 2023
15543eb
respond to review
dsainati1 Sep 28, 2023
f35d5db
Merge branch 'sainati/default-event-parsing' of github.com:onflow/cad…
dsainati1 Sep 28, 2023
936f2ba
correct scoping
dsainati1 Sep 28, 2023
5e92c18
Merge branch 'feature/stable-cadence' of github.com:onflow/cadence in…
dsainati1 Oct 24, 2023
c034b5a
respond to review
dsainati1 Oct 26, 2023
33c238d
Merge branch 'feature/remove-destructors' of github.com:onflow/cadenc…
dsainati1 Oct 26, 2023
bad0e79
Merge branch 'sainati/ban-custom-destructors' of github.com:onflow/ca…
dsainati1 Oct 26, 2023
1910211
Merge branch 'sainati/default-event-parsing' of github.com:onflow/cad…
dsainati1 Oct 26, 2023
8fb0ad2
respond to review
dsainati1 Oct 26, 2023
1d6cc42
Merge branch 'sainati/default-event-checking' of github.com:onflow/ca…
dsainati1 Oct 26, 2023
48fb4b2
prevent manually emitting default destroy events
dsainati1 Oct 27, 2023
8f044b2
respond to review
dsainati1 Oct 27, 2023
3899fdb
add tests
dsainati1 Oct 27, 2023
b1551c3
Merge pull request #2789 from onflow/sainati/ban-custom-destructors
dsainati1 Oct 30, 2023
18e4c0d
respond to review
dsainati1 Oct 30, 2023
1be5186
fix lint
dsainati1 Oct 30, 2023
e63c9e7
Merge pull request #2799 from onflow/sainati/default-event-parsing
dsainati1 Oct 30, 2023
7931d90
respond to review
dsainati1 Oct 30, 2023
1e79d89
Merge pull request #2812 from onflow/sainati/default-event-checking
dsainati1 Oct 30, 2023
3ba46df
respond to review
dsainati1 Oct 31, 2023
ceebf15
Merge branch 'feature/remove-destructors' of github.com:onflow/cadenc…
dsainati1 Oct 31, 2023
366366d
use deterministic ordered function map
dsainati1 Oct 31, 2023
229a189
Update runtime/interpreter/interpreter.go
dsainati1 Nov 1, 2023
e0b9d03
respond to review
dsainati1 Nov 1, 2023
3cd0f5d
add comment
dsainati1 Nov 1, 2023
e5af208
rename variables
dsainati1 Nov 1, 2023
d8abdd4
proper lexical scoping and testing
dsainati1 Nov 1, 2023
920ea94
use new activation for default event param evaluation
dsainati1 Nov 2, 2023
89fbe55
style
dsainati1 Nov 7, 2023
05f6aaf
Merge branch 'feature/stable-cadence' of github.com:onflow/cadence in…
dsainati1 Nov 7, 2023
4045c17
Update runtime/parser/declaration_test.go
dsainati1 Nov 7, 2023
13786b0
review comments
dsainati1 Nov 7, 2023
d1fc770
Merge branch 'sainati/merge-stable-cadence-destructors' of github.com…
dsainati1 Nov 7, 2023
3dd41d5
review comments
dsainati1 Nov 7, 2023
481826f
more argument orders
dsainati1 Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -19315,9 +19315,7 @@ func (NilValue) IsDestroyed() bool {
return false
}

func (v NilValue) Destroy(interpreter *Interpreter, _ LocationRange) {

}
func (v NilValue) Destroy(_ *Interpreter, _ LocationRange) {}

func (NilValue) String() string {
return format.Nil
Expand Down
3 changes: 1 addition & 2 deletions runtime/resourcedictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,7 @@ func TestRuntimeResourceDictionaryValues_Destruction(t *testing.T) {
require.Equal(t, events[2].EventType.ID(), "A.0000000000000001.Test.R.ResourceDestroyed")
// one of the two needs to be 1, the other needs to be 2
require.True(t,
(events[1].Fields[0].String() == "1" && events[2].Fields[0].String() == "2") ||
(events[2].Fields[0].String() == "1" && events[1].Fields[0].String() == "2"),
(events[2].Fields[0].String() == "1" && events[1].Fields[0].String() == "2"),
)
dsainati1 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
14 changes: 13 additions & 1 deletion runtime/sema/check_composite_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,10 @@ func (checker *Checker) declareCompositeLikeMembersAndValue(
checker.Elaboration.SetDefaultDestroyDeclaration(declaration, nestedCompositeDeclaration)
defaultEventType :=
checker.typeActivations.Find(identifier.Identifier)
defaultEventComposite := defaultEventType.Type.(*CompositeType)
defaultEventComposite, ok := defaultEventType.Type.(*CompositeType)
if !ok {
panic(errors.NewUnreachableError())
}
compositeType.DefaultDestroyEvent = defaultEventComposite
}

Expand Down Expand Up @@ -2006,8 +2009,11 @@ func (checker *Checker) checkDefaultDestroyParamExpressionKind(
*ast.IntegerExpression,
*ast.FixedPointExpression,
*ast.PathExpression:

break

case *ast.IdentifierExpression:
dsainati1 marked this conversation as resolved.
Show resolved Hide resolved

identifier := arg.Identifier.Identifier
// these are guaranteed to exist at time of destruction, so we allow them
if identifier == SelfIdentifier || identifier == BaseIdentifier {
Expand All @@ -2020,9 +2026,13 @@ func (checker *Checker) checkDefaultDestroyParamExpressionKind(
checker.report(&DefaultDestroyInvalidArgumentError{
Range: ast.NewRangeFromPositioned(checker.memoryGauge, arg),
})

case *ast.MemberExpression:

checker.checkDefaultDestroyParamExpressionKind(arg.Expression)

case *ast.IndexExpression:

checker.checkDefaultDestroyParamExpressionKind(arg.TargetExpression)
checker.checkDefaultDestroyParamExpressionKind(arg.IndexingExpression)

Expand All @@ -2048,9 +2058,11 @@ func (checker *Checker) checkDefaultDestroyParamExpressionKind(
})

default:

checker.report(&DefaultDestroyInvalidArgumentError{
Range: ast.NewRangeFromPositioned(checker.memoryGauge, arg),
})

}
}

Expand Down
5 changes: 4 additions & 1 deletion runtime/sema/check_interface_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,10 @@ func (checker *Checker) declareInterfaceMembersAndValue(declaration *ast.Interfa
// Find the value declaration
nestedEvent :=
checker.typeActivations.Find(nestedCompositeDeclaration.Identifier.Identifier)
defaultEventComposite := nestedEvent.Type.(*CompositeType)
defaultEventComposite, ok := nestedEvent.Type.(*CompositeType)
if !ok {
panic(errors.NewUnreachableError())
}
interfaceType.DefaultDestroyEvent = defaultEventComposite
} else {
checker.declareNestedEvent(nestedCompositeDeclaration, eventMembers, interfaceType)
Expand Down
36 changes: 19 additions & 17 deletions runtime/tests/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6594,7 +6594,7 @@ func TestInterpretResourceMoveInArrayAndDestroy(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -6643,7 +6643,7 @@ func TestInterpretResourceMoveInDictionaryAndDestroy(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -6905,7 +6905,7 @@ func TestInterpretResourceDestroyExpressionDestructor(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -6954,7 +6954,7 @@ func TestInterpretResourceDestroyExpressionNestedResources(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -6989,7 +6989,7 @@ func TestInterpretResourceDestroyArray(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -7022,7 +7022,7 @@ func TestInterpretResourceDestroyDictionary(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -7055,7 +7055,7 @@ func TestInterpretResourceDestroyOptionalSome(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -7087,7 +7087,7 @@ func TestInterpretResourceDestroyOptionalNil(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -9571,7 +9571,7 @@ func TestInterpretNestedDestroy(t *testing.T) {
}
`, ParseCheckAndInterpretOptions{
Config: &interpreter.Config{
OnEventEmitted: func(inter *interpreter.Interpreter, locationRange interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
OnEventEmitted: func(_ *interpreter.Interpreter, _ interpreter.LocationRange, event *interpreter.CompositeValue, eventType *sema.CompositeType) error {
events = append(events, event)
return nil
},
Expand Down Expand Up @@ -11724,17 +11724,12 @@ func TestInterpretSwapDictionaryKeysWithSideEffects(t *testing.T) {
t.Run("resources", func(t *testing.T) {
t.Parallel()

inter, _, err := parseCheckAndInterpretWithLogs(t, `
inter, getEvents, err := parseCheckAndInterpretWithEvents(t, `
resource Resource {
event ResourceDestroyed(value: Int = self.value)
var value: Int

init(_ value: Int) {
log(
"Creating resource with UUID "
.concat(self.uuid.toString())
.concat(" and value ")
.concat(value.toString())
)
self.value = value
}
}
Expand Down Expand Up @@ -11781,6 +11776,13 @@ func TestInterpretSwapDictionaryKeysWithSideEffects(t *testing.T) {
_, err = inter.Invoke("test")
require.NoError(t, err)

// DestructorTODO: replace with test for destruction event
events := getEvents()
require.Len(t, events, 3)
require.Equal(t, events[0].event.QualifiedIdentifier, "Resource.ResourceDestroyed")
require.Equal(t, events[0].event.GetField(inter, interpreter.EmptyLocationRange, "value"), interpreter.NewIntValueFromInt64(nil, 2))
require.Equal(t, events[1].event.QualifiedIdentifier, "Resource.ResourceDestroyed")
require.Equal(t, events[1].event.GetField(inter, interpreter.EmptyLocationRange, "value"), interpreter.NewIntValueFromInt64(nil, 1))
require.Equal(t, events[2].event.QualifiedIdentifier, "Resource.ResourceDestroyed")
require.Equal(t, events[2].event.GetField(inter, interpreter.EmptyLocationRange, "value"), interpreter.NewIntValueFromInt64(nil, 3))
})
}