forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows plugins to define functions which are only expanded by the plugin after all type checking, inference, etc etc, ie only once codegen encounters a call to the intrinsic. In this initial version, the codegen crate is reponsible for calling the plugin intrinsic codgen trait and codegening the resulting extra MIR statements. Plugins are limited to `mir::StatementKind` and those contained therein, so they can't insert extra basic blocks, or insert calls to arbitraty functions. This means the compiler can still reason about what is reachable. The form of the interface with the plugins is slightly different than what was proposed in rust-lang#51623. Additionally, signature checking is added.
- Loading branch information
1 parent
4f0ca92
commit b0ff73f
Showing
14 changed files
with
417 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
84 changes: 84 additions & 0 deletions
84
src/test/compile-fail-fulldeps/auxiliary/plugin_intrinsic_codegen.rs
This file contains 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,84 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// force-host | ||
|
||
#![feature(plugin_registrar, rustc_private)] | ||
#![deny(plugin_as_library)] // should have no effect in a plugin crate | ||
|
||
extern crate rustc; | ||
extern crate rustc_plugin; | ||
|
||
|
||
use rustc::mir::*; | ||
use rustc::ty::{Ty, TyCtxt, FnSig, subst::Substs, }; | ||
use rustc_plugin::Registry; | ||
|
||
#[plugin_registrar] | ||
pub fn plugin_registrar(reg: &mut Registry) { | ||
let codegen = Box::new(GenericCountMismatch) as Box<_>; | ||
reg.register_intrinsic("generic_count_mismatch".into(), codegen); | ||
let codegen = Box::new(InputOutputMismatch) as Box<_>; | ||
reg.register_intrinsic("type_mismatch".into(), codegen); | ||
} | ||
|
||
struct GenericCountMismatch; | ||
impl PluginIntrinsicCodegen for GenericCountMismatch { | ||
fn codegen_simple_intrinsic<'a, 'tcx>(&self, | ||
_tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
_source_info: SourceInfo, | ||
_sig: &FnSig<'tcx>, | ||
_parent_mir: &Mir<'tcx>, | ||
_parent_param_substs: &'tcx Substs<'tcx>, | ||
_args: &Vec<Operand<'tcx>>, | ||
_dest: Place<'tcx>, | ||
_extra_stmts: &mut Vec<StatementKind<'tcx>>) | ||
where 'tcx: 'a, | ||
{ | ||
unreachable!() | ||
} | ||
|
||
/// The number of generic parameters expected. | ||
fn generic_parameter_count<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>) -> usize { 5 } | ||
/// The types of the input args. | ||
fn inputs<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Vec<Ty<'tcx>> { vec![] } | ||
/// The return type. | ||
fn output<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> { | ||
tcx.mk_nil() | ||
} | ||
} | ||
|
||
struct InputOutputMismatch; | ||
impl PluginIntrinsicCodegen for InputOutputMismatch { | ||
fn codegen_simple_intrinsic<'a, 'tcx>(&self, | ||
_tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
_source_info: SourceInfo, | ||
_sig: &FnSig<'tcx>, | ||
_parent_mir: &Mir<'tcx>, | ||
_parent_param_substs: &'tcx Substs<'tcx>, | ||
_args: &Vec<Operand<'tcx>>, | ||
_dest: Place<'tcx>, | ||
_extra_stmts: &mut Vec<StatementKind<'tcx>>) | ||
where 'tcx: 'a, | ||
{ | ||
unreachable!() | ||
} | ||
|
||
/// The number of generic parameters expected. | ||
fn generic_parameter_count<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>) -> usize { 0 } | ||
/// The types of the input args. | ||
fn inputs<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Vec<Ty<'tcx>> { | ||
vec![tcx.types.u64] | ||
} | ||
/// The return type. | ||
fn output<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> { | ||
tcx.types.u64 | ||
} | ||
} |
Oops, something went wrong.