Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
seer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nils Fitinghoff
seer
Commits
8ee83a8b
Commit
8ee83a8b
authored
Dec 15, 2017
by
David Renshaw
Browse files
Options
Downloads
Patches
Plain Diff
use now-exposed rustc version of resolve_closure
parent
ce6b2121
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/eval_context.rs
+2
-78
2 additions, 78 deletions
src/eval_context.rs
with
2 additions
and
78 deletions
src/eval_context.rs
+
2
−
78
View file @
8ee83a8b
...
@@ -669,7 +669,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
...
@@ -669,7 +669,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ClosureFnPointer
=>
match
self
.operand_ty
(
operand
)
.sty
{
ClosureFnPointer
=>
match
self
.operand_ty
(
operand
)
.sty
{
ty
::
TyClosure
(
def_id
,
substs
)
=>
{
ty
::
TyClosure
(
def_id
,
substs
)
=>
{
let
instance
=
resolve_closure
(
self
.tcx
,
def_id
,
substs
,
ty
::
ClosureKind
::
FnOnce
);
let
instance
=
::
rustc
::
ty
::
Instance
::
resolve_closure
(
self
.tcx
,
def_id
,
substs
,
ty
::
ClosureKind
::
FnOnce
);
let
fn_ptr
=
self
.memory
.create_fn_alloc
(
instance
);
let
fn_ptr
=
self
.memory
.create_fn_alloc
(
instance
);
self
.write_value
(
ValTy
{
value
:
Value
::
ByVal
(
PrimVal
::
Ptr
(
fn_ptr
)),
ty
:
dest_ty
},
dest
)
?
;
self
.write_value
(
ValTy
{
value
:
Value
::
ByVal
(
PrimVal
::
Ptr
(
fn_ptr
)),
ty
:
dest_ty
},
dest
)
?
;
},
},
...
@@ -1567,83 +1568,6 @@ impl<'b, 'tcx: 'b> IntoValTyPair<'tcx> for &'b mir::Operand<'tcx> {
...
@@ -1567,83 +1568,6 @@ impl<'b, 'tcx: 'b> IntoValTyPair<'tcx> for &'b mir::Operand<'tcx> {
}
}
}
}
/// FIXME: expose trans::monomorphize::resolve_closure
pub
fn
resolve_closure
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
def_id
:
DefId
,
substs
:
ty
::
ClosureSubsts
<
'tcx
>
,
requested_kind
:
ty
::
ClosureKind
,
)
->
ty
::
Instance
<
'tcx
>
{
let
actual_kind
=
substs
.closure_kind
(
def_id
,
tcx
);
match
needs_fn_once_adapter_shim
(
actual_kind
,
requested_kind
)
{
Ok
(
true
)
=>
fn_once_adapter_instance
(
tcx
,
def_id
,
substs
),
_
=>
ty
::
Instance
::
new
(
def_id
,
substs
.substs
)
}
}
fn
fn_once_adapter_instance
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
closure_did
:
DefId
,
substs
:
ty
::
ClosureSubsts
<
'tcx
>
,
)
->
ty
::
Instance
<
'tcx
>
{
debug!
(
"fn_once_adapter_shim({:?}, {:?})"
,
closure_did
,
substs
);
let
fn_once
=
tcx
.lang_items
()
.fn_once_trait
()
.unwrap
();
let
call_once
=
tcx
.associated_items
(
fn_once
)
.find
(|
it
|
it
.kind
==
ty
::
AssociatedKind
::
Method
)
.unwrap
()
.def_id
;
let
def
=
ty
::
InstanceDef
::
ClosureOnceShim
{
call_once
};
let
self_ty
=
tcx
.mk_closure_from_closure_substs
(
closure_did
,
substs
);
let
sig
=
substs
.closure_sig
(
closure_did
,
tcx
);
let
sig
=
tcx
.erase_late_bound_regions_and_normalize
(
&
sig
);
assert_eq!
(
sig
.inputs
()
.len
(),
1
);
let
substs
=
tcx
.mk_substs
([
Kind
::
from
(
self_ty
),
Kind
::
from
(
sig
.inputs
()[
0
]),
]
.iter
()
.cloned
());
debug!
(
"fn_once_adapter_shim: self_ty={:?} sig={:?}"
,
self_ty
,
sig
);
ty
::
Instance
{
def
,
substs
}
}
fn
needs_fn_once_adapter_shim
(
actual_closure_kind
:
ty
::
ClosureKind
,
trait_closure_kind
:
ty
::
ClosureKind
)
->
Result
<
bool
,
()
>
{
match
(
actual_closure_kind
,
trait_closure_kind
)
{
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
Fn
)
|
(
ty
::
ClosureKind
::
FnMut
,
ty
::
ClosureKind
::
FnMut
)
|
(
ty
::
ClosureKind
::
FnOnce
,
ty
::
ClosureKind
::
FnOnce
)
=>
{
// No adapter needed.
Ok
(
false
)
}
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
FnMut
)
=>
{
// The closure fn `llfn` is a `fn(&self, ...)`. We want a
// `fn(&mut self, ...)`. In fact, at trans time, these are
// basically the same thing, so we can just return llfn.
Ok
(
false
)
}
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
FnOnce
)
|
(
ty
::
ClosureKind
::
FnMut
,
ty
::
ClosureKind
::
FnOnce
)
=>
{
// The closure fn `llfn` is a `fn(&self, ...)` or `fn(&mut
// self, ...)`. We want a `fn(self, ...)`. We can produce
// this by doing something like:
//
// fn call_once(self, ...) { call_mut(&self, ...) }
// fn call_once(mut self, ...) { call_mut(&mut self, ...) }
//
// These are both the same at trans time.
Ok
(
true
)
}
_
=>
Err
(()),
}
}
/// Monomorphizes a type from the AST by first applying the in-scope
/// Monomorphizes a type from the AST by first applying the in-scope
/// substitutions and then normalizing any associated types.
/// substitutions and then normalizing any associated types.
pub
fn
apply_param_substs
<
'a
,
'tcx
,
T
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
pub
fn
apply_param_substs
<
'a
,
'tcx
,
T
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment