@@ -145,11 +145,11 @@ class TemplateBase : protected ValueVisitor<Derived, TemplateResult> {
145145 return OpGen.create <SpliceOp>(Loc, ValX, ValY);
146146 }
147147
148- mlir::Value createRename (Symbol* P) {
148+ mlir::Value createRename (Symbol* P, mlir::Value ProvidedVal = nullptr ) {
149149 String* UniqueStr = P->getString ();
150150
151151 // Check for memoized SC.
152- {
152+ if (!ProvidedVal) {
153153 auto [R, SC] = RenameOps.lookup (UniqueStr);
154154 if (SC)
155155 return SC;
@@ -158,19 +158,26 @@ class TemplateBase : protected ValueVisitor<Derived, TemplateResult> {
158158 // The result will be a symbol literal.
159159 // The built RenameOps are added to the RenameOps list.
160160 SourceLocation Loc = P->getSourceLocation ();
161+ llvm::StringRef Id = P->getStringRef ();
161162
162- mlir::Value LiteralResult = createLiteral (P);
163- mlir::Value SC = OpGen.create <SyntaxClosureOp>(Loc, LiteralResult,
164- RenameEnv);
163+ mlir::Value CaptureVal = ProvidedVal ? ProvidedVal : createLiteral (P);
164+ mlir::Value SC;
165+ if (!isa<HeavySyntaxTy>(CaptureVal.getType ()))
166+ SC = OpGen.create <SyntaxClosureOp>(Loc, CaptureVal, RenameEnv);
165167
166- heavy::Context& Context = OpGen.getContext ();
167- EnvEntry Entry = Context.Lookup (P);
168- llvm::StringRef Id = P->getStringRef ();
168+ if (ProvidedVal) {
169+ mlir::Value R = OpGen.create <heavy::RenameOp>(Loc, Id, CaptureVal);
170+ RenameOps.insert ({UniqueStr, {R, SC}});
171+ return SC;
172+ }
169173
170174 // Insert RenameOps before the RenameEnv EnvFrameOp.
171175 mlir::OpBuilder::InsertionGuard IG (OpGen.Builder );
172176 OpGen.Builder .setInsertionPoint (RenameEnv);
173177
178+ heavy::Context& Context = OpGen.getContext ();
179+ EnvEntry Entry = Context.Lookup (P);
180+
174181 std::string MangledNameStr;
175182 llvm::StringRef MangledName;
176183 if (Entry && !Entry.MangledName ) {
0 commit comments