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
using Test | |
Base.setindex!(inst::CC.Instruction, args...) = CC.setindex!(inst, args...) | |
function topfunc(x) | |
return sin(x) | |
end | |
ir = first(only(Base.code_ircode(topfunc, (Float64,)))) | |
ir.stmts[1][:info] = CC.NoCallInfo() | |
ir.stmts[1][:inst] = Expr(:call, GlobalRef(Base.Math, :cos), Core.Argument(2)) | |
ir.stmts[1][:flag] |= CC.IR_FLAG_REFINED |
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
using InteractiveUtils, Test | |
using Core: MethodInstance, CodeInstance | |
using Base: CodegenParams | |
const CC = Core.Compiler | |
include("test/compiler/newinterp.jl") | |
@newinterp ConstInvokeInterp | |
function CC.concrete_eval_eligible(interp::ConstInvokeInterp, | |
@nospecialize(f), result::CC.MethodCallResult, arginfo::CC.ArgInfo, sv::CC.AbsIntState) |
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
function onegame() | |
doors = (1,2,3) | |
# drop(i::Int) = i == 1 ? (2,3) : i == 2 ? (1,3) : (1,2) | |
true_ans = rand(doors) | |
player1_ans = first_ans = rand(doors) | |
if first_ans == 1 | |
if true_ans == 1 |
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
import Core: MethodMatch | |
import Core.Compiler: _methods_by_ftype, InferenceParams, get_world_counter, MethodInstance, | |
specialize_method, InferenceResult, typeinf, InferenceState, NativeInterpreter, | |
code_cache | |
function custominvoke(f, args...) | |
@nospecialize f args | |
interp = NativeInterpreter() | |
tt = Base.signature_type(f, Tuple{map(Core.Typeof, args)...}) | |
mm = get_single_method_match(tt, InferenceParams(interp).MAX_METHODS, get_world_counter(interp)) |
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
import Core: MethodMatch | |
import Core.Compiler: _methods_by_ftype, InferenceParams, get_world_counter, MethodInstance, | |
specialize_method, InferenceResult, typeinf, InferenceState, NativeInterpreter, | |
code_cache | |
function custominvoke(f, args...) | |
@nospecialize f args | |
interp = NativeInterpreter(get_world_counter()) | |
oc = invoke_in_absint(f, interp, args...) | |
oc(args...) |
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
const CC = Core.Compiler | |
import .CC: MethodInstance, CodeInstance, InferenceResult, WorldRange, WorldView | |
struct CCProfilerCache | |
dict::IdDict{MethodInstance,CodeInstance} | |
end | |
struct CCProfiler <: CC.AbstractInterpreter | |
world::UInt | |
inf_cache::Vector{InferenceResult} | |
code_cache::CCProfilerCache |
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
# write the macro | |
macro return_const_case(x, d) | |
@assert isa(d, Symbol) | |
repr = string(d) | |
return quote | |
if $(esc(x)) == $(esc(d)) | |
return $repr | |
end | |
end |
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
interface Foo { | |
bar: undefined | Bar | |
} | |
interface Bar { | |
baz: string | |
} | |
export function getbaz(foo: Foo) { | |
if (foo.bar) { |
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
# adapted from https://github.com/JuliaCompilerPlugins/Mixtape.jl/blob/75fc4aa25e918f92bfd0ba706236f61a466efc11/examples/dynamic_overlay.jl | |
module DynamicOverlay | |
using Mixtape | |
import Mixtape: CompilationContext, transform, allow | |
using MacroTools | |
using CodeInfoTools | |
using BenchmarkTools |
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
julia> using JET, JET.JETInterfaces | |
julia> get_module(sv::Core.Compiler.InferenceState) = sv.mod | |
get_module (generic function with 2 methods) | |
julia> function get_module(linfo::Core.MethodInstance) | |
def = linfo.def | |
return isa(def, Module) ? def : def.module | |
end | |
get_module (generic function with 2 methods) |
NewerOlder