-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
introduce constructing functions with typeassert for several types #59441
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9f342c7
introduce constructing functions with typeassert for several types
nsajko 41a456b
test return type inference
nsajko 59a28fa
apply the constructing functions to some code under `base/`
nsajko 5535aaf
revert all changes that add a typeassert where there was none
nsajko 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
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,36 @@ | ||
| # Constructing functions for some concrete types. | ||
| # | ||
| # Meant to be used to improve inference, when the input arguments are not necessarily | ||
| # precisely inferred. Partial workaround for issue #42372. | ||
| module _ConstructingFunctions | ||
| export | ||
| _Bool, | ||
| _Int, _Int8, _Int16, _Int32, _Int64, _Int128, | ||
| _UInt, _UInt8, _UInt16, _UInt32, _UInt64, _UInt128, | ||
| _Char, _String | ||
| struct ConstructorStrict{F} <: Function end | ||
| # Keyword arguments are not available at this point in bootstrap, so they're not | ||
| # supported. | ||
| function (::ConstructorStrict{F})(args::Vararg{Any, N}) where {F, N} | ||
| @inline | ||
| r = F(args...) | ||
| r::F | ||
| end | ||
| const _Bool = ConstructorStrict{Bool}() | ||
| const _Int = ConstructorStrict{Int}() | ||
| const _Int8 = ConstructorStrict{Int8}() | ||
| const _Int16 = ConstructorStrict{Int16}() | ||
| const _Int32 = ConstructorStrict{Int32}() | ||
| const _Int64 = ConstructorStrict{Int64}() | ||
| const _Int128 = ConstructorStrict{Int128}() | ||
| const _UInt = ConstructorStrict{UInt}() | ||
| const _UInt8 = ConstructorStrict{UInt8}() | ||
| const _UInt16 = ConstructorStrict{UInt16}() | ||
| const _UInt32 = ConstructorStrict{UInt32}() | ||
| const _UInt64 = ConstructorStrict{UInt64}() | ||
| const _UInt128 = ConstructorStrict{UInt128}() | ||
| const _Char = ConstructorStrict{Char}() | ||
| const _String = ConstructorStrict{String}() | ||
| end | ||
|
|
||
| using ._ConstructingFunctions | ||
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
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
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.
As a historical note, soon after closing this PR I realized there's a nicer way of doing this, based on preexisting functionality and more generic:
Base.Fix2(typeassert, F) ∘ F. Registered package based on this idea:https://juliahub.com/ui/Packages/General/EnforcedTypeSignatureCallables
https://github.com/JuliaFunctional/EnforcedTypeSignatureCallables.jl