-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[mypyc] Import librt.base64 capsule automatically if needed #20233
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
8 commits
Select commit
Hold shift + click to select a range
0e603de
[mypyc] Import librt.base64 capsule automatically if needed
JukkaL 37109f2
Remove explicit flag as it's no longer needed
JukkaL 656fcf8
Update comment
JukkaL 7a45fff
Refactor
JukkaL 8220278
Refactor
JukkaL b58040d
Add irbuild tests
JukkaL 2cec528
Refactor
JukkaL b267fb5
Add test case
JukkaL 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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from mypyc.ir.func_ir import FuncIR | ||
| from mypyc.ir.ops import CallC, PrimitiveOp | ||
|
|
||
|
|
||
| def find_implicit_capsule_dependencies(fn: FuncIR) -> set[str] | None: | ||
| """Find implicit dependencies on capsules that need to be imported. | ||
|
|
||
| Using primitives or types defined in librt submodules such as "librt.base64" | ||
| requires a capsule import. | ||
|
|
||
| Note that a module can depend on a librt module even if it doesn't explicitly | ||
| import it, for example via re-exported names or via return types of functions | ||
| defined in other modules. | ||
| """ | ||
| deps: set[str] | None = None | ||
| for block in fn.blocks: | ||
| for op in block.ops: | ||
| # TODO: Also determine implicit type object dependencies (e.g. cast targets) | ||
| if isinstance(op, CallC) and op.capsule is not None: | ||
| if deps is None: | ||
| deps = set() | ||
| deps.add(op.capsule) | ||
| else: | ||
| assert not isinstance(op, PrimitiveOp), "Lowered IR is expected" | ||
| return deps |
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
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
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
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
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,37 @@ | ||
| [case testBase64_experimental] | ||
| from librt.base64 import b64encode | ||
|
|
||
| def enc(b: bytes) -> bytes: | ||
| return b64encode(b) | ||
| [out] | ||
| def enc(b): | ||
| b, r0 :: bytes | ||
| L0: | ||
| r0 = LibRTBase64_b64encode_internal(b) | ||
| return r0 | ||
|
|
||
| [case testBase64ExperimentalDisabled] | ||
| from librt.base64 import b64encode | ||
|
|
||
| def enc(b: bytes) -> bytes: | ||
| return b64encode(b) | ||
| [out] | ||
| def enc(b): | ||
| b :: bytes | ||
| r0 :: dict | ||
| r1 :: str | ||
| r2 :: object | ||
| r3 :: object[1] | ||
| r4 :: object_ptr | ||
| r5 :: object | ||
| r6 :: bytes | ||
| L0: | ||
| r0 = __main__.globals :: static | ||
| r1 = 'b64encode' | ||
| r2 = CPyDict_GetItem(r0, r1) | ||
| r3 = [b] | ||
| r4 = load_address r3 | ||
| r5 = PyObject_Vectorcall(r2, r4, 1, 0) | ||
| keep_alive b | ||
| r6 = cast(bytes, r5) | ||
| return r6 |
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
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
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 the top-level code (outside any functions) converted into a
FuncIRat this point? either way it might be good to add a test where the only use of the dependency is outside a function.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.
Yes, but I can add a test case.