lookupRdrNameInModuleForPlugins with constructors

I'm trying to construct a dictionary in a GHC plugin. I'm stuck on finding the constructor for the dictionary. When I use `-ddump-simpl` on the module that defines the class, I see "Circat.Rep.C:HasRep". To try finding that constructor, I say
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName "Circat.Rep") (mkVarUnqual "C:HasRep")
However, I keep getting `Nothing` as a result. (Same without the "C:".) I've also had this same difficulty when looking up constructors for algebraic data types and when looking up TyCons. For regular value Ids, lookup succeeds. What am I missing? Thanks, - Conal

mkVarUnqual calls mkVarOccFS, which constructs an OccName in the
varName namespace. You need to construct your RdrName via mkTyVarOcc,
which picks the Type/Class namespace.
On Tue, Mar 22, 2016 at 5:09 PM, Conal Elliott
I'm trying to construct a dictionary in a GHC plugin. I'm stuck on finding the constructor for the dictionary. When I use `-ddump-simpl` on the module that defines the class, I see "Circat.Rep.C:HasRep". To try finding that constructor, I say
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName "Circat.Rep") (mkVarUnqual "C:HasRep")
However, I keep getting `Nothing` as a result. (Same without the "C:".) I've also had this same difficulty when looking up constructors for algebraic data types and when looking up TyCons. For regular value Ids, lookup succeeds.
What am I missing?
Thanks, - Conal
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Er, dictionary... sorry, mkDataOccFS
On Tue, Mar 22, 2016 at 5:24 PM, Andrew Farmer
mkVarUnqual calls mkVarOccFS, which constructs an OccName in the varName namespace. You need to construct your RdrName via mkTyVarOcc, which picks the Type/Class namespace.
On Tue, Mar 22, 2016 at 5:09 PM, Conal Elliott
wrote: I'm trying to construct a dictionary in a GHC plugin. I'm stuck on finding the constructor for the dictionary. When I use `-ddump-simpl` on the module that defines the class, I see "Circat.Rep.C:HasRep". To try finding that constructor, I say
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName "Circat.Rep") (mkVarUnqual "C:HasRep")
However, I keep getting `Nothing` as a result. (Same without the "C:".) I've also had this same difficulty when looking up constructors for algebraic data types and when looking up TyCons. For regular value Ids, lookup succeeds.
What am I missing?
Thanks, - Conal
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Got it. Silly me. Thanks!! - Conal
On Tue, Mar 22, 2016 at 5:25 PM, Andrew Farmer
Er, dictionary... sorry, mkDataOccFS
On Tue, Mar 22, 2016 at 5:24 PM, Andrew Farmer
wrote: mkVarUnqual calls mkVarOccFS, which constructs an OccName in the varName namespace. You need to construct your RdrName via mkTyVarOcc, which picks the Type/Class namespace.
On Tue, Mar 22, 2016 at 5:09 PM, Conal Elliott
wrote: I'm trying to construct a dictionary in a GHC plugin. I'm stuck on finding the constructor for the dictionary. When I use `-ddump-simpl` on the module that defines the class, I see "Circat.Rep.C:HasRep". To try finding that constructor, I say
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName "Circat.Rep") (mkVarUnqual "C:HasRep")
However, I keep getting `Nothing` as a result. (Same without the "C:".) I've also had this same difficulty when looking up constructors for algebraic data types and when looking up TyCons. For regular value Ids, lookup succeeds.
What am I missing?
Thanks, - Conal
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

I'm now able to look up value identifiers, type constructors (including
classes), and regular data constructors, but not dictionary constructors.
Here's my failing effort to look up a dictionary constructor (in CoreM):
hasRepThing <-
maybe (panic "HasRep lookup failure") lookupThing =<<
(liftIO $
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName
"Circat.Rep")
(Unqual (mkDataOcc "C:HasRep")))
pprTrace "mkReifyEnv HasRep thing:" (ppr hasRepThing) (return ())
Result:
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.1.20160307 for x86_64-apple-darwin):
HasRep lookup failure
Same failure when I use the name string "HasRep" in place of "C:HasRep".
Any idea what I'm doing wrong here?
-- Conal
On Tue, Mar 22, 2016 at 5:40 PM, Conal Elliott
Got it. Silly me. Thanks!! - Conal
On Tue, Mar 22, 2016 at 5:25 PM, Andrew Farmer
wrote: Er, dictionary... sorry, mkDataOccFS
mkVarUnqual calls mkVarOccFS, which constructs an OccName in the varName namespace. You need to construct your RdrName via mkTyVarOcc, which picks the Type/Class namespace.
On Tue, Mar 22, 2016 at 5:09 PM, Conal Elliott
wrote: I'm trying to construct a dictionary in a GHC plugin. I'm stuck on finding the constructor for the dictionary. When I use `-ddump-simpl` on the module that defines the class, I see "Circat.Rep.C:HasRep". To try finding
On Tue, Mar 22, 2016 at 5:24 PM, Andrew Farmer
wrote: that constructor, I say
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName "Circat.Rep") (mkVarUnqual "C:HasRep")
However, I keep getting `Nothing` as a result. (Same without the "C:".) I've also had this same difficulty when looking up constructors for algebraic data types and when looking up TyCons. For regular value Ids, lookup succeeds.
What am I missing?
Thanks, - Conal
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Start with the Class. Use classTyCon to get the TyCon. Use tyConDataCons to get the data constructor. Simon From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Conal Elliott Sent: 23 March 2016 00:09 To: ghc-devs@haskell.org Subject: lookupRdrNameInModuleForPlugins with constructors I'm trying to construct a dictionary in a GHC plugin. I'm stuck on finding the constructor for the dictionary. When I use `-ddump-simpl` on the module that defines the class, I see "Circat.Rep.C:HasRep". To try finding that constructor, I say
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName "Circat.Rep") (mkVarUnqual "C:HasRep")
However, I keep getting `Nothing` as a result. (Same without the "C:".) I've also had this same difficulty when looking up constructors for algebraic data types and when looking up TyCons. For regular value Ids, lookup succeeds. What am I missing? Thanks, - Conal

Indeed, tyConDataCons does the trick. I don't know how to start with the
Class (given a name string), but I'm able to use 'mkClsOcc . Unqual' with
lookupRdrNameInModuleForPlugins and then lookupTyCon on the resulting name,
followed by 'head . tyConDataCons' to get the constructor.
Thanks, Simon!
-- Conal
On Wed, Mar 23, 2016 at 1:32 AM, Simon Peyton Jones
Start with the Class. Use classTyCon to get the TyCon. Use tyConDataCons to get the data constructor.
Simon
*From:* ghc-devs [mailto:ghc-devs-bounces@haskell.org] *On Behalf Of *Conal Elliott *Sent:* 23 March 2016 00:09 *To:* ghc-devs@haskell.org *Subject:* lookupRdrNameInModuleForPlugins with constructors
I'm trying to construct a dictionary in a GHC plugin. I'm stuck on finding the constructor for the dictionary. When I use `-ddump-simpl` on the module that defines the class, I see "Circat.Rep.C:HasRep". To try finding that constructor, I say
lookupRdrNameInModuleForPlugins hsc_env (mkModuleName "Circat.Rep") (mkVarUnqual "C:HasRep")
However, I keep getting `Nothing` as a result. (Same without the "C:".) I've also had this same difficulty when looking up constructors for algebraic data types and when looking up TyCons. For regular value Ids, lookup succeeds.
What am I missing?
Thanks, - Conal
participants (3)
-
Andrew Farmer
-
Conal Elliott
-
Simon Peyton Jones