Skip to content

Commit 85c4649

Browse files
committed
introduce constructing functions with typeassert for several types
Introduce functions to construct and typeassert several concrete types: * `Bool` * other primitive integers * `Char` * `String` The new functions are meant to be used internally instead of the original constructors to help inference. Cross-reference issue #42372.
1 parent 3396562 commit 85c4649

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

base/Base_compiler.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ end
289289
setfield!(typeof(invoke_in_world).name, :max_args, Int32(3), :monotonic) # invoke_in_world, world, f, args...
290290

291291
# core operations & types
292+
include("constructingfunctions.jl")
292293
include("promotion.jl")
293294
include("tuple.jl")
294295
include("expr.jl")

base/constructingfunctions.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Constructing functions for some concrete types.
2+
#
3+
# Meant to be used to improve inference, when the input arguments are not necessarily
4+
# precisely inferred. Partial workaround for issue #42372.
5+
module _ConstructingFunctions
6+
export
7+
_Bool,
8+
_Int, _Int8, _Int16, _Int32, _Int64, _Int128,
9+
_UInt, _UInt8, _UInt16, _UInt32, _UInt64, _UInt128,
10+
_Char, _String
11+
struct ConstructorStrict{F} <: Function end
12+
# Keyword arguments are not available at this point in bootstrap, so they're not
13+
# supported.
14+
function (::ConstructorStrict{F})(args::Vararg{Any, N}) where {F, N}
15+
@inline
16+
r = F(args...)
17+
r::F
18+
end
19+
const _Bool = ConstructorStrict{Bool}()
20+
const _Int = ConstructorStrict{Int}()
21+
const _Int8 = ConstructorStrict{Int8}()
22+
const _Int16 = ConstructorStrict{Int16}()
23+
const _Int32 = ConstructorStrict{Int32}()
24+
const _Int64 = ConstructorStrict{Int64}()
25+
const _Int128 = ConstructorStrict{Int128}()
26+
const _UInt = ConstructorStrict{UInt}()
27+
const _UInt8 = ConstructorStrict{UInt8}()
28+
const _UInt16 = ConstructorStrict{UInt16}()
29+
const _UInt32 = ConstructorStrict{UInt32}()
30+
const _UInt64 = ConstructorStrict{UInt64}()
31+
const _UInt128 = ConstructorStrict{UInt128}()
32+
const _Char = ConstructorStrict{Char}()
33+
const _String = ConstructorStrict{String}()
34+
end
35+
36+
using ._ConstructingFunctions

0 commit comments

Comments
 (0)