-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: Add Dafny standard libraries subset and partial streaming support to StandardLibrary #1321
Open
robin-aws
wants to merge
20
commits into
main
Choose a base branch
from
robin-aws/add-dafny-stdlibs-and-partial-streaming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
16900fe
Include smithy-dafny .toml subset
robin-aws 0e7b124
Fix
robin-aws fdabd5d
Fix
robin-aws fd021c5
Fix including doo file in StandardLibrary builds
robin-aws bd4ee0d
Externs and newer smithy-dafny
robin-aws 208415f
Remove robin-aws@
robin-aws ca901c6
Merge branch 'robin-aws/add-dafny-stdlibs-and-partial-streaming' of g…
robin-aws 13e6081
Updates
robin-aws ffa941c
Newer smithy-dafny
robin-aws 1174913
Merge branch 'robin-aws/add-dafny-stdlibs-and-partial-streaming' of g…
robin-aws 772a553
smithy-dafny submodule fix
robin-aws 043ae57
No need to use Dafny stdlibs when building StandardLibrary by itself
robin-aws bbc1527
Revert .dtr change
robin-aws 7fd6b7c
Revert dtr fully
robin-aws 6a45be3
Actually revert
robin-aws 898b57d
newline
robin-aws 13c0cbd
Lock down aws-lc version to avoid broken release
robin-aws f270868
Lock down Rust version
robin-aws f86fe4a
Fix version
robin-aws 36b0967
Revert locking down Rust version
robin-aws 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 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 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 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 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 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
67 changes: 67 additions & 0 deletions
67
...Library/runtimes/python/src/smithy_dafny_standard_library/internaldafny/extern/streams.py
This file contains 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,67 @@ | ||
|
||
from _dafny import Seq | ||
from smithy_python.interfaces.blobs import ByteStream | ||
from smithy_dafny_standard_library.internaldafny.generated.Std_Streams import ByteStream as DafnyByteStream, RewindableByteStream as DafnyRewindableByteStream | ||
from smithy_dafny_standard_library.internaldafny.generated.Std_Enumerators import Enumerator | ||
from smithy_dafny_standard_library.internaldafny.generated.Std_Wrappers import Option, Option_Some, Option_None | ||
|
||
# Adaptor classes for wrapping up Python-native types as their | ||
# corresponding Dafny interfaces, and vice-versa. | ||
# These are the equivalent of type conversions, | ||
# but avoiding having to load all data into memory at once. | ||
|
||
class DafnyByteStreamAsByteStream(ByteStream): | ||
"""Wrapper class adapting a Dafny ByteStream as a native ByteStream.""" | ||
|
||
def __init__(self, dafny_byte_stream): | ||
self.dafny_byte_stream = dafny_byte_stream | ||
|
||
def read(self, size: int = -1) -> bytes: | ||
# TODO: assert size is -1, buffer, | ||
# or define a more specialized Action<int, bytes> type for streams. | ||
next = self.dafny_byte_stream.Next() | ||
while next.is_Some and len(next.value) == 0: | ||
next = self.dafny_byte_stream.Next() | ||
# Do NOT return None, because that indicates "no data right now, might be more later" | ||
return bytes(next.value) if next.is_Some else bytes() | ||
|
||
|
||
class RewindableDafnyByteStreamAsByteStream(DafnyByteStreamAsByteStream): | ||
"""Wrapper class adapting a Dafny RewindableByteStream as a native ByteStream | ||
that supports tell and seek. | ||
""" | ||
|
||
def __init__(self, dafny_byte_stream): | ||
if not isinstance(dafny_byte_stream, DafnyRewindableByteStream): | ||
raise ValueError("Rewindable stream required") | ||
super().__init__(dafny_byte_stream) | ||
|
||
def tell(self) -> int: | ||
return self.dafny_byte_stream.Position() | ||
|
||
def seek(self, offset, whence=0): | ||
match whence: | ||
case 0: | ||
position = offset | ||
case 1: | ||
position = self.dafny_byte_stream.Position() + offset | ||
case 2: | ||
position = self.dafny_byte_stream.ContentLength() + offset | ||
return self.dafny_byte_stream.Seek(position) | ||
|
||
|
||
class StreamingBlobAsDafnyDataStream(DafnyByteStream): | ||
"""Wrapper class adapting a native StreamingBlob as a Dafny ByteStream.""" | ||
|
||
def __init__(self, streaming_blob): | ||
self.streaming_blob = streaming_blob | ||
|
||
def Next(self): | ||
return Enumerator.Next(self) | ||
|
||
def Invoke(self, _) -> Option: | ||
next = self.streaming_blob.read() | ||
if next: | ||
return Option_Some(Seq(next)) | ||
else: | ||
return Option_None() |
This file contains 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
Submodule smithy-dafny
updated
52 files
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.
is it possible to resolve this TODO at this time?