Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1aa74946
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1aa74946
编写于
5月 24, 2018
作者:
V
varkor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce signed_bias method
The epitome of simplicity!
上级
72cc4bd3
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
21 addition
and
45 deletion
+21
-45
src/librustc_mir/hair/pattern/_match.rs
src/librustc_mir/hair/pattern/_match.rs
+21
-45
未找到文件。
src/librustc_mir/hair/pattern/_match.rs
浏览文件 @
1aa74946
...
...
@@ -21,11 +21,13 @@
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
hir
::
RangeEnd
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
TypeFoldable
};
use
rustc
::
ty
::
layout
::{
Integer
,
IntegerExt
};
use
rustc
::
mir
::
Field
;
use
rustc
::
mir
::
interpret
::
ConstValue
;
use
rustc
::
util
::
common
::
ErrorReported
;
use
syntax
::
attr
::{
SignedInt
,
UnsignedInt
};
use
syntax_pos
::{
Span
,
DUMMY_SP
};
use
arena
::
TypedArena
;
...
...
@@ -469,10 +471,9 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
ConstantRange
(
endpoint
(
'\
u
{
E000
}
'
),
endpoint
(
'\
u
{
10
FFFF
}
'
),
RangeEnd
::
Included
),
]
}
ty
::
TyInt
(
_
)
if
exhaustive_integer_patterns
=>
{
ty
::
TyInt
(
ity
)
if
exhaustive_integer_patterns
=>
{
// FIXME(49937): refactor these bit manipulations into interpret.
let
bits
=
cx
.tcx
.layout_of
(
ty
::
ParamEnv
::
reveal_all
()
.and
(
pcx
.ty
))
.unwrap
()
.size
.bits
()
as
u128
;
let
bits
=
Integer
::
from_attr
(
cx
.tcx
,
SignedInt
(
ity
))
.size
()
.bits
()
as
u128
;
let
min
=
1u128
<<
(
bits
-
1
);
let
max
=
(
1u128
<<
(
bits
-
1
))
-
1
;
value_constructors
=
true
;
...
...
@@ -480,10 +481,9 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
ty
::
Const
::
from_bits
(
cx
.tcx
,
max
as
u128
,
pcx
.ty
),
RangeEnd
::
Included
)]
}
ty
::
TyUint
(
_
)
if
exhaustive_integer_patterns
=>
{
ty
::
TyUint
(
uty
)
if
exhaustive_integer_patterns
=>
{
// FIXME(49937): refactor these bit manipulations into interpret.
let
bits
=
cx
.tcx
.layout_of
(
ty
::
ParamEnv
::
reveal_all
()
.and
(
pcx
.ty
))
.unwrap
()
.size
.bits
()
as
u128
;
let
bits
=
Integer
::
from_attr
(
cx
.tcx
,
UnsignedInt
(
uty
))
.size
()
.bits
()
as
u128
;
let
max
=
!
0u128
>>
(
128
-
bits
);
value_constructors
=
true
;
vec!
[
ConstantRange
(
ty
::
Const
::
from_bits
(
cx
.tcx
,
0
,
pcx
.ty
),
...
...
@@ -627,7 +627,8 @@ fn from_ctor(tcx: TyCtxt<'_, 'tcx, 'tcx>,
if
let
Some
(
hi
)
=
hi
.assert_bits
(
ty
)
{
// Perform a shift if the underlying types are signed,
// which makes the interval arithmetic simpler.
let
(
lo
,
hi
)
=
Self
::
encode
(
tcx
,
ty
,
(
lo
,
hi
));
let
bias
=
IntRange
::
signed_bias
(
tcx
,
ty
);
let
(
lo
,
hi
)
=
(
lo
^
bias
,
hi
^
bias
);
// Make sure the interval is well-formed.
return
if
lo
>
hi
||
lo
==
hi
&&
*
end
==
RangeEnd
::
Excluded
{
None
...
...
@@ -642,8 +643,9 @@ fn from_ctor(tcx: TyCtxt<'_, 'tcx, 'tcx>,
ConstantValue
(
val
)
=>
{
let
ty
=
val
.ty
;
if
let
Some
(
val
)
=
val
.assert_bits
(
ty
)
{
let
(
lo
,
hi
)
=
Self
::
encode
(
tcx
,
ty
,
(
val
,
val
));
Some
(
IntRange
{
range
:
lo
..=
hi
,
ty
})
let
bias
=
IntRange
::
signed_bias
(
tcx
,
ty
);
let
val
=
val
^
bias
;
Some
(
IntRange
{
range
:
val
..=
val
,
ty
})
}
else
{
None
}
...
...
@@ -654,44 +656,14 @@ fn from_ctor(tcx: TyCtxt<'_, 'tcx, 'tcx>,
}
}
fn
encode
(
tcx
:
TyCtxt
<
'_
,
'tcx
,
'tcx
>
,
ty
:
Ty
<
'tcx
>
,
(
lo
,
hi
):
(
u128
,
u128
))
->
(
u128
,
u128
)
{
fn
signed_bias
(
tcx
:
TyCtxt
<
'_
,
'tcx
,
'tcx
>
,
ty
:
Ty
<
'tcx
>
)
->
u128
{
match
ty
.sty
{
ty
::
TyInt
(
_
)
=>
{
// FIXME(49937): refactor these bit manipulations into interpret.
let
bits
=
tcx
.layout_of
(
ty
::
ParamEnv
::
reveal_all
()
.and
(
ty
))
.unwrap
()
.size
.bits
()
as
u128
;
let
min
=
1u128
<<
(
bits
-
1
);
let
mask
=
!
0u128
>>
(
128
-
bits
);
let
offset
=
|
x
:
u128
|
x
.wrapping_sub
(
min
)
&
mask
;
(
offset
(
lo
),
offset
(
hi
))
}
_
=>
(
lo
,
hi
)
ty
::
TyInt
(
ity
)
=>
{
let
bits
=
Integer
::
from_attr
(
tcx
,
SignedInt
(
ity
))
.size
()
.bits
()
as
u128
;
1u128
<<
(
bits
-
1
)
}
_
=>
0
}
fn
decode
(
tcx
:
TyCtxt
<
'_
,
'tcx
,
'tcx
>
,
ty
:
Ty
<
'tcx
>
,
range
:
RangeInclusive
<
u128
>
)
->
Constructor
<
'tcx
>
{
let
(
lo
,
hi
)
=
range
.into_inner
();
let
(
lo
,
hi
)
=
match
ty
.sty
{
ty
::
TyInt
(
_
)
=>
{
// FIXME(49937): refactor these bit manipulations into interpret.
let
bits
=
tcx
.layout_of
(
ty
::
ParamEnv
::
reveal_all
()
.and
(
ty
))
.unwrap
()
.size
.bits
()
as
u128
;
let
min
=
1u128
<<
(
bits
-
1
);
let
mask
=
!
0u128
>>
(
128
-
bits
);
let
offset
=
|
x
:
u128
|
x
.wrapping_add
(
min
)
&
mask
;
(
offset
(
lo
),
offset
(
hi
))
}
_
=>
(
lo
,
hi
)
};
ConstantRange
(
ty
::
Const
::
from_bits
(
tcx
,
lo
,
ty
),
ty
::
Const
::
from_bits
(
tcx
,
hi
,
ty
),
RangeEnd
::
Included
)
}
fn
into_inner
(
self
)
->
(
u128
,
u128
)
{
...
...
@@ -733,7 +705,11 @@ fn ranges_subtract_pattern<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
}
// Convert the remaining ranges from pairs to inclusive `ConstantRange`s.
remaining_ranges
.into_iter
()
.map
(|
r
|
{
IntRange
::
decode
(
cx
.tcx
,
ty
,
r
)
let
(
lo
,
hi
)
=
r
.into_inner
();
let
bias
=
IntRange
::
signed_bias
(
cx
.tcx
,
ty
);
ConstantRange
(
ty
::
Const
::
from_bits
(
cx
.tcx
,
lo
^
bias
,
ty
),
ty
::
Const
::
from_bits
(
cx
.tcx
,
hi
^
bias
,
ty
),
RangeEnd
::
Included
)
})
.collect
()
}
else
{
ranges
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录