Skip to content

Commit e077335

Browse files
committed
inference: follow up #44515, correctly encode Effects.overlayed effect (#44634)
xref: <#44515 (comment)>
1 parent 953d5d3 commit e077335

File tree

8 files changed

+43
-24
lines changed

8 files changed

+43
-24
lines changed

base/boot.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ eval(Core, quote
421421
function CodeInstance(
422422
mi::MethodInstance, @nospecialize(rettype), @nospecialize(inferred_const),
423423
@nospecialize(inferred), const_flags::Int32, min_world::UInt, max_world::UInt,
424-
ipo_effects::UInt8, effects::UInt8, @nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#),
424+
ipo_effects::UInt32, effects::UInt32, @nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#),
425425
relocatability::UInt8)
426426
return ccall(:jl_new_codeinst, Ref{CodeInstance},
427-
(Any, Any, Any, Any, Int32, UInt, UInt, UInt8, UInt8, Any, UInt8),
427+
(Any, Any, Any, Any, Int32, UInt, UInt, UInt32, UInt32, Any, UInt8),
428428
mi, rettype, inferred_const, inferred, const_flags, min_world, max_world,
429429
ipo_effects, effects, argescapes,
430430
relocatability)

base/compiler/compiler.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ include("operators.jl")
5858
include("pointer.jl")
5959
include("refvalue.jl")
6060

61+
# the same constructor as defined in float.jl, but with a different name to avoid redefinition
62+
_Bool(x::Real) = x==0 ? false : x==1 ? true : throw(InexactError(:Bool, Bool, x))
63+
6164
# checked arithmetic
6265
const checked_add = +
6366
const checked_sub = -

base/compiler/types.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,33 @@ function Effects(e::Effects = EFFECTS_UNKNOWN;
7878
end
7979

8080
is_total_or_error(effects::Effects) =
81-
effects.consistent === ALWAYS_TRUE && effects.effect_free === ALWAYS_TRUE &&
81+
effects.consistent === ALWAYS_TRUE &&
82+
effects.effect_free === ALWAYS_TRUE &&
8283
effects.terminates === ALWAYS_TRUE
8384

8485
is_total(effects::Effects) =
85-
is_total_or_error(effects) && effects.nothrow === ALWAYS_TRUE
86+
is_total_or_error(effects) &&
87+
effects.nothrow === ALWAYS_TRUE
8688

8789
is_removable_if_unused(effects::Effects) =
8890
effects.effect_free === ALWAYS_TRUE &&
8991
effects.terminates === ALWAYS_TRUE &&
9092
effects.nothrow === ALWAYS_TRUE
9193

9294
function encode_effects(e::Effects)
93-
return (e.consistent.state << 1) |
94-
(e.effect_free.state << 3) |
95-
(e.nothrow.state << 5) |
96-
(e.terminates.state << 7) |
97-
(e.overlayed)
95+
return (e.consistent.state << 0) |
96+
(e.effect_free.state << 2) |
97+
(e.nothrow.state << 4) |
98+
(e.terminates.state << 6) |
99+
(UInt32(e.overlayed) << 8)
98100
end
99-
function decode_effects(e::UInt8)
101+
function decode_effects(e::UInt32)
100102
return Effects(
101-
TriState((e >> 1) & 0x03),
102-
TriState((e >> 3) & 0x03),
103-
TriState((e >> 5) & 0x03),
104-
TriState((e >> 7) & 0x03),
105-
e & 0x01 0x00,
103+
TriState((e >> 0) & 0x03),
104+
TriState((e >> 2) & 0x03),
105+
TriState((e >> 4) & 0x03),
106+
TriState((e >> 6) & 0x03),
107+
_Bool( (e >> 8) & 0x01),
106108
false)
107109
end
108110

src/dump.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,8 @@ static void jl_serialize_code_instance(jl_serializer_state *s, jl_code_instance_
618618

619619
write_uint8(s->s, TAG_CODE_INSTANCE);
620620
write_uint8(s->s, flags);
621-
write_uint8(s->s, codeinst->ipo_purity_bits);
622-
write_uint8(s->s, codeinst->purity_bits);
621+
write_uint32(s->s, codeinst->ipo_purity_bits);
622+
write_uint32(s->s, codeinst->purity_bits);
623623
jl_serialize_value(s, (jl_value_t*)codeinst->def);
624624
if (write_ret_type) {
625625
jl_serialize_value(s, codeinst->inferred);
@@ -1829,8 +1829,8 @@ static jl_value_t *jl_deserialize_value_code_instance(jl_serializer_state *s, jl
18291829
int flags = read_uint8(s->s);
18301830
int validate = (flags >> 0) & 3;
18311831
int constret = (flags >> 2) & 1;
1832-
codeinst->ipo_purity_bits = read_uint8(s->s);
1833-
codeinst->purity_bits = read_uint8(s->s);
1832+
codeinst->ipo_purity_bits = read_uint32(s->s);
1833+
codeinst->purity_bits = read_uint32(s->s);
18341834
codeinst->def = (jl_method_instance_t*)jl_deserialize_value(s, (jl_value_t**)&codeinst->def);
18351835
jl_gc_wb(codeinst, codeinst->def);
18361836
codeinst->inferred = jl_deserialize_value(s, &codeinst->inferred);

src/gf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ JL_DLLEXPORT jl_code_instance_t* jl_new_codeinst(
220220
jl_method_instance_t *mi, jl_value_t *rettype,
221221
jl_value_t *inferred_const, jl_value_t *inferred,
222222
int32_t const_flags, size_t min_world, size_t max_world,
223-
uint8_t ipo_effects, uint8_t effects, jl_value_t *argescapes,
223+
uint32_t ipo_effects, uint32_t effects, jl_value_t *argescapes,
224224
uint8_t relocatability);
225225
JL_DLLEXPORT void jl_mi_cache_insert(jl_method_instance_t *mi JL_ROOTING_ARGUMENT,
226226
jl_code_instance_t *ci JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED);
@@ -390,7 +390,7 @@ JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst(
390390
jl_method_instance_t *mi, jl_value_t *rettype,
391391
jl_value_t *inferred_const, jl_value_t *inferred,
392392
int32_t const_flags, size_t min_world, size_t max_world,
393-
uint8_t ipo_effects, uint8_t effects, jl_value_t *argescapes,
393+
uint32_t ipo_effects, uint32_t effects, jl_value_t *argescapes,
394394
uint8_t relocatability
395395
/*, jl_array_t *edges, int absolute_max*/)
396396
{

src/jltypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,7 @@ void jl_init_types(void) JL_GC_DISABLED
25202520
jl_any_type,
25212521
//jl_any_type,
25222522
//jl_bool_type,
2523-
jl_uint8_type, jl_uint8_type,
2523+
jl_uint32_type, jl_uint32_type,
25242524
jl_any_type,
25252525
jl_bool_type,
25262526
jl_bool_type,

src/julia.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,23 @@ typedef struct _jl_code_instance_t {
394394

395395
// purity results
396396
union {
397-
uint8_t ipo_purity_bits;
397+
uint32_t ipo_purity_bits;
398398
struct {
399399
uint8_t ipo_consistent:2;
400400
uint8_t ipo_effect_free:2;
401401
uint8_t ipo_nothrow:2;
402402
uint8_t ipo_terminates:2;
403+
uint8_t ipo_overlayed:1;
403404
} ipo_purity_flags;
404405
};
405406
union {
406-
uint8_t purity_bits;
407+
uint32_t purity_bits;
407408
struct {
408409
uint8_t consistent:2;
409410
uint8_t effect_free:2;
410411
uint8_t nothrow:2;
411412
uint8_t terminates:2;
413+
uint8_t overlayed:1;
412414
} purity_flags;
413415
};
414416
jl_value_t *argescapes; // escape information of call arguments

src/serialize.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ static uint16_t read_uint16(ios_t *s) JL_NOTSAFEPOINT
109109
return x;
110110
}
111111

112+
static void write_uint32(ios_t *s, uint32_t i) JL_NOTSAFEPOINT
113+
{
114+
ios_write(s, (char*)&i, 4);
115+
}
116+
117+
static uint32_t read_uint32(ios_t *s) JL_NOTSAFEPOINT
118+
{
119+
uint32_t x = 0;
120+
ios_read(s, (char*)&x, 4);
121+
return x;
122+
}
123+
112124
void *jl_lookup_ser_tag(jl_value_t *v);
113125
void *jl_lookup_common_symbol(jl_value_t *v);
114126
jl_value_t *jl_deser_tag(uint8_t tag);

0 commit comments

Comments
 (0)