@@ -49,6 +49,8 @@ func LinkGlobals(
4949 globals := make ([]Variable , len (program .Globals ))
5050 indexedGlobals := activations .NewActivation [Variable ](memoryGauge , nil )
5151
52+ var visitedLocations map [common.Location ]struct {}
53+
5254 // NOTE: ensure both the context and the mapping are updated
5355
5456 for _ , global := range program .Globals {
@@ -108,6 +110,7 @@ func LinkGlobals(
108110 typedGlobal ,
109111 context ,
110112 linkedGlobalsCache ,
113+ visitedLocations ,
111114 )
112115 globals [index ] = importedGlobal
113116
@@ -145,6 +148,7 @@ func linkImportedGlobal(
145148 importedGlobal * bbq.ImportedGlobal ,
146149 context * Context ,
147150 linkedGlobalsCache map [common.Location ]LinkedGlobals ,
151+ visitedLocations map [common.Location ]struct {},
148152) Variable {
149153 importLocation := importedGlobal .Location
150154
@@ -171,7 +175,17 @@ func linkImportedGlobal(
171175 linkedGlobalsCache ,
172176 )
173177
174- // TODO: Potentially add the imported program's sema type cache to the context's sema type cache
178+ if _ , ok := visitedLocations [importLocation ]; ! ok {
179+ // add the imported program's sema type cache to the context's sema type cache
180+ // TODO: Maybe this is excessive, balance size and performance
181+ for typeID , semaType := range importedProgram .SemaTypeCache {
182+ if _ , ok := context .semaTypeCache [typeID ]; ok {
183+ continue
184+ }
185+ context .semaTypeCache [typeID ] = semaType
186+ }
187+ visitedLocations [importLocation ] = struct {}{}
188+ }
175189 }
176190
177191 indexedGlobals = linkedGlobals .indexedGlobals
0 commit comments