@@ -3,53 +3,19 @@ module DynamicPPLJETExt
33using DynamicPPL: DynamicPPL
44using JET: JET
55
6- """
7- is_tilde_instance(x)
8-
9- Return `true` if `x` is a method instance of a tilde function, otherwise `false`.
10- """
11- is_tilde_instance (x) = false
12- is_tilde_instance (frame:: JET.VirtualFrame ) = is_tilde_instance (frame. linfo)
13- function is_tilde_instance (mi:: Core.MethodInstance )
14- types = mi. specTypes
15- # This can occur, for example, if `specTypes` is `UnionAll` due to an error.
16- return if hasproperty (types, :parameters )
17- is_tilde_instance (types. parameters[1 ])
18- else
19- false
20- end
21- end
22- is_tilde_instance (:: Type{typeof(DynamicPPL.tilde_assume!!)} ) = true
23- is_tilde_instance (:: Type{typeof(DynamicPPL.tilde_observe!!)} ) = true
24- is_tilde_instance (:: Type{typeof(DynamicPPL.dot_tilde_assume!!)} ) = true
25- is_tilde_instance (:: Type{typeof(DynamicPPL.dot_tilde_observe!!)} ) = true
26-
27- """
28- report_has_error_in_tilde(report)
29-
30- Return `true` if the given error `report` contains a tilde function in its frames, otherwise `false`.
31-
32- This is used to filter out reports that occur outside of the tilde pipeline, in an attempt to avoid
33- warning the user about DynamicPPL doing something wrong when it is in fact an issue with the user's code.
34- """
35- function report_has_error_in_tilde (report)
36- frames = report. vst
37- return any (is_tilde_instance, frames)
38- end
39-
406function DynamicPPL. is_suitable_varinfo (
417 model:: DynamicPPL.Model ,
428 context:: DynamicPPL.AbstractContext ,
439 varinfo:: DynamicPPL.AbstractVarInfo ;
44- only_tilde :: Bool = true ,
10+ only_ddpl :: Bool = true ,
4511)
4612 # Let's make sure that both evaluation and sampling doesn't result in type errors.
4713 f, argtypes = DynamicPPL. DebugUtils. gen_evaluator_call_with_types (
4814 model, varinfo, context
4915 )
5016 # If specified, we only check errors originating somewhere in the DynamicPPL.jl.
5117 # This way we don't just fall back to untyped if the user's code is the issue.
52- result = if only_tilde
18+ result = if only_ddpl
5319 JET. report_call (f, argtypes; target_modules= (JET. AnyFrameModule (DynamicPPL),))
5420 else
5521 JET. report_call (f, argtypes)
@@ -58,14 +24,14 @@ function DynamicPPL.is_suitable_varinfo(
5824end
5925
6026function DynamicPPL. _determine_varinfo_jet (
61- model:: DynamicPPL.Model , context:: DynamicPPL.AbstractContext ; only_tilde :: Bool = true
27+ model:: DynamicPPL.Model , context:: DynamicPPL.AbstractContext ; only_ddpl :: Bool = true
6228)
6329 # First we try with the typed varinfo.
6430 varinfo = DynamicPPL. typed_varinfo (model, context)
6531 issuccess = true
6632
6733 # Let's make sure that both evaluation and sampling doesn't result in type errors.
68- issuccess, result = DynamicPPL. is_suitable_varinfo (model, context, varinfo; only_tilde )
34+ issuccess, result = DynamicPPL. is_suitable_varinfo (model, context, varinfo; only_ddpl )
6935
7036 if ! issuccess
7137 # Useful information for debugging.
0 commit comments