-
Notifications
You must be signed in to change notification settings - Fork 4
Fix AllocRefValue
#773
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
Fix AllocRefValue
#773
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,13 @@ | |
| UintT, | ||
| ) | ||
| from .value import ( | ||
| NO_METADATA, | ||
| NO_SIZE, | ||
| AggregateValue, | ||
| AllocRefValue, | ||
| BoolValue, | ||
| DynamicSize, | ||
| IntValue, | ||
| Metadata, | ||
| RangeValue, | ||
| StaticSize, | ||
| StrValue, | ||
|
|
@@ -120,18 +121,30 @@ def _decode_memory_alloc_or_unable( | |
| except KeyError: | ||
| return UnableToDecodeValue(f'Unknown pointee type: {pointee_ty}') | ||
|
|
||
| metadata = _metadata(pointee_type_info) | ||
| metadata_size = _metadata_size(pointee_type_info) | ||
|
|
||
| if len(data) == 8: | ||
| # single slim pointer (assumes usize == u64) | ||
| return AllocRefValue(alloc_id=alloc_id, metadata=metadata) | ||
| return AllocRefValue( | ||
| alloc_id=alloc_id, | ||
| metadata=Metadata( | ||
| size=metadata_size, | ||
| pointer_offset=0, | ||
| origin_size=metadata_size, | ||
| ), | ||
| ) | ||
|
|
||
| if len(data) == 16 and metadata == DynamicSize(1): | ||
| if len(data) == 16 and metadata_size == DynamicSize(1): | ||
| # sufficient data to decode dynamic size (assumes usize == u64) | ||
| # expect fat pointer | ||
| actual_size = DynamicSize(int.from_bytes(data[8:16], byteorder='little', signed=False)) | ||
| return AllocRefValue( | ||
| alloc_id=alloc_id, | ||
| metadata=DynamicSize(int.from_bytes(data[8:16], byteorder='little', signed=False)), | ||
| metadata=Metadata( | ||
| size=actual_size, | ||
| pointer_offset=0, | ||
| origin_size=actual_size, | ||
| ), | ||
|
Comment on lines
+143
to
+147
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. Same here. |
||
| ) | ||
|
|
||
| return UnableToDecodeValue(f'Unable to decode alloc: {data!r}, of type: {type_info}') | ||
|
|
@@ -145,14 +158,14 @@ def _pointee_ty(type_info: TypeMetadata) -> Ty | None: | |
| return None | ||
|
|
||
|
|
||
| def _metadata(type_info: TypeMetadata) -> MetadataSize: | ||
| def _metadata_size(type_info: TypeMetadata) -> MetadataSize: | ||
| match type_info: | ||
| case ArrayT(length=None): | ||
| return DynamicSize(1) # 1 is a placeholder, the actual size is inferred from the slice data | ||
| case ArrayT(length=int() as length): | ||
| return StaticSize(length) | ||
| case _: | ||
| return NO_METADATA | ||
| return NO_SIZE | ||
|
|
||
|
|
||
| def decode_value_or_unable(data: bytes, type_info: TypeMetadata, types: Mapping[Ty, TypeMetadata]) -> Value: | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -90,21 +90,29 @@ def to_kast(self) -> KInner: | |
| class AllocRefValue(Value): | ||
| alloc_id: AllocId | ||
| # projection_elems: tuple[ProjectionElem, ...] | ||
| metadata: MetadataSize | ||
| metadata: Metadata | ||
|
|
||
| def to_kast(self) -> KInner: | ||
| return KApply( | ||
| 'Value::AllocRef', | ||
| KApply('allocId', intToken(self.alloc_id)), | ||
| KApply('ProjectionElems::empty'), # TODO | ||
| KApply( | ||
| 'Metadata', | ||
| ( | ||
| self.metadata.to_kast(), | ||
| intToken(0), | ||
| self.metadata.to_kast(), | ||
| ), | ||
| ), | ||
| self.metadata.to_kast(), | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class Metadata: | ||
| size: MetadataSize | ||
| pointer_offset: int | ||
| origin_size: MetadataSize | ||
|
|
||
| def to_kast(self) -> KInner: | ||
| return KApply( | ||
| 'Metadata', | ||
| self.size.to_kast(), | ||
| intToken(self.pointer_offset), | ||
| self.origin_size.to_kast(), | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -114,12 +122,12 @@ def to_kast(self) -> KInner: ... | |
|
|
||
|
|
||
| @dataclass | ||
| class NoMetadata(MetadataSize): | ||
| class NoSize(MetadataSize): | ||
| def to_kast(self) -> KInner: | ||
| return KApply('noMetadata') | ||
| return KApply('noMetadataSize') | ||
|
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. Thank you for changing this! I encountered a problem when running |
||
|
|
||
|
|
||
| NO_METADATA: Final = NoMetadata() | ||
| NO_SIZE: Final = NoSize() | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
||
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.
I made this assumption based on the previous version of
AllocRevValue.to_kast(), I don't know if it makes sense though.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.
I think this makes sense, when we decode we won't ever have an offset, and the
origin_sizeshould be the same as thesizefield IIUC.