Module and template name collisions

Let’s say I have an upgrade project in which I want to import modules from 2 dars that have the same name but different versions. Based on https://docs.daml.com/daml/reference/packages.html#handling-module-name-collisions, I should be able to achieve this with the following -

- '--package'
- 'foo-1.0.0 with (X as Foo1.X)'
- '--package'
- 'foo-2.0.0 with (X as Foo2.X)'

Wrt the above, if I need to import multiple modules from each dar (which is the case more often than not), do i need to have a separate line per module, or is there a way I could import multiple modules per package-import:

- 'foo-1.0.0 with (X as Foo1.X, Y as Foo1.Y, Z as Foo1.Z)'
- 'foo-2.0.0 with (X as Foo2.X, Y as Foo2.Y, Z as Foo2.Z)'

Grepping the DAML code for --package shows that this is controlled by a construct called ModRenaming. Further grepping shows that it is defined in a module called DynFlags, which is nowhere to be found in the daml source tree. This suggests the feature is imported directly from GHC; googling “ghc dynflags” yields this page, where the form

-package foo with (A as B) is ModRenaming True [(A, B)]

strongly suggests there must be a way to do what you want, as otherwise why would that last bit be a list?

Googling further for “ghc package renaming” yields this page, which has a section “Thinning and renaming modules” where you can find the following sentence:

Similarly, -package "base (Data.Bool as Bool)" -package "base (Data.List as List)" is equivalent to -package "base (Data.Bool as Bool, Data.List as List)" .

which I believe answers your question: yes you can do exactly what you suggested.

1 Like

Just to confirm, @Gary_Verhaegen is completely right here. We do technically have our own parser for those options (if you’re interested it can be found at daml/Options.hs at 7e0377dd76e0ff4be6cb3b2604eb7f80ea041bab · digital-asset/daml · GitHub) but we follow the syntax and semantics in GHC so it behaves exactly the same.

1 Like

Perfect, thanks @Gary_Verhaegen for the excellent answer! Thanks @cocreature!