-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[trace-view] Fixed a problem with reference lifetimes #24196
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,42 +167,25 @@ interface JSONTraceReadEffect { | |
| root_value_read: JSONTraceValue; | ||
| } | ||
|
|
||
| interface JSONTracePushEffect { | ||
| RuntimeValue?: JSONTraceRuntimeValueContent; | ||
| MutRef?: { | ||
| location: JSONTraceLocation; | ||
| snapshot: any[]; | ||
| }; | ||
| } | ||
|
|
||
| interface JSONTracePopEffect { | ||
| RuntimeValue?: JSONTraceRuntimeValueContent; | ||
| MutRef?: { | ||
| location: JSONTraceLocation; | ||
| snapshot: any[]; | ||
| }; | ||
| } | ||
|
|
||
| interface JSONDataLoadEffect { | ||
| ref_type: JSONTraceRefType; | ||
| location: JSONTraceLocation; | ||
| snapshot: JSONTraceMoveValue; | ||
| } | ||
|
|
||
| interface JSONTraceEffect { | ||
| Push?: JSONTracePushEffect; | ||
| Pop?: JSONTracePopEffect; | ||
| Push?: JSONTraceValue; | ||
| Pop?: JSONTraceValue; | ||
| Write?: JSONTraceWriteEffect; | ||
| Read?: JSONTraceReadEffect; | ||
| DataLoad?: JSONDataLoadEffect; | ||
| ExecutionError?: string; | ||
|
|
||
| } | ||
|
|
||
| interface JSONTraceCloseFrame { | ||
| frame_id: number; | ||
| gas_left: number; | ||
| return_: JSONTraceRuntimeValueContent[]; | ||
| return_: JSONTraceValue[]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated fix (spotted when looking at trace format code...) |
||
| } | ||
|
|
||
| interface JSONExtMoveCallSummary { | ||
|
|
@@ -582,6 +565,12 @@ export async function readTrace( | |
| } | ||
| } | ||
| localLifetimeEnds.set(frame.frame_id, lifetimeEnds); | ||
| // Extend lifetimes of locals referenced by parameters | ||
| for (const param of frame.parameters) { | ||
| if (param) { | ||
| extendLifetimeIfReference(param, localLifetimeEnds); | ||
| } | ||
| } | ||
| // Trace v3 introduces `version_id` field in frame, which represents | ||
| // address of the on-chain package version that contains the function. | ||
| // It is different from `frame.module.address` if the package has been | ||
|
|
@@ -659,6 +648,12 @@ export async function readTrace( | |
| bcodeFunEntry | ||
| }); | ||
| } else if (event.CloseFrame) { | ||
| // Extend lifetimes of locals referenced by return values | ||
| for (const returnValue of event.CloseFrame.return_) { | ||
| if (returnValue) { | ||
| extendLifetimeIfReference(returnValue, localLifetimeEnds); | ||
| } | ||
| } | ||
| events.push({ | ||
| type: TraceEventKind.CloseFrame, | ||
| id: event.CloseFrame.frame_id | ||
|
|
@@ -754,6 +749,13 @@ export async function readTrace( | |
| localLifetimeEndsMax.set(nonInlinedFrameID, lifetimeEndsMax); | ||
| } else if (event.Effect) { | ||
| const effect = event.Effect; | ||
| // Process Push/Pop effects that contain references to extend local lifetimes | ||
| if (effect.Push) { | ||
| extendLifetimeIfReference(effect.Push, localLifetimeEnds); | ||
| } | ||
| if (effect.Pop) { | ||
| extendLifetimeIfReference(effect.Pop, localLifetimeEnds); | ||
| } | ||
| if (effect.Write || effect.Read || effect.DataLoad) { | ||
| const location = effect.Write | ||
| ? effect.Write.location | ||
|
|
@@ -1233,6 +1235,24 @@ function processJSONLocation( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extends the lifetime of a local variable if it contains a reference. | ||
| * | ||
| * @param value JSON trace value that may contain a reference. | ||
| * @param localLifetimeEnds map of local variable lifetimes. | ||
| */ | ||
| function extendLifetimeIfReference( | ||
| value: JSONTraceValue, | ||
| localLifetimeEnds?: Map<number, number[]> | ||
| ): void { | ||
| if ('MutRef' in value || 'ImmRef' in value) { | ||
| const refContent = 'MutRef' in value ? value.MutRef : value.ImmRef; | ||
| if (refContent && refContent.location) { | ||
| processJSONLocation(refContent.location, [], localLifetimeEnds); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Converts a JSON trace reference value to a runtime value. | ||
| * | ||
|
|
||
11 changes: 11 additions & 0 deletions
11
external-crates/move/crates/move-analyzer/trace-adapter/tests/ref_after_lifetime/Move.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "ref_after_lifetime" | ||
| edition = "2024.beta" | ||
|
|
||
| [dependencies] | ||
| MoveStdlib = { local = "../../../../move-stdlib" } | ||
|
|
||
| [addresses] | ||
| ref_after_lifetime = "0x0" | ||
| std = "0x1" | ||
|
|
Binary file added
BIN
+222 Bytes
...zer/trace-adapter/tests/ref_after_lifetime/build/ref_after_lifetime/bytecode_modules/m.mv
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...nalyzer/trace-adapter/tests/ref_after_lifetime/build/ref_after_lifetime/debug_info/m.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"version":2,"from_file_path":"/Users/adamwelc/sui/external-crates/move/crates/move-analyzer/trace-adapter/tests/ref_after_lifetime/sources/m.move","definition_location":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":161,"end":162},"module_name":["0000000000000000000000000000000000000000000000000000000000000000","m"],"struct_map":{},"enum_map":{},"function_map":{"0":{"location":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":307,"end":368},"definition_location":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":311,"end":327},"type_parameters":[],"parameters":[["value_ref#0#0",{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":328,"end":337}]],"returns":[{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":346,"end":350}],"locals":[],"nops":{},"code_map":{"0":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":357,"end":366}},"is_native":false},"1":{"location":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":378,"end":896},"definition_location":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":382,"end":386},"type_parameters":[],"parameters":[],"returns":[],"locals":[["my_value#1#0",{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":399,"end":407}]],"nops":{},"code_map":{"0":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":410,"end":415},"1":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":399,"end":407},"2":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":558,"end":567},"3":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":541,"end":568},"4":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":525,"end":538},"5":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":568,"end":569}},"is_native":false},"2":{"location":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":134,"end":896},"definition_location":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":134,"end":896},"type_parameters":[],"parameters":[],"returns":[],"locals":[],"nops":{},"code_map":{"0":{"file_hash":[221,68,119,252,84,29,1,115,51,251,227,188,84,129,200,130,124,133,248,127,36,46,81,40,229,240,239,76,57,125,193,100],"start":134,"end":896}},"is_native":false}},"constant_map":{}} |
Binary file added
BIN
+953 Bytes
...analyzer/trace-adapter/tests/ref_after_lifetime/build/ref_after_lifetime/debug_info/m.mvd
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were actually not necessary as they are subsumed by
JSONTraceValueinterface