@@ -25,9 +25,11 @@ let infer-global-terms(tctx: TypeContext?, term: AST): (TypeContext?, AST) = (
2525 let kto = typeof-term(rhs);
2626 let ktd = kto && t0(c"GlobalVariable");
2727 tctx = tctx.bind-global(k.key, kto, ktd, term);
28- mark-global-as-seen(k.key, ktd, ta);
29- tctx = tctx.ascript(term, ktd);
30- (tctx, _) = tctx.maybe-apply-callable(c"mov", t2(c"Cons",ktd.without-phi,ktd.without-phi), term);
28+ if not(global-is-seen(k.key, ktd)) {
29+ mark-global-as-seen(k.key, ktd, ta);
30+ tctx = tctx.ascript(term, ktd);
31+ (tctx, _) = tctx.maybe-apply-callable(c"mov", t2(c"Cons",ktd.without-phi,ktd.without-phi), term);
32+ }
3133 );
3234 _ => (
3335 (tctx, term) = std-infer-expr(tctx, term, false, Unused, ta);
@@ -44,10 +46,12 @@ let infer-global-context-prim(term: AST): Nil = (
4446 Glb{ k=key, frhs=val:Abs{lhs=lhs, rhs:App{left:Lit{key:c":"}, right:App{rhs=left, right:AType{return-type=tt}}}, misc-tt=tt} } => (
4547 if k.key.has-prefix(c"primitive::") then {
4648 let ft = t2(c"Arrow", typeof-lhs(lhs), return-type.without-modifiers).without-phi-keep-state && misc-tt;
47- mark-global-as-seen(k.key, ft, misc-tt);
48- Some(mk-tctx()).ascript(term, ft);
49- Some(mk-tctx()).ascript(frhs, ft);
50- Some(mk-tctx()).bind-global(k.key, ft, ft, term);
49+ if not(global-is-seen(k.key, ft)) {
50+ mark-global-as-seen(k.key, ft, misc-tt);
51+ Some(mk-tctx()).ascript(term, ft);
52+ Some(mk-tctx()).ascript(frhs, ft);
53+ Some(mk-tctx()).bind-global(k.key, ft, ft, term);
54+ }
5155 };
5256 );
5357 _ => ();
@@ -75,10 +79,12 @@ let infer-global-context(term: AST): Nil = (
7579 else if misc-tt.is-t(c"TypedMacro",0) then bind-new-macro(k.key, frhs)
7680 else {
7781 let ft = t2(c"Arrow", typeof-lhs(lhs), return-type.rewrite-type-alias.expand-implied-phi.without-modifiers).without-phi-keep-state && misc-tt;
78- mark-global-as-seen(k.key, ft, misc-tt);
79- Some(mk-tctx()).ascript(term, ft);
80- Some(mk-tctx()).ascript(frhs, ft);
81- Some(mk-tctx()).bind-global(k.key, ft, denormalize-strong(ft), term);
82+ if not(global-is-seen(k.key, ft)) {
83+ mark-global-as-seen(k.key, ft, misc-tt);
84+ Some(mk-tctx()).ascript(term, ft);
85+ Some(mk-tctx()).ascript(frhs, ft);
86+ Some(mk-tctx()).bind-global(k.key, ft, denormalize-strong(ft), term);
87+ }
8288 };
8389 );
8490 _ => ();
0 commit comments